Search in sources :

Example 6 with CalciteSubquerySemanticException

use of org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException in project hive by apache.

the class RexNodeExprFactory method createSubqueryExpr.

/**
 * {@inheritDoc}
 */
@Override
protected RexNode createSubqueryExpr(TypeCheckCtx ctx, ASTNode expr, SubqueryType subqueryType, Object[] inputs) throws SemanticException {
    // subqueryToRelNode might be null if subquery expression anywhere other than
    // as expected in filter (where/having). We should throw an appropriate error
    // message
    Map<ASTNode, QBSubQueryParseInfo> subqueryToRelNode = ctx.getSubqueryToRelNode();
    if (subqueryToRelNode == null) {
        throw new CalciteSubquerySemanticException(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION.getMsg(" Currently SubQuery expressions are only allowed as " + "Where and Having Clause predicates"));
    }
    ASTNode subqueryOp = (ASTNode) expr.getChild(0);
    RelNode subqueryRel = subqueryToRelNode.get(expr).getSubQueryRelNode();
    // we will create subquery expression of boolean type
    switch(subqueryType) {
        case EXISTS:
            {
                if (subqueryToRelNode.get(expr).hasFullAggregate()) {
                    return createConstantExpr(TypeInfoFactory.booleanTypeInfo, true);
                }
                return RexSubQuery.exists(subqueryRel);
            }
        case IN:
            {
                assert (inputs[2] != null);
                /*
         * Check.5.h :: For In and Not In the SubQuery must implicitly or
         * explicitly only contain one select item.
         */
                if (subqueryRel.getRowType().getFieldCount() > 1) {
                    throw new CalciteSubquerySemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg("SubQuery can contain only 1 item in Select List."));
                }
                // create RexNode for LHS
                RexNode lhs = (RexNode) inputs[2];
                // create RexSubQuery node
                return RexSubQuery.in(subqueryRel, ImmutableList.<RexNode>of(lhs));
            }
        case SCALAR:
            {
                // only single subquery expr is supported
                if (subqueryRel.getRowType().getFieldCount() != 1) {
                    throw new CalciteSubquerySemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg("More than one column expression in subquery"));
                }
                if (subqueryRel.getRowType().getFieldCount() > 1) {
                    throw new CalciteSubquerySemanticException(ErrorMsg.INVALID_SUBQUERY_EXPRESSION.getMsg("SubQuery can contain only 1 item in Select List."));
                }
                // create RexSubQuery node
                return RexSubQuery.scalar(subqueryRel);
            }
        case SOME:
        case ALL:
            {
                assert (inputs[2] != null);
                // create RexNode for LHS
                RexNode lhs = (RexNode) inputs[2];
                return convertSubquerySomeAll(subqueryRel.getCluster(), (ASTNode) subqueryOp.getChild(1), subqueryType, subqueryRel, lhs);
            }
        default:
            return null;
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) QBSubQueryParseInfo(org.apache.hadoop.hive.ql.parse.QBSubQueryParseInfo) ASTNode(org.apache.hadoop.hive.ql.parse.ASTNode) CalciteSubquerySemanticException(org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

CalciteSubquerySemanticException (org.apache.hadoop.hive.ql.optimizer.calcite.CalciteSubquerySemanticException)6 RexNode (org.apache.calcite.rex.RexNode)3 RelNode (org.apache.calcite.rel.RelNode)2 ASTNode (org.apache.hadoop.hive.ql.parse.ASTNode)2 QBSubQueryParseInfo (org.apache.hadoop.hive.ql.parse.QBSubQueryParseInfo)2 ArrayList (java.util.ArrayList)1 SqlQuantifyOperator (org.apache.calcite.sql.fun.SqlQuantifyOperator)1 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)1 ExprNodeSubQueryDesc (org.apache.hadoop.hive.ql.plan.ExprNodeSubQueryDesc)1 GenericUDAFResolver (org.apache.hadoop.hive.ql.udf.generic.GenericUDAFResolver)1 CharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.CharTypeInfo)1 DecimalTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo)1 PrimitiveTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo)1 StructTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.StructTypeInfo)1 TypeInfo (org.apache.hadoop.hive.serde2.typeinfo.TypeInfo)1 VarcharTypeInfo (org.apache.hadoop.hive.serde2.typeinfo.VarcharTypeInfo)1