[
https://issues.apache.org/jira/browse/CALCITE-761?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14594838#comment-14594838
]
Maryann Xue commented on CALCITE-761:
-------------------------------------
{code}
final CalciteConnection connection =
CalciteMetaImpl.connect(schema.root(), null);
CalciteSchema.TableEntry tableEntry = schema.getTableBySql(viewSql);
RelDataType rowType = null;
if (tableEntry == null) {
Table table = tableFactory.createTable(schema, viewSql, viewSchemaPath);
final String tableName = Schemas.uniqueTableName(schema,
Util.first(suggestedTableName, "m"));
tableEntry = schema.add(tableName, table, ImmutableList.of(viewSql));
Hook.CREATE_MATERIALIZATION.run(tableName);
rowType = table.getRowType(connection.getTypeFactory());
}
{code}
In the above code from MaterializationService.defineMaterialization(), looks
like it tries to get a TableEntry by calling schema.getTableBySql() and if this
returns now it will start to create one.
After I made the change below (just a temporary fix I guess), things worked out
fine for me:
{code}
@@ -116,7 +116,10 @@ public MaterializationKey defineMaterialization(final
CalciteSchema schema,
final CalciteConnection connection =
CalciteMetaImpl.connect(schema.root(), null);
- CalciteSchema.TableEntry tableEntry = schema.getTableBySql(viewSql);
+ CalciteSchema.TableEntry tableEntry = schema.getTable(suggestedTableName,
true);
+ if (tableEntry == null) {
+ tableEntry = schema.getTableBySql(viewSql);
+ }
RelDataType rowType = null;
if (tableEntry == null) {
Table table = tableFactory.createTable(schema, viewSql, viewSchemaPath);
{code}
I also looked to see if there's any place for customization to add "viewSql -->
table" mapping, but didn't seem to find one.
> Pre-populated materializations
> ------------------------------
>
> Key: CALCITE-761
> URL: https://issues.apache.org/jira/browse/CALCITE-761
> Project: Calcite
> Issue Type: Bug
> Reporter: Julian Hyde
> Assignee: Julian Hyde
>
> The design for materializations (materialized views) allows for them to be
> populated on demand (e.g. as an ArrayTable) the first time that the
> materialization is needed or to already exist, having been populated by the
> user.
> According to [~maryannxue] the latter case does not work. Calcite tries to
> create a new table with the same name as the current table, then makes the
> name unique by adding a digit, then goes ahead and populates it.
> We need to (a) allow such materializations to be defined in the JSON model,
> (b) document how to define them, (c) make them work, (d) add tests.
> Cc [~jamestaylor], as this is related to optimization for Phoenix secondary
> indexes.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)