@@ -2684,6 +2684,79 @@ pub enum PipeOperator {
26842684 /// Syntax: `|> TABLESAMPLE SYSTEM (10 PERCENT)
26852685 /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#tablesample_pipe_operator>
26862686 TableSample { sample : Box < TableSample > } ,
2687+ /// Renames columns in the input table.
2688+ ///
2689+ /// Syntax: `|> RENAME old_name AS new_name, ...`
2690+ ///
2691+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#rename_pipe_operator>
2692+ Rename { mappings : Vec < IdentWithAlias > } ,
2693+ /// Combines the input table with one or more tables using UNION.
2694+ ///
2695+ /// Syntax: `|> UNION [ALL|DISTINCT] (<query>), (<query>), ...`
2696+ ///
2697+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#union_pipe_operator>
2698+ Union {
2699+ set_quantifier : SetQuantifier ,
2700+ queries : Vec < Query > ,
2701+ } ,
2702+ /// Returns only the rows that are present in both the input table and the specified tables.
2703+ ///
2704+ /// Syntax: `|> INTERSECT [DISTINCT] (<query>), (<query>), ...`
2705+ ///
2706+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#intersect_pipe_operator>
2707+ Intersect {
2708+ set_quantifier : SetQuantifier ,
2709+ queries : Vec < Query > ,
2710+ } ,
2711+ /// Returns only the rows that are present in the input table but not in the specified tables.
2712+ ///
2713+ /// Syntax: `|> EXCEPT DISTINCT (<query>), (<query>), ...`
2714+ ///
2715+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#except_pipe_operator>
2716+ Except {
2717+ set_quantifier : SetQuantifier ,
2718+ queries : Vec < Query > ,
2719+ } ,
2720+ /// Calls a table function or procedure that returns a table.
2721+ ///
2722+ /// Syntax: `|> CALL function_name(args) [AS alias]`
2723+ ///
2724+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#call_pipe_operator>
2725+ Call {
2726+ function : Function ,
2727+ alias : Option < Ident > ,
2728+ } ,
2729+ /// Pivots data from rows to columns.
2730+ ///
2731+ /// Syntax: `|> PIVOT(aggregate_function(column) FOR pivot_column IN (value1, value2, ...)) [AS alias]`
2732+ ///
2733+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#pivot_pipe_operator>
2734+ Pivot {
2735+ aggregate_functions : Vec < ExprWithAlias > ,
2736+ value_column : Vec < Ident > ,
2737+ value_source : PivotValueSource ,
2738+ alias : Option < Ident > ,
2739+ } ,
2740+ /// The `UNPIVOT` pipe operator transforms columns into rows.
2741+ ///
2742+ /// Syntax:
2743+ /// ```sql
2744+ /// |> UNPIVOT(value_column FOR name_column IN (column1, column2, ...)) [alias]
2745+ /// ```
2746+ ///
2747+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#unpivot_pipe_operator>
2748+ Unpivot {
2749+ value_column : Ident ,
2750+ name_column : Ident ,
2751+ unpivot_columns : Vec < Ident > ,
2752+ alias : Option < Ident > ,
2753+ } ,
2754+ /// Joins the input table with another table.
2755+ ///
2756+ /// Syntax: `|> [JOIN_TYPE] JOIN <table> [alias] ON <condition>` or `|> [JOIN_TYPE] JOIN <table> [alias] USING (<columns>)`
2757+ ///
2758+ /// See more at <https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax#join_pipe_operator>
2759+ Join ( Join ) ,
26872760}
26882761
26892762impl fmt:: Display for PipeOperator {
@@ -2739,7 +2812,87 @@ impl fmt::Display for PipeOperator {
27392812 PipeOperator :: TableSample { sample } => {
27402813 write ! ( f, "{sample}" )
27412814 }
2815+ PipeOperator :: Rename { mappings } => {
2816+ write ! ( f, "RENAME {}" , display_comma_separated( mappings) )
2817+ }
2818+ PipeOperator :: Union {
2819+ set_quantifier,
2820+ queries,
2821+ } => Self :: fmt_set_operation ( f, "UNION" , set_quantifier, queries) ,
2822+ PipeOperator :: Intersect {
2823+ set_quantifier,
2824+ queries,
2825+ } => Self :: fmt_set_operation ( f, "INTERSECT" , set_quantifier, queries) ,
2826+ PipeOperator :: Except {
2827+ set_quantifier,
2828+ queries,
2829+ } => Self :: fmt_set_operation ( f, "EXCEPT" , set_quantifier, queries) ,
2830+ PipeOperator :: Call { function, alias } => {
2831+ write ! ( f, "CALL {function}" ) ?;
2832+ Self :: fmt_optional_alias ( f, alias)
2833+ }
2834+ PipeOperator :: Pivot {
2835+ aggregate_functions,
2836+ value_column,
2837+ value_source,
2838+ alias,
2839+ } => {
2840+ write ! (
2841+ f,
2842+ "PIVOT({} FOR {} IN ({}))" ,
2843+ display_comma_separated( aggregate_functions) ,
2844+ Expr :: CompoundIdentifier ( value_column. to_vec( ) ) ,
2845+ value_source
2846+ ) ?;
2847+ Self :: fmt_optional_alias ( f, alias)
2848+ }
2849+ PipeOperator :: Unpivot {
2850+ value_column,
2851+ name_column,
2852+ unpivot_columns,
2853+ alias,
2854+ } => {
2855+ write ! (
2856+ f,
2857+ "UNPIVOT({} FOR {} IN ({}))" ,
2858+ value_column,
2859+ name_column,
2860+ display_comma_separated( unpivot_columns)
2861+ ) ?;
2862+ Self :: fmt_optional_alias ( f, alias)
2863+ }
2864+ PipeOperator :: Join ( join) => write ! ( f, "{join}" ) ,
2865+ }
2866+ }
2867+ }
2868+
2869+ impl PipeOperator {
2870+ /// Helper function to format optional alias for pipe operators
2871+ fn fmt_optional_alias ( f : & mut fmt:: Formatter < ' _ > , alias : & Option < Ident > ) -> fmt:: Result {
2872+ if let Some ( alias) = alias {
2873+ write ! ( f, " AS {alias}" ) ?;
27422874 }
2875+ Ok ( ( ) )
2876+ }
2877+
2878+ /// Helper function to format set operations (UNION, INTERSECT, EXCEPT) with queries
2879+ fn fmt_set_operation (
2880+ f : & mut fmt:: Formatter < ' _ > ,
2881+ operation : & str ,
2882+ set_quantifier : & SetQuantifier ,
2883+ queries : & [ Query ] ,
2884+ ) -> fmt:: Result {
2885+ write ! ( f, "{operation}" ) ?;
2886+ match set_quantifier {
2887+ SetQuantifier :: None => { }
2888+ _ => {
2889+ write ! ( f, " {set_quantifier}" ) ?;
2890+ }
2891+ }
2892+ write ! ( f, " " ) ?;
2893+ let parenthesized_queries: Vec < String > =
2894+ queries. iter ( ) . map ( |query| format ! ( "({query})" ) ) . collect ( ) ;
2895+ write ! ( f, "{}" , display_comma_separated( & parenthesized_queries) )
27432896 }
27442897}
27452898
0 commit comments