Search in sources :

Example 1 with DdlExecutor

use of org.apache.calcite.server.DdlExecutor in project calcite by apache.

the class CalcitePrepareImpl method executeDdl.

@Override
public void executeDdl(Context context, SqlNode node) {
    final CalciteConnectionConfig config = context.config();
    final SqlParserImplFactory parserFactory = config.parserFactory(SqlParserImplFactory.class, SqlParserImpl.FACTORY);
    final DdlExecutor ddlExecutor = parserFactory.getDdlExecutor();
    ddlExecutor.executeDdl(context, node);
}
Also used : DdlExecutor(org.apache.calcite.server.DdlExecutor) CalciteConnectionConfig(org.apache.calcite.config.CalciteConnectionConfig) SqlParserImplFactory(org.apache.calcite.sql.parser.SqlParserImplFactory)

Example 2 with DdlExecutor

use of org.apache.calcite.server.DdlExecutor 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

DdlExecutor (org.apache.calcite.server.DdlExecutor)2 ImmutableList (com.google.common.collect.ImmutableList)1 Job (io.dingodb.exec.base.Job)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)1 ColumnMetaData (org.apache.calcite.avatica.ColumnMetaData)1 Meta (org.apache.calcite.avatica.Meta)1 CalciteConnectionConfig (org.apache.calcite.config.CalciteConnectionConfig)1 RelNode (org.apache.calcite.rel.RelNode)1 RelRoot (org.apache.calcite.rel.RelRoot)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlParserImplFactory (org.apache.calcite.sql.parser.SqlParserImplFactory)1