You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "ptr.bojko@gmail.com" <pt...@gmail.com> on 2018/10/25 11:45:03 UTC

Timestamp as a parameter of UDF

Hello,

I am trying to create UDF with java.sql.Timestamp as a parameter:

public static QueryableTable getTable(
@Parameter(name = "Projection") String projection,
@Parameter(name = "Query") String query,
@Parameter(name = "Test Timestamp") Timestamp timestamp)

But when using following UDF like this:
SELECT * FROM TABLE(MYUDF('ID','',  TIMESTAMP '2013-01-01 01:01:01'))

I've got following exception and wondering whether I am missing something
or having date/time as a parameter is not fully supported yet?

[INFO] [talledLocalContainer] java.lang.AssertionError: value 2013-01-01
01:01:01 does not match type class java.sql.Timestamp
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.ConstantExpression.<init>(ConstantExpression.java:49)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.Expressions.constant(Expressions.java:588)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.OptimizeShuttle.visit(OptimizeShuttle.java:278)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.UnaryExpression.accept(UnaryExpression.java:37)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.GotoStatement.accept(GotoStatement.java:60)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.BlockBuilder.optimize(BlockBuilder.java:438)
[INFO] [talledLocalContainer] at
org.apache.calcite.linq4j.tree.BlockBuilder.toBlock(BlockBuilder.java:322)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlUserDefinedTableMacro.coerce(SqlUserDefinedTableMacro.java:190)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlUserDefinedTableMacro.convertArguments(SqlUserDefinedTableMacro.java:110)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlUserDefinedTableFunction.getRowType(SqlUserDefinedTableFunction.java:70)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.ProcedureNamespace.validateImpl(ProcedureNamespace.java:62)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:971)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:950)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3036)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3018)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3288)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:971)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:950)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:216)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:925)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:629)
[INFO] [talledLocalContainer] at
org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:553)
[INFO] [talledLocalContainer] at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:264)
[INFO] [talledLocalContainer] at
org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:230)
[INFO] [talledLocalContainer] at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:774)
[INFO] [talledLocalContainer] at
org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:638)
[INFO] [talledLocalContainer] at
org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:608)
[INFO] [talledLocalContainer] at
org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:238)
[INFO] [talledLocalContainer] at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement_(CalciteConnectionImpl.java:220)
[INFO] [talledLocalContainer] at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:209)
[INFO] [talledLocalContainer] at
org.apache.calcite.jdbc.CalciteConnectionImpl.prepareStatement(CalciteConnectionImpl.java:96)
[INFO] [talledLocalContainer] at
org.apache.calcite.avatica.AvaticaConnection.prepareStatement(AvaticaConnection.java:175)

-- 
Piotr Bojko
http://about.me/ptr.bojko

Re: Timestamp as a parameter of UDF

Posted by "ptr.bojko@gmail.com" <pt...@gmail.com>.
Hello,

I have submitted https://issues.apache.org/jira/browse/CALCITE-2641 . I've
proposed a path there in a comment but I think it would be best to accept
the approach first - then I can contribute the patch.

Thanks for help and support
Pete

On Thu, Oct 25, 2018 at 7:15 PM Julian Hyde <jh...@apache.org> wrote:

> Two existing JIRA cases that relate to this are
> https://issues.apache.org/jira/browse/CALCITE-1041 <
> https://issues.apache.org/jira/browse/CALCITE-1041> and
> https://issues.apache.org/jira/browse/CALCITE-986 <
> https://issues.apache.org/jira/browse/CALCITE-986>.
>
> This case seems different because it is a user-defined TABLE function. I
> don’t think that has been tested before, therefore I wouldn’t consider it
> “done". The first step is to a bug “DATE and TIMESTAMP arguments to
> user-defined table function”, and the second step is to write a test in
> TableFunctionTest.
>
> Julian
>
>
>
> > On Oct 25, 2018, at 5:32 AM, ptr.bojko@gmail.com wrote:
> >
> > Will try, thanks.
> >
> > On Thu, Oct 25, 2018 at 2:16 PM Vladimir Sitnikov <
> > sitnikov.vladimir@gmail.com> wrote:
> >
> >> Then it might be a bug
> >> in org/apache/calcite/linq4j/tree/OptimizeShuttle.java:277
> >> Have you tried to comment that branch out for test purposes?
> >>
> >> Vladimir
> >>
> >
> >
> > --
> > Piotr Bojko
> > http://about.me/ptr.bojko
>
>

-- 
Piotr Bojko
http://about.me/ptr.bojko

Re: Timestamp as a parameter of UDF

Posted by Julian Hyde <jh...@apache.org>.
Two existing JIRA cases that relate to this are https://issues.apache.org/jira/browse/CALCITE-1041 <https://issues.apache.org/jira/browse/CALCITE-1041> and https://issues.apache.org/jira/browse/CALCITE-986 <https://issues.apache.org/jira/browse/CALCITE-986>.

This case seems different because it is a user-defined TABLE function. I don’t think that has been tested before, therefore I wouldn’t consider it “done". The first step is to a bug “DATE and TIMESTAMP arguments to user-defined table function”, and the second step is to write a test in TableFunctionTest.

Julian



> On Oct 25, 2018, at 5:32 AM, ptr.bojko@gmail.com wrote:
> 
> Will try, thanks.
> 
> On Thu, Oct 25, 2018 at 2:16 PM Vladimir Sitnikov <
> sitnikov.vladimir@gmail.com> wrote:
> 
>> Then it might be a bug
>> in org/apache/calcite/linq4j/tree/OptimizeShuttle.java:277
>> Have you tried to comment that branch out for test purposes?
>> 
>> Vladimir
>> 
> 
> 
> -- 
> Piotr Bojko
> http://about.me/ptr.bojko


Re: Timestamp as a parameter of UDF

Posted by "ptr.bojko@gmail.com" <pt...@gmail.com>.
Will try, thanks.

On Thu, Oct 25, 2018 at 2:16 PM Vladimir Sitnikov <
sitnikov.vladimir@gmail.com> wrote:

> Then it might be a bug
> in org/apache/calcite/linq4j/tree/OptimizeShuttle.java:277
> Have you tried to comment that branch out for test purposes?
>
> Vladimir
>


-- 
Piotr Bojko
http://about.me/ptr.bojko

Re: Timestamp as a parameter of UDF

Posted by Vladimir Sitnikov <si...@gmail.com>.
Then it might be a bug
in org/apache/calcite/linq4j/tree/OptimizeShuttle.java:277
Have you tried to comment that branch out for test purposes?

Vladimir

Re: Timestamp as a parameter of UDF

Posted by "ptr.bojko@gmail.com" <pt...@gmail.com>.
Vladimir,

TimestampString with toString = 2013-01-01 01:01:01

On Thu, Oct 25, 2018 at 1:58 PM Vladimir Sitnikov <
sitnikov.vladimir@gmail.com> wrote:

> Piotr>I've got following exception and wondering whether I am missing
> something
>
> It sounds like a bug.
>
> Piotr>value 2013-01-0101:01:01 does not match type class java.sql.Timestamp
>
> Would you please set a breakpoint and/or just print the class of "value" at
> ConstantExpression.java:49 ?
>
> Vladimir
>


-- 
Piotr Bojko
http://about.me/ptr.bojko

Re: Timestamp as a parameter of UDF

Posted by Vladimir Sitnikov <si...@gmail.com>.
Piotr>I've got following exception and wondering whether I am missing
something

It sounds like a bug.

Piotr>value 2013-01-0101:01:01 does not match type class java.sql.Timestamp

Would you please set a breakpoint and/or just print the class of "value" at
ConstantExpression.java:49 ?

Vladimir