// 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 namespace DB { namespace tests { class ExpandProjectionTest : public DB::tests::ProjectionTest { }; TEST_F(ExpandProjectionTest, literalProjection) try { // Project literal(null) as nullable // scenario: expand project: "null" for a nullable varchar(x) column ColumnsWithTypeAndName columns; columns.push_back(createColumn>({"さらに入", "测试测试测试测试abcd测试", "🍻", "🏴‍☠️"})); ASSERT_COLUMN_EQ( createConstColumn>(4, {}), executeProjection(std::vector{"null"}, columns)[0]); // Project literal(null) as nullable> // scenario: expand project: "null" for a nullable int column columns.clear(); columns.push_back(createColumn>({1, 2, 3, 4})); ASSERT_COLUMN_EQ( createConstColumn>(4, {}), executeProjection(std::vector{"null"}, columns)[0]); // Project literal(null) as nullable> // scenario: expand project: "null" for a nullable double column columns.clear(); columns.push_back(createColumn>({1.0, 2.0, 3.0, 4.0})); ASSERT_COLUMN_EQ( createConstColumn>(4, {}), executeProjection(std::vector{"null"}, columns)[0]); // Project literal(null) as nullable> // scenario: expand project: "null" for a nullable float column columns.clear(); columns.push_back(createColumn>({1.0, 2.0, 3.0, 4.0})); ASSERT_COLUMN_EQ( createConstColumn>(4, {}), executeProjection(std::vector{"null"}, columns)[0]); // Project literal(null) as nullable> // scenario: expand project: "null" for a nullable datetime column columns.clear(); columns.push_back( createColumn>({MyDateTime(2020, 2, 10, 0, 0, 0, 0).toPackedUInt()})); ASSERT_COLUMN_EQ( createConstColumn>(1, {}), executeProjection(std::vector{"null"}, columns)[0]); // Special case for grouping_id column with type as Uint64 // Project literal(num) as // scenario: expand project: "1" for a grouping id column default as Uint64 columns.clear(); columns.push_back(createColumn({0, 0, 0, 0, 0})); ASSERT_COLUMN_EQ(createConstColumn(5, 1), executeProjection(std::vector{"1"}, columns)[0]); } CATCH } // namespace tests } // namespace DB