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

Equality of nested ROWs returns false for identical literal value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.21.0
    • 1.22.0
    • None

    Description

      Similar to CALCITE-3021.
      Problem can be reproduced via:

      select * from
      (values
          (1, ROW(1,1)),
          (2, ROW(2,2)),
          (3, ROW(1,1)),
          (4, ROW(2,2))) as t(id,struct)
      where t.struct = ROW(2,2);
      

      which returns no results, instead of the expected (I have run the same query in PostgreSQL, and it returns this result):

      +----+--------+
      | ID | STRUCT |
      +----+--------+
      |  2 | {2, 2} |
      |  4 | {2, 2} |
      +----+--------+
      

      The issue is that the comparison is done via SqlFunctions#eq(Object b0, Object b1)

      public static boolean eq(Object b0, Object b1) {
        return b0.equals(b1);
      }
      

      And in this case we have two different Object[], with the same content, so they should be identified as equals (but they are not, based on Object#equals). Probably the simplest solution would be overloading the eq method for Object[] parameters:

      public static boolean eq(Object[] b0, Object[] b1) {
        return Arrays.deepEquals(b0, b1);
      }
      

      Attachments

        Issue Links

          Activity

            People

              rubenql Ruben Q L
              rubenql Ruben Q L
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

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