@@ -211,11 +211,44 @@ fn parse_select_count_wildcard() {
211211 name: SQLObjectName ( vec![ "COUNT" . to_string( ) ] ) ,
212212 args: vec![ ASTNode :: SQLWildcard ] ,
213213 over: None ,
214+ distinct: false ,
214215 } ,
215216 expr_from_projection( only( & select. projection) )
216217 ) ;
217218}
218219
220+ #[ test]
221+ fn parse_select_count_distinct ( ) {
222+ let sql = "SELECT COUNT(DISTINCT + x) FROM customer" ;
223+ let select = verified_only_select ( sql) ;
224+ assert_eq ! (
225+ & ASTNode :: SQLFunction {
226+ name: SQLObjectName ( vec![ "COUNT" . to_string( ) ] ) ,
227+ args: vec![ ASTNode :: SQLUnary {
228+ operator: SQLOperator :: Plus ,
229+ expr: Box :: new( ASTNode :: SQLIdentifier ( "x" . to_string( ) ) )
230+ } ] ,
231+ over: None ,
232+ distinct: true ,
233+ } ,
234+ expr_from_projection( only( & select. projection) )
235+ ) ;
236+
237+ one_statement_parses_to (
238+ "SELECT COUNT(ALL + x) FROM customer" ,
239+ "SELECT COUNT(+ x) FROM customer" ,
240+ ) ;
241+
242+ let sql = "SELECT COUNT(ALL DISTINCT + x) FROM customer" ;
243+ let res = parse_sql_statements ( sql) ;
244+ assert_eq ! (
245+ ParserError :: ParserError (
246+ "Cannot specify both ALL and DISTINCT in function: COUNT" . to_string( )
247+ ) ,
248+ res. unwrap_err( )
249+ ) ;
250+ }
251+
219252#[ test]
220253fn parse_not ( ) {
221254 let sql = "SELECT id FROM customer WHERE NOT salary = ''" ;
@@ -676,6 +709,7 @@ fn parse_scalar_function_in_projection() {
676709 name: SQLObjectName ( vec![ "sqrt" . to_string( ) ] ) ,
677710 args: vec![ ASTNode :: SQLIdentifier ( "id" . to_string( ) ) ] ,
678711 over: None ,
712+ distinct: false ,
679713 } ,
680714 expr_from_projection( only( & select. projection) )
681715 ) ;
@@ -704,7 +738,8 @@ fn parse_window_functions() {
704738 asc: Some ( false )
705739 } ] ,
706740 window_frame: None ,
707- } )
741+ } ) ,
742+ distinct: false ,
708743 } ,
709744 expr_from_projection( & select. projection[ 0 ] )
710745 ) ;
@@ -776,6 +811,7 @@ fn parse_delimited_identifiers() {
776811 name: SQLObjectName ( vec![ r#""myfun""# . to_string( ) ] ) ,
777812 args: vec![ ] ,
778813 over: None ,
814+ distinct: false ,
779815 } ,
780816 expr_from_projection( & select. projection[ 1 ] ) ,
781817 ) ;
0 commit comments