Skip to content

Commit ffc9e28

Browse files
craig[bot]normanchenn
andcommitted
Merge #144514
144514: pgwire: add JSONPath tests r=normanchenn a=normanchenn This commit adds some basic pgwire tests to verify the text and binary formats work with JSONPath expressions. Epic: None Release note: None Co-authored-by: Norman Chen <[email protected]>
2 parents fc4a855 + 5889247 commit ffc9e28

File tree

1 file changed

+77
-70
lines changed

1 file changed

+77
-70
lines changed
Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
send
2+
Query {"String": "SELECT ''::JSONPATH"}
3+
----
4+
5+
until ignore=BindComplete
6+
ErrorResponse
7+
ReadyForQuery
8+
----
9+
{"Type":"ErrorResponse","Code":"42601"}
10+
{"Type":"ReadyForQuery","TxStatus":"I"}
11+
112
send
213
Query {"String": "SELECT '$'::JSONPATH"}
314
----
@@ -10,80 +21,76 @@ ReadyForQuery
1021
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
1122
{"Type":"ReadyForQuery","TxStatus":"I"}
1223

24+
send
25+
Parse {"Query": "SELECT '$'::JSONPATH"}
26+
Bind {"ResultFormatCodes": [1]}
27+
Execute
28+
Sync
29+
----
1330

14-
# send
15-
# Query {"String": "CREATE TABLE jsonpath_a (j JSONPATH)"}
16-
# ----
17-
18-
# until
19-
# ReadyForQuery
20-
# ----
21-
# {"Type":"CommandComplete","CommandTag":"CREATE TABLE"}
22-
# {"Type":"ReadyForQuery","TxStatus":"I"}
23-
24-
25-
# send
26-
# Query {"String": "INSERT INTO jsonpath_a VALUES ('$.a'), ('$.b[*]')"}
27-
# ----
28-
29-
# until
30-
# ReadyForQuery
31-
# ----
32-
# {"Type":"CommandComplete","CommandTag":"INSERT 0 2"}
33-
# {"Type":"ReadyForQuery","TxStatus":"I"}
34-
35-
36-
# send
37-
# Parse {"Query": "SELECT * FROM jsonpath_a"}
38-
# Bind {"ResultFormatCodes": [0]}
39-
# Execute
40-
# Sync
41-
# ----
31+
# Binary format response: 0x01 0x27 0x24 0x27
32+
# - 0x01: JSONPath version number (1)
33+
# - 0x27: ASCII code for '
34+
# - 0x24: ASCII code for $
35+
# - 0x27: ASCII code for '
36+
until
37+
ReadyForQuery
38+
----
39+
{"Type":"ParseComplete"}
40+
{"Type":"BindComplete"}
41+
{"Type":"DataRow","Values":[{"binary":"01272427"}]}
42+
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
43+
{"Type":"ReadyForQuery","TxStatus":"I"}
4244

43-
# until crdb_only
44-
# ReadyForQuery
45-
# ----
46-
# {"Type":"ParseComplete"}
47-
# {"Type":"BindComplete"}
48-
# {"Type":"DataRow","Values":[{"text":"$.a"}]}
49-
# {"Type":"DataRow","Values":[{"text":"$.b[*]"}]}
50-
# {"Type":"CommandComplete","CommandTag":"SELECT 2"}
51-
# {"Type":"ReadyForQuery","TxStatus":"I"}
45+
send
46+
Parse {"Query": "SELECT '$.abc'::JSONPATH"}
47+
Bind {"ResultFormatCodes": [0]}
48+
Execute
49+
Sync
50+
----
5251

53-
# until noncrdb_only
54-
# ReadyForQuery
55-
# ----
56-
# {"Type":"ParseComplete"}
57-
# {"Type":"BindComplete"}
58-
# {"Type":"DataRow","Values":[{"text":"$.\"a\""}]}
59-
# {"Type":"DataRow","Values":[{"text":"$.\"b\"[*]"}]}
60-
# {"Type":"CommandComplete","CommandTag":"SELECT 2"}
61-
# {"Type":"ReadyForQuery","TxStatus":"I"}
52+
until
53+
ReadyForQuery
54+
----
55+
{"Type":"ParseComplete"}
56+
{"Type":"BindComplete"}
57+
{"Type":"DataRow","Values":[{"text":"$.\"abc\""}]}
58+
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
59+
{"Type":"ReadyForQuery","TxStatus":"I"}
6260

61+
send
62+
Parse {"Query": "SELECT '$.abc'::JSONPATH"}
63+
Bind {"ResultFormatCodes": [1]}
64+
Execute
65+
Sync
66+
----
6367

64-
# send
65-
# Parse {"Query": "SELECT * FROM jsonpath_a"}
66-
# Bind {"ResultFormatCodes": [1]}
67-
# Execute
68-
# Sync
69-
# ----
68+
# Binary format response: 0x01 0x27 0x24 0x2e 0x22 0x61 0x62 0x63 0x22 0x27
69+
# - 0x01: JSONPath version number (1)
70+
# - 0x27: ASCII code for '
71+
# - 0x24: ASCII code for $
72+
# - 0x2e: ASCII code for .
73+
# - 0x22: ASCII code for "
74+
# - 0x61 0x62 0x63: ASCII codes for abc
75+
# - 0x22: ASCII code for "
76+
# - 0x27: ASCII code for '
77+
until
78+
ReadyForQuery
79+
----
80+
{"Type":"ParseComplete"}
81+
{"Type":"BindComplete"}
82+
{"Type":"DataRow","Values":[{"binary":"0127242e226162632227"}]}
83+
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
84+
{"Type":"ReadyForQuery","TxStatus":"I"}
7085

71-
# until crdb_only
72-
# ReadyForQuery
73-
# ----
74-
# {"Type":"ParseComplete"}
75-
# {"Type":"BindComplete"}
76-
# {"Type":"DataRow","Values":[{"binary":"0127242e6127"}]}
77-
# {"Type":"DataRow","Values":[{"binary":"0127242e625b2a5d27"}]}
78-
# {"Type":"CommandComplete","CommandTag":"SELECT 2"}
79-
# {"Type":"ReadyForQuery","TxStatus":"I"}
86+
send
87+
Query {"String": "SELECT jsonb_path_query('{\"a\": true}', '$.a')"}
88+
----
8089

81-
# until noncrdb_only
82-
# ReadyForQuery
83-
# ----
84-
# {"Type":"ParseComplete"}
85-
# {"Type":"BindComplete"}
86-
# {"Type":"DataRow","Values":[{"binary":"01242e226122"}]}
87-
# {"Type":"DataRow","Values":[{"binary":"01242e2262225b2a5d"}]}
88-
# {"Type":"CommandComplete","CommandTag":"SELECT 2"}
89-
# {"Type":"ReadyForQuery","TxStatus":"I"}
90+
until
91+
ReadyForQuery
92+
----
93+
{"Type":"RowDescription","Fields":[{"Name":"jsonb_path_query","TableOID":0,"TableAttributeNumber":0,"DataTypeOID":3802,"DataTypeSize":-1,"TypeModifier":-1,"Format":0}]}
94+
{"Type":"DataRow","Values":[{"text":"true"}]}
95+
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
96+
{"Type":"ReadyForQuery","TxStatus":"I"}

0 commit comments

Comments
 (0)