// We recursively create the exprNodeDesc. Base cases: when we encounter
// a column ref, we convert that into an exprNodeColumnDesc; when we encounter
// a constant, we convert that into an exprNodeConstantDesc. For others we just
// build the exprNodeFuncDesc with recursively built children.
exprNodeDesc desc = null;
// Is this a simple expr node (not a TOK_COLREF or a TOK_FUNCTION or an operator)?
desc = SemanticAnalyzer.genSimpleExprNodeDesc(expr);
if (desc != null) {
return desc;
}
int tokType = expr.getType();
switch (tokType) {
case HiveParser.TOK_COLREF: {
String tabAlias = null;
String colName = null;
if (expr.getChildCount() != 1) {
assert(expr.getChildCount() == 2);
tabAlias = BaseSemanticAnalyzer.unescapeIdentifier(expr.getChild(0).getText());
colName = BaseSemanticAnalyzer.unescapeIdentifier(expr.getChild(1).getText());
}
else {
colName = BaseSemanticAnalyzer.unescapeIdentifier(expr.getChild(0).getText());
tabAlias = SemanticAnalyzer.getTabAliasForCol(this.metaData, colName, (ASTNode)expr.getChild(0));
}
// Set value to null if it's not partition column
if (tabAlias.equalsIgnoreCase(tableAlias) && tab.isPartitionKey(colName)) {
desc = new exprNodeColumnDesc(String.class, colName);
} else {
try {
// might be a column from another table
Table t = this.metaData.getTableForAlias(tabAlias);
if (t.isPartitionKey(colName)) {
desc = new exprNodeConstantDesc(String.class, null);
}
else {
TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(
this.metaData.getTableForAlias(tabAlias).getDeserializer().getObjectInspector());
desc = new exprNodeConstantDesc(typeInfo.getStructFieldTypeInfo(colName), null);
containsPartCols = false;
}
} catch (SerDeException e){
throw new RuntimeException(e);
}
}
break;
}
default: {
boolean isFunction = (expr.getType() == HiveParser.TOK_FUNCTION);
// Create all children
int childrenBegin = (isFunction ? 1 : 0);
ArrayList<exprNodeDesc> children = new ArrayList<exprNodeDesc>(expr.getChildCount() - childrenBegin);
for (int ci=childrenBegin; ci<expr.getChildCount(); ci++) {
exprNodeDesc child = genExprNodeDesc((ASTNode)expr.getChild(ci));
assert(child.getTypeInfo() != null);
children.add(child);
}
// Create function desc
desc = TypeCheckProcFactory.DefaultExprProcessor.getXpathOrFuncExprNodeDesc(expr, isFunction, children);