From 5b1fcc5f6ad13b2402ab3623ea3a807e75199f46 Mon Sep 17 00:00:00 2001 From: Konstantin Burkalev Date: Fri, 28 Feb 2025 17:48:40 +0200 Subject: [PATCH] fix/specify some types --- .../src/orchestrator/PreAggregationLoader.ts | 10 ++++--- .../PreAggregationPartitionRangeLoader.ts | 3 ++- .../src/orchestrator/PreAggregations.ts | 2 ++ .../src/orchestrator/QueryCache.ts | 26 ++++--------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts index f559998a568e9..906fcd05cfc46 100644 --- a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts +++ b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoader.ts @@ -12,7 +12,7 @@ import { UnloadOptions } from '@cubejs-backend/base-driver'; import { DriverFactory } from './DriverFactory'; -import { QueryCache, QueryTuple } from './QueryCache'; +import { PreAggTableToTempTableNames, QueryCache, QueryTuple } from './QueryCache'; import { ContinueWaitError } from './ContinueWaitError'; import { LargeStreamWarning } from './StreamObjectsCounter'; import { @@ -20,6 +20,7 @@ import { InvalidationKeys, LoadPreAggregationResult, PreAggregations, + PreAggregationTableToTempTable, tablesToVersionEntries, version, VersionEntriesObj, @@ -51,7 +52,7 @@ export class PreAggregationLoader { public preAggregation: any; - private preAggregationsTablesToTempTables: any; + private readonly preAggregationsTablesToTempTables: PreAggregationTableToTempTable[]; /** * Determines whether current instance instantiated for a jobbed build query @@ -922,7 +923,7 @@ export class PreAggregationLoader { await this.dropOrphanedTables(externalDriver, table, saveCancelFn, true, queryOptions); } - protected async createIndexes(driver, newVersionEntry: VersionEntry, saveCancelFn: SaveCancelFn, queryOptions: QueryOptions) { + protected async createIndexes(driver: DriverInterface, newVersionEntry: VersionEntry, saveCancelFn: SaveCancelFn, queryOptions: QueryOptions) { const indexesSql = this.prepareIndexesSql(newVersionEntry, queryOptions); for (let i = 0; i < indexesSql.length; i++) { const [query, params] = indexesSql[i].sql; @@ -941,9 +942,10 @@ export class PreAggregationLoader { table_name: indexName }; this.logger('Creating pre-aggregation index', queryOptions); + const preAggTableToTempTableNames = this.preAggregationsTablesToTempTables as PreAggTableToTempTableNames[]; const resultingSql = QueryCache.replacePreAggregationTableNames( query, - this.preAggregationsTablesToTempTables.concat([ + preAggTableToTempTableNames.concat([ [this.preAggregation.tableName, { targetTableName: this.targetTableName(newVersionEntry) }], [indexName, { targetTableName: this.targetTableName(indexVersionEntry) }] ]) diff --git a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts index 53c2caf85c064..6f77a0b5cf7d9 100644 --- a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts +++ b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts @@ -22,6 +22,7 @@ import { PartitionRanges, PreAggregationDescription, PreAggregations, + PreAggregationTableToTempTable, QueryDateRange } from './PreAggregations'; import { PreAggregationLoader } from './PreAggregationLoader'; @@ -65,7 +66,7 @@ export class PreAggregationPartitionRangeLoader { private readonly queryCache: QueryCache, private readonly preAggregations: PreAggregations, private readonly preAggregation: PreAggregationDescription, - private readonly preAggregationsTablesToTempTables: [string, LoadPreAggregationResult][], + private readonly preAggregationsTablesToTempTables: PreAggregationTableToTempTable[], private readonly loadCache: PreAggregationLoadCache, private readonly options: PreAggsPartitionRangeLoaderOpts = { maxPartitions: 10000, diff --git a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts index 3d3ecaa13f7b1..d81b8314a9981 100644 --- a/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts +++ b/packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts @@ -144,6 +144,8 @@ export type LoadPreAggregationResult = { partitionRange?: QueryDateRange; }; +export type PreAggregationTableToTempTable = [string, LoadPreAggregationResult]; + export type LambdaOptions = { maxSourceRows: number }; diff --git a/packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts b/packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts index 087f401106d7b..a3f4ef7deeef4 100644 --- a/packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts +++ b/packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts @@ -16,7 +16,7 @@ import { QueryQueue } from './QueryQueue'; import { ContinueWaitError } from './ContinueWaitError'; import { LocalCacheDriver } from './LocalCacheDriver'; import { DriverFactory, DriverFactoryByDataSource } from './DriverFactory'; -import { PreAggregationDescription } from './PreAggregations'; +import { LoadPreAggregationResult, PreAggregationDescription } from './PreAggregations'; import { getCacheHash } from './utils'; import { CacheAndQueryDriverType } from './QueryOrchestrator'; @@ -71,25 +71,7 @@ export type QueryBody = { /** * Temp (partition/lambda) table definition. */ -export type TempTable = { - type: string; // for ex.: "rollup" - buildRangeEnd: string; - lastUpdatedAt: number; - queryKey: unknown; - refreshKeyValues: [{ - 'refresh_key': string, - }][]; - targetTableName: string; // full table name (with suffix) - lambdaTable?: { - name: string, - columns: { - name: string, - type: string, - attributes?: string[], - }[]; - csvRows: string; - }; -}; +export type TempTable = LoadPreAggregationResult; /** * Pre-aggregation table (stored in the first element) to temp table @@ -100,6 +82,8 @@ export type PreAggTableToTempTable = [ TempTable, ]; +export type PreAggTableToTempTableNames = [string, { targetTableName: string; }]; + export type CacheKeyItem = string | string[] | QueryTuple | QueryTuple[] | undefined; export type CacheKey = @@ -397,7 +381,7 @@ export class QueryCache { public static replacePreAggregationTableNames( queryAndParams: string | QueryWithParams, - preAggregationsTablesToTempTables: PreAggTableToTempTable[], + preAggregationsTablesToTempTables: PreAggTableToTempTableNames[], ): string | QueryTuple { const [keyQuery, params, queryOptions] = Array.isArray(queryAndParams) ? queryAndParams