JSON_PATH_MATCH (Lakehouse v1)
Verifica se uma expressão de caminho JSON especificada corresponde a determinadas condições em dados JSON. Observação: o operador @@ é sinônimo desta função. Para obter mais informações, consulte Operadores JSON.
Sintaxe do Analyze
Seção intitulada “Sintaxe do Analyze”func.json_path_match(<json_data>, <json_path_expression)Exemplos do Analyze
Seção intitulada “Exemplos do Analyze”func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1')┌──────────────────────────────────────────────────────────────────────────┐│ func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1') │├──────────────────────────────────────────────────────────────────────────┤│ true │└──────────────────────────────────────────────────────────────────────────┘
func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1')┌────────────────────────────────────────────────────────────────────────────┐│ func.json_path_match(func.parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1') │├────────────────────────────────────────────────────────────────────────────┤│ false │└────────────────────────────────────────────────────────────────────────────┘Sintaxe SQL
Seção intitulada “Sintaxe SQL”JSON_PATH_MATCH(<json_data>, <json_path_expression>)json_data: especifica os dados JSON que você deseja examinar. Pode ser um objeto JSON ou um array.json_path_expression: especifica as condições a serem verificadas nos dados JSON. Essa expressão descreve o caminho ou os critérios específicos a serem correspondidos, como verificar se determinados valores de campo na estrutura JSON atendem a certas condições. O símbolo$representa a raiz dos dados JSON. Ele é usado para iniciar a expressão de caminho e indica o objeto de nível superior na estrutura JSON.
Tipo de retorno
Seção intitulada “Tipo de retorno”A função retorna:
truese a expressão de caminho JSON especificada corresponder às condições nos dados JSON.falsese a expressão de caminho JSON especificada não corresponder às condições nos dados JSON.- NULL se
json_dataoujson_path_expressionfor NULL ou inválido.
Exemplos de SQL
Seção intitulada “Exemplos de SQL”-- Check if the value at JSON path $.a is equal to 1SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1');
┌────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.a == 1') │├────────────────────────────────────────────────────────────────┤│ true │└────────────────────────────────────────────────────────────────┘
-- Check if the first element in the array at JSON path $.b is greater than 1SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1');
┌──────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[0] > 1') │├──────────────────────────────────────────────────────────────────┤│ false │└──────────────────────────────────────────────────────────────────┘
-- Check if any element in the array at JSON path $.b-- from the second one to the last are greater than or equal to 2SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[1 to last] >= 2');
┌───────────────────────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), '$.b[1 to last] >= 2') │├───────────────────────────────────────────────────────────────────────────┤│ true │└───────────────────────────────────────────────────────────────────────────┘
-- NULL is returned if either the json_data or json_path_expression is NULL or invalid.SELECT JSON_PATH_MATCH(parse_json('{"a":1,"b":[1,2,3]}'), NULL);
┌──────────────────────────────────────────────────────────┐│ json_path_match(parse_json('{"a":1,"b":[1,2,3]}'), null) │├──────────────────────────────────────────────────────────┤│ NULL │└──────────────────────────────────────────────────────────┘
SELECT JSON_PATH_MATCH(NULL, '$.a == 1');
┌───────────────────────────────────┐│ json_path_match(null, '$.a == 1') │├───────────────────────────────────┤│ NULL │└───────────────────────────────────┘