Hi, Shubham Kumar
If I understand correctly, you want get the optimized(by materialized view)
SQL String. I wrote a simple test as below, please check if it's helpful
for you.
@Test public void testDEV() {
final String m = "select \"deptno\", \"empid\", \"name\""
+ "from \"emps\" where \"deptno\" = 10";
final String q = "select \"empid\" + 1 as x, \"name\""
+ "from \"emps\" where \"deptno\" = 10";
CalciteAssert.that()
.withMaterializations(HR_FKUK_MODEL, "m0", m)
.query(q)
.withHook(Hook.SUB, (Consumer<RelNode>) r ->
{
RelToSqlConverter converter =
new RelToSqlConverter(CalciteSqlDialect.DEFAULT);
final SqlNode sqlNode = converter.visitChild(0, r).asStatement();
System.out.println(sqlNode.toSqlString(CalciteSqlDialect.DEFAULT).getSql());
})
.enableMaterializations(true)
.explainContains("hr, m0");
}
The output is as below:
SELECT "empid" + 1 AS "X", "name"
FROM "hr"."m0"
Danny Chan <[email protected]> 于2019年9月16日周一 下午1:44写道:
> Hi, Shubham Kumar ~
>
> > However, I wanted the optimized rewrite SQL query if possible, not just
> the
> > plan. So far, I tried to use the rel2sql api but when I print
> > RelNode.toString(), it gives me a plan which involves scanning the raw
> > tables and hence the SQL generated by rel2sql is not the one which
> utilized
> > the materialized view. Any pointers to get the rewrite query.
>
> Did you try the RelNode.toString() after the volcano planner promotion, it
> is not expected to involve scanning the raw tables.
>
> Best,
> Danny Chan
> 在 2019年9月11日 +0800 PM9:42,[email protected],写道:
> >
> > However, I wanted the optimized rewrite SQL query if possible, not just
> the
> > plan. So far, I tried to use the rel2sql api but when I print
> > RelNode.toString(), it gives me a plan which involves scanning the raw
> > tables and hence the SQL generated by rel2sql is not the one which
> utilized
> > the materialized view. Any pointers to get the rewrite query.
>