use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRexExprList in project hive by apache.
the class RexNodeExprFactory method addExprToExprsList.
/**
* {@inheritDoc}
*/
@Override
protected void addExprToExprsList(RexNode columnList, RexNode expr) {
HiveRexExprList l = (HiveRexExprList) columnList;
l.addExpression(expr);
}
use of org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRexExprList in project hive by apache.
the class CalcitePlanner method genAllRexNode.
/**
* Generates all of the Calcite {@link RexNode}s for the expression and children of it
* passed in the arguments. This function uses the row resolver and the metadata information
* that are passed as arguments to resolve the column names to internal names.
*
* @param expr
* The expression
* @param input
* The row resolver
* @param tcCtx
* Customized type-checking context
* @return expression to exprNodeDesc mapping
* @throws SemanticException Failed to evaluate expression
*/
Map<ASTNode, RexNode> genAllRexNode(ASTNode expr, RowResolver input, TypeCheckCtx tcCtx) throws SemanticException {
// Create the walker and the rules dispatcher.
tcCtx.setUnparseTranslator(unparseTranslator);
Map<ASTNode, RexNode> nodeOutputs = RexNodeTypeCheck.genExprNode(expr, tcCtx);
RexNode desc = nodeOutputs.get(expr);
if (desc == null) {
String tableOrCol = BaseSemanticAnalyzer.unescapeIdentifier(expr.getChild(0).getText());
ColumnInfo colInfo = input.get(null, tableOrCol);
String errMsg;
if (colInfo == null && input.getIsExprResolver()) {
errMsg = ASTErrorUtils.getMsg(ErrorMsg.NON_KEY_EXPR_IN_GROUPBY.getMsg(), expr);
} else {
errMsg = tcCtx.getError();
}
throw new SemanticException(Optional.ofNullable(errMsg).orElse("Error in parsing "));
}
if (desc instanceof HiveRexExprList) {
throw new SemanticException("TOK_ALLCOLREF is not supported in current context");
}
if (!unparseTranslator.isEnabled()) {
// Not creating a view, so no need to track view expansions.
return nodeOutputs;
}
List<ASTNode> fieldDescList = new ArrayList<>();
for (Map.Entry<ASTNode, RexNode> entry : nodeOutputs.entrySet()) {
if (!(entry.getValue() instanceof RexInputRef)) {
// struct<>.
if (entry.getValue() instanceof RexFieldAccess) {
fieldDescList.add(entry.getKey());
}
continue;
}
ASTNode node = entry.getKey();
RexInputRef columnDesc = (RexInputRef) entry.getValue();
int index = columnDesc.getIndex();
String[] tmp;
if (index < input.getColumnInfos().size()) {
ColumnInfo columnInfo = input.getColumnInfos().get(index);
if (columnInfo.getTabAlias() == null || columnInfo.getTabAlias().length() == 0) {
// internal expressions used in the representation of aggregation.
continue;
}
tmp = input.reverseLookup(columnInfo.getInternalName());
} else {
// in subquery case, tmp may be from outside.
ColumnInfo columnInfo = tcCtx.getOuterRR().getColumnInfos().get(index - input.getColumnInfos().size());
if (columnInfo.getTabAlias() == null || columnInfo.getTabAlias().length() == 0) {
continue;
}
tmp = tcCtx.getOuterRR().reverseLookup(columnInfo.getInternalName());
}
StringBuilder replacementText = new StringBuilder();
replacementText.append(HiveUtils.unparseIdentifier(tmp[0], conf));
replacementText.append(".");
replacementText.append(HiveUtils.unparseIdentifier(tmp[1], conf));
unparseTranslator.addTranslation(node, replacementText.toString());
}
for (ASTNode node : fieldDescList) {
Map<ASTNode, String> map = translateFieldDesc(node);
for (Entry<ASTNode, String> entry : map.entrySet()) {
unparseTranslator.addTranslation(entry.getKey(), entry.getValue().toLowerCase());
}
}
return nodeOutputs;
}
Aggregations