I am trying to setup a simple function that converts ISO8601 format date string to sql date as below:

Connection conn = DriverManager.getConnection("jdbc:calcite:", info);
        CalciteConnection calConn = conn.unwrap(CalciteConnection.class);
        calConn.getRootSchema().add("employee", new JsonTable());
calConn.getRootSchema().add("TO_DATE_ISO8601", ScalarFunctionImpl.create(
            MyFunctions.class, "to_date_iso8601"));

        String query =
"select * from \"employee\" \"e\" where \"join_date\" < to_date_iso8601('2016-04-05T22:42:15+05:00')";

    The function is given below:

     public static class MyFunctions
    {
public static java.sql.Date to_date_iso8601(String str) throws Exception
        {
            long t = DatatypeFactory.newInstance().newXMLGregorianCalendar(
                str).toGregorianCalendar().getTime().getTime();
            return new java.sql.Date(t);
        }
    }

    The error I am getting when I run is:

Caused by: java.lang.RuntimeException: Error while compiling generated Java code:
org.apache.calcite.DataContext root;

public org.apache.calcite.linq4j.Enumerable bind(final org.apache.calcite.DataContext root0) {
  root = root0;
final org.apache.calcite.rel.RelNode v0stashed = (org.apache.calcite.rel.RelNode) root.get("v0stashed"); final org.apache.calcite.interpreter.Interpreter _inputEnumerable = new org.apache.calcite.interpreter.Interpreter(
    root,
    v0stashed);
  return new org.apache.calcite.linq4j.AbstractEnumerable(){
      public org.apache.calcite.linq4j.Enumerator enumerator() {
        return new org.apache.calcite.linq4j.Enumerator(){
public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable.enumerator();
            public void reset() {
              inputEnumerator.reset();
            }

            public boolean moveNext() {
              while (inputEnumerator.moveNext()) {
final Object[] current = (Object[]) inputEnumerator.current(); if (org.apache.calcite.runtime.SqlFunctions.internalToDate(current[3]) != null && com.kalkitech.calcite.Main.MyFunctions.to_date_iso8601("2016-04-05T22:42:15+05:00") != null && (Integer) current[3] < org.apache.calcite.runtime.SqlFunctions.toIntOptional(com.kalkitech.calcite.Main.MyFunctions.to_date_iso8601("2016-04-05T22:42:15+05:00"))) {
                  return true;
                }
              }
              return false;
            }

            public void close() {
              inputEnumerator.close();
            }

            public Object current() {
final Object[] current = (Object[]) inputEnumerator.current();
              return new Object[] {
                  current[0],
                  current[1],
                  current[2],
                  current[3]};
            }

          };
      }

    };
}


public Class getElementType() {
  return java.lang.Object[].class;
}


Caused by: org.codehaus.commons.compiler.CompileException: Line 20, Column 76: No applicable constructor/method found for actual parameters "java.lang.Object"; candidates are: "public static java.sql.Date org.apache.calcite.runtime.SqlFunctions.internalToDate(java.lang.Integer)", "public static java.sql.Date org.apache.calcite.runtime.SqlFunctions.internalToDate(int)" at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:10092) at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:7506)

    What am I doing wrong here ? I am using calcite 1.7 and java 8.

-Regards
-SP
"Disclaimer: This message is being sent from Kalki Communication Technologies
Pvt Ltd (KALKITECH). and may contain information which is confidential or
privileged. If you are not the intended recipient, please advise the sender
immediately by reply e-mail and delete this message and any attachments
without retaining a copy. Any unauthorized use of the content of this message
can expose the responsible party to civil and/or criminal penalties,
and may constitute a more serious offense. Further the company does not accept
liability for any errors, omissions, viruses or computer problems
experienced as a result of this transmission. If you have received this
message in error, notice is hereby given that no representation, contract or other binding obligation shall be created by this e-mail."

Reply via email to