@@ -2413,35 +2413,76 @@ impl fmt::Display for OffsetRows {
24132413 }
24142414}
24152415
2416+ /// Pipe syntax, first introduced in Google BigQuery.
2417+ /// Example:
2418+ ///
2419+ /// ```sql
2420+ /// FROM Produce
2421+ /// |> WHERE sales > 0
2422+ /// |> AGGREGATE SUM(sales) AS total_sales, COUNT(*) AS num_sales
2423+ /// GROUP BY item;
2424+ /// ```
2425+ ///
2426+ /// See https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#pipe_syntax
24162427#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
24172428#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
24182429#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
24192430pub enum PipeOperator {
2420- Limit {
2421- expr : Expr ,
2422- offset : Option < Expr > ,
2423- } ,
2424- Where {
2425- expr : Expr ,
2426- } ,
2427- OrderBy {
2428- exprs : Vec < OrderByExpr > ,
2429- } ,
2430- Select {
2431- exprs : Vec < SelectItem > ,
2432- } ,
2433- Extend {
2434- exprs : Vec < SelectItem > ,
2435- } ,
2436- Set {
2437- assignments : Vec < Assignment > ,
2438- } ,
2439- Drop {
2440- columns : Vec < Ident > ,
2441- } ,
2442- Alias {
2443- alias : Ident ,
2444- } ,
2431+ /// Limits the number of rows to return in a query, with an optional OFFSET clause to skip over rows.
2432+ ///
2433+ /// Syntax: `|> LIMIT <n> [OFFSET <m>]`
2434+ ///
2435+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#limit_pipe_operator
2436+ Limit { expr : Expr , offset : Option < Expr > } ,
2437+ /// Filters the results of the input table.
2438+ ///
2439+ /// Syntax: `|> WHERE <condition>`
2440+ ///
2441+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#where_pipe_operator
2442+ Where { expr : Expr } ,
2443+ /// ORDER BY <expr> [ASC|DESC], ...
2444+ OrderBy { exprs : Vec < OrderByExpr > } ,
2445+ /// Produces a new table with the listed columns, similar to the outermost SELECT clause in a table subquery in standard syntax.
2446+ ///
2447+ /// Syntax `|> SELECT <expr> [[AS] alias], ...`
2448+ ///
2449+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#select_pipe_operator
2450+ Select { exprs : Vec < SelectItem > } ,
2451+ /// Propagates the existing table and adds computed columns, similar to SELECT *, new_column in standard syntax.
2452+ ///
2453+ /// Syntax: `|> EXTEND <expr> [[AS] alias], ...`
2454+ ///
2455+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#extend_pipe_operator
2456+ Extend { exprs : Vec < SelectItem > } ,
2457+ /// Replaces the value of a column in the current table, similar to SELECT * REPLACE (expression AS column) in standard syntax.
2458+ ///
2459+ /// Syntax: `|> SET <column> = <expression>, ...`
2460+ ///
2461+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#set_pipe_operator
2462+ Set { assignments : Vec < Assignment > } ,
2463+ /// Removes listed columns from the current table, similar to SELECT * EXCEPT (column) in standard syntax.
2464+ ///
2465+ /// Syntax: `|> DROP <column>, ...`
2466+ ///
2467+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#drop_pipe_operator
2468+ Drop { columns : Vec < Ident > } ,
2469+ /// Introduces a table alias for the input table, similar to applying the AS alias clause on a table subquery in standard syntax.
2470+ ///
2471+ /// Syntax: `|> AS <alias>`
2472+ ///
2473+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#as_pipe_operator
2474+ As { alias : Ident } ,
2475+ /// Performs aggregation on data across grouped rows or an entire table.
2476+ ///
2477+ /// Syntax: `|> AGGREGATE <agg_expr> [[AS] alias], ...`
2478+ ///
2479+ /// Syntax:
2480+ /// ```
2481+ /// |> AGGREGATE [<agg_expr> [[AS] alias], ...]
2482+ /// GROUP BY <grouping_expr> [AS alias], ...
2483+ /// ```
2484+ ///
2485+ /// See more at https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#aggregate_pipe_operator
24452486 Aggregate {
24462487 full_table_exprs : Vec < ExprWithAlias > ,
24472488 group_by_exprs : Vec < ExprWithAlias > ,
@@ -2463,7 +2504,7 @@ impl fmt::Display for PipeOperator {
24632504 PipeOperator :: Drop { columns } => {
24642505 write ! ( f, "DROP {}" , display_comma_separated( columns. as_slice( ) ) )
24652506 }
2466- PipeOperator :: Alias { alias } => {
2507+ PipeOperator :: As { alias } => {
24672508 write ! ( f, "AS {}" , alias)
24682509 }
24692510 PipeOperator :: Limit { expr, offset } => {
0 commit comments