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

Extend the PARTITIONED BY clause to accept string literals for the time partitioning #15836

Merged
merged 12 commits into from
Feb 9, 2024

Conversation

zachjsh
Copy link
Contributor

@zachjsh zachjsh commented Feb 6, 2024

Description

This PR contains a portion of the changes from the inactive draft PR for integrating the catalog with the Calcite planner #13686 from @paul-rogers, extending the PARTITION BY clause to accept string literals for the time partitioning

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.

}
]
|
e = Expression(ExprContext.ACCEPT_SUB_QUERY)
{
granularity = DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e);
Copy link
Member

Choose a reason for hiding this comment

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

I think some validation should happen here; I don't see a nice way to do it but I've found this:

result = new SqlLiteral(DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e), SYMBOL, getPos());

which might work (but the typeName must be supplied - other candidate could be: UNKNOWN )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added validation here in another way, let me know if ok.

Copy link
Member

Choose a reason for hiding this comment

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

ok - but why not do the conversion here - I think you might also able to do similar thing on all the other branches

result = new SqlLiteral(DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e), SYMBOL, getPos());

you could shortcut the transient String + Symbol stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a new SqlNode type, let me know if good now.

Copy link
Contributor

@abhishekrb19 abhishekrb19 left a comment

Choose a reason for hiding this comment

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

Had a few questions and suggestions. Also, to future proof this new functionality, I would recommend adding tests in different parts of the code in case things get lost with refactoring or something breaks between Calcite upgrades. For example, https://github.com/apache/druid/blob/master/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java#L608 could be extended to test the newly added literal support.

Copy link
Contributor

@abhishekrb19 abhishekrb19 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @zachjsh!

Comment on lines +38 to +39
private String unparseString;
private Granularity granularity;
Copy link
Member

Choose a reason for hiding this comment

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

note: these can be final

@Override
public void unparse(SqlWriter writer, int leftPrec, int rightPrec)
{
if (unparseString != null) {
Copy link
Member

Choose a reason for hiding this comment

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

note: not sure if you need to be defensive here; its @NonNull in the constructor

}
}

private static Granularity convertSqlIdentiferToGranularity(SqlIdentifier identifier)
Copy link
Member

Choose a reason for hiding this comment

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

these 2 methods are almost identical; the difference is how they get to the String ; can you leave just one with a String arg - and do the X2String conversion before calling that method?

@zachjsh zachjsh merged commit f9ee2c3 into apache:master Feb 9, 2024
83 checks passed
@zachjsh zachjsh deleted the partition-by-accepts-string-literals branch February 9, 2024 16:45
zachjsh added a commit to zachjsh/druid that referenced this pull request Feb 24, 2024
zachjsh added a commit that referenced this pull request Mar 25, 2024
…urce input expressions (#15962)

* * address remaining comments from #15836

* *  address remaining comments from #15908

* * add test that exposes relational algebra issue

* * simplify test exposing issue

* * fix

* * add tests for sealed / non-sealed

* * update test descriptions

* * fix test failure when -Ddruid.generic.useDefaultValueForNull=true

* * check type assignment based on natice Druid types

* * add tests that cover missing jacoco coverage

* * add replace tests

* * add more tests and comments about column ordering

* * simplify tests

* * review comments

* * remove commented line

* * STRING family types should be validated as non-null
@abhishekrb19 abhishekrb19 changed the title Extend the PARTITION BY clause to accept string literals for the time partitioning Extend the PARTITIONED BY clause to accept string literals for the time partitioning Apr 9, 2024
@adarshsanjeev adarshsanjeev added this to the 30.0.0 milestone May 6, 2024
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