-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
* Sub-classes must override the method to ensure the resulting value is non-nullable. | ||
* | ||
* @return SqlTypeName, never null | ||
*/ | ||
public SqlTypeName getSqlTypeName() { | ||
return null; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
See https://issues.apache.org/jira/browse/CALCITE-4214