distinctJSONPathsAndTypes
Introducido en: v24.9.0
Calcula la lista de rutas distintas y sus tipos almacenados en la columna JSON.
Si la declaración JSON contiene rutas con tipos especificados, estas rutas siempre se incluirán en el resultado de las funciones distinctJSONPaths/distinctJSONPathsAndTypes, aunque los datos de entrada no tuvieran valores para esas rutas.
Sintaxis
distinctJSONPathsAndTypes(json)
Argumentos
json — columna JSON. JSON
Valor devuelto
Devuelve el mapa ordenado de rutas y tipos. Map(String, Array(String))
Ejemplos
Uso básico con tipos mixtos
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))']} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Con rutas JSON definidas
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))']} │
└────────────────────────────────────────────────────────────────┘