org.apache.calcite.prepare.RelOptTableImpl Java Examples
The following examples show how to use
org.apache.calcite.prepare.RelOptTableImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryOperationConverter.java From flink with Apache License 2.0 | 6 votes |
@Override public <U> RelNode visit(TableSourceQueryOperation<U> tableSourceTable) { final Table relTable = new TableSourceTable<>( tableSourceTable.getTableSource(), !tableSourceTable.isBatch(), FlinkStatistic.UNKNOWN()); CatalogReader catalogReader = (CatalogReader) relBuilder.getRelOptSchema(); // TableSourceScan requires a unique name of a Table for computing a digest. // We are using the identity hash of the TableSource object. String refId = "unregistered_" + System.identityHashCode(tableSourceTable.getTableSource()); return new FlinkLogicalTableSourceScan( relBuilder.getCluster(), relBuilder.getCluster().traitSet().replace(FlinkConventions.LOGICAL()), RelOptTableImpl.create( catalogReader, relTable.getRowType(relBuilder.getTypeFactory()), relTable, Schemas.path(catalogReader.getRootSchema(), Collections.singletonList(refId))), tableSourceTable.getTableSource(), Option.empty() ); }
Example #2
Source File: PushDownLogicTableRule.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
@NotNull private RelNode global(RelOptCluster cluster, Bindables.BindableTableScan bindableTableScan, RelOptSchema relOptSchema, MycatLogicTable logicTable) { final HashSet<String> context = new HashSet<>(); RelNode logicalTableScan; MycatPhysicalTable mycatPhysicalTable = logicTable.getMycatGlobalPhysicalTable(context); RelOptTable dataNode = RelOptTableImpl.create( relOptSchema, logicTable.getRowType(cluster.getTypeFactory()),//这里使用logicTable,避免类型不一致 mycatPhysicalTable, ImmutableList.of(mycatPhysicalTable.getBackendTableInfo().getUniqueName())); logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of()); return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects); }
Example #3
Source File: SqlWorker.java From quark with Apache License 2.0 | 6 votes |
private void populateMaterializationsAndLattice( QuarkMaterializeCluster.RelOptPlannerHolder plannerHolder, CalciteSchema rootSchema) { if (materializations == null) { materializations = MaterializationService.instance().query(rootSchema); } Materializer materializer = new Materializer(materializations); materializer.populateMaterializations(context.getPrepareContext(), plannerHolder); List<CalciteSchema.LatticeEntry> lattices = Schemas.getLatticeEntries(rootSchema); for (CalciteSchema.LatticeEntry lattice : lattices) { final CalciteSchema.TableEntry starTable = lattice.getStarTable(); final JavaTypeFactory typeFactory = context.getTypeFactory(); final RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, starTable.getTable().getRowType(typeFactory), starTable, null); plannerHolder.getPlanner().addLattice( new RelOptLattice(lattice.getLattice(), starRelOptTable)); } }
Example #4
Source File: QueryOperationConverter.java From flink with Apache License 2.0 | 6 votes |
@Override public <U> RelNode visit(TableSourceQueryOperation<U> tableSourceTable) { final Table relTable = new TableSourceTable<>( tableSourceTable.getTableSchema(), tableSourceTable.getTableSource(), !tableSourceTable.isBatch(), FlinkStatistic.UNKNOWN()); CatalogReader catalogReader = (CatalogReader) relBuilder.getRelOptSchema(); // TableSourceScan requires a unique name of a Table for computing a digest. // We are using the identity hash of the TableSource object. String refId = "unregistered_" + System.identityHashCode(tableSourceTable.getTableSource()); return new FlinkLogicalTableSourceScan( relBuilder.getCluster(), relBuilder.getCluster().traitSet().replace(FlinkConventions.LOGICAL()), RelOptTableImpl.create( catalogReader, relTable.getRowType(relBuilder.getTypeFactory()), relTable, Schemas.path(catalogReader.getRootSchema(), Collections.singletonList(refId))), tableSourceTable.getTableSchema(), tableSourceTable.getTableSource(), Option.empty() ); }
Example #5
Source File: StreamRules.java From calcite with Apache License 2.0 | 6 votes |
@Override public void onMatch(RelOptRuleCall call) { final Delta delta = call.rel(0); final TableScan scan = call.rel(1); final RelOptCluster cluster = delta.getCluster(); final RelOptTable relOptTable = scan.getTable(); final StreamableTable streamableTable = relOptTable.unwrap(StreamableTable.class); if (streamableTable != null) { final Table table1 = streamableTable.stream(); final RelOptTable relOptTable2 = RelOptTableImpl.create(relOptTable.getRelOptSchema(), relOptTable.getRowType(), table1, ImmutableList.<String>builder() .addAll(relOptTable.getQualifiedName()) .add("(STREAM)").build()); final LogicalTableScan newScan = LogicalTableScan.create(cluster, relOptTable2, scan.getHints()); call.transformTo(newScan); } }
Example #6
Source File: RelBuilder.java From calcite with Apache License 2.0 | 6 votes |
/** * Creates a {@link TableScan} on a {@link TransientTable} with the given name and type. * * @param tableName table name * @param rowType row type of the table */ @Experimental public RelBuilder transientScan(String tableName, RelDataType rowType) { TransientTable transientTable = new ListTransientTable(tableName, rowType); RelOptTable relOptTable = RelOptTableImpl.create( relOptSchema, rowType, transientTable, ImmutableList.of(tableName)); RelNode scan = struct.scanFactory.createScan( ViewExpanders.toRelContext(viewExpander, cluster), relOptTable); push(scan); rename(rowType.getFieldNames()); return this; }
Example #7
Source File: MycatRelBuilder.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
/** * todo for update * @param targetName * @param relDataType * @param sql * @return */ public RelNode makeBySql(String targetName,RelDataType relDataType, String sql) { MycatConvention convention = MycatConvention.of(targetName, MysqlSqlDialect.DEFAULT); MycatSQLTableScan transientTable = new MycatSQLTableScan(convention,relDataType,sql); id++; RelOptTable relOptTable = RelOptTableImpl.create( this.getRelOptSchema(), relDataType, transientTable, ImmutableList.of(id +"$"+targetName, id+sql));//名称唯一 return new MycatTransientSQLTableScan(this.getCluster(), convention, relOptTable, () -> sql); }
Example #8
Source File: PushDownLogicTableRule.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
@NotNull private static RelNode getBindableTableScan(Bindables.BindableTableScan bindableTableScan, RelOptCluster cluster, RelOptSchema relOptSchema, DataNode backendTableInfo) { String uniqueName = backendTableInfo.getUniqueName(); MycatLogicTable unwrap = bindableTableScan.getTable().unwrap(MycatLogicTable.class); MycatPhysicalTable mycatPhysicalTable = new MycatPhysicalTable(unwrap,backendTableInfo); RelOptTable dataNode = RelOptTableImpl.create( relOptSchema, mycatPhysicalTable.getRowType(cluster.getTypeFactory()), mycatPhysicalTable, ImmutableList.of(uniqueName)); RelNode logicalTableScan = LogicalTableScan.create(cluster, dataNode, ImmutableList.of()); return RelOptUtil.createProject(RelOptUtil.createFilter(logicalTableScan, bindableTableScan.filters), bindableTableScan.projects); }
Example #9
Source File: CopyWithCluster.java From dremio-oss with Apache License 2.0 | 5 votes |
public RelOptTable copyOf(RelOptTable table) { if (table instanceof RelOptTableWrapper) { final RelOptTableWrapper wrapper = (RelOptTableWrapper) table; return new RelOptTableWrapper( wrapper.getQualifiedName(), copyOf(wrapper.getRelOptTable()) ); } else if (table instanceof RelOptTableImpl) { final RelOptTableImpl impl = (RelOptTableImpl) table; return impl.copy(copyOf(impl.getRowType())); // this won't copy the RelOptSchema } notSupported(table); return table; }
Example #10
Source File: QuarkViewTable.java From quark with Apache License 2.0 | 5 votes |
public QuarkViewTable(QuarkSchema schema, String name, RelOptTableImpl relOptTable, QuarkTable backupTable, CalciteSchema tableSchema) { super(schema, name, backupTable.getColumns()); this.backUpRelOptTable = relOptTable; this.backupTable = backupTable; this.backupTableSchema = tableSchema; }
Example #11
Source File: QuarkTileTable.java From quark with Apache License 2.0 | 5 votes |
public QuarkTileTable(QuarkTile quarkTile, CalciteCatalogReader calciteCatalogReader, RelDataType relDataType, Path path, QuarkTable backingTable) { this.quarkTile = quarkTile; this.backingTable = backingTable; this.relOptTable = RelOptTableImpl.create( calciteCatalogReader, relDataType, this, path); }
Example #12
Source File: JdbcTableUtils.java From calcite-sql-rewriter with Apache License 2.0 | 4 votes |
static JdbcTable getJdbcTable(RelNode originalRel) { return (JdbcTable) get(RelOptTableImpl.class, originalRel.getTable(), "table"); }
Example #13
Source File: EmptyScope.java From calcite with Apache License 2.0 | 4 votes |
private void resolve_(final CalciteSchema rootSchema, List<String> names, List<String> schemaNames, SqlNameMatcher nameMatcher, Path path, Resolved resolved) { final List<String> concat = ImmutableList.<String>builder() .addAll(schemaNames).addAll(names).build(); CalciteSchema schema = rootSchema; SqlValidatorNamespace namespace = null; List<String> remainingNames = concat; for (String schemaName : concat) { if (schema == rootSchema && nameMatcher.matches(schemaName, schema.name)) { remainingNames = Util.skip(remainingNames); continue; } final CalciteSchema subSchema = schema.getSubSchema(schemaName, nameMatcher.isCaseSensitive()); if (subSchema != null) { path = path.plus(null, -1, subSchema.name, StructKind.NONE); remainingNames = Util.skip(remainingNames); schema = subSchema; namespace = new SchemaNamespace(validator, ImmutableList.copyOf(path.stepNames())); continue; } CalciteSchema.TableEntry entry = schema.getTable(schemaName, nameMatcher.isCaseSensitive()); if (entry == null) { entry = schema.getTableBasedOnNullaryFunction(schemaName, nameMatcher.isCaseSensitive()); } if (entry != null) { path = path.plus(null, -1, entry.name, StructKind.NONE); remainingNames = Util.skip(remainingNames); final Table table = entry.getTable(); SqlValidatorTable table2 = null; if (table instanceof Wrapper) { table2 = ((Wrapper) table).unwrap(Prepare.PreparingTable.class); } if (table2 == null) { final RelOptSchema relOptSchema = validator.catalogReader.unwrap(RelOptSchema.class); final RelDataType rowType = table.getRowType(validator.typeFactory); table2 = RelOptTableImpl.create(relOptSchema, rowType, entry, null); } namespace = new TableNamespace(validator, table2); resolved.found(namespace, false, null, path, remainingNames); return; } // neither sub-schema nor table if (namespace != null && !remainingNames.equals(names)) { resolved.found(namespace, false, null, path, remainingNames); } return; } }
Example #14
Source File: RelOptAbstractTable.java From calcite with Apache License 2.0 | 4 votes |
public List<ColumnStrategy> getColumnStrategies() { return RelOptTableImpl.columnStrategies(this); }
Example #15
Source File: PigTable.java From calcite with Apache License 2.0 | 3 votes |
/** * Creates a {@link RelOptTable} for a schema only table. * * @param schema Catalog object * @param rowType Relational schema for the table * @param names Names of Pig table */ public static RelOptTable createRelOptTable(RelOptSchema schema, RelDataType rowType, List<String> names) { final PigTable pigTable = new PigTable(rowType); return RelOptTableImpl.create(schema, rowType, names, pigTable, Expressions.constant(Boolean.TRUE)); }