Review Board 1.7.22


HIVE-3179: HBase Handler doesn't handle NULLs properly

Review Request #5542 - Created June 25, 2012 and updated

Lars Francke
HIVE-3179
Reviewers
hive
hive-git
This patch moves the initialization of the fieldsInited variable to the end of the loop because otherwise NULL values will return stale data on the second iteration. All other cases should be unaffected by this change. 
Debugged problem, added code to existing test to force wrong behavior which is fixed by this patch, ran the hbase-handler unit tests
hbase-handler/src/java/org/apache/hadoop/hive/hbase/LazyHBaseRow.java
Revision d35bb52 New Change
[20] 130 lines
[+20] [+] public Object getField(int fieldID) {
131

    
   
131

   
132
    LazyObject<?> [] fields = getFields();
132
    LazyObject<?> [] fields = getFields();
133
    boolean [] fieldsInited = getFieldInited();
133
    boolean [] fieldsInited = getFieldInited();
134

    
   
134

   
135
    if (!fieldsInited[fieldID]) {
135
    if (!fieldsInited[fieldID]) {
136
      fieldsInited[fieldID] = true;

   
137
      ByteArrayRef ref = null;
136
      ByteArrayRef ref = null;
138
      ColumnMapping colMap = columnsMapping.get(fieldID);
137
      ColumnMapping colMap = columnsMapping.get(fieldID);
139

    
   
138

   
140
      if (colMap.hbaseRowKey) {
139
      if (colMap.hbaseRowKey) {
141
        ref = new ByteArrayRef();
140
        ref = new ByteArrayRef();
[+20] [20] 20 lines
[+20] public Object getField(int fieldID) {
162
      if (ref != null) {
161
      if (ref != null) {
163
        fields[fieldID].init(ref, 0, ref.getData().length);
162
        fields[fieldID].init(ref, 0, ref.getData().length);
164
      }
163
      }
165
    }
164
    }
166

    
   
165

   

    
   
166
    // Has to be set last because of HIVE-3179: NULL fields would not work otherwise

    
   
167
    fieldsInited[fieldID] = true;

    
   
168

   
167
    return fields[fieldID].getObject();
169
    return fields[fieldID].getObject();
168
  }
170
  }
169

    
   
171

   
170
  /**
172
  /**
171
   * Get the values of the fields as an ArrayList.
173
   * Get the values of the fields as an ArrayList.
[+20] [20] 23 lines
hbase-handler/src/test/org/apache/hadoop/hive/hbase/TestLazyHBaseObject.java
Revision f91be4c New Change
 
  1. hbase-handler/src/java/org/apache/hadoop/hive/hbase/LazyHBaseRow.java: Loading...
  2. hbase-handler/src/test/org/apache/hadoop/hive/hbase/TestLazyHBaseObject.java: Loading...