본문으로 바로가기
본문으로 바로가기

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))']} │
└────────────────────────────────────────────────────────────────┘