Hi,
I tried to implement new UserDefinedFunction based on the
JdbcTest.testUserDefinedFunction()
My Model Configuration:
schemas: [
{ type: 'jdbc',
name: 'BASEJDBC',
jdbcDriver: 'org.hsqldb.jdbcDriver',
jdbcUrl: jdbc:hsqldb:mem:.',
},
{ name: 'ADHOC',
functions: [
{ name: 'MY_PLUS',
className:
'org.apache.calcite.test.JdbcTest.MyPlusFunction'
}]
}]
Problem:
When processing query
"select rnum, col1, ADHOC.MY_PLUS(col1, 10) from tab1",
Calcite does not implement the UserDefinedFunction but send it down to
remote jdbc driver instead (which eventually fail as the function is not
available on remote DB). See generated code below.
Is this a supported configuration? or did I miss out anything.
Thank you.
Rgds,
jay
Generated Code:
/* 1 */ org.apache.calcite.DataContext root;
/* 2 */
/* 3 */ public org.apache.calcite.linq4j.Enumerable bind(final
org.apache.calcite.DataContext root0) {
/* 4 */ root = root0;
/* 5 */ final org.apache.calcite.linq4j.function.Function1
rowBuilderFactory = new org.apache.calcite.linq4j.function.Function1() {
/* 6 */ public org.apache.calcite.linq4j.function.Function0
apply(final java.sql.ResultSet resultSet) {
/* 7 */ return new org.apache.calcite.linq4j.function.Function0() {
/* 8 */ public Object apply() {
/* 9 */ try {
/* 10 */ final Object[] values = new Object[3];
/* 11 */ values[0] = resultSet.getObject(1);
/* 12 */ values[1] = resultSet.getObject(2);
/* 13 */ values[2] = resultSet.getObject(3);
/* 14 */ return values;
/* 15 */ } catch (java.sql.SQLException e) {
/* 16 */ throw new RuntimeException(
/* 17 */ e);
/* 18 */ }
/* 19 */ }
/* 20 */ }
/* 21 */ ;
/* 22 */ }
/* 23 */ public Object apply(final Object resultSet) {
/* 24 */ return apply(
/* 25 */ (java.sql.ResultSet) resultSet);
/* 26 */ }
/* 27 */ }
/* 28 */ ;
/* 29 */ final org.apache.calcite.linq4j.Enumerable enumerable =
org.apache.calcite.runtime.ResultSetEnumerable.of(((org.apache.calcite.adapter.jdbc.JdbcSchema)
root.getRootSchema().getSubSchema("BASEJDBC").unwrap(org.apache.calcite.adapter.jdbc.JdbcSchema.class)).getDataSource(),
"*SELECT \"RNUM\", \"COL1\", \"ADHOC\".\"MY_PLUS\"(\"COL1\", 10) AS
\"EXPR$2\"\nFROM \"TAB1*\"", rowBuilderFactory);
/* 30 */ return enumerable;
/* 31 */ }
/* 32 */
/* 33 */
/* 34 */ public java.lang.reflect.Type getElementType() {
/* 35 */ return java.lang.Object[].class;
/* 36 */ }
/* 37 */
/* 38 */