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

Order of fields in JavaTypeFactoryImpl#createStructType is unstable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Major
    • Resolution: Unresolved
    • 1.17.0
    • None
    • core

    Description

      JavaTypeFactoryImpl#createStructType relies on java.lang.Class#getFields to get public fields, however it does not sort elements.

      That might produce confusing results since Calcite relies on field order.
      That might result in flaky tests as well (as execution plans rely on field order).

      There are other #getFields usages.
      For instance: org.apache.calcite.rel.type.RelDataTypeFactoryImpl#fieldsOf, org.apache.calcite.interpreter.TableScanNode#createQueryable, etc.

      It looks like we should implement Calcite-specific sort of the fields, and avoid adding new usages getFields to Calcite code.

      For instance:
      a) We might want to sort the fields from the super class to derived class. That is derived fields should come after the fields of a base class.
      b) When annotation is missing, we might want to sort fields on field names/field types (so the order is consistent)
      c) Add field-level annotation @CalciteField(int order)
      d) We might want to exclude certain fields by flagging with annotation as well (e.g. @CalciteField(exclude=true)

      Note: a and b are enough to get consistent field order.

      Attachments

        Issue Links

          Activity

            People

              asolimando Alessandro Solimando
              vladimirsitnikov Vladimir Sitnikov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

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