← Back to Pull requests

Support the rest of Druid's pipe syntax #135

Closed
unknown closed this pull request without merging on Oct 29, 2026 18:31 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 07:02 UTC
Author

Summary

Adds more pipe syntax.

 PipeOperatorBody
   SELECT        (+ DISTINCT / ALL)
   WHERE
   AGGREGATE     (+ order suffixes: COUNT(*) AS c DESC GROUP BY a ASC NULLS LAST)
   ORDER BY
   LIMIT
+  UNION [ALL | DISTINCT] (q), (q)    SqlUnionPipeOperator
   EXTEND
   SET
   DROP
+  RENAME a [AS] b                    SqlRenamePipeOperator
+  AS t                               SqlAsPipeOperator
+  DISTINCT                           SqlDistinctPipeOperator
+  [NATURAL] [type] JOIN ...          SqlJoinPipeOperator (wraps a SqlJoinPart)

 QueryBody
   SELECT ...
-  WITH ... (query)
+  WITH ... (query) | FROM ... | TABLE t | VALUES ...   SqlWithQuery
   VALUES ...
   TABLE t
-  FROM <table>                                        SqlFromQuery.table
+  FROM <whole FROM clause>                            SqlFromQuery.fromClause
+  (query) followed by UNION ALL / ORDER BY / ...      SqlParensQuery

  • |> AGGREGATE COUNT() DESC used to parse with DESC as an alias, so unpipe() printed COUNT() AS DESC. Order-suffixed items are now SqlOrderByExpressions, which is why that class is now an SqlExpression.

  • unpipe() converts every new form (and bare FROM queries nested anywhere), e.g. |> UNION DISTINCT (q) becomes SELECT DISTINCT FROM (... UNION ALL q), and AGGREGATE order suffixes become an ORDER BY.
  • Pipes now bind to everything before them:

     A UNION ALL B |> AGGREGATE COUNT(*) AS c
    -  A UNION ALL (B |> AGGREGATE ...)                 pipes on the last query of the union
    +  (A UNION ALL B) |> AGGREGATE ...                 SqlPipesQuery.query = the whole union
    
     WITH c AS (FROM t) SELECT k, v FROM c |> WHERE k IN (FROM c |> SELECT k)
    -  (WITH c AS (...) SELECT k, v FROM c) |> WHERE ...   CTEs out of reach of the pipes
    +  WITH c AS (...) (SELECT k, v FROM c |> WHERE ...)   SqlPipesQuery.withClause
    
     FROM t |> WHERE x UNION ALL FROM u
    -  parsed, with the union after the pipeline
    +  parse error (use |> UNION ALL (FROM u))
    

  • unpipe() keeps the WITH on the outermost SELECT, so CTEs stay visible after a pipe forces a sub query: WITH c AS (SELECT FROM t) SELECT FROM (... GROUP BY k) WHERE k IN (SELECT k FROM c).

  • removePipeOperator gives the WITH back to the starting query. SqlPipesQuery.create takes the WITH off a SqlQuery root, so built and parsed trees match.
  • Evidence

  • Before: each of these fails to parse (Expected "AGGREGATE", "DROP", ...), except AGGREGATE ... DESC, which misparses.

  • After: all parse and round-trip.

    WITH x AS (FROM t) FROM x |> ...
    FROM t AS x |> ...                         FROM t a, (SELECT ...) |> ...
    FROM t AS a JOIN u AS b ON ... |> ...
    |> SELECT DISTINCT a                       |> UNION ALL (FROM t |> SELECT a), (SELECT b FROM u)
    |> AS a |> JOIN ... AS b ON a.x = b.x      |> DISTINCT
    |> RENAME a AS b, c d                      |> AGGREGATE COUNT(*) AS c DESC GROUP BY a ASC NULLS LAST, b
    (FROM t) UNION ALL (FROM u) |> WHERE ...
    

  • Before: SELECT a FROM t UNION ALL SELECT a FROM u |> AGGREGATE COUNT() AS c parsed as a SqlQuery with the pipes on its second query, which unpiped to SELECT a FROM t UNION ALL SELECT COUNT() AS c FROM (SELECT a FROM u).

  • After: SELECT COUNT(
    ) AS c FROM (SELECT a FROM t UNION ALL SELECT a FROM u).
  • Before: WITH c AS (FROM t) FROM c |> AGGREGATE COUNT() AS n GROUP BY k |> WHERE k IN (FROM c) unpiped to SELECT FROM (WITH c ... GROUP BY k) WHERE k IN (SELECT FROM c), where c is out of scope.

  • After: WITH c AS (SELECT
    FROM t) SELECT FROM (SELECT k, COUNT() AS n FROM c GROUP BY k) WHERE k IN (SELECT * FROM c).
  • npm test: 3094 tests pass (eslint, prettier, snapshot indent, jest). Nested-paren parse times unchanged vs master.
  • Merge Danger

    Door: two-way until released, one-way after

    Reverting the PR is cheap; once the changesets release goes out, the SqlFromQuery API change is published (changeset is minor, as #133 was).

    Blast Radius: consumers

  • SqlFromQuery.table, getTableName, changeTable, changeTableName, getNamespaceName and changeNamespace are gone; use fromClause and the FROM clause methods.

  • SqlOrderByExpression now passes instanceof SqlExpression, so walkers that branch on that will see ORDER BY items too.

  • Every query statement can now start with (, so some parse error messages for parenthesized input change.

  • |> AGGREGATE x DESC / GROUP BY x DESC now parse to a SqlOrderByExpression instead of a SqlAlias named DESC.

  • In A UNION ALL B |> ... the pipes moved from B to a SqlPipesQuery around the whole union, and a leading WITH moved from the root query to SqlPipesQuery.withClause. Code that reads those trees sees a different shape.

  • ... |> op UNION ALL ... no longer parses, and a SqlPipesQuery throws if given a unionQuery.
  • 🤖 Generated with Claude Code

    Diff: 616 lines (+462 / -154) across 7 files Reviewer: gianm Review duration: 2128m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 616 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.384
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #135"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.2% (MEDIUM) · Higher = larger blast radius
    50.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.8% · Safe to merge
    19.8%