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

Sql. Conditions in NATURAL JOINs do not use type coercion rules.

    XMLWordPrintableJSON

Details

    • Docs Required, Release Notes Required

    Description

      NATURAL JOINs 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 NATURAL JOIN t12");
      

      Error:

      Caused by: java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
      	at org.apache.ignite.internal.util.ColocationUtils.append(ColocationUtils.java:67)
      	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)
      	a
      

      An equivalent query passes with no issues:

      SELECT * FROM t11 JOIN t12 ON t11.c1 = t12.c1 AND t11.c2 = t12.c2
      

      Solution

      Because NATURAL JOINs equivalent to JOINs that with ON condition, it would be better to rewrite them with equivalent JOINs with ON conditions prior to optimisation (even at the parsing stage) to leverage the code that handles type coercion.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mzhuravkov Maksim Zhuravkov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: