@@ -599,6 +599,8 @@ fn parse_join_constraint_unnest_alias() {
599
599
fn parse_trailing_comma ( ) {
600
600
for ( sql, canonical) in [
601
601
( "SELECT a," , "SELECT a" ) ,
602
+ ( "SELECT 1," , "SELECT 1" ) ,
603
+ ( "SELECT 1,2," , "SELECT 1, 2" ) ,
602
604
( "SELECT a, b," , "SELECT a, b" ) ,
603
605
( "SELECT a, b AS c," , "SELECT a, b AS c" ) ,
604
606
( "SELECT a, b AS c, FROM t" , "SELECT a, b AS c FROM t" ) ,
@@ -768,6 +770,58 @@ fn test_select_wildcard_with_except() {
768
770
) ;
769
771
}
770
772
773
+ #[ test]
774
+ fn test_select_wildcard_with_replace ( ) {
775
+ let select = bigquery_and_generic ( )
776
+ . verified_only_select ( r#"SELECT * REPLACE ('widget' AS item_name) FROM orders"# ) ;
777
+ let expected = SelectItem :: Wildcard ( WildcardAdditionalOptions {
778
+ opt_replace : Some ( ReplaceSelectItem {
779
+ items : vec ! [ Box :: new( ReplaceSelectElement {
780
+ expr: Expr :: Value ( Value :: SingleQuotedString ( "widget" . to_owned( ) ) ) ,
781
+ column_name: Ident :: new( "item_name" ) ,
782
+ as_keyword: true ,
783
+ } ) ] ,
784
+ } ) ,
785
+ ..Default :: default ( )
786
+ } ) ;
787
+ assert_eq ! ( expected, select. projection[ 0 ] ) ;
788
+
789
+ let select = bigquery_and_generic ( ) . verified_only_select (
790
+ r#"SELECT * REPLACE (quantity / 2 AS quantity, 3 AS order_id) FROM orders"# ,
791
+ ) ;
792
+ let expected = SelectItem :: Wildcard ( WildcardAdditionalOptions {
793
+ opt_replace : Some ( ReplaceSelectItem {
794
+ items : vec ! [
795
+ Box :: new( ReplaceSelectElement {
796
+ expr: Expr :: BinaryOp {
797
+ left: Box :: new( Expr :: Identifier ( Ident :: new( "quantity" ) ) ) ,
798
+ op: BinaryOperator :: Divide ,
799
+ #[ cfg( not( feature = "bigdecimal" ) ) ]
800
+ right: Box :: new( Expr :: Value ( Value :: Number ( "2" . to_string( ) , false ) ) ) ,
801
+ #[ cfg( feature = "bigdecimal" ) ]
802
+ right: Box :: new( Expr :: Value ( Value :: Number (
803
+ BigDecimal :: from_str( "2" ) . unwrap( ) ,
804
+ false ,
805
+ ) ) ) ,
806
+ } ,
807
+ column_name: Ident :: new( "quantity" ) ,
808
+ as_keyword: true ,
809
+ } ) ,
810
+ Box :: new( ReplaceSelectElement {
811
+ #[ cfg( not( feature = "bigdecimal" ) ) ]
812
+ expr: Expr :: Value ( Value :: Number ( "3" . to_string( ) , false ) ) ,
813
+ #[ cfg( feature = "bigdecimal" ) ]
814
+ expr: Expr :: Value ( Value :: Number ( BigDecimal :: from_str( "3" ) . unwrap( ) , false ) ) ,
815
+ column_name: Ident :: new( "order_id" ) ,
816
+ as_keyword: true ,
817
+ } ) ,
818
+ ] ,
819
+ } ) ,
820
+ ..Default :: default ( )
821
+ } ) ;
822
+ assert_eq ! ( expected, select. projection[ 0 ] ) ;
823
+ }
824
+
771
825
fn bigquery ( ) -> TestedDialects {
772
826
TestedDialects {
773
827
dialects : vec ! [ Box :: new( BigQueryDialect { } ) ] ,
0 commit comments