From 77a7afe73fa4f7431a1c305254fe4bbba62f2fe2 Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Sat, 8 Feb 2025 21:44:53 +0300 Subject: [PATCH] new json --- test/ch/connection_test.exs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/ch/connection_test.exs b/test/ch/connection_test.exs index ff00898..c8fee18 100644 --- a/test/ch/connection_test.exs +++ b/test/ch/connection_test.exs @@ -568,18 +568,25 @@ defmodule Ch.ConnectionTest do }} = Ch.query(conn, "SELECT * FROM t_uuid ORDER BY y") end - @tag :skip + # https://clickhouse.com/docs/en/sql-reference/data-types/newjson + # 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 test "json", %{conn: conn} do - settings = [allow_experimental_object_type: 1] + settings = [enable_json_type: 1] - Ch.query!(conn, "CREATE TABLE json(o JSON) ENGINE = Memory", [], settings: settings) + Ch.query!(conn, "CREATE TABLE test_json(json JSON) ENGINE = Memory", [], settings: settings) - Ch.query!(conn, ~s|INSERT INTO json VALUES ('{"a": 1, "b": { "c": 2, "d": [1, 2, 3] }}')|) + 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 o.a, o.b.c, o.b.d[3] FROM json").rows == [[1, 2, 3]] + assert Ch.query!(conn, "SELECT json FROM test_json") == :asdf - # named tuples are not supported yet - assert_raise ArgumentError, fn -> Ch.query!(conn, "SELECT o FROM json") end + assert Ch.query!(conn, "SELECT json.a, json.b.c, json.b.d[3] FROM test_json").rows == [ + [1, 2, 3] + ] end # TODO enum16