You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "dtenedor (via GitHub)" <gi...@apache.org> on 2025/11/10 22:55:16 UTC

[PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

dtenedor opened a new pull request, #52983:
URL: https://github.com/apache/spark/pull/52983

   ### What changes were proposed in this pull request?
   
   This PR adds support for `|` as an alternative to `|>` for the SQL pipe operator token, while maintaining full backwards compatibility with existing bitwise OR operations.
   
   For example, this is now supported:
   
   ```sql
   table t
   | select x, y
   | where x < 2;
   ```
   
   as an alternative to:
   
   ```sql
   table t
   |> select x, y
   |> where x < 2;
   ```
   
   The implementation uses a semantic predicate with 2-token lookahead (`isOperatorPipeStart()`) to disambiguate between:
   - **Pipe operators**: When `|` is followed by keywords like `SELECT`, `WHERE`, `EXTEND`, `JOIN`, etc.
   - **Bitwise OR**: When `|` is part of an expression (e.g., `col1 | col2`)
   
   This approach ensures that existing SQL queries using `|` for bitwise OR operations continue to work without any changes, including edge cases where column names match pipe operator keywords (e.g., `col1 | select` where `select` is a column name).
   
   ### Why are the changes needed?
   
   This provides syntax compatibility with other languages that use `|` for pipe operations, such as:
   - Splunk SPL
   - Kusto (KQL)
   - Unix shell pipes
   
   **Background:**
   
   We previously attempted this in https://github.com/apache/spark/pull/50284 but abandoned that approach because it inadvertently broke bitwise OR expression usage. After further investigation, we've developed a solution using ANTLR semantic predicates that properly disambiguates the two contexts.
   
   As discussed in that PR:
   - Jeff Shute (author of the SQL pipe syntax paper from Google) confirmed that Google uses an LALR parser which makes it impossible for them to support `|` due to ambiguity with bitwise operations
   - There is growing industry consensus that `|>` should be the primary/universal token, but engines may optionally support additional tokens
   - This approach aligns with how other databases have addressed this (see https://superdb.org/docs/language/pipe-ambiguity/)
   
   Spark's use of ANTLR (not LALR) enables us to support both tokens through lookahead-based disambiguation.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, users can now use `|` as a more concise alternative to `|>` for pipe operators.
   
   **This change is fully backwards-compatible:**
   - All existing queries using `|>` continue to work
   - All existing queries using `|` for bitwise OR continue to work
   - Users can even mix `|` and `|>` in the same query
   
   ### How was this patch tested?
   
   This PR includes comprehensive test coverage in `pipe-operators.sql`:
   
   **Positive tests:** All pipe operator types using `|` syntax:
   - SELECT, EXTEND, SET, DROP, AS, WHERE
   - PIVOT, UNPIVOT, TABLESAMPLE
   - JOIN (all types: inner, cross, left, right, full, semi, anti, lateral, natural)
   - Set operations (UNION, EXCEPT, INTERSECT, MINUS)
   - ORDER BY, LIMIT, OFFSET, DISTRIBUTE BY, CLUSTER BY
   - AGGREGATE, WINDOW
   - Chained operations with multiple pipe operators
   - Mixed `|` and `|>` syntax in the same query
   
   **Negative tests (backwards compatibility):** Bitwise OR operations with keyword column names:
   - Tested bitwise OR with columns named: `select`, `extend`, `set`, `drop`, `as`, `where`, `order`, `limit`, `aggregate`, `window`, `pivot`, `unpivot`, `join`, `union`, `intersect`, `except`
   - Complex bitwise OR expressions: `(col1 | select) + (where | order)`
   - Multiple bitwise OR chains: `col1 | select | where | order`
   - Bitwise OR in WHERE clauses: `where (col1 | select) > 2`
   
   All tests pass successfully.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes, `claude-4.5-sonnet` with manual review and editing.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #52983:
URL: https://github.com/apache/spark/pull/52983#discussion_r2528745591


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3849,6 +3849,16 @@ object SQLConf {
     .booleanConf
     .createWithDefault(false)
 
+  val SINGLE_CHARACTER_PIPE_OPERATOR_ENABLED =
+    buildConf("spark.sql.parser.singleCharacterPipeOperator.enabled")
+    .doc("When true, the single character pipe token '|' can be used as an alternative to '|>' " +
+      "for SQL pipe operators. When false, only '|>' is recognized as a pipe operator, and '|' " +
+      "is only used for bitwise OR operations. This provides syntax compatibility with other " +
+      "languages like Splunk SPL and Kusto that use '|' for pipe operations.")
+    .version("4.1.0")

Review Comment:
   it should be `4.2.0`, right?



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on code in PR #52983:
URL: https://github.com/apache/spark/pull/52983#discussion_r2528787514


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3849,6 +3849,16 @@ object SQLConf {
     .booleanConf
     .createWithDefault(false)
 
+  val SINGLE_CHARACTER_PIPE_OPERATOR_ENABLED =
+    buildConf("spark.sql.parser.singleCharacterPipeOperator.enabled")
+    .doc("When true, the single character pipe token '|' can be used as an alternative to '|>' " +
+      "for SQL pipe operators. When false, only '|>' is recognized as a pipe operator, and '|' " +
+      "is only used for bitwise OR operations. This provides syntax compatibility with other " +
+      "languages like Splunk SPL and Kusto that use '|' for pipe operations.")
+    .version("4.1.0")

Review Comment:
   @cloud-fan Here is a follow up PR to fix it: https://github.com/apache/spark/pull/53072



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3514237151

   cc @srielau @cloud-fan 


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on code in PR #52983:
URL: https://github.com/apache/spark/pull/52983#discussion_r2528776545


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3849,6 +3849,16 @@ object SQLConf {
     .booleanConf
     .createWithDefault(false)
 
+  val SINGLE_CHARACTER_PIPE_OPERATOR_ENABLED =
+    buildConf("spark.sql.parser.singleCharacterPipeOperator.enabled")
+    .doc("When true, the single character pipe token '|' can be used as an alternative to '|>' " +
+      "for SQL pipe operators. When false, only '|>' is recognized as a pipe operator, and '|' " +
+      "is only used for bitwise OR operations. This provides syntax compatibility with other " +
+      "languages like Splunk SPL and Kusto that use '|' for pipe operations.")
+    .version("4.1.0")

Review Comment:
   Yes, this is correct. Thanks for catching this, I'll prepare a follow up PR to fix it.



-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3523316447

   > Thank you for adding the test cases, @dtenedor .
   > Could you send out an email to dev@spark mailing list once more as a head-up if you are proposing this to Apache Spark 4.1.0?
   
   @dongjoon-hyun Thanks for catching this, I think the version numbering was a mistake. I see no reason this has to go into 4.1.0, we can leave it in 4.2.0 instead.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3534331773

   late LGTM except for https://github.com/apache/spark/pull/52983#discussion_r2528745591


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3530005890

   Thanks all for reviews.
   Let me please take another closer look at this one more time before merging, since it is a rather tricky parser case. 👍 


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dongjoon-hyun (via GitHub)" <gi...@apache.org>.
dongjoon-hyun commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3523343181

   Great! I updated the JIRA information as you mentioned.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor commented on PR #52983:
URL: https://github.com/apache/spark/pull/52983#issuecomment-3534213091

   Took another close look, everything works as expected. Merging to master.


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token [spark]

Posted by "dtenedor (via GitHub)" <gi...@apache.org>.
dtenedor closed pull request #52983: [SPARK-51518][SQL] Support | as an alternative to |> for the SQL pipe operator token 
URL: https://github.com/apache/spark/pull/52983


-- 
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: reviews-unsubscribe@spark.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org