Skip to content

Commit e425e84

Browse files
committed
fix date formatting in replacePartitionSqlAndParams
1 parent 37375d3 commit e425e84

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/cubejs-backend-shared/src/time.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ export const localTimestampToUtc = (timezone: string, timestampFormat: string, t
239239
return moment.tz(timestamp, timezone).utc().format(timestampFormat);
240240
};
241241

242+
export const reformatUtcTimestamp = (timestampFormat: string, timestamp: string): string => moment.utc(timestamp).format(timestampFormat);
243+
242244
/**
243245
* Takes timestamp in UTC, shift it into provided timezone and returns the corresponding timestamp in UTC
244246
*/

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
timeSeries,
1111
localTimestampToUtc,
1212
parseLocalDate,
13+
reformatUtcTimestamp,
1314
} from '@cubejs-backend/shared';
1415
import { InlineTable, TableStructure } from '@cubejs-backend/base-driver';
1516
import { DriverFactory } from './DriverFactory';
@@ -161,9 +162,10 @@ export class PreAggregationPartitionRangeLoader {
161162
return [sql.replace(this.preAggregation.tableName, partitionTableName), params?.map(
162163
param => {
163164
if (dateRange && param === FROM_PARTITION_RANGE) {
164-
return dateRange[0];
165+
// Timestamp is already in UTC, but different format might be expected so we need to convert (e.g. for Kafka)
166+
return reformatUtcTimestamp(this.preAggregation.timestampFormat, dateRange[0]);
165167
} else if (dateRange && param === TO_PARTITION_RANGE) {
166-
return dateRange[1];
168+
return reformatUtcTimestamp(this.preAggregation.timestampFormat, dateRange[1]);
167169
} else {
168170
return param;
169171
}

0 commit comments

Comments
 (0)