Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-19031

Sql. Joins with USING condition do not use type coercion rules.

Agile BoardAttach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 3.0.0-beta2
    • None
    • sql
    • Docs Required, Release Notes Required

    Description

      JOINs with USING condition do not use type coercion and that causes some queries to fail with ClassCastException, even though equivalent JOINs complete successfully.

      sql("CREATE TABLE T11 (c1 int primary key, c2 INTEGER)");
      sql("CREATE TABLE T12 (c1 BIGINT primary key, c2 BIGINT)");
      
      Transaction tx = CLUSTER_NODES.get(0).transactions().begin();
      sql(tx, "INSERT INTO T11 VALUES(1, 2)");
      sql(tx, "INSERT INTO T11 VALUES(2, 3)");
      sql(tx, "INSERT INTO T12 VALUES(1, 2)");
      sql(tx, "INSERT INTO T12 VALUES(2, 4)");
      tx.commit();
      
      sql("SELECT * FROM t11 JOIN t12 USING (c1)");
      

      Error:

      Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Long (java.lang.Integer and java.lang.Long are in module java.base of loader 'bootstrap')
      	at org.apache.ignite.internal.util.ColocationUtils.append(ColocationUtils.java:71)
      	at org.apache.ignite.internal.sql.engine.util.HashFunctionFactoryImpl$TypesAwareHashFunction.hashOf(HashFunctionFactoryImpl.java:116)
      	at org.apache.ignite.internal.sql.engine.trait.Partitioned.targets(Partitioned.java:47)
      	at org.apache.ignite.internal.sql.engine.exec.rel.Outbox.flush(Outbox.java:242)
      	at org.apache.ignite.internal.sql.engine.exec.rel.Outbox.push(Outbox.java:151)
      	at org.apache.ignite.internal.sql.engine.exec.rel.SortNode.flush(SortNode.java:193)
      	at org.apache.ignite.internal.sql.engine.exec.rel.SortNode.end(SortNode.java:154)
      

      An equivalent query passes with no issues:

      sql("SELECT * FROM t11 JOIN t12 ON t11.c1 = t12.c1");
      

      Solution

      Because JOINs that use USING join condition are equivalent to JOINs that use ON condition, It would be better to rewrite USING condition with equivalent ON condition prior to optimisation (even at the parsing stage) to leverage the code that handles type coercion.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            mzhuravkov Maksim Zhuravkov

            Dates

              Created:
              Updated:

              Slack

                Issue deployment