@@ -599,7 +599,49 @@ describe('PreAggregations', () => {
599599 }
600600 ]
601601 });
602- ` ) ;
602+
603+ cube('cube_pre_agg_proxy_a', {
604+ sql: \`SELECT '2025-10-01 12:00:00'::timestamp as starts_at\`,
605+
606+ dimensions: {
607+ starts_at: {
608+ sql: \`\${CUBE}.starts_at\`,
609+ type: 'time'
610+ }
611+ }
612+ });
613+
614+ cube('cube_pre_agg_proxy_b', {
615+ sql: \`SELECT 'id' as id\`,
616+
617+ joins: {
618+ cube_pre_agg_proxy_a: {
619+ relationship: 'one_to_one',
620+ sql: '1 = 1'
621+ }
622+ },
623+
624+ dimensions: {
625+ id: {
626+ sql: \`\${CUBE}.id\`,
627+ type: 'string',
628+ primary_key: true
629+ },
630+
631+ terminal_date: {
632+ type: 'time',
633+ sql: \`\${cube_pre_agg_proxy_a.starts_at}\`
634+ }
635+ },
636+
637+ pre_aggregations: {
638+ main: {
639+ time_dimension: terminal_date,
640+ granularity: 'day'
641+ }
642+ }
643+ });
644+ ` ) ;
603645
604646 it ( 'simple pre-aggregation' , async ( ) => {
605647 await compiler . compile ( ) ;
@@ -2773,4 +2815,39 @@ describe('PreAggregations', () => {
27732815 expect ( loadSql [ 0 ] ) . not . toMatch ( / G R O U P B Y / ) ;
27742816 expect ( loadSql [ 0 ] ) . toMatch ( / T H E N 1 E N D ` r e a l _ t i m e _ l a m b d a _ v i s i t o r s _ _ c o u n t ` / ) ;
27752817 } ) ;
2818+
2819+ it ( 'querying proxied to external cube pre-aggregation time-dimension' , async ( ) => {
2820+ await compiler . compile ( ) ;
2821+
2822+ const query = new PostgresQuery ( { joinGraph, cubeEvaluator, compiler } , {
2823+ measures : [ ] ,
2824+ dimensions : [ ] ,
2825+ timezone : 'America/Los_Angeles' ,
2826+ preAggregationsSchema : '' ,
2827+ timeDimensions : [ {
2828+ dimension : 'cube_pre_agg_proxy_b.terminal_date' ,
2829+ granularity : 'day' ,
2830+ } ] ,
2831+ order : [ ] ,
2832+ } ) ;
2833+
2834+ const queryAndParams = query . buildSqlAndParams ( ) ;
2835+ console . log ( queryAndParams ) ;
2836+ const preAggregationsDescription = query . preAggregations ?. preAggregationsDescription ( ) ;
2837+ console . log ( JSON . stringify ( preAggregationsDescription , null , 2 ) ) ;
2838+
2839+ expect ( ( < any > preAggregationsDescription ) [ 0 ] . loadSql [ 0 ] ) . toMatch ( / m a i n / ) ;
2840+
2841+ const queries = dbRunner . tempTablePreAggregations ( preAggregationsDescription ) ;
2842+
2843+ console . log ( JSON . stringify ( queries . concat ( queryAndParams ) ) ) ;
2844+
2845+ return dbRunner . evaluateQueryWithPreAggregations ( query ) . then ( res => {
2846+ expect ( res ) . toEqual (
2847+ [ {
2848+ cube_pre_agg_proxy_b__terminal_date_day : '2025-10-01T00:00:00.000Z' ,
2849+ } ]
2850+ ) ;
2851+ } ) ;
2852+ } ) ;
27762853} ) ;
0 commit comments