aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/udfs/common/json2/test/cases/SqlExists.sql
blob: 34f475fe5a827f066fb84c97d46913d072754a3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* syntax version 1 */

$path = Json2::CompilePath("strict $.x");

-- Key exists
SELECT
    Json2::SqlExists(CAST(@@{"x": 123}@@ as Json), $path, AsDict(), false),
    Json2::SqlExists(CAST(@@{"x": {"key": "value"}}@@ as Json), $path, AsDict(), false),
    Json2::SqlExists(CAST(@@{"x": [1, 2, 3]}@@ as Json), $path, AsDict(), false),
    Json2::SqlExists(CAST(@@{"x": null}@@ as Json), $path, AsDict(), false);

-- Key is missing
SELECT
    Json2::SqlExists(NULL, $path, AsDict(), false),
    Json2::SqlExists(CAST(@@{"not_x": 123}@@ as Json), $path, AsDict(), false),
    Json2::SqlExists(CAST("{}" as Json), $path, AsDict(), false),
    Json2::SqlExists(CAST("[]" as Json), $path, AsDict(), false);

-- Error handling
$json = CAST("[]" as Json);

SELECT
    Json2::SqlExists($json, $path, AsDict(), false),
    Json2::SqlExists($json, $path, AsDict(), true),
    Json2::SqlExists($json, $path, AsDict(), NULL);