You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by 王仁杰 <wa...@std.uestc.edu.cn> on 2022/07/07 15:24:33 UTC
some question when using calcite to rewrite materialized views query
hello,I am a novice user of calcite and want to implement a graduation project throught calcit.but i face some question when i want to rewrite materialized views query.
this is my create table and create materialize view Sql,I create a table with attr1 and attr2 columns,and create a materialized view with filter attr1>10 on this table:
String sql = "create table opttable (attr1 int, attr2 int)";
String mvsql = "create materialized view if not exists optmv " +
"as select attr1,attr2 from opttable where attr1 >10";
I want to use HBO to rewrite my materialized view query,and below is my rule and query sql:
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleInstance(MaterializedViewRules.FILTER);
HepPlanner hepPlanner = new HepPlanner(builder.build());
next ,I add materialized view to HBO planner:
String querySql = mView.getView().getQuery();
Planner planner = Frameworks.getPlanner(config);
SqlNode sqlNode = planner.parse(querySql);
planner.validate(sqlNode);
RelRoot relRoot = planner.rel(sqlNode);
RelNode relNode = relRoot.project();
if (null == cluster) {
cluster = relRoot.rel.getCluster();
}
final RelDataTypeFactory typeFactory = cluster.getTypeFactory();
CalciteCatalogReader catalogReader =
new CalciteCatalogReader(
prepareContext.getRootSchema(),
prepareContext.getDefaultSchemaPath(),
typeFactory,
prepareContext.config());
RelNode queryRel=relNode;
RelBuilder relBuilder = RelFactories.LOGICAL_BUILDER.create(cluster, catalogReader);
final RelNode replacement = relBuilder.scan("optmv").build();
RelOptMaterialization materialization =
new RelOptMaterialization(tableScan, queryRel, null, ImmutableList.of("default", "optmv"));
relOptPlanner.addMaterialization(materialization);
but,when i execute sql:select attr1 from opttable where attr1 >9, this program face crash.I debug this and find that FILTER operator and UNION operator be child of each other,and program trap in loop.
I wonder if you can give me some advice. Thank you very much!