-
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
Add replace statement to sql parser #12386
Add replace statement to sql parser #12386
Conversation
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/DruidSqlReplace.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.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/DruidSqlReplace.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/planner/DruidPlanner.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.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.
Changes and tests look LGTM. Some NIT comments. Also, since we are reusing a lot of Calcite's rules for column and table names, can you please confirm we are not allowing a superset of the actual grammar to pass through the syntax phase? (For example, where we have a column list, we only want the column name and not anything like col1 as alias1
. My guess is not since you have initialized the constructor, so it should be fine)
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.java
Outdated
Show resolved
Hide resolved
The reuse is taken from the standard SqlInsert which DruidSqlInsert wraps, that has been restricted by trimming some of the syntax as you noted, so even at worst, it shouldn't be more than what is currently allowed in INSERT syntax. |
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.
LGTM
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/DruidSqlReplace.java
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidPlanner.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/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java
Outdated
Show resolved
Hide resolved
case LESS_THAN: | ||
columnValuePair = createColumnValuePair(sqlBasicCall.getOperandList(), dateTimeZone); | ||
return new BoundDimFilter(columnValuePair.left, null, columnValuePair.right, null, true, null, null, StringComparators.NUMERIC); | ||
default: |
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.
we should also add support for BETWEEN if possible.
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 support. One thing to note is that BETWEEN in sql is inclusive for the interval. This might lead to some strange queries in most use cases, like __time BETWEEN TIMESTAMP '2000-01-01' AND TIMESTAMP '2000-01-31 23:59:59.999'
. Should we stick with convention or make the end time exclusive?
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class CalciteReplaceDmlTest extends CalciteIngestionDmlTest |
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.
Please also add tests for negative scenarios where users are trying to use REPLACE
in a way that is not supported.
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.
There are tests for the following negative scenarios
- Invalid or missing overwrite where clause
- Unsupported operator in overwrite where
- A column other than __time is used in the query
- Misaligned partition in the query
- With no partition spec
- Interval is empty
Are there any other scenarios I have missed that I should add tests for?
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.
Question - Is ORDER BY or any other similar clauses prohibited in the REPLACE statement?
And, If so, can do tests for those need to be added?
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 test for this
sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java
Outdated
Show resolved
Hide resolved
sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlUnparseTest.java
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.
+1 after CI
Relevant Issue: #11929
This PR has: