@@ -3,10 +3,7 @@ import {
33 BucketDataSourceDefinition ,
44 BucketSource ,
55 BucketSourceType ,
6- CreateSourceParams ,
7- DebugMergedSource ,
8- mergeParameterLookupSources ,
9- mergeParameterQuerierSources
6+ CreateSourceParams
107} from './BucketSource.js' ;
118import { ColumnDefinition } from './ExpressionType.js' ;
129import { IdSequence } from './IdSequence.js' ;
@@ -30,12 +27,14 @@ export interface QueryParseResult {
3027 errors : SqlRuleError [ ] ;
3128}
3229
33- export class SqlBucketDescriptor implements BucketDataSourceDefinition , BucketSource {
30+ export class SqlBucketDescriptor implements BucketSource {
3431 name : string ;
3532 private bucketParametersInternal : string [ ] | null = null ;
3633
3734 public readonly subscribedToByDefault : boolean = true ;
3835
36+ private readonly dataSource = new BucketDefinitionDataSource ( this ) ;
37+
3938 /**
4039 * source table -> queries
4140 */
@@ -58,7 +57,7 @@ export class SqlBucketDescriptor implements BucketDataSourceDefinition, BucketSo
5857 }
5958
6059 get dataSources ( ) {
61- return [ this ] ;
60+ return [ this . dataSource ] ;
6261 }
6362
6463 get parameterLookupSources ( ) {
@@ -107,11 +106,51 @@ export class SqlBucketDescriptor implements BucketDataSourceDefinition, BucketSo
107106 } ;
108107 }
109108
109+ debugRepresentation ( ) {
110+ let all_parameter_queries = [ ...this . parameterQueries . values ( ) ] . flat ( ) ;
111+ let all_data_queries = [ ...this . dataQueries . values ( ) ] . flat ( ) ;
112+ return {
113+ name : this . name ,
114+ type : BucketSourceType [ this . type ] ,
115+ bucket_parameters : this . bucketParameters ,
116+ global_parameter_queries : this . globalParameterQueries . map ( ( q ) => {
117+ return {
118+ sql : q . sql
119+ } ;
120+ } ) ,
121+ parameter_queries : all_parameter_queries . map ( ( q ) => {
122+ return {
123+ sql : q . sql ,
124+ table : q . sourceTable ,
125+ input_parameters : q . inputParameters
126+ } ;
127+ } ) ,
128+ data_queries : all_data_queries . map ( ( q ) => {
129+ return {
130+ sql : q . sql ,
131+ table : q . sourceTable ,
132+ columns : q . columnOutputNames ( )
133+ } ;
134+ } )
135+ } ;
136+ }
137+ }
138+
139+ export class BucketDefinitionDataSource implements BucketDataSourceDefinition {
140+ constructor ( private descriptor : SqlBucketDescriptor ) { }
141+
142+ /**
143+ * For debug use only.
144+ */
145+ get bucketParameters ( ) {
146+ return this . descriptor . bucketParameters ;
147+ }
148+
110149 createDataSource ( params : CreateSourceParams ) : BucketDataSource {
111150 return {
112151 evaluateRow : ( options ) => {
113152 let results : EvaluationResult [ ] = [ ] ;
114- for ( let query of this . dataQueries ) {
153+ for ( let query of this . descriptor . dataQueries ) {
115154 if ( ! query . applies ( options . sourceTable ) ) {
116155 continue ;
117156 }
@@ -125,20 +164,14 @@ export class SqlBucketDescriptor implements BucketDataSourceDefinition, BucketSo
125164
126165 getSourceTables ( ) : Set < TablePattern > {
127166 let result = new Set < TablePattern > ( ) ;
128- for ( let query of this . parameterQueries ) {
129- result . add ( query . sourceTable ) ;
130- }
131- for ( let query of this . dataQueries ) {
167+ for ( let query of this . descriptor . dataQueries ) {
132168 result . add ( query . sourceTable ) ;
133169 }
134-
135- // Note: No physical tables for global_parameter_queries
136-
137170 return result ;
138171 }
139172
140173 tableSyncsData ( table : SourceTableInterface ) : boolean {
141- for ( let query of this . dataQueries ) {
174+ for ( let query of this . descriptor . dataQueries ) {
142175 if ( query . applies ( table ) ) {
143176 return true ;
144177 }
@@ -147,13 +180,13 @@ export class SqlBucketDescriptor implements BucketDataSourceDefinition, BucketSo
147180 }
148181
149182 resolveResultSets ( schema : SourceSchema , tables : Record < string , Record < string , ColumnDefinition > > ) {
150- for ( let query of this . dataQueries ) {
183+ for ( let query of this . descriptor . dataQueries ) {
151184 query . resolveResultSets ( schema , tables ) ;
152185 }
153186 }
154187
155188 debugWriteOutputTables ( result : Record < string , { query : string } [ ] > ) : void {
156- for ( let q of this . dataQueries ) {
189+ for ( let q of this . descriptor . dataQueries ) {
157190 result [ q . table ! . sqlName ] ??= [ ] ;
158191 const r = {
159192 query : q . sql
@@ -162,33 +195,4 @@ export class SqlBucketDescriptor implements BucketDataSourceDefinition, BucketSo
162195 result [ q . table ! . sqlName ] . push ( r ) ;
163196 }
164197 }
165-
166- debugRepresentation ( ) {
167- let all_parameter_queries = [ ...this . parameterQueries . values ( ) ] . flat ( ) ;
168- let all_data_queries = [ ...this . dataQueries . values ( ) ] . flat ( ) ;
169- return {
170- name : this . name ,
171- type : BucketSourceType [ this . type ] ,
172- bucket_parameters : this . bucketParameters ,
173- global_parameter_queries : this . globalParameterQueries . map ( ( q ) => {
174- return {
175- sql : q . sql
176- } ;
177- } ) ,
178- parameter_queries : all_parameter_queries . map ( ( q ) => {
179- return {
180- sql : q . sql ,
181- table : q . sourceTable ,
182- input_parameters : q . inputParameters
183- } ;
184- } ) ,
185- data_queries : all_data_queries . map ( ( q ) => {
186- return {
187- sql : q . sql ,
188- table : q . sourceTable ,
189- columns : q . columnOutputNames ( )
190- } ;
191- } )
192- } ;
193- }
194198}
0 commit comments