Skip to content

Commit 442392c

Browse files
authored
Adjust the tests that rely on the old Object('json') data type (#299)
1 parent 2988c50 commit 442392c

File tree

3 files changed

+71
-200
lines changed

3 files changed

+71
-200
lines changed
Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
11
import { createClient } from '@clickhouse/client' // or '@clickhouse/client-web'
22

33
// Ephemeral columns documentation: https://clickhouse.com/docs/en/sql-reference/statements/create/table#ephemeral
4-
// This example is inspired by https://github.com/ClickHouse/clickhouse-js/issues/217
54
void (async () => {
65
const tableName = 'insert_ephemeral_columns'
7-
const client = createClient({
8-
clickhouse_settings: {
9-
allow_experimental_object_type: 1, // allows JSON type usage
10-
},
11-
})
6+
const client = createClient({})
127

138
await client.command({
149
query: `
1510
CREATE OR REPLACE TABLE ${tableName}
1611
(
17-
event_type LowCardinality(String) DEFAULT JSONExtractString(message_raw, 'type'),
18-
repo_name LowCardinality(String) DEFAULT JSONExtractString(message_raw, 'repo', 'name'),
19-
message JSON DEFAULT message_raw,
20-
message_raw String EPHEMERAL
12+
id UInt64,
13+
message String DEFAULT message_default,
14+
message_default String EPHEMERAL
2115
)
2216
ENGINE MergeTree()
23-
ORDER BY (event_type, repo_name)
17+
ORDER BY (id)
2418
`,
2519
})
2620

2721
await client.insert({
2822
table: tableName,
2923
values: [
3024
{
31-
message_raw: {
32-
type: 'MyEventType',
33-
repo: {
34-
name: 'foo',
35-
},
36-
},
25+
id: '42',
26+
message_default: 'foo',
3727
},
3828
{
39-
message_raw: {
40-
type: 'SomeOtherType',
41-
repo: {
42-
name: 'bar',
43-
},
44-
},
29+
id: '144',
30+
message_default: 'bar',
4531
},
4632
],
4733
format: 'JSONEachRow',
4834
// The name of the ephemeral column has to be specified here
4935
// to trigger the default values logic for the rest of the columns
50-
columns: ['message_raw'],
36+
columns: ['id', 'message_default'],
5137
})
5238

5339
const rows = await client.query({
54-
query: `SELECT * FROM ${tableName}`,
55-
format: 'JSONCompactEachRowWithNames',
40+
query: `SELECT *
41+
FROM ${tableName}`,
42+
format: 'JSONEachRow',
5643
})
5744

58-
console.info(await rows.text())
45+
console.info(await rows.json())
5946
await client.close()
6047
})()

packages/client-common/__tests__/integration/data_types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ describe('data types', () => {
516516
o: { a: 2, b: { c: 3, d: [4, 5, 6] } },
517517
},
518518
]
519-
const table = await createTableWithFields(client, 'o JSON', {
519+
const table = await createTableWithFields(client, `o Object('json')`, {
520520
allow_experimental_object_type: 1,
521521
})
522522
await insertAndAssert(table, values)

0 commit comments

Comments
 (0)