public void doPhase1QBExpr(ASTNode ast, QBExpr qbexpr, String id, String alias) throws SemanticException { doPhase1QBExpr(ast, qbexpr, id, alias, false); }
public void doPhase1QBExpr(ASTNode ast, QBExpr qbexpr, String id, String alias) throws SemanticException { doPhase1QBExpr(ast, qbexpr, id, alias, false); } @SuppressWarnings("nls")
private void addCTEAsSubQuery(QB qb, String cteName, String cteAlias) throws SemanticException { cteAlias = cteAlias == null ? cteName : cteAlias; CTEClause cte = findCTEFromName(qb, cteName); ASTNode cteQryNode = cte.cteNode; QBExpr cteQBExpr = new QBExpr(cteAlias); doPhase1QBExpr(cteQryNode, cteQBExpr, qb.getId(), cteAlias); qb.rewriteCTEToSubq(cteAlias, cteName, cteQBExpr); }
private void gatherCTEReferences(QB qb, CTEClause current) throws HiveException { for (String alias : qb.getTabAliases()) { String tabName = qb.getTabNameForAlias(alias); String cteName = tabName.toLowerCase(); CTEClause cte = findCTEFromName(qb, cteName); if (cte != null) { if (ctesExpanded.contains(cteName)) { throw new SemanticException("Recursive cte " + cteName + " detected (cycle: " + StringUtils.join(ctesExpanded, " -> ") + " -> " + cteName + ")."); } cte.reference++; current.parents.add(cte); if (cte.qbExpr != null) { continue; } cte.qbExpr = new QBExpr(cteName); doPhase1QBExpr(cte.cteNode, cte.qbExpr, qb.getId(), cteName); ctesExpanded.add(cteName); gatherCTEReferences(cte.qbExpr, cte); ctesExpanded.remove(ctesExpanded.size() - 1); } } for (String alias : qb.getSubqAliases()) { gatherCTEReferences(qb.getSubqForAlias(alias), current); } }
private void addCTEAsSubQuery(QB qb, String cteName, String cteAlias) throws SemanticException { cteAlias = cteAlias == null ? cteName : cteAlias; CTEClause cte = findCTEFromName(qb, cteName); ASTNode cteQryNode = cte.cteNode; QBExpr cteQBExpr = new QBExpr(cteAlias); doPhase1QBExpr(cteQryNode, cteQBExpr, qb.getId(), cteAlias); qb.rewriteCTEToSubq(cteAlias, cteName, cteQBExpr); }
private void gatherCTEReferences(QB qb, CTEClause current) throws HiveException { for (String alias : qb.getTabAliases()) { String tabName = qb.getTabNameForAlias(alias); String cteName = tabName.toLowerCase(); CTEClause cte = findCTEFromName(qb, cteName); if (cte != null) { if (ctesExpanded.contains(cteName)) { throw new SemanticException("Recursive cte " + cteName + " detected (cycle: " + StringUtils.join(ctesExpanded, " -> ") + " -> " + cteName + ")."); } cte.reference++; current.parents.add(cte); if (cte.qbExpr != null) { continue; } cte.qbExpr = new QBExpr(cteName); doPhase1QBExpr(cte.cteNode, cte.qbExpr, qb.getId(), cteName); ctesExpanded.add(cteName); gatherCTEReferences(cte.qbExpr, cte); ctesExpanded.remove(ctesExpanded.size() - 1); } } for (String alias : qb.getSubqAliases()) { gatherCTEReferences(qb.getSubqForAlias(alias), current); } }
doPhase1QBExpr(viewTree, qbexpr, qb.getId(), alias, true);
doPhase1QBExpr(viewTree, qbexpr, qb.getId(), alias, true);
private String processSubQuery(QB qb, ASTNode subq) throws SemanticException { // This is a subquery and must have an alias if (subq.getChildCount() != 2) { throw new SemanticException(ErrorMsg.NO_SUBQUERY_ALIAS.getMsg(subq)); } ASTNode subqref = (ASTNode) subq.getChild(0); String alias = unescapeIdentifier(subq.getChild(1).getText()); // Recursively do the first phase of semantic analysis for the subquery QBExpr qbexpr = new QBExpr(alias); doPhase1QBExpr(subqref, qbexpr, qb.getId(), alias, qb.isInsideView()); // If the alias is already there then we have a conflict if (qb.exists(alias)) { throw new SemanticException(ErrorMsg.AMBIGUOUS_TABLE_ALIAS.getMsg(subq .getChild(1))); } // Insert this map into the stats qb.setSubqAlias(alias, qbexpr); qb.addAlias(alias); unparseTranslator.addIdentifierTranslation((ASTNode) subq.getChild(1)); return alias; }
doPhase1QBExpr((ASTNode) ast.getChild(0), qbexpr1, id, alias + SUBQUERY_TAG_1, insideView); qbexpr.setQBExpr1(qbexpr1); doPhase1QBExpr((ASTNode) ast.getChild(1), qbexpr2, id, alias + SUBQUERY_TAG_2, insideView); qbexpr.setQBExpr2(qbexpr2);
doPhase1QBExpr((ASTNode) ast.getChild(0), qbexpr1, id + SUBQUERY_TAG_1, alias + SUBQUERY_TAG_1, insideView); qbexpr.setQBExpr1(qbexpr1); doPhase1QBExpr((ASTNode) ast.getChild(1), qbexpr2, id + SUBQUERY_TAG_2, alias + SUBQUERY_TAG_2, insideView); qbexpr.setQBExpr2(qbexpr2);
private String processSubQuery(QB qb, ASTNode subq) throws SemanticException { // This is a subquery and must have an alias if (subq.getChildCount() != 2) { throw new SemanticException(ErrorMsg.NO_SUBQUERY_ALIAS.getMsg(subq)); } ASTNode subqref = (ASTNode) subq.getChild(0); String alias = unescapeIdentifier(subq.getChild(1).getText()); // Recursively do the first phase of semantic analysis for the subquery QBExpr qbexpr = new QBExpr(alias); doPhase1QBExpr(subqref, qbexpr, qb.getId(), alias, qb.isInsideView()); // If the alias is already there then we have a conflict if (qb.exists(alias)) { throw new SemanticException(ErrorMsg.AMBIGUOUS_TABLE_ALIAS.getMsg(subq .getChild(1))); } // Insert this map into the stats qb.setSubqAlias(alias, qbexpr); qb.addAlias(alias); unparseTranslator.addIdentifierTranslation((ASTNode) subq.getChild(1)); return alias; }
doPhase1QBExpr(viewTree, qbexpr, qb.getId(), alias); qb.rewriteViewToSubq(alias, tab_name, qbexpr);
private void addCTEAsSubQuery(QB qb, String cteName, String cteAlias) throws SemanticException { cteAlias = cteAlias == null ? cteName : cteAlias; ASTNode cteQryNode = findCTEFromName(qb, cteName); QBExpr cteQBExpr = new QBExpr(cteAlias); String cteText = ctx.getTokenRewriteStream().toString( cteQryNode.getTokenStartIndex(), cteQryNode.getTokenStopIndex()); final ASTNodeOrigin cteOrigin = new ASTNodeOrigin("CTE", cteName, cteText, cteAlias, cteQryNode); cteQryNode = (ASTNode) ParseDriver.adaptor.dupTree(cteQryNode); SubQueryUtils.setOriginDeep(cteQryNode, cteOrigin); doPhase1QBExpr(cteQryNode, cteQBExpr, qb.getId(), cteAlias); qb.rewriteCTEToSubq(cteAlias, cteName, cteQBExpr); }
doPhase1QBExpr(viewTree, qbexpr, qb.getId(), alias); qb.rewriteViewToSubq(alias, tab_name, qbexpr);
@SuppressWarnings("nls") public void doPhase1QBExpr(ASTNode ast, QBExpr qbexpr, String id, String alias) throws SemanticException { assert (ast.getToken() != null); switch (ast.getToken().getType()) { case HiveParser.TOK_QUERY: { QB qb = new QB(id, alias, true); doPhase1(ast, qb, initPhase1Ctx()); qbexpr.setOpcode(QBExpr.Opcode.NULLOP); qbexpr.setQB(qb); } break; case HiveParser.TOK_UNION: { qbexpr.setOpcode(QBExpr.Opcode.UNION); // query 1 assert (ast.getChild(0) != null); QBExpr qbexpr1 = new QBExpr(alias + "-subquery1"); doPhase1QBExpr((ASTNode) ast.getChild(0), qbexpr1, id + "-subquery1", alias + "-subquery1"); qbexpr.setQBExpr1(qbexpr1); // query 2 assert (ast.getChild(0) != null); QBExpr qbexpr2 = new QBExpr(alias + "-subquery2"); doPhase1QBExpr((ASTNode) ast.getChild(1), qbexpr2, id + "-subquery2", alias + "-subquery2"); qbexpr.setQBExpr2(qbexpr2); } break; } }
doPhase1QBExpr((ASTNode) ast.getChild(0), qbexpr1, id + SUBQUERY_TAG_1, alias + SUBQUERY_TAG_1); qbexpr.setQBExpr1(qbexpr1); doPhase1QBExpr((ASTNode) ast.getChild(1), qbexpr2, id + SUBQUERY_TAG_2, alias + SUBQUERY_TAG_2); qbexpr.setQBExpr2(qbexpr2);
private String processSubQuery(QB qb, ASTNode subq) throws SemanticException { // This is a subquery and must have an alias if (subq.getChildCount() != 2) { throw new SemanticException(ErrorMsg.NO_SUBQUERY_ALIAS.getMsg(subq)); } ASTNode subqref = (ASTNode) subq.getChild(0); String alias = unescapeIdentifier(subq.getChild(1).getText()); // Recursively do the first phase of semantic analysis for the subquery QBExpr qbexpr = new QBExpr(alias); doPhase1QBExpr(subqref, qbexpr, qb.getId(), alias); // If the alias is already there then we have a conflict if (qb.exists(alias)) { throw new SemanticException(ErrorMsg.AMBIGUOUS_TABLE_ALIAS.getMsg(subq .getChild(1))); } // Insert this map into the stats qb.setSubqAlias(alias, qbexpr); qb.addAlias(alias); unparseTranslator.addIdentifierTranslation((ASTNode) subq.getChild(1)); return alias; }
private String processSubQuery(QB qb, ASTNode subq) throws SemanticException { // This is a subquery and must have an alias if (subq.getChildCount() != 2) { throw new SemanticException(ErrorMsg.NO_SUBQUERY_ALIAS.getMsg(subq)); } ASTNode subqref = (ASTNode) subq.getChild(0); String alias = unescapeIdentifier(subq.getChild(1).getText()); // Recursively do the first phase of semantic analysis for the subquery QBExpr qbexpr = new QBExpr(alias); doPhase1QBExpr(subqref, qbexpr, qb.getId(), alias); // If the alias is already there then we have a conflict if (qb.exists(alias)) { throw new SemanticException(ErrorMsg.AMBIGUOUS_TABLE_ALIAS.getMsg(subq .getChild(1))); } // Insert this map into the stats qb.setSubqAlias(alias, qbexpr); qb.addAlias(alias); unparseTranslator.addIdentifierTranslation((ASTNode) subq.getChild(1)); return alias; }