/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
schemaPlus.add(cube.name, cube.build(CalciteSchema.from(queryContext.getRootSchema()), (QuarkTable) tileTEntry.getTable()));
final RelMetadataQuery mq = call.getMetadataQuery(); final double rowCount = aggregate.estimateRowCount(mq); final Table aggregateTable = tableEntry.getTable(); final RelDataType aggregateTableRowType = aggregateTable.getRowType(cluster.getTypeFactory());
final QuarkTileTable aggregateTable = (QuarkTileTable) tableEntry.getTable(); final RelDataType aggregateTableRowType = aggregateTable.getRowType(scan.getCluster().getTypeFactory());
final RelMetadataQuery mq = call.getMetadataQuery(); final double rowCount = aggregate.estimateRowCount(mq); final Table aggregateTable = tableEntry.getTable(); final RelDataType aggregateTableRowType = aggregateTable.getRowType(cluster.getTypeFactory());
final TileKey tileKey = pair.right; final double rowCount = aggregate.getRows(); final QuarkTileTable aggregateTable = (QuarkTileTable) tableEntry.getTable();
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) {
List<String> qualifiedTableName = materialization.materializedTable.path(); materializationList.add( new RelOptMaterialization(materialization.tableRel, final RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, starTable.getTable().getRowType(typeFactory), starTable, null); latticeList.add( new RelOptLattice(lattice.getLattice(), starRelOptTable));
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) {
List<String> qualifiedTableName = materialization.materializedTable.path(); materializationList.add( new RelOptMaterialization(materialization.tableRel, final RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, starTable.getTable().getRowType(typeFactory), starTable, null); latticeList.add( new RelOptLattice(lattice.getLattice(), starRelOptTable));
false); assert viewTEntry != null; Table backupTable = viewTEntry.getTable(); final RelDataType rowType = backupTable.getRowType(queryContext.getTypeFactory());
/** Populates a materialization record, converting a table path * (essentially a list of strings, like ["hr", "sales"]) into a table object * that can be used in the planning process. */ void populate(Materialization materialization) { SqlParser parser = SqlParser.create(materialization.sql); SqlNode node; try { node = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder() .withTrimUnusedFields(true).build(); SqlToRelConverter sqlToRelConverter2 = getSqlToRelConverter(getSqlValidator(), catalogReader, config); materialization.queryRel = sqlToRelConverter2.convertQuery(node, true, true).rel; // Identify and substitute a StarTable in queryRel. // // It is possible that no StarTables match. That is OK, but the // materialization patterns that are recognized will not be as rich. // // It is possible that more than one StarTable matches. TBD: should we // take the best (whatever that means), or all of them? useStar(schema, materialization); RelOptTable table = this.catalogReader.getTable(materialization.materializedTable.path()); materialization.tableRel = sqlToRelConverter2.toRel(table); }
/** Populates a materialization record, converting a table path * (essentially a list of strings, like ["hr", "sales"]) into a table object * that can be used in the planning process. */ void populate(Materialization materialization) { SqlParser parser = SqlParser.create(materialization.sql); SqlNode node; try { node = parser.parseStmt(); } catch (SqlParseException e) { throw new RuntimeException("parse failed", e); } final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder() .withTrimUnusedFields(true).build(); SqlToRelConverter sqlToRelConverter2 = getSqlToRelConverter(getSqlValidator(), catalogReader, config); materialization.queryRel = sqlToRelConverter2.convertQuery(node, true, true).rel; // Identify and substitute a StarTable in queryRel. // // It is possible that no StarTables match. That is OK, but the // materialization patterns that are recognized will not be as rich. // // It is possible that more than one StarTable matches. TBD: should we // take the best (whatever that means), or all of them? useStar(schema, materialization); RelOptTable table = this.catalogReader.getTable(materialization.materializedTable.path()); materialization.tableRel = sqlToRelConverter2.toRel(table); }
/** Converts a relational expression to use a * {@link org.apache.calcite.schema.impl.StarTable} defined in {@code schema}. * Uses the first star table that fits. */ private Iterable<Callback> useStar(CalciteSchema schema, RelNode queryRel) { List<CalciteSchema.TableEntry> starTables = Schemas.getStarTables(schema.root()); if (starTables.isEmpty()) { // Don't waste effort converting to leaf-join form. return ImmutableList.of(); } final List<Callback> list = new ArrayList<>(); final RelNode rel2 = RelOptMaterialization.toLeafJoinForm(queryRel); for (CalciteSchema.TableEntry starTable : starTables) { final Table table = starTable.getTable(); assert table instanceof StarTable; RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, table.getRowType(typeFactory), starTable, null); final RelNode rel3 = RelOptMaterialization.tryUseStar(rel2, starRelOptTable); if (rel3 != null) { list.add(new Callback(rel3, starTable, starRelOptTable)); } } return list; }
/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
/** Converts a relational expression to use a * {@link org.apache.calcite.schema.impl.StarTable} defined in {@code schema}. * Uses the first star table that fits. */ private Iterable<Callback> useStar(CalciteSchema schema, RelNode queryRel) { List<CalciteSchema.TableEntry> starTables = Schemas.getStarTables(schema.root()); if (starTables.isEmpty()) { // Don't waste effort converting to leaf-join form. return ImmutableList.of(); } final List<Callback> list = new ArrayList<>(); final RelNode rel2 = RelOptMaterialization.toLeafJoinForm(queryRel); for (CalciteSchema.TableEntry starTable : starTables) { final Table table = starTable.getTable(); assert table instanceof StarTable; RelOptTableImpl starRelOptTable = RelOptTableImpl.create(catalogReader, table.getRowType(typeFactory), starTable, null); final RelNode rel3 = RelOptMaterialization.tryUseStar(rel2, starRelOptTable); if (rel3 != null) { list.add(new Callback(rel3, starTable, starRelOptTable)); } } return list; }
/** * Given a table alias, find the corresponding {@link Table} associated with it * */ private Table findTable(String alias) { List<String> names = null; if (tableScope == null) { // no tables to find return null; } for (ScopeChild child : tableScope.children) { if (catalogReader.nameMatcher().matches(child.name, alias)) { names = ((SqlIdentifier) child.namespace.getNode()).names; break; } } if (names == null || names.size() == 0) { return null; } else if (names.size() == 1) { return findTable(catalogReader.getRootSchema(), names.get(0), catalogReader.nameMatcher().isCaseSensitive()); } CalciteSchema.TableEntry entry = SqlValidatorUtil.getTableEntry(catalogReader, names); return entry == null ? null : entry.getTable(); }
Enumerable<MetaTable> tables(final MetaSchema schema_) { final CalciteMetaSchema schema = (CalciteMetaSchema) schema_; return Linq4j.asEnumerable(schema.calciteSchema.getTableNames()) .select((Function1<String, MetaTable>) name -> { final Table table = schema.calciteSchema.getTable(name, true).getTable(); return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, name); }) .concat( Linq4j.asEnumerable( schema.calciteSchema.getTablesBasedOnNullaryFunctions() .entrySet()) .select(pair -> { final Table table = pair.getValue(); return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, pair.getKey()); })); }
Enumerable<MetaTable> tables(final MetaSchema schema_) { final CalciteMetaSchema schema = (CalciteMetaSchema) schema_; return Linq4j.asEnumerable(schema.calciteSchema.getTableNames()) .select((Function1<String, MetaTable>) name -> { final Table table = schema.calciteSchema.getTable(name, true).getTable(); return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, name); }) .concat( Linq4j.asEnumerable( schema.calciteSchema.getTablesBasedOnNullaryFunctions() .entrySet()) .select(pair -> { final Table table = pair.getValue(); return new CalciteMetaTable(table, schema.tableCatalog, schema.tableSchem, pair.getKey()); })); }
@Override public Table createTable(CalciteSchema schema, String viewSql, List<String> viewSchemaPath) { assert nzTile.tableName != null; CalciteCatalogReader calciteCatalogReader = new CalciteCatalogReader( schema.root(), false, queryContext.getDefaultSchemaPath(), queryContext.getTypeFactory()); CalciteSchema tileSchema = calciteCatalogReader.getTable(nzTile.tableName) .unwrap(CalciteSchema.class); assert tileSchema != null; CalciteSchema.TableEntry tileTEntry = tileSchema.getTable( Util.last(nzTile.tableName), false); assert tileTEntry != null; return new QuarkTileTable(nzTile, calciteCatalogReader, tileTEntry.getTable().getRowType(queryContext.getTypeFactory()), Schemas.path(rootSchema, nzTile.alias), (QuarkTable) tileTEntry.getTable()); } };