Skip to content

Commit 3e38d6a

Browse files
committed
Add more test cases for json_query function
1 parent 5f4b492 commit 3e38d6a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

core/trino-main/src/test/java/io/trino/sql/query/TestJsonQueryFunction.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,38 @@ SELECT json_query(
439439
VALUES cast('[[true,{"c":{"c":null}}],{"c":null},null]'AS varchar)
440440
""");
441441
}
442+
443+
@Test
444+
public void testDescendantMemberSingleChildWithoutArrayWrapperAccessor()
445+
{
446+
// Test json_query to read the result of a single descendant member in json
447+
assertThat(assertions.query(
448+
"""
449+
select json_query(
450+
'{"author":"Diana","id":{"value":1},"notes":[{"type":1,"comment":"foo"},{"type":2,"comment":null}],"comment":["bar","baz"]}',
451+
'lax $..author'
452+
omit quotes)
453+
"""))
454+
.matches(
455+
"""
456+
VALUES cast('Diana' as varchar)
457+
""");
458+
}
459+
460+
@Test
461+
public void testDescendantMemberMultipleChildrenWithoutArrayWrapperAccessor()
462+
{
463+
// Test json_query to read the result of a multiple descendant member in json
464+
assertThat(assertions.query(
465+
"""
466+
select json_query(
467+
'{"author":"Diana","id":{"value":1, "author":"John"},"notes":[{"type":1,"comment":"foo"},{"type":2,"comment":null}],"comment":["bar","baz"]}',
468+
'lax $..author'
469+
omit quotes)
470+
"""))
471+
.matches(
472+
"""
473+
VALUES cast(NULL as varchar)
474+
""");
475+
}
442476
}

0 commit comments

Comments
 (0)