-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
IGNITE-23008 SQL Calcite: Fix binary type dynamic parameter type coercion #11606
Conversation
@@ -315,7 +316,7 @@ public RelDataType createCustomType(Type type) { | |||
public RelDataType createCustomType(Type type, boolean nullable) { | |||
if (UUID.class == type) | |||
return canonize(new UuidType(nullable)); | |||
else if (Object.class == type) | |||
else if (Object.class == type || (type instanceof Class && BinaryObject.class.isAssignableFrom((Class<?>)type))) |
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.
type instanceof Class
looks useless
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? In case of not Class
type we can get an exception on cast to Class
, so it's safer to check type.
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 think we can't get any problem here. Calcite expects a class in createType(Type type)
:
if (!(type instanceof Class)) { throw new UnsupportedOperationException("TODO: implement " + type); } final Class clazz = (Class) type;
An assert
looks enough to me. Up to you,
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.
In createType
we call super.createType
if custom type is null. So type
other than Class
can be processed by superclass.
@@ -315,7 +316,7 @@ public RelDataType createCustomType(Type type) { | |||
public RelDataType createCustomType(Type type, boolean nullable) { | |||
if (UUID.class == type) | |||
return canonize(new UuidType(nullable)); | |||
else if (Object.class == type) | |||
else if (Object.class == type || (type instanceof Class && BinaryObject.class.isAssignableFrom((Class<?>)type))) | |||
return canonize(new OtherType(nullable)); |
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.
Actually, canonize()
is not working for IgniteCustomType
. Does nothing
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.
It canonized by DATATYPE_CACHE.intern
and always return the same instance for OtherType
. Why do you think it does nothing?
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.
This is the reason. It always return the same value.
|
||
setValidatedNodeType(node, (param == null) ? typeFactory().createSqlType(SqlTypeName.NULL) : | ||
typeFactory().toSql(typeFactory().createType(param.getClass()))); | ||
setValidatedNodeType(node, (param == null) ? typeFactory().createSqlType(SqlTypeName.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.
typeFactory().createSqlType(SqlTypeName.NULL)
might be cached. The brackets (param == null)
can be removed too.
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.
typeFactory().createSqlType(SqlTypeName.NULL)
used only once. Where it might be cached?
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.
In IgniteSqlValidator
for example. No need to create type every time for every null param.
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.
Planning is a resource consuming process, types caching during planning does not give any performance boost. I don't know why, but types are not cached in Calcite anywhere. On the other hand we cache it during execution (see ExpressionFactoryImpl#nullType), since it's more critical here.
e37fada
to
19de95e
Compare
} | ||
else | ||
assertEquals(F.asList(p0), res.get(0).get(0)); | ||
|
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.
Useless linebreak
|
Fixes apache#11606. Signed-off-by: Aleksey Plekhanov <[email protected]>
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
The Contribution Checklist
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summary
whereXXXX
- number of JIRA issue.(see the Maintainers list)
the
green visa
attached to the JIRA ticket (see TC.Bot: Check PR)Notes
If you need any help, please email [email protected] or ask anу advice on http://asf.slack.com #ignite channel.