Review Board 1.7.22


HIVE-5552: Merging of QBJoinTrees doesn't handle filter pushdowns correctly

Review Request #14856 - Created Oct. 22, 2013 and submitted

Harish Butani
HIVE-5552
Reviewers
hive
ashutoshc
hive-git
Merging of QBJoinTrees doesn't handle filter pushdowns correctly
ran all join tests.
added join_merging.q test
ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java
Revision 12a0a69 New Change
[20] 125 lines
[+20] [+] public static VarcharTypeInfo getVarcharTypeInfo(String typeName, ASTNode node)
126
    }
126
    }
127

    
   
127

   
128
    String lengthStr = node.getChild(0).getText();
128
    String lengthStr = node.getChild(0).getText();
129
    return TypeInfoFactory.getVarcharTypeInfo(Integer.valueOf(lengthStr));
129
    return TypeInfoFactory.getVarcharTypeInfo(Integer.valueOf(lengthStr));
130
  }
130
  }

    
   
131

   

    
   
132
  static int getIndex(String[] list, String elem) {

    
   
133
    for(int i=0; i < list.length; i++) {

    
   
134
      if (list[i].toLowerCase().equals(elem)) {

    
   
135
        return i;

    
   
136
      }

    
   
137
    }

    
   
138
    return -1;

    
   
139
  }

    
   
140

   

    
   
141
  /*

    
   
142
   * if the given filterCondn refers to only 1 table alias in the QBJoinTree,

    
   
143
   * we return that alias's position. Otherwise we return -1

    
   
144
   */

    
   
145
  static int checkJoinFilterRefersOneAlias(String[] tabAliases, ASTNode filterCondn) {

    
   
146

   

    
   
147
    switch(filterCondn.getType()) {

    
   
148
    case HiveParser.TOK_TABLE_OR_COL:

    
   
149
      String tableOrCol = SemanticAnalyzer.unescapeIdentifier(filterCondn.getChild(0).getText()

    
   
150
          .toLowerCase());

    
   
151
      return getIndex(tabAliases, tableOrCol);

    
   
152
    case HiveParser.Identifier:

    
   
153
    case HiveParser.Number:

    
   
154
    case HiveParser.StringLiteral:

    
   
155
    case HiveParser.BigintLiteral:

    
   
156
    case HiveParser.SmallintLiteral:

    
   
157
    case HiveParser.TinyintLiteral:

    
   
158
    case HiveParser.DecimalLiteral:

    
   
159
    case HiveParser.TOK_STRINGLITERALSEQUENCE:

    
   
160
    case HiveParser.TOK_CHARSETLITERAL:

    
   
161
    case HiveParser.TOK_DATELITERAL:

    
   
162
    case HiveParser.KW_TRUE:

    
   
163
    case HiveParser.KW_FALSE:

    
   
164
    case HiveParser.TOK_NULL:

    
   
165
      return -1;

    
   
166
    default:

    
   
167
      int idx = -1;

    
   
168
      int i = filterCondn.getType() == HiveParser.TOK_FUNCTION ? 1 : 0;

    
   
169
      for (; i < filterCondn.getChildCount(); i++) {

    
   
170
        int cIdx = checkJoinFilterRefersOneAlias(tabAliases, (ASTNode) filterCondn.getChild(i));

    
   
171
        if ( cIdx != idx ) {

    
   
172
          if ( idx != -1 && cIdx != -1 ) {

    
   
173
            return -1;

    
   
174
          }

    
   
175
          idx = idx == -1 ? cIdx : idx;

    
   
176
        }

    
   
177
      }

    
   
178
      return idx;

    
   
179
    }

    
   
180
  }

    
   
181

   
131
}
182
}
ql/src/java/org/apache/hadoop/hive/ql/parse/QBJoinTree.java
Revision 9834e73 New Change
 
ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
Revision c886760 New Change
 
ql/src/test/queries/clientpositive/join_merging.q
New File
 
ql/src/test/results/clientpositive/join_merging.q.out
New File
 
  1. ql/src/java/org/apache/hadoop/hive/ql/parse/ParseUtils.java: Loading...
  2. ql/src/java/org/apache/hadoop/hive/ql/parse/QBJoinTree.java: Loading...
  3. ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java: Loading...
  4. ql/src/test/queries/clientpositive/join_merging.q: Loading...
  5. ql/src/test/results/clientpositive/join_merging.q.out: Loading...