@@ -50,10 +50,10 @@ class GroupBy extends Projection {
5050 }
5151 private map ( ) {
5252 let node : Node = this . current ;
53- for ( const mapper of this . mappers ) {
53+ for ( const mapper of this . mappers ) {
5454 const value : any = mapper . value ( ) ;
5555 let child : Node | undefined = node . children . get ( value ) ;
56- if ( child === undefined ) {
56+ if ( child === undefined ) {
5757 child = new Node ( value ) ;
5858 node . children . set ( value , child ) ;
5959 }
@@ -62,38 +62,46 @@ class GroupBy extends Projection {
6262 this . current = node ;
6363 }
6464 private reduce ( ) {
65- if ( this . current . elements === null ) {
66- this . current . elements = this . reducers . map ( reducer => reducer . element ( ) ) ;
65+ if ( this . current . elements === null ) {
66+ this . current . elements = this . reducers . map ( ( reducer ) => reducer . element ( ) ) ;
6767 }
6868 const elements : AggregationElement [ ] = this . current . elements ;
6969 this . reducers . forEach ( ( reducer , index ) => {
7070 reducer . reduce ( elements [ index ] ) ;
7171 } ) ;
7272 }
7373 private get mappers ( ) : Expression [ ] {
74- if ( this . _mappers === null ) {
74+ if ( this . _mappers === null ) {
7575 this . _mappers = [ ...this . _generate_mappers ( ) ] ;
7676 }
7777 return this . _mappers ;
7878 }
7979 private * _generate_mappers ( ) : Generator < Expression > {
80- for ( const [ expression , _ ] of this . expressions ( ) ) {
81- if ( expression . mappable ( ) ) {
80+ for ( const [ expression , _ ] of this . expressions ( ) ) {
81+ if ( expression . mappable ( ) ) {
8282 yield expression ;
8383 }
8484 }
8585 }
8686 private get reducers ( ) : AggregateFunction [ ] {
87- if ( this . _reducers === null ) {
88- this . _reducers = this . children . map ( ( child ) => {
89- return ( child as Expression ) . reducers ( ) ;
90- } ) . flat ( ) ;
87+ if ( this . _reducers === null ) {
88+ this . _reducers = this . children
89+ . map ( ( child ) => {
90+ return ( child as Expression ) . reducers ( ) ;
91+ } )
92+ . flat ( ) ;
9193 }
9294 return this . _reducers ;
9395 }
94- public * generate_results ( mapperIndex : number = 0 , node : Node = this . root ) : Generator < Record < string , any > > {
95- if ( node . children . size > 0 ) {
96- for ( const child of node . children . values ( ) ) {
96+ public * generate_results (
97+ mapperIndex : number = 0 ,
98+ node : Node = this . root
99+ ) : Generator < Record < string , any > > {
100+ if ( mapperIndex === 0 && node . children . size === 0 && this . mappers . length > 0 ) {
101+ return ;
102+ }
103+ if ( node . children . size > 0 ) {
104+ for ( const child of node . children . values ( ) ) {
97105 this . mappers [ mapperIndex ] . overridden = child . value ;
98106 yield * this . generate_results ( mapperIndex + 1 , child ) ;
99107 }
@@ -102,10 +110,10 @@ class GroupBy extends Projection {
102110 this . reducers [ reducerIndex ] . overridden = element . value ;
103111 } ) ;
104112 const record : Record < string , any > = { } ;
105- for ( const [ expression , alias ] of this . expressions ( ) ) {
113+ for ( const [ expression , alias ] of this . expressions ( ) ) {
106114 record [ alias ] = expression . value ( ) ;
107115 }
108- if ( this . where ) {
116+ if ( this . where ) {
109117 yield record ;
110118 }
111119 }
@@ -114,11 +122,11 @@ class GroupBy extends Projection {
114122 this . _where = where ;
115123 }
116124 public get where ( ) : boolean {
117- if ( this . _where === null ) {
125+ if ( this . _where === null ) {
118126 return true ;
119127 }
120128 return this . _where . value ( ) ;
121129 }
122- } ;
130+ }
123131
124- export default GroupBy ;
132+ export default GroupBy ;
0 commit comments