use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserQBSubQuery in project flink by apache.
the class HiveParserCalcitePlanner method subqueryRestrictionCheck.
private void subqueryRestrictionCheck(HiveParserQB qb, HiveParserASTNode searchCond, RelNode srcRel, boolean forHavingClause, Set<HiveParserASTNode> corrScalarQueries) throws SemanticException {
List<HiveParserASTNode> subQueriesInOriginalTree = HiveParserSubQueryUtils.findSubQueries(searchCond);
HiveParserASTNode clonedSearchCond = (HiveParserASTNode) HiveParserSubQueryUtils.ADAPTOR.dupTree(searchCond);
List<HiveParserASTNode> subQueries = HiveParserSubQueryUtils.findSubQueries(clonedSearchCond);
for (int i = 0; i < subQueriesInOriginalTree.size(); i++) {
int sqIdx = qb.incrNumSubQueryPredicates();
HiveParserASTNode originalSubQueryAST = subQueriesInOriginalTree.get(i);
HiveParserASTNode subQueryAST = subQueries.get(i);
// HiveParserSubQueryUtils.rewriteParentQueryWhere(clonedSearchCond, subQueryAST);
ObjectPair<Boolean, Integer> subqInfo = new ObjectPair<>(false, 0);
if (!topLevelConjunctCheck(clonedSearchCond, subqInfo)) {
// Restriction.7.h :: SubQuery predicates can appear only as top level conjuncts.
throw new SemanticException(HiveParserErrorMsg.getMsg(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION, subQueryAST, "Only SubQuery expressions that are top level conjuncts are allowed"));
}
HiveParserASTNode outerQueryExpr = (HiveParserASTNode) subQueryAST.getChild(2);
if (outerQueryExpr != null && outerQueryExpr.getType() == HiveASTParser.TOK_SUBQUERY_EXPR) {
throw new SemanticException(HiveParserErrorMsg.getMsg(ErrorMsg.UNSUPPORTED_SUBQUERY_EXPRESSION, outerQueryExpr, "IN/NOT IN subqueries are not allowed in LHS"));
}
HiveParserQBSubQuery subQuery = HiveParserSubQueryUtils.buildSubQuery(sqIdx, subQueryAST, originalSubQueryAST, semanticAnalyzer.ctx, frameworkConfig, cluster);
HiveParserRowResolver inputRR = relToRowResolver.get(srcRel);
String havingInputAlias = null;
boolean isCorrScalarWithAgg = subQuery.subqueryRestrictionsCheck(inputRR, forHavingClause, havingInputAlias);
if (isCorrScalarWithAgg) {
corrScalarQueries.add(originalSubQueryAST);
}
}
}
Aggregations