// Copyright 2023 PingCAP, Inc. // // Licensed 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. #include #include #include #include #include #include #include #include #include #include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-compare" #include #pragma GCC diagnostic pop namespace DB { namespace tests { class StringLength : public DB::tests::FunctionTest { }; TEST_F(StringLength, length) { { // test const ASSERT_COLUMN_EQ(createConstColumn(0, 0), executeFunction("length", createConstColumn(0, ""))); ASSERT_COLUMN_EQ( createConstColumn(1, 3), executeFunction("length", createConstColumn(1, "aaa"))); ASSERT_COLUMN_EQ( createConstColumn(3, 3), executeFunction("length", createConstColumn(3, "aaa"))); } { // test vec ASSERT_COLUMN_EQ(createColumn({}), executeFunction("length", createColumn({}))); ASSERT_COLUMN_EQ( createColumn({0, 3, 5, 7, 6, 9, 0, 9, 16, 0}), executeFunction( "length", createColumn( {"", "hi~", "23333", "pingcap", "你好", "233哈哈", "", "asdの的", "ヽ( ̄▽ ̄)و", ""}))); } { // test nullable const ASSERT_COLUMN_EQ( createConstColumn(0, {}), executeFunction("length", createConstColumn>(0, "aaa"))); ASSERT_COLUMN_EQ( createConstColumn(1, {3}), executeFunction("length", createConstColumn>(1, "aaa"))); ASSERT_COLUMN_EQ( createConstColumn(3, {3}), executeFunction("length", createConstColumn>(3, "aaa"))); } { // test nullable vec std::vector null_map{1, 0, 1, 0, 0, 1}; ASSERT_COLUMN_EQ( createNullableColumn({0, 4, 0, 6, 6, 0}, null_map), executeFunction( "length", createNullableColumn({"a", "abcd", "嗯", "饼干", "馒头", "???"}, null_map))); } } } // namespace tests } // namespace DB