I like the idea of an adapter-supplied function, but it’s not in Calcite right 
now.

The easiest thing is probably to define the function in the JSON model [1]. 
That should get you through validation (which is where you’re tripping up right 
now).

Then you’ll need to push the function down to the storage engine. There isn’t a 
nice way of declaring what UDFs a particular engine can handle. I fear that 
you’ll need to modify the Solr rules.

Julian

[1] https://calcite.apache.org/docs/model.html#function 
<https://calcite.apache.org/docs/model.html#function>


> On Mar 27, 2017, at 11:23 AM, Timothy Potter <thelabd...@gmail.com> wrote:
> 
> I'm trying to add the ability to push-down the evaluation of a
> function to my storage engine (Solr in this case). For instance,
> 
> select movie_id, user_id, custom_rating('foo') as rating from movie_ratings
> 
> where custom_rating('foo') is some function in my storage engine.
> 
> This seems like a UDF in Calcite terms but I'm not having any luck
> getting the function node passed to my adapter code.
> 
> I've tried adding a ScalarFunction to my schema but it gets evaluated
> early (long before my adapter code gets hit).
> 
> I've also tried a TableFunction, but always end up with this error (using 
> 1.11)
> 
> Caused by: org.apache.calcite.runtime.CalciteContextException: From
> line 1, column 27 to line 1, column 36: No match found for function
> signature custom_rating(<CHARACTER>)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>    at 
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>    at 
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
>    at 
> org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:463)
>    at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:796)
>    at org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:784)
>    at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:4080)
>    at 
> org.apache.calcite.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(SqlValidatorImpl.java:1614)
>    at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:278)
>    at org.apache.calcite.sql.SqlFunction.deriveType(SqlFunction.java:223)
>    at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:4445)
>    at 
> org.apache.calcite.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:4432)
>    at org.apache.calcite.sql.SqlCall.accept(SqlCall.java:137)
> 
> 
> which when debugging looks like the function isn't registered
> correctly in the schema but I've overridden protected Multimap<String,
> Function> getFunctionMultimap() in my schema impl. to include my
> function.
> 
> I scanned the docs and the UDF code (e.g. Smalls) but don't see an
> example of a adapter supplied function. Any guidance you can provide
> is appreciated.
> 
> Thanks.
> Tim

Reply via email to