-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Extend the PARTITIONED BY clause to accept string literals for the time partitioning #15836
Conversation
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java
Outdated
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlIngest.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlReplace.java
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
} | ||
] | ||
| | ||
e = Expression(ExprContext.ACCEPT_SUB_QUERY) | ||
{ | ||
granularity = DruidSqlParserUtils.convertSqlNodeToGranularityThrowingParseExceptions(e); |
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 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
)
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.
Added validation here in another way, let me know if ok.
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.
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
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.
Added a new SqlNode type, let me know if good now.
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Fixed
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Fixed
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlReplace.java
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java
Outdated
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlUnparseTest.java
Outdated
Show resolved
Hide resolved
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.
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.
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlReplace.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Show resolved
Hide resolved
sql/src/test/resources/calcite/expected/ingest/insertWithClusteredBy-logicalPlan.txt
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/SqlGranularityLiteral.java
Fixed
Show fixed
Hide fixed
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.
Thanks for the changes @zachjsh!
private String unparseString; | ||
private Granularity granularity; |
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.
note: these can be final
@Override | ||
public void unparse(SqlWriter writer, int leftPrec, int rightPrec) | ||
{ | ||
if (unparseString != 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.
note: not sure if you need to be defensive here; its @NonNull
in the constructor
} | ||
} | ||
|
||
private static Granularity convertSqlIdentiferToGranularity(SqlIdentifier identifier) |
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.
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?
…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
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: