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

IGNITE-23008 SQL Calcite: Fix binary type dynamic parameter type coercion #11606

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alex-plekhanov
Copy link
Contributor

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

  • There is a single JIRA ticket related to the pull request.
  • The web-link to the pull request is attached to the JIRA ticket.
  • The JIRA ticket has the Patch Available state.
  • The pull request body describes changes that have been made.
    The description explains WHAT and WHY was made instead of HOW.
  • The pull request title is treated as the final commit message.
    The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
  • A reviewer has been mentioned through the JIRA comments
    (see the Maintainers list)
  • The pull request has been checked by the Teamcity Bot and
    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.

@@ -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)))
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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,

Copy link
Contributor Author

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));
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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) :
Copy link
Contributor

@Vladsz83 Vladsz83 Oct 21, 2024

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link

sonarcloud bot commented Oct 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants