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

The operand type inference of SqlMapValueConstructor is incorrect

    XMLWordPrintableJSON

Details

    Description

      we have a simple test case:

      f.checkScalar("map[1, null]", "{1=null}",
      "(INTEGER NOT NULL, NULL) MAP NOT NULL"); 

      The result is:

      java.lang.AssertionError: Query: values (map[1, null])
      Expected: is "(INTEGER NOT NULL, NULL) MAP NOT NULL"
           but: was "(INTEGER NOT NULL, INTEGER) MAP NOT NULL"
      

      however, the asserted actual result "(INTEGER NOT NULL, INTEGER) MAP NOT NULL" for this case is wrong. If we switch to  this asserted actual result it throws another exception:

      java.lang.AssertionError: Query: select map[p0, null] from (values (1)) as t(p0)
      Expected: is "(INTEGER NOT NULL, INTEGER) MAP NOT NULL"
           but: was "(INTEGER NOT NULL, NULL) MAP NOT NULL"
      

      No matter how you write this result type in this test case, it is wrong. 

      by checking the plan, it seems the deduced value type of NULL has converted to INTEGER.

      More serious scenario, if it is `map[1, 'x', 2, null]`, an exception will be thrown directly and fail.

      because the null converted to FIRST_KNOWN INTEGER(however it should keep NULL, then leaseRestrictive type will be char). 

      the form such as `map[1, null, 2,'x']` has same problem.

      Attachments

        Issue Links

          Activity

            People

              taoran Ran Tao
              taoran Ran Tao
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: