You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Mark Pasterkamp <ma...@gmail.com> on 2019/07/02 13:35:00 UTC

Using the materialization sevice to define a materialized view

Dear all,

I was wondering if someone could tell me whether I am using the
materialization service to define a materialized view correctly.

The materializationService.defineMaterialization[1] takes a few arguments,
the one I might be confused about is the viewSql argument. Right now I have
the materialized view definition written in there.

so for example, given 2 tables A and B, and the name of the materialized
view is A_B, I would have as viewSql the definition select * from A join B.

Everything works so far, but now I am looking into union rewriting and it
starts to stackoverflow.
using the following definition for A_B: select * from A join B where A.id <
100, and attempting to find a rewriting for the query select * from A join
B, I get a stackoverflow because circular references have been rewritten
into the tree.
I believe this is due to the definition of the materialized view. Without
any other rewriting rules, the A.id < 100 selection is done over the join
of A and B, which is union rewritten to include a filter of A < 100 over a
join between A and B (this is where the stackoverflow comes from)

Looking through the code, I found a workaround by setting the maximum
amount of matches to 1.

Because this feels more like a workaround than a correct approach, I was
wondering if this is something I did not do correctly.
I also couldn't find many uses of this function in the codebase, which is
why I am contacting the mailing list.

Mark


[1]
https://github.com/apache/calcite/blob/3fa29455664bec0056c436491b369e0cd72242ea/core/src/main/java/org/apache/calcite/materialize/MaterializationService.java#L87