Hi Shubham,

View based rewriting is performed during planning (check the call hierarchy
of [1] for more details).
If you obtain a plan (RelNode) after the planner then most likely rel2sql
API should give you the right SQL string.
On the other hand if you are just using sql2rel API then rewritings are not
considered.

Best,
Stamatis

[1]
https://github.com/apache/calcite/blob/d3c718328d4c83fb24007c8349b31b420dddd187/core/src/main/java/org/apache/calcite/plan/RelOptPlanner.java#L177

On Wed, Sep 11, 2019 at 3:42 PM Shubham Kumar <shubhamkumar1...@gmail.com>
wrote:

> Hi Contributors,
>
> I have recently started to experiment with Apache Calcite's materialized
> views and I needed a bit of help.
>
> I have explicitly defined materialized views which are stored in data
> source by defining it in root.schema.materializations of model file.
>
> Now for a query which should use the Materialized View:
>
> Explain plan for "query" gives a plan which shows that the MV is being
> utilized.
>
> 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.
>
> --
> Thanks & Regards
>
> Shubham Kumar
>

Reply via email to