Skip to content

Commit

Permalink
fix/specify some types
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Feb 28, 2025
1 parent 6a5b563 commit 5b1fcc5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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 {
getStructureVersion,
InvalidationKeys,
LoadPreAggregationResult,
PreAggregations,
PreAggregationTableToTempTable,
tablesToVersionEntries,
version,
VersionEntriesObj,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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) }]
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
PartitionRanges,
PreAggregationDescription,
PreAggregations,
PreAggregationTableToTempTable,
QueryDateRange
} from './PreAggregations';
import { PreAggregationLoader } from './PreAggregationLoader';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export type LoadPreAggregationResult = {
partitionRange?: QueryDateRange;
};

export type PreAggregationTableToTempTable = [string, LoadPreAggregationResult];

export type LambdaOptions = {
maxSourceRows: number
};
Expand Down
26 changes: 5 additions & 21 deletions packages/cubejs-query-orchestrator/src/orchestrator/QueryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b1fcc5

Please sign in to comment.