File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,21 +125,27 @@ fn build_select_doc<'a>(select: &ast::Select) -> Doc<'a> {
125125 }
126126
127127 if let Some ( group) = & select. group_by_clause ( ) {
128- doc = doc. append (
129- Doc :: line_or_space ( )
130- . append ( Doc :: text ( "group by" ) )
131- . append ( Doc :: space ( ) )
132- . append ( Doc :: text (
133- group. group_by_list ( ) . unwrap ( ) . syntax ( ) . to_string ( ) ,
134- ) ) ,
135- ) ;
128+ let mut group_doc = Doc :: line_or_space ( ) . append ( leading_comments ( group. syntax ( ) ) ) ;
129+ group_doc = group_doc. append ( Doc :: text ( "group" ) ) . append ( Doc :: space ( ) ) ;
130+ if let Some ( by_token) = group. by_token ( ) {
131+ group_doc = group_doc. append ( leading_comments_token ( & by_token) ) ;
132+ }
133+ group_doc = group_doc. append ( Doc :: text ( "by" ) ) . append ( Doc :: space ( ) ) ;
134+ if let Some ( list) = group. group_by_list ( ) {
135+ group_doc = group_doc. append ( build_group_by_list ( list) ) ;
136+ }
137+ doc = doc. append ( group_doc) ;
136138 }
137139
138140 doc = doc. append ( build_semicolon ( select. semicolon_token ( ) ) ) ;
139141
140142 doc. group ( )
141143}
142144
145+ fn build_group_by_list < ' a > ( list : ast:: GroupByList ) -> Doc < ' a > {
146+ leading_comments ( list. syntax ( ) ) . append ( Doc :: text ( list. syntax ( ) . to_string ( ) ) )
147+ }
148+
143149fn build_semicolon < ' a > ( semi : Option < SyntaxToken > ) -> Doc < ' a > {
144150 let Some ( semi) = semi else {
145151 return Doc :: nil ( ) ;
Original file line number Diff line number Diff line change 1313select foo as " Quoted Alias" from " Quoted Table" ;
1414
1515select 1 as foo ;
16+
17+ select 1 /* a*/ group /* b */ by /* c */ 1 ;
Original file line number Diff line number Diff line change @@ -7,3 +7,5 @@ select 'really long string '
77select foo as " Quoted Alias" from " Quoted Table" ;
88
99select 1 as " foo" ;
10+
11+ select 1 /* a*/ group /* b */ by/* c */ 1 ;
You can’t perform that action at this time.
0 commit comments