You can wrap an enum constant as if it were a literal. Using lisp
terminology, I usually refer to such a thing as a "symbol". Try

  builder.call(SqlStdOperatorTable.EXTRACT_DATE,
    builder.field(1, 0, "my_date"),
    builder.literal(TimeUnitRange.YEAR));

Run JdbcTest.testExtract and put a break point in the constructor of
RexCall and you should see what's going on.

Extracting time values (e.g. HOUR) is a little more complicated
because there is no EXTRACT_TIME function. These operations are turned
into millisecond arithmetic at sql-to-rel time.

Julian


On Wed, May 10, 2017 at 3:09 AM, Chris Baynes <[email protected]> wrote:
> We're trying to use the date extract & floor functions via the relbuilder,
> but can't figure out the right syntax.
>
> 1. Trying YEAR(field)
> ...Relbuilder builder;
> // could use SqlStdOperatorTable.EXTRACT, but then how do we pass YEAR as
> an argument?
> builder.call(SqlStdOperatorTable.YEAR,
>     builder.field(1, 0, "my_date")
> );
>
> Cause: java.lang.RuntimeException: cannot translate call YEAR($t2)
> at
> org.apache.calcite.adapter.enumerable.RexToLixTranslator.translateCall(RexToLixTranslator.java:563)
> at
> org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate0(RexToLixTranslator.java:537)
> at
> org.apache.calcite.adapter.enumerable.RexToLixTranslator.translate(RexToLixTranslator.java:223)
>
> 2. Using floor
> builder.call(SqlStdOperatorTable.FLOOR,
>     // -> need to specify `YEAR` here somehow as a RexNode
>     builder.field(1, 0, "my_date")
> );
>
> Thanks in advance!

Reply via email to