Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-226

User-defined functions should work without explicit schema prefix

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      It looks like user-defined-functions have to be fully qualified with schema name for unknown reason.

      I've played with `JdbcTest.testUserDefinedFunction` a bit.
      If using `con.setSchema("adhoc")` then `select "deptno" as p from EMPLOYEES` works, but `select my_double("deptno") ...` throws:

      ```
      java.lang.RuntimeException: exception while executing [select my_double("deptno") as p from EMPLOYEES]
      at net.hydromatic.optiq.test.OptiqAssert$AssertQuery.returns(OptiqAssert.java:779)
      at net.hydromatic.optiq.test.OptiqAssert$AssertQuery.returns(OptiqAssert.java:766)
      at net.hydromatic.optiq.test.JdbcTest.testUserDefinedFunction(JdbcTest.java:2695)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
      Caused by: java.lang.RuntimeException: With materializationsEnabled=false, limit=0
      at net.hydromatic.optiq.test.OptiqAssert.assertQuery(OptiqAssert.java:343)
      at net.hydromatic.optiq.test.OptiqAssert$AssertQuery.returns(OptiqAssert.java:775)
      ... 28 more
      Caused by: java.sql.SQLException: while executing SQL: select my_double("deptno") as p from EMPLOYEES
      at net.hydromatic.avatica.Helper.createException(Helper.java:40)
      at net.hydromatic.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:80)
      at net.hydromatic.optiq.test.OptiqAssert.assertQuery(OptiqAssert.java:318)
      ... 29 more
      Caused by: org.eigenbase.util.EigenbaseContextException: From line 1, column 8 to line 1, column 26
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      at org.eigenbase.resource.Resources$ExInstWithCause.ex(Resources.java:348)
      at org.eigenbase.sql.SqlUtil.newContextException(SqlUtil.java:674)
      at org.eigenbase.sql.SqlUtil.newContextException(SqlUtil.java:662)
      at org.eigenbase.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:3504)
      at org.eigenbase.sql.validate.SqlValidatorImpl.handleUnresolvedFunction(SqlValidatorImpl.java:1406)
      at org.eigenbase.sql.SqlFunction.deriveType(SqlFunction.java:282)
      at org.eigenbase.sql.SqlFunction.deriveType(SqlFunction.java:206)
      at org.eigenbase.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:3862)
      at org.eigenbase.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:3849)
      at org.eigenbase.sql.SqlCall.accept(SqlCall.java:133)
      at org.eigenbase.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1323)
      at org.eigenbase.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1306)
      at org.eigenbase.sql.SqlAsOperator.deriveType(SqlAsOperator.java:117)
      at org.eigenbase.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:3862)
      at org.eigenbase.sql.validate.SqlValidatorImpl$DeriveTypeVisitor.visit(SqlValidatorImpl.java:3849)
      at org.eigenbase.sql.SqlCall.accept(SqlCall.java:133)
      at org.eigenbase.sql.validate.SqlValidatorImpl.deriveTypeImpl(SqlValidatorImpl.java:1323)
      at org.eigenbase.sql.validate.SqlValidatorImpl.deriveType(SqlValidatorImpl.java:1306)
      at org.eigenbase.sql.validate.SqlValidatorImpl.expandSelectItem(SqlValidatorImpl.java:416)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validateSelectList(SqlValidatorImpl.java:3010)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:2763)
      at org.eigenbase.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)
      at org.eigenbase.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:80)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:745)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:734)
      at org.eigenbase.sql.SqlSelect.validate(SqlSelect.java:209)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:708)
      at org.eigenbase.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:424)
      at org.eigenbase.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:426)
      at net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:209)
      at net.hydromatic.optiq.prepare.Prepare.prepareSql(Prepare.java:178)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare2_(OptiqPrepareImpl.java:334)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepare_(OptiqPrepareImpl.java:243)
      at net.hydromatic.optiq.prepare.OptiqPrepareImpl.prepareSql(OptiqPrepareImpl.java:212)
      at net.hydromatic.optiq.jdbc.OptiqConnectionImpl.parseQuery(OptiqConnectionImpl.java:146)
      at net.hydromatic.optiq.jdbc.MetaImpl.prepare(MetaImpl.java:603)
      at net.hydromatic.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:77)
      ... 30 more
      Caused by: org.eigenbase.sql.validate.SqlValidatorException: No match found for function signature MY_DOUBLE(<NUMERIC>)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      at org.eigenbase.resource.Resources$ExInstWithCause.ex(Resources.java:348)
      at org.eigenbase.resource.Resources$ExInst.ex(Resources.java:457)
      ... 66 more
      ```

      ---------------- Imported from GitHub ----------------
      Url: https://github.com/julianhyde/optiq/issues/226
      Created by: vlsi
      Labels:
      Created at: Wed Apr 02 21:36:53 CEST 2014
      State: closed

        Activity

        Hide
        github-import GitHub Import added a comment -

        [Date: Wed Apr 02 21:45:15 CEST 2014, Author: julianhyde]

        The SQL standard says that functions should be resolved using the `path`, variable, not `schema`. See how, for example, <a href="https://github.com/LucidDB/luciddb/blob/master/luciddb/test/sql/udr/udf/date_internal.ref">this LucidDB script</a> starts

        ```sql
        set schema = 'udftest';
        set path ='udftest';
        ```

        Optiq should implement that, and also add `path` as a connect string parameter and add `defaultPath` alongside `defaultSchema` in the model.

        Until then, you'll have to explicitly qualify.

        Show
        github-import GitHub Import added a comment - [Date: Wed Apr 02 21:45:15 CEST 2014, Author: julianhyde ] The SQL standard says that functions should be resolved using the `path`, variable, not `schema`. See how, for example, <a href="https://github.com/LucidDB/luciddb/blob/master/luciddb/test/sql/udr/udf/date_internal.ref">this LucidDB script</a> starts ```sql set schema = 'udftest'; set path ='udftest'; ``` Optiq should implement that, and also add `path` as a connect string parameter and add `defaultPath` alongside `defaultSchema` in the model. Until then, you'll have to explicitly qualify.
        Hide
        github-import GitHub Import added a comment -

        [Date: Thu Apr 03 08:58:33 CEST 2014, Author: vlsi]

        Ok, then I will add UDFs to the root schema. UDF in root schema works without qualification.

        As optiq does not support `emp.address.location.city.name` expressions (even without recursive types), I am going to use UDF workaround: `getref(emp, "address.location.city.name")`.

        Show
        github-import GitHub Import added a comment - [Date: Thu Apr 03 08:58:33 CEST 2014, Author: vlsi ] Ok, then I will add UDFs to the root schema. UDF in root schema works without qualification. As optiq does not support `emp.address.location.city.name` expressions (even without recursive types), I am going to use UDF workaround: `getref(emp, "address.location.city.name")`.
        Hide
        github-import GitHub Import added a comment -

        [Date: Thu Apr 03 19:22:29 CEST 2014, Author: julianhyde]

        I like how you are testing (and breaking!) other parts of the system while working around other missing features. Thanks for your patience! We'll get it all working soon, I promise.

        Show
        github-import GitHub Import added a comment - [Date: Thu Apr 03 19:22:29 CEST 2014, Author: julianhyde ] I like how you are testing (and breaking!) other parts of the system while working around other missing features. Thanks for your patience! We'll get it all working soon, I promise.
        Hide
        github-import GitHub Import added a comment -

        [Date: Fri Apr 04 22:49:47 CEST 2014, Author: julianhyde]

        Relevant bits from SQL 2011:

        > 4.28: The value specified by `CURRENT_PATH` is the value of the SQL-path of the current SQL-session. This SQL-path is used to search for the subject routine of a <routine invocation> whose <routine name> does not contain a <schema name> when the <routine invocation> is contained in <preparable statement>s that are prepared in the current SQL-session by either an <execute immediate statement> or a <prepare statement>, or contained in <direct SQL statement>s that are invoked directly.

        > 19.8 <set path statement>

        The syntax is `SET PATH <value specification>`.

        > 11.1 Schema definition

        A schema may have a path. Syntax is `CREATE SCHEMA name [ PATH schemaName [ , schemaName ]... ] etc.`

        Show
        github-import GitHub Import added a comment - [Date: Fri Apr 04 22:49:47 CEST 2014, Author: julianhyde ] Relevant bits from SQL 2011: > 4.28: The value specified by `CURRENT_PATH` is the value of the SQL-path of the current SQL-session. This SQL-path is used to search for the subject routine of a <routine invocation> whose <routine name> does not contain a <schema name> when the <routine invocation> is contained in <preparable statement>s that are prepared in the current SQL-session by either an <execute immediate statement> or a <prepare statement>, or contained in <direct SQL statement>s that are invoked directly. > 19.8 <set path statement> The syntax is `SET PATH <value specification>`. > 11.1 Schema definition A schema may have a path. Syntax is `CREATE SCHEMA name [ PATH schemaName [ , schemaName ]... ] etc.`

          People

          • Assignee:
            Unassigned
            Reporter:
            github-import GitHub Import
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development