Re: Adding RelOptMaterializations to a planner

2019-10-06 Thread Stamatis Zampetakis
Hi Shubham,

Regarding point 1) you can easily get around it by defining a few of your
own classes in a package with the same name as Prepare although I doubt is
the right approach.

Perhaps MaterializationTest [1] can help you get a few more ideas on how to
use the respective service.

Other than that if you want to see how to instantiate CatalogReader,
Validator, etc., maybe the code sample in [2] can help.

Best,
Stamatis

[1]
https://github.com/apache/calcite/blob/master/core/src/test/java/org/apache/calcite/test/MaterializationTest.java
[2]
https://github.com/zabetak/calcite/blob/livecodingdemo/core/src/test/java/org/apache/calcite/examples/foodmart/java/EndToEndExampleEnumerable.java

On Fri, Oct 4, 2019 at 12:22 PM Shubham Kumar 
wrote:

> Hi contributors,
>
> I am trying to retrieve materialized view query rewrite from Calcite.
>
> In order to do that, I have created a planner and wanted to get the
> optimized relNode after applying Materializations which is equivalent to
> applying [1] present in Prepare class of Calcite. However, I am facing
> difficulties while trying to do so. I have so far tried:
>
> 1) Doing exactly what's being done in [1] but it turned out some members of
>  can't be accessed outside package, so I am
> unable to obtain   RelOptMaterialization from it.
>
> 2) I figured I only need (tableRel, queryRel) relNodes for making a
> RelOptMaterialization which can be made from Materialization.sql but when I
> try to so with the a planner instance (i.e. planner.rel(validatedNode).rel)
> : I am getting errors:
>
> i) When using the different planner instance:
> Relational expression LogicalFilter#24 belongs to a different planner than
> is currently being used.
> ii) When using the same planner instance:
> java.lang.IllegalArgumentException: cannot move to STATE_2_READY from
> STATE_5_CONVERTED
>
> I figured out that maybe SqlToRelConverter could help out in this use case
> but I don't know how to get instances of CatalogReader, Validator,
> ViewExpander and SqlRexConvertletTable.
>
> Can someone point out where I am going wrong and what's the correct way to
> go about it.
>
> [1]
>
> https://github.com/apache/calcite/blob/73023148e7f37d494f6caf92b01b090f6dde13cd/core/src/main/java/org/apache/calcite/prepare/Prepare.java#L320
> --
> Thanks & Regards
>
> Shubham Kumar
>


Re: how to return dates in java/enumerable convention?

2019-10-06 Thread Stamatis Zampetakis
Hi Jess,

In most cases the internal representation of date objects in the Enumerable
convention are longs [1].
Keep in mind that there are also other cases (e.g., [2]) where there are
conversion of dates to other types.

Best,
Stamatis

[1]
https://github.com/apache/calcite/blob/35c5f57d7db2b4745086178602ca69195ffb858e/core/src/main/java/org/apache/calcite/jdbc/JavaTypeFactoryImpl.java#L193
[2]
https://github.com/apache/calcite/blob/35c5f57d7db2b4745086178602ca69195ffb858e/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumUtils.java#L243


On Fri, Oct 4, 2019 at 5:26 PM Jess Balint  wrote:

> I'm returning string objects from my enumerable, but getting an exception
> when trying to use the MONTH function which compiles to:
>
>
>
> org.apache.calcite.avatica.util.DateTimeUtils.unixDateExtract(org.apache.calcite.avatica.util.TimeUnitRange.MONTH,
> org.apache.calcite.runtime.SqlFunctions.toInt(current[1]))};
>
> current[1] is a string here and an exception is thrown. are dates expected
> to be java.util.Date objects? Is there documentation on this?
>
> Thanks.
>
> Jess
>