Pular para o conteúdo principal

distinctJSONPathsAndTypes

Introduzido em: v24.9.0 Calcula a lista de caminhos distintos e seus tipos armazenados na coluna JSON.
Se a declaração JSON contiver caminhos com tipos especificados, esses caminhos sempre serão incluídos no resultado das funções distinctJSONPaths/distinctJSONPathsAndTypes, mesmo que os dados de entrada não contenham valores para esses caminhos.
Sintaxe
distinctJSONPathsAndTypes(json)
Argumentos
  • json — coluna JSON. JSON
Valor retornado Retorna o mapa ordenado de caminhos e tipos. Map(String, Array(String)) Exemplos Uso básico com tipos mistos
Query
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;
Response
┌─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))']} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Com caminhos JSON declarados
Query
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;
Response
┌─distinctJSONPathsAndTypes(json)────────────────────────────────┐
│ {'a':['UInt32'],'b':['String'],'c':['Array(Nullable(Int64))']} │
└────────────────────────────────────────────────────────────────┘
Última modificação em 10 de junho de 2026