Search in sources :

Example 11 with Job

use of io.dingodb.exec.base.Job 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

Job (io.dingodb.exec.base.Job)11 ImmutableList (com.google.common.collect.ImmutableList)5 ValuesOperator (io.dingodb.exec.operator.ValuesOperator)5 List (java.util.List)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 Test (org.junit.jupiter.api.Test)5 DingoConventions (io.dingodb.calcite.DingoConventions)4 DingoParser (io.dingodb.calcite.DingoParser)4 DingoParserContext (io.dingodb.calcite.DingoParserContext)4 Assert (io.dingodb.calcite.assertion.Assert)4 MockMetaServiceProvider (io.dingodb.calcite.mock.MockMetaServiceProvider)4 DingoCoalesce (io.dingodb.calcite.rel.DingoCoalesce)4 DingoDistributedValues (io.dingodb.calcite.rel.DingoDistributedValues)4 DingoExchange (io.dingodb.calcite.rel.DingoExchange)4 DingoPartModify (io.dingodb.calcite.rel.DingoPartModify)4 DingoPartScan (io.dingodb.calcite.rel.DingoPartScan)4 DingoValues (io.dingodb.calcite.rel.DingoValues)4 TableId (io.dingodb.common.table.TableId)4 CoalesceOperator (io.dingodb.exec.operator.CoalesceOperator)4 PartModifyOperator (io.dingodb.exec.operator.PartModifyOperator)4