Skip to content

Commit 357ebeb

Browse files
committed
chore: fix super strange format issue
1 parent 95616b6 commit 357ebeb

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,13 @@ export class ClickHouseQuery extends BaseQuery {
7474
const timeUnit = this.diffTimeUnitForInterval(interval);
7575
const beginOfTime = 'fromUnixTimestamp(0)';
7676

77-
const dateBinResult = `date_add(${timeUnit},
77+
return `date_add(${timeUnit},
7878
FLOOR(
7979
date_diff(${timeUnit}, ${alignedOrigin}, ${source}) /
8080
date_diff(${timeUnit}, ${beginOfTime}, ${beginOfTime} + ${intervalFormatted})
8181
) * date_diff(${timeUnit}, ${beginOfTime}, ${beginOfTime} + ${intervalFormatted}),
8282
${alignedOrigin}
8383
)`;
84-
85-
// Normalize the result to DateTime64(0) for consistent formatting
86-
return `toDateTime64(${dateBinResult}, 0, '${this.timezone}')`;
8784
}
8885

8986
public subtractInterval(date: string, interval: string): string {

packages/cubejs-schema-compiler/test/integration/clickhouse/ClickHouseDbRunner.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GenericContainer } from 'testcontainers';
44
import type { StartedTestContainer } from 'testcontainers';
55
import { format as formatSql } from 'sqlstring';
66
import { v4 as uuidv4 } from 'uuid';
7+
import * as moment from 'moment/moment';
78
import { ClickHouseQuery } from '../../../src/adapter/ClickHouseQuery';
89
import { BaseDbRunner } from '../utils/BaseDbRunner';
910

@@ -210,10 +211,14 @@ export class ClickHouseDbRunner extends BaseDbRunner {
210211
if (fieldMeta === undefined) {
211212
throw new Error(`Missing meta for field ${field}`);
212213
}
213-
if (fieldMeta.type.includes('DateTime')) {
214+
215+
if (fieldMeta.type.includes('DateTime64')) {
216+
row[field] = moment.utc(value).format(moment.HTML5_FMT.DATETIME_LOCAL_MS);
217+
} else if (fieldMeta.type.includes('DateTime') /** Can be DateTime or DateTime('timezone') */) {
214218
if (typeof value !== 'string') {
215219
throw new Error(`Unexpected value for ${field}`);
216220
}
221+
217222
row[field] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
218223
} else if (fieldMeta.type.includes('Date')) {
219224
row[field] = `${value}T00:00:00.000`;

packages/cubejs-schema-compiler/test/unit/base-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ describe('SQL Generation', () => {
10121012
relationship: 'one_to_one'
10131013
},
10141014
}`
1015-
}).replace(`sql: \`\${CUBE}.location = 'San Francisco'\``, `sql: \`\${FILTER_PARAMS.cardsA.location.filter('location')}\``),
1015+
}).replace('sql: `${CUBE}.location = \'San Francisco\'`', 'sql: `${FILTER_PARAMS.cardsA.location.filter(\'location\')}`'),
10161016
createCubeSchema({
10171017
name: 'cardsB',
10181018
sqlTable: 'card2_tbl',

0 commit comments

Comments
 (0)