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

Cast expr to target type should respect nullable when it is complex type

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.34.0
    • 1.35.0
    • core

    Description

      // code placeholder
       
      // code placeholder
      sql("select cast(array[1,null,2] as int array) from (values (1))")
      .columnType("INTEGER NOT NULL ARRAY NOT NULL");
      
      it is not correct, it should return INTEGER ARRAY NOT NULL   

       

      according the sql standard, cast to type, which can not be nulable and nullable is tabel level attribute which can not changed by cast.

      current the calcite cast will using nullable of expr to replace target type , it is true. but it shoud also set array element type

      // code placeholder
      /** Derives the type of "CAST(expression AS targetType)". */
      public static RelDataType deriveType(RelDataTypeFactory typeFactory,
          RelDataType expressionType, RelDataType targetType, boolean safe) {
        return typeFactory.createTypeWithNullability(targetType,
            expressionType.isNullable() || safe);
      } 

       

      Attachments

        Issue Links

          Activity

            People

              jackylau Jacky Lau
              jackylau Jacky Lau
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: