Search in sources :

Example 1 with HiveParserQueryState

use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState in project flink by apache.

the class HiveParser method processCmd.

private List<Operation> processCmd(String cmd, HiveConf hiveConf, HiveShim hiveShim, HiveCatalog hiveCatalog) {
    try {
        final HiveParserContext context = new HiveParserContext(hiveConf);
        // parse statement to get AST
        final HiveParserASTNode node = HiveASTParseUtils.parse(cmd, context);
        Operation operation;
        if (DDL_NODES.contains(node.getType())) {
            HiveParserQueryState queryState = new HiveParserQueryState(hiveConf);
            HiveParserDDLSemanticAnalyzer ddlAnalyzer = new HiveParserDDLSemanticAnalyzer(queryState, hiveCatalog, getCatalogManager(), this, hiveShim, context, dmlHelper);
            operation = ddlAnalyzer.convertToOperation(node);
            return Collections.singletonList(operation);
        } else {
            final boolean explain = node.getType() == HiveASTParser.TOK_EXPLAIN;
            // first child is the underlying explicandum
            HiveParserASTNode input = explain ? (HiveParserASTNode) node.getChild(0) : node;
            operation = analyzeSql(context, hiveConf, hiveShim, input);
            // explain an nop is also considered nop
            if (explain && !(operation instanceof NopOperation)) {
                operation = new ExplainOperation(operation);
            }
        }
        return Collections.singletonList(operation);
    } catch (HiveASTParseException e) {
        // ParseException can happen for flink-specific statements, e.g. catalog DDLs
        try {
            return super.parse(cmd);
        } catch (SqlParserException parserException) {
            throw new SqlParserException("SQL parse failed", e);
        }
    } catch (SemanticException e) {
        throw new ValidationException("HiveParser failed to parse " + cmd, e);
    }
}
Also used : HiveParserDDLSemanticAnalyzer(org.apache.flink.table.planner.delegation.hive.parse.HiveParserDDLSemanticAnalyzer) NopOperation(org.apache.flink.table.operations.NopOperation) SqlParserException(org.apache.flink.table.api.SqlParserException) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) HiveParserASTNode(org.apache.flink.table.planner.delegation.hive.copy.HiveParserASTNode) ValidationException(org.apache.flink.table.api.ValidationException) HiveParserContext(org.apache.flink.table.planner.delegation.hive.copy.HiveParserContext) HiveParserQueryState(org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState) PlannerQueryOperation(org.apache.flink.table.planner.operations.PlannerQueryOperation) Operation(org.apache.flink.table.operations.Operation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) NopOperation(org.apache.flink.table.operations.NopOperation) HiveASTParseException(org.apache.flink.table.planner.delegation.hive.copy.HiveASTParseException) SemanticException(org.apache.hadoop.hive.ql.parse.SemanticException)

Example 2 with HiveParserQueryState

use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState in project flink by apache.

the class HiveParser method analyzeSql.

private Operation analyzeSql(HiveParserContext context, HiveConf hiveConf, HiveShim hiveShim, HiveParserASTNode node) throws SemanticException {
    HiveParserCalcitePlanner analyzer = createCalcitePlanner(context, new HiveParserQueryState(hiveConf), hiveShim);
    RelNode relNode = analyzer.genLogicalPlan(node);
    if (relNode == null) {
        return new NopOperation();
    }
    // if not a query, treat it as an insert
    if (!analyzer.getQB().getIsQuery()) {
        return dmlHelper.createInsertOperation(analyzer, relNode);
    } else {
        return new PlannerQueryOperation(relNode);
    }
}
Also used : NopOperation(org.apache.flink.table.operations.NopOperation) PlannerQueryOperation(org.apache.flink.table.planner.operations.PlannerQueryOperation) RelNode(org.apache.calcite.rel.RelNode) HiveParserQueryState(org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState)

Aggregations

NopOperation (org.apache.flink.table.operations.NopOperation)2 HiveParserQueryState (org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState)2 PlannerQueryOperation (org.apache.flink.table.planner.operations.PlannerQueryOperation)2 RelNode (org.apache.calcite.rel.RelNode)1 SqlParserException (org.apache.flink.table.api.SqlParserException)1 ValidationException (org.apache.flink.table.api.ValidationException)1 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)1 Operation (org.apache.flink.table.operations.Operation)1 HiveASTParseException (org.apache.flink.table.planner.delegation.hive.copy.HiveASTParseException)1 HiveParserASTNode (org.apache.flink.table.planner.delegation.hive.copy.HiveParserASTNode)1 HiveParserContext (org.apache.flink.table.planner.delegation.hive.copy.HiveParserContext)1 HiveParserDDLSemanticAnalyzer (org.apache.flink.table.planner.delegation.hive.parse.HiveParserDDLSemanticAnalyzer)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1