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

The type of generated search argument literal is wrong if the literal types of RelBuilder.in are different and compatible

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • core

    Description

      The type of resulted search argument literal is wrong if the literal types of RelBuilder.in are different and compatible with each other.
      For example,

        /**
         * Custom type system that converts different length of CHAR type to VARCHAR type.
         */
        public static class VaryingTypeSystem extends RelDataTypeSystemImpl {
      
          public static final RelDataTypeSystem INSTANCE = new VaryingTypeSystem();
      
          @Override public boolean shouldConvertRaggedUnionTypesToVarying() {
            return true;
          }
        }
      
          RelBuilder relBuilder = RelBuilder.create(config().typeSystem(VaryingTypeSystem.INSTANCE).build());
          relBuilder.scan("EMP");
          RexNode condition = relBuilder.in(relBuilder.field("JOB"), relBuilder.literal("CLERK"), relBuilder.literal("A"));
      
      

      In the above example, we overwrite the shouldConvertRaggedUnionTypesToVarying to suggest the least restrictive type of a number of CHAR types of different lengths should be a VARCHAR type.
      We expect the type of the generated SARGS literal to be VACHAR(5).
      Actually, the type of generated SARGS literal is CHAR(5) and the literal with value 'A' is converted to char(5), which leads to wrong result data.

      Attachments

        1. screenshot-3.png
          327 kB
          Jing Zhang
        2. screenshot-2.png
          282 kB
          Jing Zhang
        3. screenshot-1.png
          248 kB
          Jing Zhang
        4. image-2021-11-23-10-31-05-137.png
          359 kB
          jingzhang#1

        Issue Links

          Activity

            People

              Unassigned Unassigned
              jingzhang Jing Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              7 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 - 2.5h
                  2.5h