You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2022/02/09 17:17:06 UTC

[GitHub] [druid] LakshSingla opened a new pull request #12246: Surface a user friendly error when PARTITIONED BY is omitted

LakshSingla opened a new pull request #12246:
URL: https://github.com/apache/druid/pull/12246


   ### Description
   
   https://github.com/apache/druid/pull/12163 makes `PARTITIONED BY` a required clause in INSERT queries. While this is required, if a user accidentally omits the clause, it emits a JavaCC/Calcite error, since it's syntactically incorrect. The error message is cryptic. Since it's a custom clause, this PR aims to make the clause optional on the syntactic side, but move the validation to `DruidSqlInsert` where we can surface a friendlier error. 
   ```
   Older error message:
   Was expecting one of: "PARTITIONED" ... "ORDER" ... "LIMIT" ... "OFFSET" ... "FETCH" ... "NATURAL" ... "JOIN" ... "INNER" ... "LEFT" ... "RIGHT" ... "FULL" ... "CROSS" ... "," ... "OUTER" ... "EXTEND" ... "(" ... "FOR" ... "MATCH_RECOGNIZE" ... "." ... "AS" ... <IDENTIFIER> ... <QUOTED_IDENTIFIER> ... <BACK_QUOTED_IDENTIFIER> ... <BRACKET_QUOTED_IDENTIFIER> ... <UNICODE_QUOTED_IDENTIFIER> ... "TABLESAMPLE" ... "WHERE" ... "GROUP" ... "HAVING" ... "WINDOW" ... "UNION" ... "INTERSECT" ... "EXCEPT" ... "MINUS"
   
   Newer error message:
   INSERT statements should specify PARTITIONED BY clause explicitly.
   ```
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `insert.ftl`
    * `DruidSqlInsert`
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [x] 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](https://github.com/apache/druid/blob/master/dev/license.md)
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] abhishekagarwal87 merged pull request #12246: Surface a user friendly error when PARTITIONED BY is omitted

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 merged pull request #12246:
URL: https://github.com/apache/druid/pull/12246


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] LakshSingla commented on a change in pull request #12246: Surface a user friendly error when PARTITIONED BY is omitted

Posted by GitBox <gi...@apache.org>.
LakshSingla commented on a change in pull request #12246:
URL: https://github.com/apache/druid/pull/12246#discussion_r803706160



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
##########
@@ -62,10 +68,14 @@ public DruidSqlInsert(
         insertNode.getSource(),
         insertNode.getTargetColumnList()
     );
-    Preconditions.checkNotNull(partitionedBy); // Shouldn't hit due to how the parser is written
+    if (partitionedBy == null) {
+      throw new ParseException("INSERT statements should specify PARTITIONED BY clause explictly");

Review comment:
       Updated the error message. Thanks for the tip. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] gianm commented on a change in pull request #12246: Surface a user friendly error when PARTITIONED BY is omitted

Posted by GitBox <gi...@apache.org>.
gianm commented on a change in pull request #12246:
URL: https://github.com/apache/druid/pull/12246#discussion_r803071379



##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
##########
@@ -62,10 +68,14 @@ public DruidSqlInsert(
         insertNode.getSource(),
         insertNode.getTargetColumnList()
     );
-    Preconditions.checkNotNull(partitionedBy); // Shouldn't hit due to how the parser is written
+    if (partitionedBy == null) {
+      throw new ParseException("INSERT statements should specify PARTITIONED BY clause explictly");

Review comment:
       The word "must" is better than "should" here. (RFC 2119 doesn't govern here, but is still a helpful guide for technical writing. "Should" means "recommended, but not strictly required".)

##########
File path: sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlInsert.java
##########
@@ -48,12 +48,18 @@
   @Nullable
   private final SqlNodeList clusteredBy;
 
+  /**
+   * While partitionedBy and partitionedByStringForUnparse can be null as arguments to the constructor, this is
+   * disallowed (semantically) and the constructor performs checks to ensure that. This helps in producing friendly
+   * errors when the PARTITIONED BY custom clause is not present, and keeps its error separate from JavaCC/Calcite's
+   * custom errors which can be cryptic when someone accidentaly forgets to explicitly specify the PARTITIONED BY clause

Review comment:
       accidentally (spelling)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org