Skip to content

Commit ecb241a

Browse files
branch-3.0: [regression-test](Variant) add escaped chars cases #52657 (#52697)
Cherry-picked from #52657 Co-authored-by: lihangyu <[email protected]>
1 parent dd3595a commit ecb241a

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !select --
3+
1 {"a":123,"b":"test with escape \\" characters"}
4+
2 {"a":456,"b":"another test with escape \\\\ characters"}
5+
3 {"a":789,"b":"test with single quote ' characters"}
6+
4 {"a":101112,"b":"test with newline \\n characters"}
7+
5 {"a":131415,"b":"test with tab \\t characters"}
8+
6 {"a":161718,"b":"test with backslash \\b characters"}
9+
10+
-- !select --
11+
test with escape " characters
12+
another test with escape \\ characters
13+
test with single quote ' characters
14+
test with newline \n characters
15+
test with tab \ characters
16+
test with backslash  characters
17+
18+
-- !select --
19+
test with escape " characters
20+
another test with escape \\ characters
21+
test with single quote ' characters
22+
test with newline \n characters
23+
test with tab \ characters
24+
test with backslash  characters
25+
26+
-- !select --
27+
1 {"c_json":{"a":"a\\nb"}} {"c_json":{"quote":"\\"Helvetica tofu try-hard gluten-free gentrify leggings.\\" - Remington Trantow"}} {"c_json":{"quote":"\\"Helvetica tofu try-hard gluten-free gentrify leggings.\\" - Remington Trantow"}} {"c_json":{"a":"a\\nb"}}
28+
29+
-- !select --
30+
{"a":"a\\nb"} {"a":"a\\nb"}
31+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("regression_test_variant_escaped_chars", "p0"){
19+
def tableName = "variant_escape_chars"
20+
21+
sql """ DROP TABLE IF EXISTS variant_escape_chars """
22+
23+
sql """
24+
CREATE TABLE IF NOT EXISTS variant_escape_chars (
25+
`id` INT,
26+
`description` VARIANT
27+
) ENGINE=OLAP
28+
DUPLICATE KEY(`id`)
29+
COMMENT 'This is a test table with escape characters in description'
30+
DISTRIBUTED BY HASH(`id`) BUCKETS 1
31+
PROPERTIES (
32+
"replication_num" = "1"
33+
);
34+
"""
35+
36+
sql """
37+
INSERT INTO variant_escape_chars VALUES
38+
(1, '{"a" : 123, "b" : "test with escape \\\\" characters"}'),
39+
(2, '{"a" : 456, "b" : "another test with escape \\\\\\\\ characters"}'),
40+
(3, '{"a" : 789, "b" : "test with single quote \\\' characters"}'),
41+
(4, '{"a" : 101112, "b" : "test with newline \\\\n characters"}'),
42+
(5, '{"a" : 131415, "b" : "test with tab \\\\t characters"}'),
43+
(6, '{"a" : 161718, "b" : "test with backslash \\\\b characters"}');
44+
"""
45+
46+
// test json value with escaped characters
47+
qt_select """ SELECT * FROM variant_escape_chars ORDER BY id """
48+
qt_select """ SELECT description['b'] FROM variant_escape_chars ORDER BY id """
49+
qt_select """ SELECT CAST(description['b'] AS TEXT) FROM variant_escape_chars ORDER BY id """
50+
51+
sql """
52+
drop table if exists t01;
53+
create table t01(id int, b json, c json, d variant, e variant) properties ("replication_num" = "1");
54+
insert into t01 values (1, '{"c_json":{"a":"a\\\\nb"}}', '{"c_json": {"quote":"\\\\"Helvetica tofu try-hard gluten-free gentrify leggings.\\\\" - Remington Trantow"}}', '{"c_json": {"quote":"\\\\"Helvetica tofu try-hard gluten-free gentrify leggings.\\\\" - Remington Trantow"}}', '{"c_json":{"a":"a\\\\nb"}}');
55+
"""
56+
qt_select """ SELECT * FROM t01 """
57+
qt_select """select json_extract(b, "\$.c_json"), e["c_json"] from t01;"""
58+
59+
// test json keys with escaped characters, FIXED in 3.1.0
60+
// sql "truncate table variant_escape_chars"
61+
// sql """
62+
// INSERT INTO variant_escape_chars VALUES
63+
// (1, '{"test with escape \\\\" characters" : 123}'),
64+
// (2, '{"another test with escape \\\\\\\\ characters" : 123}'),
65+
// (3, '{"test with single quote \\\' characters" : 123}'),
66+
// (4, '{"test with newline \\\\n characters":123}'),
67+
// (5, '{"test with tab \\\\t characters" : 123}'),
68+
// (6, '{"test with backslash \\\\b characters" : 123}');
69+
// """
70+
// qt_select """ SELECT * FROM variant_escape_chars ORDER BY id """
71+
}

0 commit comments

Comments
 (0)