|
| 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