Passer au contenu principal

distinctJSONPathsAndTypes

Introduit dans : v24.9.0 Calcule la liste des chemins distincts et de leurs types stockés dans une colonne JSON.
Si la déclaration JSON contient des chemins avec des types spécifiés, ces chemins seront toujours inclus dans le résultat des fonctions distinctJSONPaths/distinctJSONPathsAndTypes, même si les données d’entrée ne contenaient pas de valeurs pour ces chemins.
Syntaxe
distinctJSONPathsAndTypes(json)
Arguments
  • json — colonne JSON. JSON
Valeur renvoyée Renvoie la map triée des chemins et des types. Map(String, Array(String)) Exemples Utilisation de base avec des types mixtes
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))']} │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Avec des chemins JSON déclarés
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))']} │
└────────────────────────────────────────────────────────────────┘
Dernière modification le 25 juin 2026