Skip to content

Commit 3715d7e

Browse files
Merge pull request #1590 from ClickHouse/dynamic_json_serialization_version_2
`Dynamic`/`JSON` Serialization Version 3
2 parents 5bc93d8 + 2555f87 commit 3715d7e

File tree

19 files changed

+397
-322
lines changed

19 files changed

+397
-322
lines changed

examples/clickhouse_api/dynamic.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ func DynamicExample() error {
2727
ctx := context.Background()
2828

2929
conn, err := GetNativeConnection(clickhouse.Settings{
30-
"allow_experimental_dynamic_type": true,
30+
"allow_experimental_dynamic_type": true,
31+
"output_format_native_use_flattened_dynamic_and_json_serialization": true,
3132
}, nil, nil)
3233
if err != nil {
3334
return err
3435
}
3536

36-
if !CheckMinServerVersion(conn, 24, 8, 0) {
37+
if !CheckMinServerVersion(conn, 25, 6, 0) {
3738
fmt.Print("unsupported clickhouse version for Dynamic type")
3839
return nil
3940
}

examples/clickhouse_api/json_fast_structs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ func JSONFastStructExample() error {
9191
ctx := context.Background()
9292

9393
conn, err := GetNativeConnection(clickhouse.Settings{
94-
"allow_experimental_json_type": true,
94+
"allow_experimental_json_type": true,
95+
"output_format_native_use_flattened_dynamic_and_json_serialization": true,
9596
}, nil, nil)
9697
if err != nil {
9798
return err
9899
}
99100

100-
if !CheckMinServerVersion(conn, 24, 9, 0) {
101+
if !CheckMinServerVersion(conn, 25, 6, 0) {
101102
fmt.Print("unsupported clickhouse version for JSON type")
102103
return nil
103104
}

examples/clickhouse_api/json_paths.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ func JSONPathsExample() error {
2828
ctx := context.Background()
2929

3030
conn, err := GetNativeConnection(clickhouse.Settings{
31-
"allow_experimental_json_type": true,
31+
"allow_experimental_json_type": true,
32+
"output_format_native_use_flattened_dynamic_and_json_serialization": true,
3233
}, nil, nil)
3334
if err != nil {
3435
return err
3536
}
3637

37-
if !CheckMinServerVersion(conn, 24, 9, 0) {
38+
if !CheckMinServerVersion(conn, 25, 6, 0) {
3839
fmt.Print("unsupported clickhouse version for JSON type")
3940
return nil
4041
}

examples/clickhouse_api/json_strings.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ func JSONStringExample() error {
2727
ctx := context.Background()
2828

2929
conn, err := GetNativeConnection(clickhouse.Settings{
30-
"allow_experimental_json_type": true,
31-
"output_format_native_write_json_as_string": true,
30+
"allow_experimental_json_type": true,
31+
"output_format_native_write_json_as_string": true,
32+
"output_format_native_use_flattened_dynamic_and_json_serialization": true,
3233
}, nil, nil)
3334
if err != nil {
3435
return err
3536
}
3637

37-
if !CheckMinServerVersion(conn, 24, 9, 0) {
38+
if !CheckMinServerVersion(conn, 25, 6, 0) {
3839
fmt.Print("unsupported clickhouse version for JSON type")
3940
return nil
4041
}

examples/clickhouse_api/json_structs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ func JSONStructExample() error {
6161
ctx := context.Background()
6262

6363
conn, err := GetNativeConnection(clickhouse.Settings{
64-
"allow_experimental_json_type": true,
64+
"allow_experimental_json_type": true,
65+
"output_format_native_use_flattened_dynamic_and_json_serialization": true,
6566
}, nil, nil)
6667
if err != nil {
6768
return err
6869
}
6970

70-
if !CheckMinServerVersion(conn, 24, 9, 0) {
71+
if !CheckMinServerVersion(conn, 25, 6, 0) {
7172
fmt.Print("unsupported clickhouse version for JSON type")
7273
return nil
7374
}

examples/clickhouse_api/main_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,5 @@ func TestJSONFastStructExample(t *testing.T) {
234234

235235
func TestJSONStringExample(t *testing.T) {
236236
clickhouse_tests.SkipOnCloud(t, "cannot modify JSON settings on cloud")
237-
t.Skip("client cannot receive JSON strings")
238237
require.NoError(t, JSONStringExample())
239238
}

examples/std/dynamic.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func DynamicExample() error {
3131
return err
3232
}
3333

34-
if !CheckMinServerVersion(conn, 24, 8, 0) {
34+
if !CheckMinServerVersion(conn, 25, 6, 0) {
3535
fmt.Print("unsupported clickhouse version for Dynamic type")
3636
return nil
3737
}
@@ -41,6 +41,11 @@ func DynamicExample() error {
4141
return err
4242
}
4343

44+
_, err = conn.ExecContext(ctx, "SET output_format_native_use_flattened_dynamic_and_json_serialization = 1")
45+
if err != nil {
46+
return err
47+
}
48+
4449
defer func() {
4550
conn.Exec("DROP TABLE go_dynamic_example")
4651
}()

examples/std/json_paths.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func JSONPathsExample() error {
3232
return err
3333
}
3434

35-
if !CheckMinServerVersion(conn, 24, 9, 0) {
35+
if !CheckMinServerVersion(conn, 25, 6, 0) {
3636
fmt.Print("unsupported clickhouse version for JSON type")
3737
return nil
3838
}
@@ -41,6 +41,10 @@ func JSONPathsExample() error {
4141
if err != nil {
4242
return err
4343
}
44+
_, err = conn.ExecContext(ctx, "SET output_format_native_use_flattened_dynamic_and_json_serialization = 1")
45+
if err != nil {
46+
return err
47+
}
4448

4549
defer func() {
4650
conn.Exec("DROP TABLE go_json_example")

examples/std/main_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,5 @@ func TestJSONPathsExample(t *testing.T) {
166166

167167
func TestJSONStringExample(t *testing.T) {
168168
clickhouse_tests.SkipOnCloud(t, "cannot modify JSON settings on cloud")
169-
t.Skip("client cannot receive JSON strings")
170169
require.NoError(t, JSONStringExample())
171170
}

lib/column/codegen/column.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ func (t Type) Column(name string, tz *time.Location) (Interface, error) {
121121
case "Point":
122122
return &Point{name: name}, nil
123123
case "String":
124-
return &String{name: name, col: colStrProvider()}, nil
125-
case "SharedVariant":
126-
return &SharedVariant{name: name}, nil
124+
return &String{name: name, col: colStrProvider(name)}, nil
127125
case "Object('json')":
128126
return &JSONObject{name: name, root: true, tz: tz}, nil
129127
}

0 commit comments

Comments
 (0)