Search in sources :

Example 1 with HiveRexExprList

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);
}
Also used : HiveRexExprList(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRexExprList)

Example 2 with HiveRexExprList

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;
}
Also used : ArrayList(java.util.ArrayList) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) NotNullConstraint(org.apache.hadoop.hive.ql.metadata.NotNullConstraint) HiveRexExprList(org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRexExprList) RexInputRef(org.apache.calcite.rex.RexInputRef) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) RexFieldAccess(org.apache.calcite.rex.RexFieldAccess) RexNode(org.apache.calcite.rex.RexNode) CalciteSubquerySemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException) CalciteSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException) CalciteViewSemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException)

Aggregations

HiveRexExprList (org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveRexExprList)2 ImmutableBiMap (com.google.common.collect.ImmutableBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RexFieldAccess (org.apache.calcite.rex.RexFieldAccess)1 RexInputRef (org.apache.calcite.rex.RexInputRef)1 RexNode (org.apache.calcite.rex.RexNode)1 ColumnInfo (org.apache.hadoop.hive.ql.exec.ColumnInfo)1 NotNullConstraint (org.apache.hadoop.hive.ql.metadata.NotNullConstraint)1 CalciteSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSemanticException)1 CalciteSubquerySemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException)1 CalciteViewSemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteViewSemanticException)1