Skip to content

Instantly share code, notes, and snippets.

@miyakelp
Last active April 1, 2021 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyakelp/a89c1df9e11000b709da6d0a4f372175 to your computer and use it in GitHub Desktop.
Save miyakelp/a89c1df9e11000b709da6d0a4f372175 to your computer and use it in GitHub Desktop.
sparksql_please.diff
diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
index 55ba375..c4bbea8 100644
--- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
+++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
@@ -531,8 +531,12 @@ transformClause
(RECORDREADER recordReader=STRING)?
;
+pleasePhrase
+ : PLEASE
+ ;
+
selectClause
- : SELECT (hints+=hint)* setQuantifier? namedExpressionSeq
+ : pleasePhrase? SELECT (hints+=hint)* setQuantifier? namedExpressionSeq
;
setClause
@@ -1396,6 +1400,7 @@ nonReserved
| PERCENTLIT
| PIVOT
| PLACING
+ | PLEASE
| POSITION
| PRECEDING
| PRIMARY
@@ -1653,6 +1658,7 @@ PARTITIONS: 'PARTITIONS';
PERCENTLIT: 'PERCENT';
PIVOT: 'PIVOT';
PLACING: 'PLACING';
+PLEASE: 'PLEASE';
POSITION: 'POSITION';
PRECEDING: 'PRECEDING';
PRIMARY: 'PRIMARY';
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
index dc87398..48a71c5 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
@@ -736,8 +736,11 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with SQLConfHelper with Logg
createProject()
}
+ val please = selectClause.pleasePhrase() != null && selectClause.pleasePhrase().PLEASE() != null
+
// Distinct
val withDistinct = if (
+ !please ||
selectClause.setQuantifier() != null &&
selectClause.setQuantifier().DISTINCT() != null) {
Distinct(withProject)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment