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

Allow casted literal values in SQL functions accepting literals (Part 2) #15316

Merged
merged 4 commits into from
Nov 3, 2023

Conversation

LakshSingla
Copy link
Contributor

@LakshSingla LakshSingla commented Nov 2, 2023

Description

This is a follow-up to #15282. I missed a few instances of type checkers being used which internally used the OperandTypes.LITERAL, causing the same issue as described in the mentioned PR. This PR cleans up those usages as well, and unfortunately duplicates a fair bit of code from Calcite, to change a few calls which define whether or not casted literals can be used or not.

Release note


Key changed/added classes in this PR
  • MyFoo
  • OurBar
  • TheirBaz

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@cryptoe cryptoe added this to the 28.0 milestone Nov 3, 2023

import java.math.BigDecimal;

public class CastedLiteralOperandTypeCheckers
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: What are the implications of this during calcite upgrade ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or better yet move them to apache calcite ?

Copy link
Contributor Author

@LakshSingla LakshSingla Nov 3, 2023

Choose a reason for hiding this comment

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

Nit: What are the implications of this during the Calcite upgrade?

Since this code is a copy & paste from the Calcite, on upgrading Calcite (minor version), it'd be good to check if anything major has changed it in the code. On a major version upgrade, the interfaces and method signatures are likely to change so we'd probably have to copy & paste the new class with the desired changes.

Or better yet move them to Apache Calcite?

Casting a literal isn't a very valid operation. Either the type-checking code should allow the dynamic parameters (in Calcite), or we need a different way to replace the parameters. This is kind of a hacky fix, which allows CAST on literals using the type checker in the code. The real fix would be to allow the users to not write dynamic parameters with CAST.

The only downside with this approach, and Druid 28 is that since we are suggesting users do a CAST(? AS TYPE) while writing JDBC queries, we would need to support this method even if we fix the real reason because users might be writing the queries with an explicit cast. However, that cannot be helped by this fix. This just allows what users have been advised to pass through the Druid's functions.

@LakshSingla
Copy link
Contributor Author

LakshSingla commented Nov 3, 2023

There would be a few code coverage failures, which is expected, given that I have copied functions from Calcite. Adding a few negative tests might improve it but won't fix it completely, so I am favor of leaving them as is.

@LakshSingla LakshSingla merged commit 0cc8839 into apache:master Nov 3, 2023
77 of 82 checks passed
abhishekagarwal87 pushed a commit that referenced this pull request Nov 4, 2023
CaseyPan pushed a commit to CaseyPan/druid that referenced this pull request Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants