Skip to content

Commit 58fde93

Browse files
committed
improve partitionTableName() in PreAggregationPartitionRangeLoader
1 parent 9234293 commit 58fde93

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export class PreAggregationPartitionRangeLoader {
6363
private readonly driverFactory: DriverFactory,
6464
private readonly logger: any,
6565
private readonly queryCache: QueryCache,
66-
// eslint-disable-next-line no-use-before-define
6766
private readonly preAggregations: PreAggregations,
6867
private readonly preAggregation: PreAggregationDescription,
6968
private readonly preAggregationsTablesToTempTables: [string, LoadPreAggregationResult][],
@@ -246,7 +245,7 @@ export class PreAggregationPartitionRangeLoader {
246245
let loadResultAndLoaders = await loadPreAggregationsByPartitionRanges(await this.partitionRanges());
247246
if (this.options.externalRefresh && loadResultAndLoaders.loadResults.length === 0) {
248247
loadResultAndLoaders = await loadPreAggregationsByPartitionRanges(await this.partitionRanges(true));
249-
// In case there're no partitions ready at matched time dimension intersection then no data can be retrieved.
248+
// In case there are no partitions ready at matched time dimension intersection then no data can be retrieved.
250249
// We need to provide any table so query can just execute successfully.
251250
if (loadResultAndLoaders.loadResults.length > 0) {
252251
loadResultAndLoaders.loadResults = [loadResultAndLoaders.loadResults[loadResultAndLoaders.loadResults.length - 1]];
@@ -482,11 +481,25 @@ export class PreAggregationPartitionRangeLoader {
482481
});
483482
}
484483

485-
public static partitionTableName(tableName: string, partitionGranularity: string, dateRange: string[]) {
484+
public static partitionTableName(tableName: string, partitionGranularity: string, dateRange: QueryDateRange) {
485+
let dateLenCut: number;
486+
switch (partitionGranularity) {
487+
case 'hour':
488+
dateLenCut = 13;
489+
break;
490+
case 'minute':
491+
dateLenCut = 16;
492+
break;
493+
default:
494+
dateLenCut = 10;
495+
break;
496+
}
497+
486498
const partitionSuffix = dateRange[0].substring(
487499
0,
488-
partitionGranularity === 'hour' ? 13 : 10
500+
dateLenCut
489501
).replace(/[-T:]/g, '');
502+
490503
return `${tableName}${partitionSuffix}`;
491504
}
492505

packages/cubejs-schema-compiler/test/integration/utils/BaseDbRunner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class BaseDbRunner {
109109
desc,
110110
suffix,
111111
partitionGranularity: string | null = null,
112-
dateRange: string[] | null = null
112+
dateRange: [string, string] | null = null
113113
) {
114114
const [toReplace, params] = query;
115115
const tableName = partitionGranularity && dateRange ? PreAggregationPartitionRangeLoader.partitionTableName(

0 commit comments

Comments
 (0)