Skip to content

Commit

Permalink
improve partitionTableName() in PreAggregationPartitionRangeLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Feb 26, 2025
1 parent 01a87b0 commit 8160bc3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class PreAggregationPartitionRangeLoader {
private readonly driverFactory: DriverFactory,
private readonly logger: any,
private readonly queryCache: QueryCache,
// eslint-disable-next-line no-use-before-define
private readonly preAggregations: PreAggregations,
private readonly preAggregation: PreAggregationDescription,
private readonly preAggregationsTablesToTempTables: [string, LoadPreAggregationResult][],
Expand Down Expand Up @@ -246,7 +245,7 @@ export class PreAggregationPartitionRangeLoader {
let loadResultAndLoaders = await loadPreAggregationsByPartitionRanges(await this.partitionRanges());
if (this.options.externalRefresh && loadResultAndLoaders.loadResults.length === 0) {
loadResultAndLoaders = await loadPreAggregationsByPartitionRanges(await this.partitionRanges(true));
// In case there're no partitions ready at matched time dimension intersection then no data can be retrieved.
// In case there are no partitions ready at matched time dimension intersection then no data can be retrieved.
// We need to provide any table so query can just execute successfully.
if (loadResultAndLoaders.loadResults.length > 0) {
loadResultAndLoaders.loadResults = [loadResultAndLoaders.loadResults[loadResultAndLoaders.loadResults.length - 1]];
Expand Down Expand Up @@ -482,11 +481,25 @@ export class PreAggregationPartitionRangeLoader {
});
}

public static partitionTableName(tableName: string, partitionGranularity: string, dateRange: string[]) {
public static partitionTableName(tableName: string, partitionGranularity: string, dateRange: QueryDateRange) {
let dateLenCut: number;
switch (partitionGranularity) {
case 'hour':
dateLenCut = 13;
break;
case 'minute':
dateLenCut = 16;
break;
default:
dateLenCut = 10;
break;
}

const partitionSuffix = dateRange[0].substring(
0,
partitionGranularity === 'hour' ? 13 : 10
dateLenCut
).replace(/[-T:]/g, '');

return `${tableName}${partitionSuffix}`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class BaseDbRunner {
desc,
suffix,
partitionGranularity: string | null = null,
dateRange: string[] | null = null
dateRange: [string, string] | null = null
) {
const [toReplace, params] = query;
const tableName = partitionGranularity && dateRange ? PreAggregationPartitionRangeLoader.partitionTableName(
Expand Down

0 comments on commit 8160bc3

Please sign in to comment.