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

Query with ORDER BY or GROUP BY on TIMESTAMP column throws CompileException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.11.0
    • Fix Version/s: 1.12.0
    • Component/s: core
    • Labels:
      None
    • Flags:
      Important

      Description

      Getting below error while executing the 'order by' or 'group by' queries with timestamp data type column.

      Caused by: org.codehaus.commons.compiler.CompileException: Line 11, Column 76: No applicable constructor/method found for actual parameters "java.lang.Object"; candidates are: "public static java.sql.Timestamp org.apache.calcite.runtime.SqlFunctions.internalToTimestamp(java.lang.Long)", "public static java.sql.Timestamp org.apache.calcite.runtime.SqlFunctions.internalToTimestamp(long)"
      

      I could able to reproduce this problem in CsvTests.
      Fire a test with query "select * from \"DATE\" order by \"JOINTIMES\"" you will see test failing with exception.

      Root cause and fix:
      The fix for this to overload the SqlFunctions.internalToTimestamp() to accept the timestamp or object and return timestamp value. I tested and it's working

      Stack trace
      at org.apache.calcite.avatica.Helper.wrap(Helper.java:37)
      	at org.apache.calcite.adapter.enumerable.EnumerableInterpretable.toBindable(EnumerableInterpretable.java:108)
      	at org.apache.calcite.prepare.CalcitePrepareImpl$CalcitePreparingStmt.implement(CalcitePrepareImpl.java:1233)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:303)
      	at org.apache.calcite.prepare.Prepare.prepareSql(Prepare.java:200)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare2_(CalcitePrepareImpl.java:761)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepare_(CalcitePrepareImpl.java:617)
      	at org.apache.calcite.prepare.CalcitePrepareImpl.prepareSql(CalcitePrepareImpl.java:587)
      	at org.apache.calcite.jdbc.CalciteConnectionImpl.parseQuery(CalciteConnectionImpl.java:214)
      	at org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:595)
      	at org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:615)
      	at org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:148)
      	... 29 more
      Caused by: org.codehaus.commons.compiler.CompileException: Line 11, Column 76: No applicable constructor/method found for actual parameters "java.lang.Object"; candidates are: "public static java.sql.Timestamp org.apache.calcite.runtime.SqlFunctions.internalToTimestamp(java.lang.Long)", "public static java.sql.Timestamp org.apache.calcite.runtime.SqlFunctions.internalToTimestamp(long)"
      	at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:10092)
      	at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:7506)
      	at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:7376)
      	at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:7280)
      	at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3850)
      	at org.codehaus.janino.UnitCompiler.access$6900(UnitCompiler.java:183)
      	at org.codehaus.janino.UnitCompiler$10.visitMethodInvocation(UnitCompiler.java:3251)
      	at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:3974)
      	at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:3278)
      

        Issue Links

          Activity

          Hide
          julianhyde Julian Hyde added a comment -

          Resolved in release 1.12.0 (2017-03-24).

          Show
          julianhyde Julian Hyde added a comment - Resolved in release 1.12.0 (2017-03-24).
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/8e0d76bb . Thanks for the PR, Gangadhar Kairi !
          Hide
          Gkairi Gangadhar Kairi added a comment -

          Thanks for the update and quick resolution. Appreciate your support!!

          Show
          Gkairi Gangadhar Kairi added a comment - Thanks for the update and quick resolution. Appreciate your support!!
          Hide
          julianhyde Julian Hyde added a comment -

          I re-worked in https://github.com/julianhyde/calcite/commit/1706d67571be0fd69b87e658746e3f428e568ebd. The solution is to fix the compiler, not the run-time. I will squash and merge to master shortly.

          Show
          julianhyde Julian Hyde added a comment - I re-worked in https://github.com/julianhyde/calcite/commit/1706d67571be0fd69b87e658746e3f428e568ebd . The solution is to fix the compiler, not the run-time. I will squash and merge to master shortly.
          Hide
          Gkairi Gangadhar Kairi added a comment -

          Hi Julian,

          As suggested, created the pull request with the fix, please review and accept
          Link: https://github.com/apache/calcite/pull/389/commits

          Thanks,
          Gangadhar

          Show
          Gkairi Gangadhar Kairi added a comment - Hi Julian, As suggested, created the pull request with the fix, please review and accept Link: https://github.com/apache/calcite/pull/389/commits Thanks, Gangadhar
          Hide
          Gkairi Gangadhar Kairi added a comment -

          Thanks for the quick reply Julian. Yes, your insight is correct these are all related and the root cause with timestamp conversion to long. Do you have any insight on where this conversion is going wrong. I can spend sometime to fixing it because we are getting bunch of issues with this timestamp column.
          -Gangadhar

          Show
          Gkairi Gangadhar Kairi added a comment - Thanks for the quick reply Julian. Yes, your insight is correct these are all related and the root cause with timestamp conversion to long. Do you have any insight on where this conversion is going wrong. I can spend sometime to fixing it because we are getting bunch of issues with this timestamp column. -Gangadhar
          Hide
          julianhyde Julian Hyde added a comment -

          Gangadhar Kairi, I'm not sure that the extra function is the right solution. The compiler seems to think that the value is "internal" format (i.e. long) but apparently it is a java.sql.Timestamp. So your fix might be a band-aid for a deeper problem. But please submit a pull request with your fix, including test cases for both GROUP BY and ORDER BY, and we'll see if we can improve it.

          Show
          julianhyde Julian Hyde added a comment - Gangadhar Kairi , I'm not sure that the extra function is the right solution. The compiler seems to think that the value is "internal" format (i.e. long ) but apparently it is a java.sql.Timestamp . So your fix might be a band-aid for a deeper problem. But please submit a pull request with your fix, including test cases for both GROUP BY and ORDER BY, and we'll see if we can improve it.
          Hide
          julianhyde Julian Hyde added a comment -

          CALCITE-1054 and CALCITE-1427 are similar, and may be related.

          But, like CALCITE-1569, I'm not sure the answer is to convert to java.sql.Timestamp. Internally we should be using long (or java.lang.Long) values for timestamps.

          Show
          julianhyde Julian Hyde added a comment - CALCITE-1054 and CALCITE-1427 are similar, and may be related. But, like CALCITE-1569 , I'm not sure the answer is to convert to java.sql.Timestamp. Internally we should be using long (or java.lang.Long ) values for timestamps.
          Hide
          Gkairi Gangadhar Kairi added a comment - - edited

          Hi Julian,
          See if this fix is useful. new method in SqlFunctions.

          public static java.sql.Timestamp internalToTimestamp(Object v) {
              if (v == null ) {
                return null;
              } else if ( v instanceof Timestamp ) {
                return (Timestamp)v;
              }
              throw new RuntimeException(" Invalid type, cannot convert " + v + " to " + Timestamp.class.getName());
            }
          

          Please let me know if you are okay with this fix, so that shall create patch and pull request.

          Show
          Gkairi Gangadhar Kairi added a comment - - edited Hi Julian, See if this fix is useful. new method in SqlFunctions. public static java.sql.Timestamp internalToTimestamp( Object v) { if (v == null ) { return null ; } else if ( v instanceof Timestamp ) { return (Timestamp)v; } throw new RuntimeException( " Invalid type, cannot convert " + v + " to " + Timestamp.class.getName()); } Please let me know if you are okay with this fix, so that shall create patch and pull request.

            People

            • Assignee:
              julianhyde Julian Hyde
              Reporter:
              Gkairi Gangadhar Kairi
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified

                  Development