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

JdbcAdapter: Cast for dynamic filter arguments is lost

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.36.0
    • None
    • jdbc-adapter
    • None

    Description

      Hey, 

      today we encouraged some issues with the jdbc adapter behaviour.

      We have a statement like this:

      SELECT CASE WHEN CAST(? AS VARCHAR) = CAST(? AS VARCHAR) THEN "NAME" END
      FROM "AUTHORS"
      The parameters are ["some", 1].
      

      The statement that is pushed via JDBC Adapter looks like this:

      SELECT CASE WHEN ? =  ? THEN "NAME" END
      FROM "AUTHORS"
      

      The cast in the resulting statement is lost and therefore we get:
      ERROR: operator does not exist: character varying = integer Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

      As this example is not minimal I was able to reproduce it with the following test in JdbcTests:

        @Test void testFilterPush() {
          CalciteAssert.that()
              .with(CalciteAssert.Config.FOODMART_CLONE)
              .query("SELECT * FROM \"foodmart\".\"sales_fact_1997\"" +
                     " WHERE cast(? as varchar) = cast(? as varchar)")
              .planHasSql("SELECT *\n" +
                          "FROM \"foodmart\".\"sales_fact_1997\"\n" +
                          "WHERE cast(? as varchar) = cast(? as varchar)");
        }
      

      The test shows the exact behaviour as it fails with the following:
      Caused by: java.sql.SQLSyntaxErrorException: data type cast needed for parameter or null literal in statement [SELECT *
      FROM "foodmart"."sales_fact_1997"
      WHERE ? = ?

      As can be seen in the exception message, the cast is also lost in this scenario

      To me it seems like an obvious bug, but maybe I am missing something here.
      I hope some1 can help

      BR,
      Corvin

      Attachments

        Activity

          People

            Unassigned Unassigned
            corvinkuebler Corvin Kuebler
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: