From 820971a384017431e4b36cb191b8a4bc20468f91 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 11:18:26 +0800 Subject: [PATCH] branch-2.1: [regression-test](Variant) add escaped chars cases #52657 (#52699) Cherry-picked from #52657 Co-authored-by: lihangyu --- .../data/variant_p0/escaped_chars.out | 31 ++++++++ .../suites/variant_p0/escaped_chars.groovy | 71 +++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 regression-test/data/variant_p0/escaped_chars.out create mode 100644 regression-test/suites/variant_p0/escaped_chars.groovy diff --git a/regression-test/data/variant_p0/escaped_chars.out b/regression-test/data/variant_p0/escaped_chars.out new file mode 100644 index 0000000000..ddfa3abdfc --- /dev/null +++ b/regression-test/data/variant_p0/escaped_chars.out @@ -0,0 +1,31 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select -- +1 {"a":123,"b":"test with escape \\" characters"} +2 {"a":456,"b":"another test with escape \\\\ characters"} +3 {"a":789,"b":"test with single quote ' characters"} +4 {"a":101112,"b":"test with newline \\n characters"} +5 {"a":131415,"b":"test with tab \\t characters"} +6 {"a":161718,"b":"test with backslash \\b characters"} + +-- !select -- +test with escape " characters +another test with escape \\ characters +test with single quote ' characters +test with newline \n characters +test with tab \ characters +test with backslash  characters + +-- !select -- +test with escape " characters +another test with escape \\ characters +test with single quote ' characters +test with newline \n characters +test with tab \ characters +test with backslash  characters + +-- !select -- +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"}} + +-- !select -- +{"a":"a\\nb"} {"a":"a\\nb"} + diff --git a/regression-test/suites/variant_p0/escaped_chars.groovy b/regression-test/suites/variant_p0/escaped_chars.groovy new file mode 100644 index 0000000000..f92797d03b --- /dev/null +++ b/regression-test/suites/variant_p0/escaped_chars.groovy @@ -0,0 +1,71 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("regression_test_variant_escaped_chars", "p0"){ + def tableName = "variant_escape_chars" + + sql """ DROP TABLE IF EXISTS variant_escape_chars """ + + sql """ + CREATE TABLE IF NOT EXISTS variant_escape_chars ( + `id` INT, + `description` VARIANT + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + COMMENT 'This is a test table with escape characters in description' + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_num" = "1" + ); + """ + + sql """ + INSERT INTO variant_escape_chars VALUES + (1, '{"a" : 123, "b" : "test with escape \\\\" characters"}'), + (2, '{"a" : 456, "b" : "another test with escape \\\\\\\\ characters"}'), + (3, '{"a" : 789, "b" : "test with single quote \\\' characters"}'), + (4, '{"a" : 101112, "b" : "test with newline \\\\n characters"}'), + (5, '{"a" : 131415, "b" : "test with tab \\\\t characters"}'), + (6, '{"a" : 161718, "b" : "test with backslash \\\\b characters"}'); + """ + + // test json value with escaped characters + qt_select """ SELECT * FROM variant_escape_chars ORDER BY id """ + qt_select """ SELECT description['b'] FROM variant_escape_chars ORDER BY id """ + qt_select """ SELECT CAST(description['b'] AS TEXT) FROM variant_escape_chars ORDER BY id """ + + sql """ + drop table if exists t01; + create table t01(id int, b json, c json, d variant, e variant) properties ("replication_num" = "1"); + 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"}}'); + """ + qt_select """ SELECT * FROM t01 """ + qt_select """select json_extract(b, "\$.c_json"), e["c_json"] from t01;""" + + // test json keys with escaped characters, FIXED in 3.1.0 + // sql "truncate table variant_escape_chars" + // sql """ + // INSERT INTO variant_escape_chars VALUES + // (1, '{"test with escape \\\\" characters" : 123}'), + // (2, '{"another test with escape \\\\\\\\ characters" : 123}'), + // (3, '{"test with single quote \\\' characters" : 123}'), + // (4, '{"test with newline \\\\n characters":123}'), + // (5, '{"test with tab \\\\t characters" : 123}'), + // (6, '{"test with backslash \\\\b characters" : 123}'); + // """ + // qt_select """ SELECT * FROM variant_escape_chars ORDER BY id """ +}