Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4199 Add nullability annotations to the methods and fields, ensure consistency with checkerframework
  3. CALCITE-4311

Add non-nullable experimental accessors side by side with their nullable counterparts

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.25.0
    • None
    • None
    • None

    Description

      Certain APIs are declared to return nullable values, however, they are often used in "I know this must be non-null" context.

      For instance: Wrapper#unwrap(Class).
      It happens so that .unwrap(Table.class) is quite common.
      For instance:

                  final Table leftTable = leftRelOptTable.unwrap(Table.class);
                  final int leftCount = leftRelOptTable.getRowType().getFieldCount();
      

      It would be nice if unwrap could fail with a proper message like "oh, I can't find Table in ...", so the end users would get better error messages, and the code would be way easier to read.

      For instance:

      // unwrapNonNull can be declared as a default implementation
                  final Table leftTable = leftRelOptTable.unwrapOrThrow(Table.class);
                  final int leftCount = leftRelOptTable.getRowType().getFieldCount();
      

      Another case is org.apache.calcite.sql.SqlSelect#getSelectList. The method returns a nullable value, however, it is often used as if it was non-nullable.

      Initially, I thought of adding static helper methods to utility classes/interfaces, however, now I'm inlined to adding non-nullable getters right to the original classes/interfaces.
      That would make the code easier to read and write.

      Another quite common case is metadata: sometimes users need non-null value for the metadata, so it would be nice to have a default value via argument or throw in case of missing metadata.
      See CALCITE-4215

      Attachments

        Activity

          People

            Unassigned Unassigned
            vladimirsitnikov Vladimir Sitnikov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: