Skip to content

Commit

Permalink
Add the Object(json) test back
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn committed Aug 19, 2024
1 parent 3fd43cf commit 80b40b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 6 additions & 6 deletions examples/insert_ephemeral_columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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({
Expand Down
21 changes: 20 additions & 1 deletion packages/client-common/__tests__/integration/data_types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit 80b40b5

Please sign in to comment.