Skip to content

Commit 8bb04ca

Browse files
committed
chore: fix super strange format issue
1 parent 95616b6 commit 8bb04ca

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

packages/cubejs-schema-compiler/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@
8282
"source-map-support": "^0.5.19",
8383
"sqlstring": "^2.3.1",
8484
"testcontainers": "^10.28.0",
85-
"typescript": "~5.2.2"
85+
"typescript": "~5.2.2",
86+
"moment": "^2.30.1"
8687
},
8788
"license": "Apache-2.0",
8889
"eslintConfig": {

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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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 moment from 'moment';
8+
79
import { ClickHouseQuery } from '../../../src/adapter/ClickHouseQuery';
810
import { BaseDbRunner } from '../utils/BaseDbRunner';
911

@@ -210,10 +212,14 @@ export class ClickHouseDbRunner extends BaseDbRunner {
210212
if (fieldMeta === undefined) {
211213
throw new Error(`Missing meta for field ${field}`);
212214
}
213-
if (fieldMeta.type.includes('DateTime')) {
215+
216+
if (fieldMeta.type.includes('DateTime64')) {
217+
row[field] = moment.utc(value).format(moment.HTML5_FMT.DATETIME_LOCAL_MS);
218+
} else if (fieldMeta.type.includes('DateTime') /** Can be DateTime or DateTime('timezone') */) {
214219
if (typeof value !== 'string') {
215220
throw new Error(`Unexpected value for ${field}`);
216221
}
222+
217223
row[field] = `${value.substring(0, 10)}T${value.substring(11, 22)}.000`;
218224
} else if (fieldMeta.type.includes('Date')) {
219225
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',

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19505,10 +19505,10 @@ moment-timezone@^0.5.15, moment-timezone@^0.5.33, moment-timezone@^0.5.46, momen
1950519505
dependencies:
1950619506
moment "^2.29.4"
1950719507

19508-
moment@^2.17.1, moment@^2.24.0, moment@^2.25.3, moment@^2.29.1, moment@^2.29.4:
19509-
version "2.29.4"
19510-
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
19511-
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==
19508+
moment@^2.17.1, moment@^2.24.0, moment@^2.25.3, moment@^2.29.1, moment@^2.29.4, moment@^2.30.1:
19509+
version "2.30.1"
19510+
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
19511+
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==
1951219512

1951319513
1951419514
version "2.0.0"

0 commit comments

Comments
 (0)