@@ -197,11 +197,44 @@ fn parse_select_count_wildcard() {
197197 name: SQLObjectName ( vec![ "COUNT" . to_string( ) ] ) ,
198198 args: vec![ ASTNode :: SQLWildcard ] ,
199199 over: None ,
200+ distinct: false ,
200201 } ,
201202 expr_from_projection( only( & select. projection) )
202203 ) ;
203204}
204205
206+ #[ test]
207+ fn parse_select_count_distinct ( ) {
208+ let sql = "SELECT COUNT(DISTINCT + x) FROM customer" ;
209+ let select = verified_only_select ( sql) ;
210+ assert_eq ! (
211+ & ASTNode :: SQLFunction {
212+ name: SQLObjectName ( vec![ "COUNT" . to_string( ) ] ) ,
213+ args: vec![ ASTNode :: SQLUnary {
214+ operator: SQLOperator :: Plus ,
215+ expr: Box :: new( ASTNode :: SQLIdentifier ( "x" . to_string( ) ) )
216+ } ] ,
217+ over: None ,
218+ distinct: true ,
219+ } ,
220+ expr_from_projection( only( & select. projection) )
221+ ) ;
222+
223+ one_statement_parses_to (
224+ "SELECT COUNT(ALL + x) FROM customer" ,
225+ "SELECT COUNT(+ x) FROM customer" ,
226+ ) ;
227+
228+ let sql = "SELECT COUNT(ALL DISTINCT + x) FROM customer" ;
229+ let res = parse_sql_statements ( sql) ;
230+ assert_eq ! (
231+ ParserError :: ParserError (
232+ "Cannot specify both ALL and DISTINCT in function: COUNT" . to_string( )
233+ ) ,
234+ res. unwrap_err( )
235+ ) ;
236+ }
237+
205238#[ test]
206239fn parse_not ( ) {
207240 let sql = "SELECT id FROM customer WHERE NOT salary = ''" ;
@@ -662,6 +695,7 @@ fn parse_scalar_function_in_projection() {
662695 name: SQLObjectName ( vec![ "sqrt" . to_string( ) ] ) ,
663696 args: vec![ ASTNode :: SQLIdentifier ( "id" . to_string( ) ) ] ,
664697 over: None ,
698+ distinct: false ,
665699 } ,
666700 expr_from_projection( only( & select. projection) )
667701 ) ;
@@ -690,7 +724,8 @@ fn parse_window_functions() {
690724 asc: Some ( false )
691725 } ] ,
692726 window_frame: None ,
693- } )
727+ } ) ,
728+ distinct: false ,
694729 } ,
695730 expr_from_projection( & select. projection[ 0 ] )
696731 ) ;
@@ -762,6 +797,7 @@ fn parse_delimited_identifiers() {
762797 name: SQLObjectName ( vec![ r#""myfun""# . to_string( ) ] ) ,
763798 args: vec![ ] ,
764799 over: None ,
800+ distinct: false ,
765801 } ,
766802 expr_from_projection( & select. projection[ 1 ] ) ,
767803 ) ;
0 commit comments