private QBParseInfo getQBParseInfo(QB qb) throws CalciteSemanticException { return qb.getParseInfo(); }
private QBParseInfo getQBParseInfo(QB qb) throws CalciteSemanticException { return qb.getParseInfo(); }
private boolean optimizeMapAggrGroupBy(String dest, QB qb) throws SemanticException { List<ASTNode> grpByExprs = getGroupByForClause(qb.getParseInfo(), dest); if ((grpByExprs != null) && !grpByExprs.isEmpty()) { return false; } if (!qb.getParseInfo().getDistinctFuncExprsForClause(dest).isEmpty()) { return false; } return true; }
private boolean optimizeMapAggrGroupBy(String dest, QB qb) throws SemanticException { List<ASTNode> grpByExprs = getGroupByForClause(qb.getParseInfo(), dest); if ((grpByExprs != null) && !grpByExprs.isEmpty()) { return false; } if (!qb.getParseInfo().getDistinctFuncExprsForClause(dest).isEmpty()) { return false; } return true; }
private Operator<?> genSelectPlan(String dest, QB qb, Operator<?> input, Operator<?> inputForSelectStar) throws SemanticException { ASTNode selExprList = qb.getParseInfo().getSelForClause(dest); Operator<?> op = genSelectPlan(dest, selExprList, qb, input, inputForSelectStar, false); if (LOG.isDebugEnabled()) { LOG.debug("Created Select Plan for clause: " + dest); } return op; }
private Operator genLateralViewPlanForDest(String dest, QB qb, Operator op) throws SemanticException { ASTNode lateralViewTree = qb.getParseInfo().getDestToLateralView().get(dest); if (lateralViewTree != null) { return genLateralViewPlan(qb, op, lateralViewTree); } return op; }
private Operator<?> genSelectPlan(String dest, QB qb, Operator<?> input, Operator<?> inputForSelectStar) throws SemanticException { ASTNode selExprList = qb.getParseInfo().getSelForClause(dest); Operator<?> op = genSelectPlan(dest, selExprList, qb, input, inputForSelectStar, false); if (LOG.isDebugEnabled()) { LOG.debug("Created Select Plan for clause: " + dest); } return op; }
private Operator genLateralViewPlanForDest(String dest, QB qb, Operator op) throws SemanticException { ASTNode lateralViewTree = qb.getParseInfo().getDestToLateralView().get(dest); if (lateralViewTree != null) { return genLateralViewPlan(qb, op, lateralViewTree); } return op; }
public void getHintsFromQB(QB qb, List<ASTNode> hints) { if (qb.getParseInfo().getHints() != null) { hints.add(qb.getParseInfo().getHints()); } Set<String> aliases = qb.getSubqAliases(); for (String alias : aliases) { getHintsFromQB(qb.getSubqForAlias(alias), hints); } }
Operator genOPTree(ASTNode ast, PlannerContext plannerCtx) throws SemanticException { // fetch all the hints in qb List<ASTNode> hintsList = new ArrayList<>(); getHintsFromQB(qb, hintsList); getQB().getParseInfo().setHintList(hintsList); return genPlan(qb); }
/** * Some initial checks for a query to see if we can look this query up in the results cache. */ private boolean queryTypeCanUseCache() { if (this instanceof ColumnStatsSemanticAnalyzer) { // Column stats generates "select compute_stats() .." queries. // Disable caching for these. return false; } if (queryState.getHiveOperation() != HiveOperation.QUERY) { return false; } if (qb.getParseInfo().isAnalyzeCommand()) { return false; } if (qb.getParseInfo().hasInsertTables()) { return false; } // HIVE-19096 - disable for explain analyze if (ctx.getExplainAnalyze() != null) { return false; } return true; }
private void copyInfoToQueryProperties(QueryProperties queryProperties) { if (qb != null) { queryProperties.setQuery(qb.getIsQuery()); queryProperties.setAnalyzeCommand(qb.getParseInfo().isAnalyzeCommand()); queryProperties.setNoScanAnalyzeCommand(qb.getParseInfo().isNoScanAnalyzeCommand()); queryProperties.setAnalyzeRewrite(qb.isAnalyzeRewrite()); queryProperties.setCTAS(qb.getTableDesc() != null); queryProperties.setHasOuterOrderBy(!qb.getParseInfo().getIsSubQ() && !qb.getParseInfo().getDestToOrderBy().isEmpty()); queryProperties.setOuterQueryLimit(qb.getParseInfo().getOuterQueryLimit()); queryProperties.setMaterializedView(qb.getViewDesc() != null); } } private void warn(String msg) {
Operator<?> handleInsertStatement(String dest, Operator<?> input, RowResolver inputRR, QB qb) throws SemanticException { ArrayList<ExprNodeDesc> colList = new ArrayList<ExprNodeDesc>(); ArrayList<ColumnInfo> columns = inputRR.getColumnInfos(); for (int i = 0; i < columns.size(); i++) { ColumnInfo col = columns.get(i); colList.add(new ExprNodeColumnDesc(col)); } ASTNode selExprList = qb.getParseInfo().getSelForClause(dest); RowResolver out_rwsch = handleInsertStatementSpec(colList, dest, inputRR, qb, selExprList); ArrayList<String> columnNames = new ArrayList<String>(); Map<String, ExprNodeDesc> colExprMap = new HashMap<String, ExprNodeDesc>(); for (int i = 0; i < colList.size(); i++) { String outputCol = getColumnInternalName(i); colExprMap.put(outputCol, colList.get(i)); columnNames.add(outputCol); } Operator<?> output = putOpInsertMap(OperatorFactory.getAndMakeChild(new SelectDesc(colList, columnNames), new RowSchema(out_rwsch.getColumnInfos()), input), out_rwsch); output.setColumnExprMap(colExprMap); return output; }
private void copyInfoToQueryProperties(QueryProperties queryProperties) { if (qb != null) { queryProperties.setQuery(qb.getIsQuery()); queryProperties.setAnalyzeCommand(qb.getParseInfo().isAnalyzeCommand()); queryProperties.setPartialScanAnalyzeCommand(qb.getParseInfo().isPartialScanAnalyzeCommand()); queryProperties.setNoScanAnalyzeCommand(qb.getParseInfo().isNoScanAnalyzeCommand()); queryProperties.setAnalyzeRewrite(qb.isAnalyzeRewrite()); queryProperties.setCTAS(qb.getTableDesc() != null); queryProperties.setHasOuterOrderBy(!qb.getParseInfo().getIsSubQ() && !qb.getParseInfo().getDestToOrderBy().isEmpty()); queryProperties.setOuterQueryLimit(qb.getParseInfo().getOuterQueryLimit()); queryProperties.setMaterializedView(qb.getViewDesc() != null); } } private void warn(String msg) {
private void handleTopLimit(Operator<?> rootOp) { if (rootOp instanceof LimitOperator) { // this can happen only on top most limit, not while visiting Limit Operator // since that can be within subquery. this.semanticAnalyzer.getQB().getParseInfo().setOuterQueryLimit(((LimitOperator) rootOp).getConf().getLimit()); } }
private void handleTopLimit(Operator<?> rootOp) { if (rootOp instanceof LimitOperator) { // this can happen only on top most limit, not while visiting Limit Operator // since that can be within subquery. this.semanticAnalyzer.getQB().getParseInfo().setOuterQueryLimit(((LimitOperator) rootOp).getConf().getLimit()); } }
private List<String> getMapSideJoinTables(QB qb) { List<String> cols = new ArrayList<String>(); ASTNode hints = qb.getParseInfo().getHints(); for (int pos = 0; pos < hints.getChildCount(); pos++) { ASTNode hint = (ASTNode) hints.getChild(pos); if (((ASTNode) hint.getChild(0)).getToken().getType() == HintParser.TOK_MAPJOIN) { // the user has specified to ignore mapjoin hint if (!conf.getBoolVar(HiveConf.ConfVars.HIVEIGNOREMAPJOINHINT) && !conf.getVar(HiveConf.ConfVars.HIVE_EXECUTION_ENGINE).equals("tez")) { ASTNode hintTblNames = (ASTNode) hint.getChild(1); int numCh = hintTblNames.getChildCount(); for (int tblPos = 0; tblPos < numCh; tblPos++) { String tblName = ((ASTNode) hintTblNames.getChild(tblPos)).getText() .toLowerCase(); if (!cols.contains(tblName)) { cols.add(tblName); } } } else { queryProperties.setMapJoinRemoved(true); } } } return cols; }
private void checkImmutableTable(QB qb, Table dest_tab, Path dest_path, boolean isPart) throws SemanticException { // If the query here is an INSERT_INTO and the target is an immutable table, // verify that our destination is empty before proceeding if (!dest_tab.isImmutable() || !qb.getParseInfo().isInsertIntoTable( dest_tab.getDbName(), dest_tab.getTableName())) { return; } try { FileSystem fs = dest_path.getFileSystem(conf); if (! org.apache.hadoop.hive.metastore.utils.FileUtils.isDirEmpty(fs,dest_path)){ LOG.warn("Attempted write into an immutable table : " + dest_tab.getTableName() + " : " + dest_path); throw new SemanticException( ErrorMsg.INSERT_INTO_IMMUTABLE_TABLE.getMsg(dest_tab.getTableName())); } } catch (IOException ioe) { LOG.warn("Error while trying to determine if immutable table " + (isPart ? "partition " : "") + "has any data : " + dest_tab.getTableName() + " : " + dest_path); throw new SemanticException(ErrorMsg.INSERT_INTO_IMMUTABLE_TABLE.getMsg(ioe.getMessage())); } }
private void parseStreamTables(QBJoinTree joinTree, QB qb) { List<String> streamAliases = joinTree.getStreamAliases(); for (Node hintNode : qb.getParseInfo().getHints().getChildren()) { ASTNode hint = (ASTNode) hintNode; if (hint.getChild(0).getType() == HintParser.TOK_STREAMTABLE) { for (int i = 0; i < hint.getChild(1).getChildCount(); i++) { if (streamAliases == null) { streamAliases = new ArrayList<String>(); } streamAliases.add(hint.getChild(1).getChild(i).getText()); } } } joinTree.setStreamAliases(streamAliases); }
private void parseStreamTables(QBJoinTree joinTree, QB qb) { List<String> streamAliases = joinTree.getStreamAliases(); for (Node hintNode : qb.getParseInfo().getHints().getChildren()) { ASTNode hint = (ASTNode) hintNode; if (hint.getChild(0).getType() == HintParser.TOK_STREAMTABLE) { for (int i = 0; i < hint.getChild(1).getChildCount(); i++) { if (streamAliases == null) { streamAliases = new ArrayList<String>(); } streamAliases.add(hint.getChild(1).getChild(i).getText()); } } } joinTree.setStreamAliases(streamAliases); }