Search in sources :

Example 41 with Dispatcher

use of org.apache.hadoop.hive.ql.lib.Dispatcher in project hive by apache.

the class SyntheticJoinPredicate method transform.

@Override
public ParseContext transform(ParseContext pctx) throws SemanticException {
    boolean enabled = false;
    String queryEngine = pctx.getConf().getVar(ConfVars.HIVE_EXECUTION_ENGINE);
    if (queryEngine.equals("tez") && pctx.getConf().getBoolVar(ConfVars.TEZ_DYNAMIC_PARTITION_PRUNING)) {
        enabled = true;
    } else if ((queryEngine.equals("spark") && pctx.getConf().isSparkDPPAny())) {
        enabled = true;
    }
    if (!enabled) {
        return pctx;
    }
    Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
    opRules.put(new RuleRegExp("R1", "(" + TableScanOperator.getOperatorName() + "%" + ".*" + ReduceSinkOperator.getOperatorName() + "%" + JoinOperator.getOperatorName() + "%)"), new JoinSynthetic());
    // The dispatcher fires the processor corresponding to the closest matching
    // rule and passes the context along
    SyntheticContext context = new SyntheticContext(pctx);
    Dispatcher disp = new DefaultRuleDispatcher(null, opRules, context);
    GraphWalker ogw = new PreOrderOnceWalker(disp);
    // Create a list of top op nodes
    List<Node> topNodes = new ArrayList<Node>();
    topNodes.addAll(pctx.getTopOps().values());
    ogw.startWalking(topNodes, null);
    return pctx;
}
Also used : NodeProcessor(org.apache.hadoop.hive.ql.lib.NodeProcessor) DefaultRuleDispatcher(org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher) Node(org.apache.hadoop.hive.ql.lib.Node) RuleRegExp(org.apache.hadoop.hive.ql.lib.RuleRegExp) ArrayList(java.util.ArrayList) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher) DefaultRuleDispatcher(org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher) LinkedHashMap(java.util.LinkedHashMap) PreOrderOnceWalker(org.apache.hadoop.hive.ql.lib.PreOrderOnceWalker) Rule(org.apache.hadoop.hive.ql.lib.Rule) GraphWalker(org.apache.hadoop.hive.ql.lib.GraphWalker)

Example 42 with Dispatcher

use of org.apache.hadoop.hive.ql.lib.Dispatcher in project flink by apache.

the class HiveParserSemanticAnalyzer method replaceViewReferenceWithDefinition.

private void replaceViewReferenceWithDefinition(HiveParserQB qb, Table tab, String tabName, String alias) throws SemanticException {
    HiveParserASTNode viewTree;
    final HiveParserASTNodeOrigin viewOrigin = new HiveParserASTNodeOrigin("VIEW", tab.getTableName(), tab.getViewExpandedText(), alias, qb.getParseInfo().getSrcForAlias(alias));
    try {
        // Reparse text, passing null for context to avoid clobbering
        // the top-level token stream.
        String viewText = tab.getViewExpandedText();
        viewTree = HiveASTParseUtils.parse(viewText, ctx, tab.getCompleteName());
        Dispatcher nodeOriginDispatcher = (nd, stack, nodeOutputs) -> {
            ((HiveParserASTNode) nd).setOrigin(viewOrigin);
            return null;
        };
        GraphWalker nodeOriginTagger = new HiveParserDefaultGraphWalker(nodeOriginDispatcher);
        nodeOriginTagger.startWalking(Collections.singleton(viewTree), null);
    } catch (HiveASTParseException e) {
        // A user could encounter this if a stored view definition contains
        // an old SQL construct which has been eliminated in a later Hive
        // version, so we need to provide full debugging info to help
        // with fixing the view definition.
        LOG.error(org.apache.hadoop.util.StringUtils.stringifyException(e));
        throw new SemanticException(e.getMessage(), e);
    }
    HiveParserQBExpr qbexpr = new HiveParserQBExpr(alias);
    doPhase1QBExpr(viewTree, qbexpr, qb.getId(), alias, true);
    // if HIVE_STATS_COLLECT_SCANCOLS is enabled, check.
    if ((!this.skipAuthorization() && !qb.isInsideView() && HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED)) || HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_STATS_COLLECT_SCANCOLS)) {
        qb.rewriteViewToSubq(alias, tabName, qbexpr, tab);
    } else {
        qb.rewriteViewToSubq(alias, tabName, qbexpr, null);
    }
}
Also used : JoinType(org.apache.hadoop.hive.ql.parse.JoinType) HiveParserBaseSemanticAnalyzer.getUnescapedName(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.getUnescapedName) FunctionRegistry(org.apache.hadoop.hive.ql.exec.FunctionRegistry) StringUtils(org.apache.commons.lang3.StringUtils) PrunedPartitionList(org.apache.hadoop.hive.ql.parse.PrunedPartitionList) HiveParserBaseSemanticAnalyzer.unescapeIdentifier(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unescapeIdentifier) HiveParserTypeCheckProcFactory(org.apache.flink.table.planner.delegation.hive.HiveParserTypeCheckProcFactory) RCFileInputFormat(org.apache.hadoop.hive.ql.io.RCFileInputFormat) Map(java.util.Map) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) QueryProperties(org.apache.hadoop.hive.ql.QueryProperties) CreateViewDesc(org.apache.hadoop.hive.ql.plan.CreateViewDesc) GlobalLimitCtx(org.apache.hadoop.hive.ql.parse.GlobalLimitCtx) Set(java.util.Set) GraphWalker(org.apache.hadoop.hive.ql.lib.GraphWalker) HiveASTParser(org.apache.flink.table.planner.delegation.hive.parse.HiveASTParser) ErrorMsg(org.apache.hadoop.hive.ql.ErrorMsg) HiveOperation(org.apache.hadoop.hive.ql.plan.HiveOperation) HiveParserBaseSemanticAnalyzer.doPhase1GetDistinctFuncExprs(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.doPhase1GetDistinctFuncExprs) ClassicToken(org.antlr.runtime.ClassicToken) HiveParserBaseSemanticAnalyzer.containsLeadLagUDF(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.containsLeadLagUDF) CreateTableDesc(org.apache.hadoop.hive.ql.plan.CreateTableDesc) HiveParserBaseSemanticAnalyzer.getAliasId(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.getAliasId) HiveShim(org.apache.flink.table.catalog.hive.client.HiveShim) ArrayList(java.util.ArrayList) ExprNodeFieldDesc(org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc) LinkedHashMap(java.util.LinkedHashMap) TableSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.TableSpec) LinkedHashSet(java.util.LinkedHashSet) PlanUtils(org.apache.hadoop.hive.ql.plan.PlanUtils) HiveUtils(org.apache.hadoop.hive.ql.metadata.HiveUtils) Files(java.nio.file.Files) PTFQueryInputType(org.apache.hadoop.hive.ql.parse.PTFInvocationSpec.PTFQueryInputType) FileUtils(org.apache.commons.io.FileUtils) Table(org.apache.hadoop.hive.ql.metadata.Table) File(java.io.File) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) Node(org.apache.hadoop.hive.ql.lib.Node) Partition(org.apache.hadoop.hive.ql.metadata.Partition) HiveParserBaseSemanticAnalyzer.getColumnInternalName(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.getColumnInternalName) HiveParserBaseSemanticAnalyzer.processPTFPartitionSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.processPTFPartitionSpec) HiveParserBaseSemanticAnalyzer.handleQueryWindowClauses(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.handleQueryWindowClauses) HiveParserBaseSemanticAnalyzer.unescapeSQLString(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unescapeSQLString) ColumnAccessInfo(org.apache.hadoop.hive.ql.parse.ColumnAccessInfo) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) ConfVars(org.apache.hadoop.hive.conf.HiveConf.ConfVars) LoggerFactory(org.slf4j.LoggerFactory) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException) HiveParserUtils(org.apache.flink.table.planner.delegation.hive.HiveParserUtils) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) HiveParserErrorMsg(org.apache.flink.table.planner.delegation.hive.parse.HiveParserErrorMsg) Token(org.antlr.runtime.Token) HiveParserBaseSemanticAnalyzer.processWindowFunction(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.processWindowFunction) InputFormat(org.apache.hadoop.mapred.InputFormat) Path(org.apache.hadoop.fs.Path) WindowFunctionSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserWindowingSpec.WindowFunctionSpec) RelOptCluster(org.apache.calcite.plan.RelOptCluster) HiveParserDDLSemanticAnalyzer(org.apache.flink.table.planner.delegation.hive.parse.HiveParserDDLSemanticAnalyzer) PatternSyntaxException(java.util.regex.PatternSyntaxException) HiveOutputFormat(org.apache.hadoop.hive.ql.io.HiveOutputFormat) Preconditions(org.apache.flink.util.Preconditions) SessionState(org.apache.hadoop.hive.ql.session.SessionState) List(java.util.List) OrcInputFormat(org.apache.hadoop.hive.ql.io.orc.OrcInputFormat) Entry(java.util.Map.Entry) Pattern(java.util.regex.Pattern) HiveException(org.apache.hadoop.hive.ql.metadata.HiveException) PTFQueryInputSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserPTFInvocationSpec.PTFQueryInputSpec) PartitioningSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserPTFInvocationSpec.PartitioningSpec) HashMap(java.util.HashMap) HiveParserBaseSemanticAnalyzer.findSimpleTableName(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.findSimpleTableName) ReadEntity(org.apache.hadoop.hive.ql.hooks.ReadEntity) HiveParserBaseSemanticAnalyzer.findTabRefIdxs(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.findTabRefIdxs) HiveParserBaseSemanticAnalyzer.initPhase1Ctx(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.initPhase1Ctx) HiveParserBaseSemanticAnalyzer.readProps(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.readProps) Utilities(org.apache.hadoop.hive.ql.exec.Utilities) HashSet(java.util.HashSet) SpecType(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.TableSpec.SpecType) PartitionedTableFunctionSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserPTFInvocationSpec.PartitionedTableFunctionSpec) SqlOperator(org.apache.calcite.sql.SqlOperator) ColumnInfo(org.apache.hadoop.hive.ql.exec.ColumnInfo) Hive(org.apache.hadoop.hive.ql.metadata.Hive) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) Logger(org.slf4j.Logger) SplitSample(org.apache.hadoop.hive.ql.parse.SplitSample) HiveConf(org.apache.hadoop.hive.conf.HiveConf) RelNode(org.apache.calcite.rel.RelNode) HiveParserBaseSemanticAnalyzer.validatePartSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.validatePartSpec) Tree(org.antlr.runtime.tree.Tree) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) HiveTableUtil(org.apache.flink.table.catalog.hive.util.HiveTableUtil) HiveParserBaseSemanticAnalyzer.unparseExprForValuesClause(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unparseExprForValuesClause) ObjectPair(org.apache.hadoop.hive.common.ObjectPair) PTFInputSpec(org.apache.flink.table.planner.delegation.hive.copy.HiveParserPTFInvocationSpec.PTFInputSpec) ExprNodeDescUtils(org.apache.hadoop.hive.ql.plan.ExprNodeDescUtils) Collections(java.util.Collections) HiveParserBaseSemanticAnalyzer.stripQuotes(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.stripQuotes) HiveParserBaseSemanticAnalyzer.unescapeSQLString(org.apache.flink.table.planner.delegation.hive.copy.HiveParserBaseSemanticAnalyzer.unescapeSQLString) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher) GraphWalker(org.apache.hadoop.hive.ql.lib.GraphWalker) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 43 with Dispatcher

use of org.apache.hadoop.hive.ql.lib.Dispatcher in project hive by apache.

the class SerializeFilter method resolve.

@Override
public PhysicalContext resolve(PhysicalContext pctx) throws SemanticException {
    pctx.getConf();
    // create dispatcher and graph walker
    Dispatcher disp = new Serializer(pctx);
    TaskGraphWalker ogw = new TaskGraphWalker(disp);
    // get all the tasks nodes from root task
    ArrayList<Node> topNodes = new ArrayList<Node>();
    topNodes.addAll(pctx.getRootTasks());
    // begin to walk through the task tree.
    ogw.startWalking(topNodes, null);
    return pctx;
}
Also used : TaskGraphWalker(org.apache.hadoop.hive.ql.lib.TaskGraphWalker) Node(org.apache.hadoop.hive.ql.lib.Node) ArrayList(java.util.ArrayList) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher) DefaultRuleDispatcher(org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)

Example 44 with Dispatcher

use of org.apache.hadoop.hive.ql.lib.Dispatcher in project hive by apache.

the class SortMergeJoinResolver method resolve.

@Override
public PhysicalContext resolve(PhysicalContext pctx) throws SemanticException {
    // create dispatcher and graph walker
    Dispatcher disp = new SortMergeJoinTaskDispatcher(pctx);
    TaskGraphWalker ogw = new TaskGraphWalker(disp);
    // get all the tasks nodes from root task
    List<Node> topNodes = new ArrayList<Node>();
    topNodes.addAll(pctx.rootTasks);
    // begin to walk through the task tree.
    ogw.startWalking(topNodes, null);
    return pctx;
}
Also used : TaskGraphWalker(org.apache.hadoop.hive.ql.lib.TaskGraphWalker) Node(org.apache.hadoop.hive.ql.lib.Node) ArrayList(java.util.ArrayList) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher)

Example 45 with Dispatcher

use of org.apache.hadoop.hive.ql.lib.Dispatcher in project hive by apache.

the class TableAccessAnalyzer method analyzeTableAccess.

public TableAccessInfo analyzeTableAccess() throws SemanticException {
    // Set up the rules for the graph walker for group by and join operators
    Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
    opRules.put(new RuleRegExp("R1", GroupByOperator.getOperatorName() + "%"), new GroupByProcessor(pGraphContext));
    opRules.put(new RuleRegExp("R2", JoinOperator.getOperatorName() + "%"), new JoinProcessor(pGraphContext));
    opRules.put(new RuleRegExp("R3", MapJoinOperator.getOperatorName() + "%"), new JoinProcessor(pGraphContext));
    TableAccessCtx tableAccessCtx = new TableAccessCtx();
    Dispatcher disp = new DefaultRuleDispatcher(getDefaultProc(), opRules, tableAccessCtx);
    GraphWalker ogw = new DefaultGraphWalker(disp);
    // Create a list of topop nodes and walk!
    List<Node> topNodes = new ArrayList<Node>();
    topNodes.addAll(pGraphContext.getTopOps().values());
    ogw.startWalking(topNodes, null);
    return tableAccessCtx.getTableAccessInfo();
}
Also used : NodeProcessor(org.apache.hadoop.hive.ql.lib.NodeProcessor) DefaultRuleDispatcher(org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher) DefaultGraphWalker(org.apache.hadoop.hive.ql.lib.DefaultGraphWalker) Node(org.apache.hadoop.hive.ql.lib.Node) RuleRegExp(org.apache.hadoop.hive.ql.lib.RuleRegExp) ArrayList(java.util.ArrayList) Dispatcher(org.apache.hadoop.hive.ql.lib.Dispatcher) DefaultRuleDispatcher(org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher) LinkedHashMap(java.util.LinkedHashMap) Rule(org.apache.hadoop.hive.ql.lib.Rule) DefaultGraphWalker(org.apache.hadoop.hive.ql.lib.DefaultGraphWalker) GraphWalker(org.apache.hadoop.hive.ql.lib.GraphWalker)

Aggregations

Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)97 Node (org.apache.hadoop.hive.ql.lib.Node)97 ArrayList (java.util.ArrayList)92 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)87 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)86 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 LinkedHashMap (java.util.LinkedHashMap)67 DefaultGraphWalker (org.apache.hadoop.hive.ql.lib.DefaultGraphWalker)62 RuleRegExp (org.apache.hadoop.hive.ql.lib.RuleRegExp)59 HashMap (java.util.HashMap)21 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)17 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)16 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)15 ExprNodeGenericFuncDesc (org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)14 TypeRule (org.apache.hadoop.hive.ql.lib.TypeRule)11 List (java.util.List)10 ReduceSinkOperator (org.apache.hadoop.hive.ql.exec.ReduceSinkOperator)10 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)10 Test (org.junit.Test)10