use of io.mycat.calcite.table.MycatLogicTable in project Mycat2 by MyCATApache.
the class HBTQueryConvertor method filterFromTable.
public RelNode filterFromTable(FilterFromTableSchema input) {
List<String> names = input.getNames();
relBuilder.scan(names);
TableScan tableScan = (TableScan) relBuilder.peek();
RelOptTable table = tableScan.getTable();
relBuilder.as(names.get(names.size() - 1));
relBuilder.filter(toRex(input.getFilter()));
Filter build = (Filter) relBuilder.build();
relBuilder.clear();
MycatLogicTable mycatTable = table.unwrap(MycatLogicTable.class);
Distribution distribution = mycatTable.createDistribution();
Iterable<Partition> dataNodes = distribution.getDataNodes().flatMap(i -> i.values().stream()).collect(Collectors.toList());
return build.copy(build.getTraitSet(), ImmutableList.of(toPhyTable(mycatTable, dataNodes)));
}
use of io.mycat.calcite.table.MycatLogicTable 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));
}
use of io.mycat.calcite.table.MycatLogicTable in project Mycat2 by MyCATApache.
the class MycatImplementor method visit.
@Override
public Result visit(TableScan e) {
try {
MycatLogicTable logicTable = e.getTable().unwrap(MycatLogicTable.class);
if (logicTable != null) {
String hintText = "";
if (dialect instanceof MysqlSqlDialect) {
for (RelHint hint : e.getHints()) {
if ("INDEX".equalsIgnoreCase(hint.hintName)) {
hintText = "USE INDEX(" + String.join(",", hint.listOptions) + ")";
}
}
}
TableHandler tableHandler = logicTable.logicTable();
SqlNode tableParamSqlNode = new TableParamSqlNode(ImmutableList.of(tableHandler.getSchemaName(), tableHandler.getTableName()), tableHandler.getUniqueName(), hintText);
return result(tableParamSqlNode, ImmutableList.of(Clause.FROM), e, null);
}
return super.visit(e);
} catch (Throwable e1) {
LOGGER.error("", e1);
return null;
}
}
use of io.mycat.calcite.table.MycatLogicTable in project Mycat2 by MyCATApache.
the class DrdsRunnerHelper method convertRoSchemaPlus.
public static SchemaPlus convertRoSchemaPlus(NameMap<SchemaHandler> schemaHandlers) {
SchemaPlus plus = CalciteSchema.createRootSchema(false).plus();
List<MycatSchema> schemas = new ArrayList<>();
for (Map.Entry<String, SchemaHandler> entry : schemaHandlers.entrySet()) {
String schemaName = entry.getKey();
SchemaHandler schemaHandler = entry.getValue();
Map<String, Table> logicTableMap = new HashMap<>();
for (TableHandler tableHandler : schemaHandler.logicTables().values()) {
MycatLogicTable logicTable = new MycatLogicTable(tableHandler);
logicTableMap.put(logicTable.getTable().getTableName(), logicTable);
}
MycatSchema schema = MycatSchema.create(schemaName, logicTableMap);
plus.add(schemaName, schema);
schemas.add(schema);
}
return plus;
}
use of io.mycat.calcite.table.MycatLogicTable 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);
}
Aggregations