Skip to content

Commit

Permalink
eh?
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Feb 8, 2025
1 parent 77a7afe commit 1874e71
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/ch/row_binary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ defmodule Ch.RowBinary do
:uuid,
:date,
:date32,
:json,
:ipv4,
:ipv6,
:point,
Expand Down Expand Up @@ -865,6 +866,9 @@ defmodule Ch.RowBinary do
<<d::32-little-signed, bin::bytes>> = bin
decode_rows(types_rest, bin, [Date.add(@epoch_date, d) | row], rows, types)

:json ->
raise ArgumentError, "JSON type is not supported for decoding: #{inspect(bin)}"

{:datetime, timezone} ->
<<s::32-little, bin::bytes>> = bin

Expand Down
1 change: 1 addition & 0 deletions lib/ch/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule Ch.Types do
# {"DateTime", :datetime, []},
{"Date32", :date32, []},
{"Date", :date, []},
{"JSON", :json, []},
{"LowCardinality", :low_cardinality, [:type]},
for size <- [32, 64, 128, 256] do
{"Decimal#{size}", :"decimal#{size}", [:int]}
Expand Down
34 changes: 25 additions & 9 deletions test/ch/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -572,23 +572,39 @@ defmodule Ch.ConnectionTest do
# https://clickhouse.com/docs/en/integrations/data-formats/json/overview
# https://clickhouse.com/blog/a-new-powerful-json-data-type-for-clickhouse
# https://clickhouse.com/blog/json-bench-clickhouse-vs-mongodb-elasticsearch-duckdb-postgresql
# https://github.com/ClickHouse/ClickHouse/pull/70288
# https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/TypeId.h
test "json", %{conn: conn} do

Check failure on line 577 in test/ch/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.17.1, 27, 24.12.2.29, UTC)

test types json (Ch.ConnectionTest)
settings = [enable_json_type: 1]

Ch.query!(conn, "CREATE TABLE test_json(json JSON) ENGINE = Memory", [], settings: settings)
assert Ch.query!(
conn,
~s|select '{"a":42,"b":10}'::JSON|,
[],
settings: settings,
decode: false,
format: "RowBinary"
).rows == [
<<2, 1, 97, 10, 42, 0, 0, 0, 0, 0, 0, 0, 1, 98, 10, 10, 0, 0, 0, 0, 0, 0, 0>>
]

Ch.query!(
conn,
~s|INSERT INTO test_json VALUES ('{"a" : {"b" : 42}, "c" : [1, 2, 3]}'), ('{"f" : "Hello, World!"}'), ('{"a" : {"b" : 43, "e" : 10}, "c" : [4, 5, 6]}')|
)
# Ch.query!(conn, "CREATE TABLE test_json(json JSON) ENGINE = Memory", [], settings: settings)

assert Ch.query!(conn, "SELECT json FROM test_json") == :asdf
# Ch.query!(
# conn,
# ~s|INSERT INTO test_json VALUES ('{"a" : {"b" : 42}, "c" : [1, 2, 3]}'), ('{"f" : "Hello, World!"}'), ('{"a" : {"b" : 43, "e" : 10}, "c" : [4, 5, 6]}')|
# )

assert Ch.query!(conn, "SELECT json.a, json.b.c, json.b.d[3] FROM test_json").rows == [
[1, 2, 3]
]
# assert Ch.query!(conn, "SELECT json FROM test_json") == :asdf

# assert Ch.query!(conn, "SELECT json.a, json.b.c, json.b.d[3] FROM test_json").rows == [
# [1, 2, 3]
# ]
end

# TODO variant (is there?)
# TODO dynamic

# TODO enum16

test "enum8", %{conn: conn} do
Expand Down

0 comments on commit 1874e71

Please sign in to comment.