Search in sources :

Example 81 with RelRoot

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelRoot in project dingo by dingodb.

the class DingoDriverParser method parseQuery.

@Nonnull
public DingoSignature parseQuery(String sql, CalcitePrepare.Context context) throws SqlParseException {
    SqlNode sqlNode = parse(sql);
    if (sqlNode.getKind().belongsTo(SqlKind.DDL)) {
        final DdlExecutor ddlExecutor = parserConfig.parserFactory().getDdlExecutor();
        ddlExecutor.executeDdl(context, sqlNode);
        return new DingoSignature(ImmutableList.of(), sql, Meta.CursorFactory.OBJECT, Meta.StatementType.OTHER_DDL);
    }
    JavaTypeFactory typeFactory = context.getTypeFactory();
    sqlNode = validate(sqlNode);
    Meta.StatementType statementType;
    RelDataType type;
    switch(sqlNode.getKind()) {
        case INSERT:
        case DELETE:
        case UPDATE:
            statementType = Meta.StatementType.IS_DML;
            type = RelOptUtil.createDmlRowType(sqlNode.getKind(), typeFactory);
            break;
        default:
            statementType = Meta.StatementType.SELECT;
            type = getValidatedNodeType(sqlNode);
            break;
    }
    RelDataType jdbcType = makeStruct(typeFactory, type);
    List<List<String>> originList = getFieldOrigins(sqlNode);
    final List<ColumnMetaData> columns = getColumnMetaDataList(typeFactory, jdbcType, originList);
    final Meta.CursorFactory cursorFactory = Meta.CursorFactory.ARRAY;
    RelRoot relRoot = convert(sqlNode);
    RelNode relNode = optimize(relRoot.rel, DingoConventions.ROOT);
    Job job = DingoJobVisitor.createJob(relNode, true);
    return new DingoSignature(columns, sql, null, null, cursorFactory, statementType, job);
}
Also used : Meta(org.apache.calcite.avatica.Meta) RelDataType(org.apache.calcite.rel.type.RelDataType) RelRoot(org.apache.calcite.rel.RelRoot) DdlExecutor(org.apache.calcite.server.DdlExecutor) RelNode(org.apache.calcite.rel.RelNode) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ColumnMetaData(org.apache.calcite.avatica.ColumnMetaData) Job(io.dingodb.exec.base.Job) SqlNode(org.apache.calcite.sql.SqlNode) Nonnull(javax.annotation.Nonnull)

Aggregations

RelRoot (org.apache.calcite.rel.RelRoot)77 SqlNode (org.apache.calcite.sql.SqlNode)30 RelNode (org.apache.calcite.rel.RelNode)22 Test (org.junit.jupiter.api.Test)18 NlsString (org.apache.calcite.util.NlsString)17 DingoTableScan (io.dingodb.calcite.rel.DingoTableScan)13 SqlParseException (org.apache.calcite.sql.parser.SqlParseException)11 SqlToRelConverter (org.apache.calcite.sql2rel.SqlToRelConverter)11 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)9 SamzaSqlDslConverterFactory (org.apache.samza.sql.dsl.SamzaSqlDslConverterFactory)8 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)7 RelDataType (org.apache.calcite.rel.type.RelDataType)7 RexBuilder (org.apache.calcite.rex.RexBuilder)7 SqlValidator (org.apache.calcite.sql.validate.SqlValidator)7 DslConverter (org.apache.samza.sql.interfaces.DslConverter)7 Test (org.junit.Test)7 RelOptCluster (org.apache.calcite.plan.RelOptCluster)6 SqlParser (org.apache.calcite.sql.parser.SqlParser)6 Planner (org.apache.calcite.tools.Planner)6 LogicalFilter (org.apache.calcite.rel.logical.LogicalFilter)5