メインコンテンツへスキップ
メインコンテンツへスキップ

distinctJSONPathsAndTypes

distinctJSONPathsAndTypes

導入バージョン: v24.9

JSON カラムに保存されている異なるパスとその型の一覧を算出します。

注記

JSON 宣言内に型が指定されたパスが含まれている場合、入力データにこれらのパスに対応する値が存在しない場合でも、これらのパスは常に distinctJSONPaths/distinctJSONPathsAndTypes 関数の結果に含まれます。

構文

distinctJSONPathsAndTypes(json)

引数

  • json — JSON カラム。 JSON

戻り値

パスと型のソート済みのマップを返します。 Map(String, Array(String))

混在する型での基本的な使用例

DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"a" : 42, "b" : "Hello"}'), ('{"b" : [1, 2, 3], "c" : {"d" : {"e" : "2020-01-01"}}}'), ('{"a" : 43, "c" : {"d" : {"f" : [{"g" : 42}]}}}');

SELECT distinctJSONPathsAndTypes(json) FROM test_json;
┌─distinctJSONPathsAndTypes(json)───────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ {'a':['Int64'],'b':['Array(Nullable(Int64))','String'],'c.d.e':['Date'],'c.d.f':['Array(JSON(max_dynamic_types=16, max_dynamic_paths=256))']} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

JSON パスを宣言した場合

DROP TABLE IF EXISTS test_json;
CREATE TABLE test_json(json JSON(a UInt32)) ENGINE = Memory;
INSERT INTO test_json VALUES ('{"b" : "Hello"}'), ('{"b" : "World", "c" : [1, 2, 3]}');

SELECT distinctJSONPathsAndTypes(json) FROM test_json;
┌─distinctJSONPathsAndTypes(json)────────────────────────────────┐
│ {'a':['UInt32'],'b':['String'],'c':['Array(Nullable(Int64))']} │
└────────────────────────────────────────────────────────────────┘