Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CALCITE-4214] Make RelDataType.getSqlTypeName non-nullable #2135

Merged
merged 1 commit into from
Sep 27, 2020

Conversation

vlsi
Copy link
Contributor

@vlsi vlsi commented Sep 2, 2020

* Sub-classes must override the method to ensure the resulting value is non-nullable.
*
* @return SqlTypeName, never null
*/
public SqlTypeName getSqlTypeName() {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this null? How about SqlTypeName.ANY ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code was like that for ages, and this return null is never used in Calcite (it is always overridden).
Another option could be removing this implementation (the class is abstract anyway), however, that sounds like a backward-incompatible change, so I just kept the method as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks weird, the document says it never returns null but there is a default code returns null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we replace it with another SqlTypeName instead of null ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid no any default value is suitable here, for example SqlTypeName .ANY, because each SqlTypeName has a specific semantic, there is no default, returns a default value will cause confusion in some cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no default value is suitable, maybe we should throw an UnSupportedOperationException here to make sure it is always overriden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to un-implement the method, however, it might happen that there is third-party code that extends the class, and it keeps the default return null implementation. It might even be the case that the default null implementation works because the code never tries to call methods on the result of getSqlTypeName().

That is why I'm inclined to keep the default return null, and deal with it later (e.g. announce the method would become abstract in 6 months).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in case, there's getSqlIdentifier:

  public SqlTypeName getSqlTypeName() {
    // The implementations must provide non-null value, however, we keep this for compatibility
    return castNonNull(null);
  }

  public @Nullable SqlIdentifier getSqlIdentifier() {
    SqlTypeName typeName = getSqlTypeName();
    if (typeName == null) {
      return null;
    }

So I would keep the method return null as before.

@vlsi vlsi added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Sep 4, 2020
@vlsi vlsi merged commit 0d52063 into apache:master Sep 27, 2020
@vlsi vlsi deleted the getSqlTypeName branch November 15, 2020 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants