From 663f6816174e2ffeb37c2649641091182d157a94 Mon Sep 17 00:00:00 2001 From: xzhangxian1008 Date: Sat, 15 Oct 2022 09:57:51 +0800 Subject: [PATCH 1/3] This is an automated cherry-pick of #6133 Signed-off-by: ti-chi-bot --- dbms/src/Functions/FunctionsLogical.h | 16 +- dbms/src/Functions/tests/gtest_logical.cpp | 183 +++++++++++++++++++++ 2 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 dbms/src/Functions/tests/gtest_logical.cpp diff --git a/dbms/src/Functions/FunctionsLogical.h b/dbms/src/Functions/FunctionsLogical.h index edb2f792ea2..9865efa5776 100644 --- a/dbms/src/Functions/FunctionsLogical.h +++ b/dbms/src/Functions/FunctionsLogical.h @@ -97,7 +97,14 @@ struct NotImpl { using ResultType = UInt8; +<<<<<<< HEAD static inline UInt8 apply(A a) { return !a; } +======= + static inline bool apply(A a) + { + return !a; + } +>>>>>>> 1e0e3c8973 (fix inconsistent result before deleting some rows (#6133)) }; @@ -134,7 +141,7 @@ struct AssociativeOperationImpl AssociativeOperationImpl(UInt8ColumnPtrs & in) : vec(in[in.size() - N]->getData()), continuation(in) {} /// Returns a combination of values in the i-th row of all columns stored in the constructor. - inline UInt8 apply(size_t i) const + inline bool apply(size_t i) const { if (Op::isSaturable()) { @@ -176,7 +183,14 @@ struct AssociativeOperationImpl AssociativeOperationImpl(UInt8ColumnPtrs & in) : vec(in[in.size() - 1]->getData()) {} +<<<<<<< HEAD inline UInt8 apply(size_t i) const { return vec[i]; } +======= + inline bool apply(size_t i) const + { + return vec[i]; + } +>>>>>>> 1e0e3c8973 (fix inconsistent result before deleting some rows (#6133)) }; diff --git a/dbms/src/Functions/tests/gtest_logical.cpp b/dbms/src/Functions/tests/gtest_logical.cpp new file mode 100644 index 00000000000..bdab91fda52 --- /dev/null +++ b/dbms/src/Functions/tests/gtest_logical.cpp @@ -0,0 +1,183 @@ +// Copyright 2022 PingCAP, Ltd. +// +// 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 + +namespace DB::tests +{ +class Logical : public DB::tests::FunctionTest +{ +}; + +TEST_F(Logical, andTest) +try +{ + const String & func_name = "and"; + + // column, column + ASSERT_COLUMN_EQ( + createColumn>({0, 1, 0, 0, {}, 0}), + executeFunction( + func_name, + createColumn>({0, 1, 0, 1, {}, 0}), + createColumn>({0, 1, 1, 0, 1, {}}))); + // column, const + ASSERT_COLUMN_EQ( + createColumn>({1, 0}), + executeFunction( + func_name, + createConstColumn>(2, 1), + createColumn>({1, 0}))); + // const, const + ASSERT_COLUMN_EQ( + createConstColumn(1, 1), + executeFunction( + func_name, + createConstColumn>(1, 1), + createConstColumn>(1, 1))); + // only null + ASSERT_COLUMN_EQ( + createColumn>({{}, 0}), + executeFunction( + func_name, + createOnlyNullColumnConst(2), + createColumn>({1, 0}))); + // issue 6127 + ASSERT_COLUMN_EQ( + createColumn({0, 1, 0, 0}), + executeFunction( + func_name, + createColumn({0, 123, 0, 41}), + createColumn({0, 11, 221, 0}))); + // issue 6127, position of UInt8 column may affect the result + ASSERT_COLUMN_EQ( + createColumn({0, 1, 0, 0}), + executeFunction( + func_name, + createColumn({0, 123, 0, 41}), + createColumn({0, 11, 221, 0}))); +} +CATCH + +TEST_F(Logical, orTest) +try +{ + const String & func_name = "or"; + + // column, column + ASSERT_COLUMN_EQ( + createColumn>({0, 1, 1, 1, 1, {}}), + executeFunction( + func_name, + createColumn>({0, 1, 0, 1, {}, 0}), + createColumn>({0, 1, 1, 0, 1, {}}))); + // column, const + ASSERT_COLUMN_EQ( + createColumn>({1, 1}), + executeFunction( + func_name, + createConstColumn>(2, 1), + createColumn>({1, 0}))); + // const, const + ASSERT_COLUMN_EQ( + createConstColumn(1, 1), + executeFunction( + func_name, + createConstColumn>(1, 1), + createConstColumn>(1, 0))); + // only null + ASSERT_COLUMN_EQ( + createColumn>({1, {}}), + executeFunction( + func_name, + createOnlyNullColumnConst(2), + createColumn>({1, 0}))); + // issue 5849 + ASSERT_COLUMN_EQ( + createColumn({0, 1, 1, 1}), + executeFunction( + func_name, + createColumn({0, 123, 0, 41}), + createColumn({0, 11, 221, 0}))); +} +CATCH + +TEST_F(Logical, xorTest) +try +{ + const String & func_name = "xor"; + + // column, column + ASSERT_COLUMN_EQ( + createColumn>({0, 0, 1, 1, {}, {}}), + executeFunction( + func_name, + createColumn>({0, 1, 0, 1, {}, 0}), + createColumn>({0, 1, 1, 0, 1, {}}))); + // column, const + ASSERT_COLUMN_EQ( + createColumn>({0, 1}), + executeFunction( + func_name, + createConstColumn>(2, 1), + createColumn>({1, 0}))); + // const, const + ASSERT_COLUMN_EQ( + createConstColumn(1, 0), + executeFunction( + func_name, + createConstColumn>(1, 1), + createConstColumn>(1, 1))); + // only null + ASSERT_COLUMN_EQ( + createOnlyNullColumnConst(2), + executeFunction( + func_name, + createOnlyNullColumnConst(2), + createColumn>({1, 0}))); +} +CATCH + +TEST_F(Logical, notTest) +try +{ + const String & func_name = "not"; + + // column + ASSERT_COLUMN_EQ( + createColumn>({1, 0, {}}), + executeFunction( + func_name, + createColumn>({0, 1, {}}))); + // const + ASSERT_COLUMN_EQ( + createConstColumn(1, 0), + executeFunction( + func_name, + createConstColumn>(1, 1))); + // only null + ASSERT_COLUMN_EQ( + createOnlyNullColumnConst(1), + executeFunction( + func_name, + createOnlyNullColumnConst(1))); +} +CATCH + +} // namespace DB::tests \ No newline at end of file From 9c446020f63c78cc1155a540bed8c064bad39947 Mon Sep 17 00:00:00 2001 From: xzhangxian1008 Date: Tue, 18 Oct 2022 11:17:04 +0800 Subject: [PATCH 2/3] fix --- dbms/src/Functions/FunctionsLogical.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/dbms/src/Functions/FunctionsLogical.h b/dbms/src/Functions/FunctionsLogical.h index 9865efa5776..159e7dfd632 100644 --- a/dbms/src/Functions/FunctionsLogical.h +++ b/dbms/src/Functions/FunctionsLogical.h @@ -97,14 +97,10 @@ struct NotImpl { using ResultType = UInt8; -<<<<<<< HEAD - static inline UInt8 apply(A a) { return !a; } -======= static inline bool apply(A a) { return !a; } ->>>>>>> 1e0e3c8973 (fix inconsistent result before deleting some rows (#6133)) }; @@ -183,14 +179,10 @@ struct AssociativeOperationImpl AssociativeOperationImpl(UInt8ColumnPtrs & in) : vec(in[in.size() - 1]->getData()) {} -<<<<<<< HEAD - inline UInt8 apply(size_t i) const { return vec[i]; } -======= inline bool apply(size_t i) const { return vec[i]; } ->>>>>>> 1e0e3c8973 (fix inconsistent result before deleting some rows (#6133)) }; From 625ebe45af4423735e4903ded1fd8323969232d0 Mon Sep 17 00:00:00 2001 From: xzhangxian1008 Date: Tue, 18 Oct 2022 16:43:17 +0800 Subject: [PATCH 3/3] fix --- dbms/src/Functions/tests/gtest_logical.cpp | 183 --------------------- 1 file changed, 183 deletions(-) delete mode 100644 dbms/src/Functions/tests/gtest_logical.cpp diff --git a/dbms/src/Functions/tests/gtest_logical.cpp b/dbms/src/Functions/tests/gtest_logical.cpp deleted file mode 100644 index bdab91fda52..00000000000 --- a/dbms/src/Functions/tests/gtest_logical.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2022 PingCAP, Ltd. -// -// 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 - -namespace DB::tests -{ -class Logical : public DB::tests::FunctionTest -{ -}; - -TEST_F(Logical, andTest) -try -{ - const String & func_name = "and"; - - // column, column - ASSERT_COLUMN_EQ( - createColumn>({0, 1, 0, 0, {}, 0}), - executeFunction( - func_name, - createColumn>({0, 1, 0, 1, {}, 0}), - createColumn>({0, 1, 1, 0, 1, {}}))); - // column, const - ASSERT_COLUMN_EQ( - createColumn>({1, 0}), - executeFunction( - func_name, - createConstColumn>(2, 1), - createColumn>({1, 0}))); - // const, const - ASSERT_COLUMN_EQ( - createConstColumn(1, 1), - executeFunction( - func_name, - createConstColumn>(1, 1), - createConstColumn>(1, 1))); - // only null - ASSERT_COLUMN_EQ( - createColumn>({{}, 0}), - executeFunction( - func_name, - createOnlyNullColumnConst(2), - createColumn>({1, 0}))); - // issue 6127 - ASSERT_COLUMN_EQ( - createColumn({0, 1, 0, 0}), - executeFunction( - func_name, - createColumn({0, 123, 0, 41}), - createColumn({0, 11, 221, 0}))); - // issue 6127, position of UInt8 column may affect the result - ASSERT_COLUMN_EQ( - createColumn({0, 1, 0, 0}), - executeFunction( - func_name, - createColumn({0, 123, 0, 41}), - createColumn({0, 11, 221, 0}))); -} -CATCH - -TEST_F(Logical, orTest) -try -{ - const String & func_name = "or"; - - // column, column - ASSERT_COLUMN_EQ( - createColumn>({0, 1, 1, 1, 1, {}}), - executeFunction( - func_name, - createColumn>({0, 1, 0, 1, {}, 0}), - createColumn>({0, 1, 1, 0, 1, {}}))); - // column, const - ASSERT_COLUMN_EQ( - createColumn>({1, 1}), - executeFunction( - func_name, - createConstColumn>(2, 1), - createColumn>({1, 0}))); - // const, const - ASSERT_COLUMN_EQ( - createConstColumn(1, 1), - executeFunction( - func_name, - createConstColumn>(1, 1), - createConstColumn>(1, 0))); - // only null - ASSERT_COLUMN_EQ( - createColumn>({1, {}}), - executeFunction( - func_name, - createOnlyNullColumnConst(2), - createColumn>({1, 0}))); - // issue 5849 - ASSERT_COLUMN_EQ( - createColumn({0, 1, 1, 1}), - executeFunction( - func_name, - createColumn({0, 123, 0, 41}), - createColumn({0, 11, 221, 0}))); -} -CATCH - -TEST_F(Logical, xorTest) -try -{ - const String & func_name = "xor"; - - // column, column - ASSERT_COLUMN_EQ( - createColumn>({0, 0, 1, 1, {}, {}}), - executeFunction( - func_name, - createColumn>({0, 1, 0, 1, {}, 0}), - createColumn>({0, 1, 1, 0, 1, {}}))); - // column, const - ASSERT_COLUMN_EQ( - createColumn>({0, 1}), - executeFunction( - func_name, - createConstColumn>(2, 1), - createColumn>({1, 0}))); - // const, const - ASSERT_COLUMN_EQ( - createConstColumn(1, 0), - executeFunction( - func_name, - createConstColumn>(1, 1), - createConstColumn>(1, 1))); - // only null - ASSERT_COLUMN_EQ( - createOnlyNullColumnConst(2), - executeFunction( - func_name, - createOnlyNullColumnConst(2), - createColumn>({1, 0}))); -} -CATCH - -TEST_F(Logical, notTest) -try -{ - const String & func_name = "not"; - - // column - ASSERT_COLUMN_EQ( - createColumn>({1, 0, {}}), - executeFunction( - func_name, - createColumn>({0, 1, {}}))); - // const - ASSERT_COLUMN_EQ( - createConstColumn(1, 0), - executeFunction( - func_name, - createConstColumn>(1, 1))); - // only null - ASSERT_COLUMN_EQ( - createOnlyNullColumnConst(1), - executeFunction( - func_name, - createOnlyNullColumnConst(1))); -} -CATCH - -} // namespace DB::tests \ No newline at end of file