Search in sources :

Example 1 with HiveParserContext

use of org.apache.flink.table.planner.delegation.hive.copy.HiveParserContext 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 HiveParserContext

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

the class HiveASTParserTest method assertDDLType.

private void assertDDLType(int type, String... sqls) throws Exception {
    for (String sql : sqls) {
        HiveParserContext parserContext = new HiveParserContext(hiveConf);
        assertEquals(type, HiveASTParseUtils.parse(sql, parserContext).getType());
    }
}
Also used : HiveParserContext(org.apache.flink.table.planner.delegation.hive.copy.HiveParserContext)

Aggregations

HiveParserContext (org.apache.flink.table.planner.delegation.hive.copy.HiveParserContext)2 SqlParserException (org.apache.flink.table.api.SqlParserException)1 ValidationException (org.apache.flink.table.api.ValidationException)1 ExplainOperation (org.apache.flink.table.operations.ExplainOperation)1 NopOperation (org.apache.flink.table.operations.NopOperation)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 HiveParserQueryState (org.apache.flink.table.planner.delegation.hive.copy.HiveParserQueryState)1 HiveParserDDLSemanticAnalyzer (org.apache.flink.table.planner.delegation.hive.parse.HiveParserDDLSemanticAnalyzer)1 PlannerQueryOperation (org.apache.flink.table.planner.operations.PlannerQueryOperation)1 SemanticException (org.apache.hadoop.hive.ql.parse.SemanticException)1