Search in sources :

Example 1 with MycatRelDataType

use of io.mycat.beans.mycat.MycatRelDataType in project Mycat2 by MyCATApache.

the class VisualTablescanFactory method create.

@Override
public PhysicalPlan create(ComplierContext context) {
    RelOptTable table = tableScan.getRelNode().getTable();
    MycatLogicTable logicTable = table.unwrap(MycatLogicTable.class);
    TableHandler tableHandler = logicTable.getTable();
    Observable<Object[]> tableObservable = context.getTableObservable(tableHandler.getSchemaName(), tableHandler.getTableName());
    MycatRelDataType mycatRelDataTypeByCalcite = tableScan.getMycatRelDataTypeByCalcite();
    Schema schema = toArrowSchema(mycatRelDataTypeByCalcite);
    return ValuesPlan.create(schema, MycatRxJavaUtl.blockingIterable(tableObservable));
}
Also used : TableHandler(io.mycat.TableHandler) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) Schema(org.apache.arrow.vector.types.pojo.Schema) FactoryUtil.toArrowSchema(io.ordinate.engine.factory.FactoryUtil.toArrowSchema) RelOptTable(org.apache.calcite.plan.RelOptTable)

Example 2 with MycatRelDataType

use of io.mycat.beans.mycat.MycatRelDataType in project Mycat2 by MyCATApache.

the class LocalTableScan method getMycatRelDataType.

@Override
public MycatRelDataType getMycatRelDataType() {
    MycatLogicTable mycatTable = getTable().unwrap(MycatLogicTable.class);
    TableHandler tableTable = mycatTable.getTable();
    List<MycatField> mycatFields = tableTable.getColumns().stream().map(c -> c.toMycatField()).collect(Collectors.toList());
    return MycatRelDataType.of(mycatFields);
}
Also used : RelInput(org.apache.calcite.rel.RelInput) TableScan(org.apache.calcite.rel.core.TableScan) TableHandler(io.mycat.TableHandler) RelFactories(org.apache.calcite.rel.core.RelFactories) MycatField(io.mycat.beans.mycat.MycatField) Collectors(java.util.stream.Collectors) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) RelWriter(org.apache.calcite.rel.RelWriter) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelHint(org.apache.calcite.rel.hint.RelHint) Map(java.util.Map) AbstractMycatTable(io.mycat.calcite.table.AbstractMycatTable) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) org.apache.calcite.plan(org.apache.calcite.plan) TableHandler(io.mycat.TableHandler) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) MycatField(io.mycat.beans.mycat.MycatField)

Example 3 with MycatRelDataType

use of io.mycat.beans.mycat.MycatRelDataType in project Mycat2 by MyCATApache.

the class DatasourcePoolTest method getSqlMycatRelDataType.

@NotNull
private static MycatRelDataType getSqlMycatRelDataType() {
    String sql = getSql("s", "t");
    MySqlCreateTableStatement sqlStatement = (MySqlCreateTableStatement) SQLUtils.parseSingleMysqlStatement(sql);
    MycatRelDataType mycatRelType = MycatRelDataType.getMycatRelType(sqlStatement);
    return mycatRelType;
}
Also used : MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) ToString(lombok.ToString) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MycatRelDataType

use of io.mycat.beans.mycat.MycatRelDataType in project Mycat2 by MyCATApache.

the class DatasourcePoolTest method main.

@SneakyThrows
public static void main(String[] args) {
    DatasourceConfig datasourceConfig = new DatasourceConfig();
    datasourceConfig.setDbType("mysql");
    datasourceConfig.setUser("root");
    datasourceConfig.setPassword("123456");
    datasourceConfig.setName("prototypeDs");
    datasourceConfig.setUrl("jdbc:mysql://localhost:3307/mysql");
    datasourceConfig.setMaxCon(10);
    Map<String, DatasourceConfig> datasources = Maps.of("prototypeDs", datasourceConfig);
    MetaClusterCurrent.register(JdbcConnectionManager.class, new JdbcConnectionManager(datasources, new DruidDatasourceProvider()));
    MetaClusterCurrent.register(IOExecutor.class, IOExecutor.DEFAULT);
    MycatDatasourcePool jdbcDs = new JdbcDatasourcePoolImpl("prototypeDs");
    NewMycatConnection newMycatConnection = jdbcDs.getConnection().toCompletionStage().toCompletableFuture().get();
    Observable<VectorSchemaRoot> observable = newMycatConnection.prepareQuery("select 1", Collections.emptyList(), new RootAllocator());
    List<VectorSchemaRoot> vectorSchemaRoots = observable.toList().blockingGet();
    System.out.println();
    // ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    MycatDatasourcePool nativeDs = new VertxMySQLDatasourcePoolImpl(datasourceConfig, "prototypeDs");
    MycatRelDataType sqlMycatRelType = getSqlMycatRelDataType();
    TestResult testResult = getTestResult(jdbcDs);
    TestResult testResult2 = getTestResult(nativeDs);
    // List<String> collect = newMycatConnection.prepareQuery(querySql, Collections.emptyList()).toList().blockingGet().stream().map(i -> i.toString()).collect(Collectors.toList());
    MycatRowMetaData mycatRowMetaData1 = testResult.queryResult.getMycatRowMetaData();
    MycatRowMetaData mycatRowMetaData2 = testResult2.queryResult.getMycatRowMetaData();
    MycatRelDataType mycatRelDataType1 = mycatRowMetaData1.getMycatRelDataType();
    MycatRelDataType mycatRelDataType2 = mycatRowMetaData2.getMycatRelDataType();
    System.out.println(mycatRelDataType1);
    System.out.println(mycatRelDataType2);
    System.out.println("=====================================================================================================");
    boolean equals = mycatRelDataType1.equals(mycatRelDataType2);
    // Assert.assertTrue(equals);
    equals = mycatRelDataType1.equals(sqlMycatRelType);
    System.out.println(sqlMycatRelType);
    System.out.println(mycatRelDataType1);
    observable = newMycatConnection.prepareQuery("select * from testSchema.testColumnTable", Collections.emptyList(), new RootAllocator());
    vectorSchemaRoots = observable.toList().blockingGet();
    System.out.println();
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) MycatDatasourcePool(io.mycat.commands.MycatDatasourcePool) NewMycatConnection(io.mycat.newquery.NewMycatConnection) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) ToString(lombok.ToString) DruidDatasourceProvider(io.mycat.datasource.jdbc.DruidDatasourceProvider) DatasourceConfig(io.mycat.config.DatasourceConfig) JdbcDatasourcePoolImpl(io.mycat.commands.JdbcDatasourcePoolImpl) VertxMySQLDatasourcePoolImpl(io.mycat.commands.VertxMySQLDatasourcePoolImpl) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData) SneakyThrows(lombok.SneakyThrows)

Example 5 with MycatRelDataType

use of io.mycat.beans.mycat.MycatRelDataType in project Mycat2 by MyCATApache.

the class CalciteCompiler method convertValues.

public PhysicalPlan convertValues(Values values) {
    ImmutableList<ImmutableList<RexLiteral>> tuples = values.getTuples();
    ArrayList<Function[]> rowList = new ArrayList<>();
    for (ImmutableList<RexLiteral> tuple : tuples) {
        int size = tuple.size();
        Function[] functions = new Function[size];
        int index = 0;
        for (RexLiteral rexLiteral : tuple) {
            Function function = rexConverter.convertToFunction(rexLiteral);
            functions[index] = function;
            index++;
        }
        rowList.add(functions);
    }
    RelDataType rowType = values.getRowType();
    MycatRelDataType mycatRelDataType = MycatRelDataTypeUtil.getMycatRelDataType(rowType);
    Schema schema = FactoryUtil.toArrowSchema(mycatRelDataType);
    return executeCompiler.values(rowList, schema);
}
Also used : RexLiteral(org.apache.calcite.rex.RexLiteral) ColumnFunction(io.ordinate.engine.function.column.ColumnFunction) IntFunction(io.ordinate.engine.function.IntFunction) VariableParameterFunction(io.ordinate.engine.function.bind.VariableParameterFunction) Function(io.ordinate.engine.function.Function) AccumulatorFunction(io.ordinate.engine.function.aggregate.AccumulatorFunction) ImmutableList(com.google.common.collect.ImmutableList) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) Schema(org.apache.arrow.vector.types.pojo.Schema) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) RelDataType(org.apache.calcite.rel.type.RelDataType)

Aggregations

MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)6 TableHandler (io.mycat.TableHandler)3 MycatLogicTable (io.mycat.calcite.table.MycatLogicTable)3 Schema (org.apache.arrow.vector.types.pojo.Schema)3 ImmutableList (com.google.common.collect.ImmutableList)2 FactoryUtil.toArrowSchema (io.ordinate.engine.factory.FactoryUtil.toArrowSchema)2 ToString (lombok.ToString)2 RelOptTable (org.apache.calcite.plan.RelOptTable)2 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)1 MetadataManager (io.mycat.MetadataManager)1 MycatField (io.mycat.beans.mycat.MycatField)1 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)1 AbstractMycatTable (io.mycat.calcite.table.AbstractMycatTable)1 JdbcDatasourcePoolImpl (io.mycat.commands.JdbcDatasourcePoolImpl)1 MycatDatasourcePool (io.mycat.commands.MycatDatasourcePool)1 VertxMySQLDatasourcePoolImpl (io.mycat.commands.VertxMySQLDatasourcePoolImpl)1 DatasourceConfig (io.mycat.config.DatasourceConfig)1 DruidDatasourceProvider (io.mycat.datasource.jdbc.DruidDatasourceProvider)1 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)1 NewMycatConnection (io.mycat.newquery.NewMycatConnection)1