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;
}
}
Aggregations