diff --git a/examples/insert_ephemeral_columns.ts b/examples/insert_ephemeral_columns.ts index 756d12f..f0b257c 100644 --- a/examples/insert_ephemeral_columns.ts +++ b/examples/insert_ephemeral_columns.ts @@ -9,9 +9,9 @@ void (async () => { query: ` CREATE OR REPLACE TABLE ${tableName} ( - id UInt64, - message String DEFAULT message_raw, - message_raw String EPHEMERAL + id UInt64, + message String DEFAULT message_default, + message_default String EPHEMERAL ) ENGINE MergeTree() ORDER BY (id) @@ -23,17 +23,17 @@ void (async () => { values: [ { id: '42', - message_raw: 'foo', + message_default: 'foo', }, { id: '144', - message_raw: 'bar', + message_default: 'bar', }, ], format: 'JSONEachRow', // The name of the ephemeral column has to be specified here // to trigger the default values logic for the rest of the columns - columns: ['message_raw'], + columns: ['id', 'message_default'], }) const rows = await client.query({ diff --git a/packages/client-common/__tests__/integration/data_types.test.ts b/packages/client-common/__tests__/integration/data_types.test.ts index cbc1760..0c6f0c5 100644 --- a/packages/client-common/__tests__/integration/data_types.test.ts +++ b/packages/client-common/__tests__/integration/data_types.test.ts @@ -4,7 +4,7 @@ import type { } from '@clickhouse/client-common' import { randomUUID } from '@test/utils/guid' import { createTableWithFields } from '../fixtures/table_with_fields' -import { createTestClient, getRandomInt } from '../utils' +import { createTestClient, getRandomInt, TestEnv, whenOnEnv } from '../utils' describe('data types', () => { let client: ClickHouseClient @@ -504,6 +504,25 @@ describe('data types', () => { await insertAndAssert(table, values) }) + // JSON cannot be used on a "modern" Cloud instance + whenOnEnv(TestEnv.LocalSingleNode, TestEnv.LocalCluster, TestEnv.Cloud).it( + 'should work with JSON', + async () => { + const values = [ + { + o: { a: 1, b: { c: 2, d: [1, 2, 3] } }, + }, + { + o: { a: 2, b: { c: 3, d: [4, 5, 6] } }, + }, + ] + const table = await createTableWithFields(client, `o Object('json')`, { + allow_experimental_object_type: 1, + }) + await insertAndAssert(table, values) + }, + ) + describe('Nested', () => { it('should work by default', async () => { const values = [