|
1 | 1 | import { getEnv } from '@cubejs-backend/shared'; |
2 | 2 | import { UserError } from '../../../src/compiler/UserError'; |
3 | | -import type { BaseQuery } from '../../../src'; |
4 | 3 | import { PostgresQuery } from '../../../src/adapter/PostgresQuery'; |
5 | 4 | import { BigqueryQuery } from '../../../src/adapter/BigqueryQuery'; |
6 | 5 | import { PrestodbQuery } from '../../../src/adapter/PrestodbQuery'; |
7 | 6 | import { prepareJsCompiler } from '../../unit/PrepareCompiler'; |
8 | 7 | import { dbRunner } from './PostgresDBRunner'; |
9 | 8 | import { createJoinedCubesSchema } from '../../unit/utils'; |
| 9 | +import { testWithPreAggregation } from './pre-aggregation-utils'; |
10 | 10 |
|
11 | 11 | describe('SQL Generation', () => { |
12 | 12 | jest.setTimeout(200000); |
@@ -885,27 +885,6 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL |
885 | 885 | ); |
886 | 886 | } |
887 | 887 |
|
888 | | - type QueryWithParams = [string, Array<unknown>]; |
889 | | - |
890 | | - async function testWithPreAgg( |
891 | | - preAggregationsDescription: { loadSql: QueryWithParams, invalidateKeyQueries: Array<QueryWithParams> }, |
892 | | - query: BaseQuery, |
893 | | - ) { |
894 | | - const preAggSql = preAggregationsDescription |
895 | | - .loadSql[0] |
896 | | - // Without `ON COMMIT DROP` temp tables are session-bound, and can live across multiple transactions |
897 | | - .replace(/CREATE TABLE (.+) AS SELECT/, 'CREATE TEMP TABLE $1 ON COMMIT DROP AS SELECT'); |
898 | | - const preAggParams = preAggregationsDescription.loadSql[1]; |
899 | | - |
900 | | - const queries = [ |
901 | | - ...preAggregationsDescription.invalidateKeyQueries, |
902 | | - [preAggSql, preAggParams], |
903 | | - query.buildSqlAndParams(), |
904 | | - ]; |
905 | | - |
906 | | - return dbRunner.testQueries(queries); |
907 | | - } |
908 | | - |
909 | 888 | it('simple join total', async () => runQueryTest({ |
910 | 889 | measures: [ |
911 | 890 | 'visitors.visitor_revenue', |
@@ -2184,7 +2163,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL |
2184 | 2163 |
|
2185 | 2164 | const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription()[0]; |
2186 | 2165 |
|
2187 | | - const res = await testWithPreAgg(preAggregationsDescription, query); |
| 2166 | + const res = await testWithPreAggregation(preAggregationsDescription, query); |
2188 | 2167 | expect(res).toEqual( |
2189 | 2168 | // Empty result set, only segments in query |
2190 | 2169 | [{}] |
@@ -2225,7 +2204,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL |
2225 | 2204 | const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription()[0]; |
2226 | 2205 | console.log(preAggregationsDescription); |
2227 | 2206 |
|
2228 | | - const res = await testWithPreAgg(preAggregationsDescription, query); |
| 2207 | + const res = await testWithPreAggregation(preAggregationsDescription, query); |
2229 | 2208 | console.log(JSON.stringify(res)); |
2230 | 2209 | expect(res).toEqual( |
2231 | 2210 | [ |
@@ -2266,7 +2245,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL |
2266 | 2245 | const preAggregationsDescription: any = query.preAggregations?.preAggregationsDescription()[0]; |
2267 | 2246 | console.log(preAggregationsDescription); |
2268 | 2247 |
|
2269 | | - const res = await testWithPreAgg(preAggregationsDescription, query); |
| 2248 | + const res = await testWithPreAggregation(preAggregationsDescription, query); |
2270 | 2249 | console.log(JSON.stringify(res)); |
2271 | 2250 | expect(res).toEqual( |
2272 | 2251 | [{ |
|
0 commit comments