Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inconsistent result before deleting some rows #6133

Merged
merged 4 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dbms/src/Functions/FunctionsLogical.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ struct AssociativeOperationImpl
{
if (Op::isSaturable())
{
// cast_bool_reason
// cast a: UInt8 -> bool -> UInt8 is a trick
// TiFlash converts columns with non-UInt8 type to UInt8 type and sets value to 0 or 1
// which correspond to false or true. However, for columns with UInt8 type,
Expand All @@ -219,7 +220,8 @@ struct AssociativeOperationImpl
}
else
{
return Op::apply(vec[i], continuation.apply(i));
// Searching keyword "cast_bool_reason" in this file to get the reason for static_cast<bool>
return Op::apply(static_cast<bool>(vec[i]), continuation.apply(i));
xzhangxian1008 marked this conversation as resolved.
Show resolved Hide resolved
}
}
};
Expand All @@ -240,7 +242,8 @@ struct AssociativeOperationImpl<Op, 1>

inline UInt8 apply(size_t i) const
{
return vec[i];
// Searching keyword "cast_bool_reason" in this file to get the reason for static_cast<bool>
return static_cast<bool>(vec[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can change the return type of apply to bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can change the return type of apply to bool?

okk

}
};

Expand Down
28 changes: 21 additions & 7 deletions dbms/src/Functions/tests/gtest_logical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ try
func_name,
createOnlyNullColumnConst(2),
createColumn<Nullable<UInt8>>({1, 0})));
// issue 6127
ASSERT_COLUMN_EQ(
createColumn<UInt8>({0, 1, 0, 0}),
executeFunction(
func_name,
createColumn<Int64>({0, 123, 0, 41}),
createColumn<UInt8>({0, 11, 221, 0})));
// issue 6127, position of UInt8 column may affect the result
ASSERT_COLUMN_EQ(
createColumn<UInt8>({0, 1, 0, 0}),
executeFunction(
func_name,
createColumn<UInt8>({0, 123, 0, 41}),
createColumn<Int64>({0, 11, 221, 0})));
}
CATCH

Expand All @@ -73,13 +87,6 @@ try
func_name,
createColumn<Nullable<UInt8>>({0, 1, 0, 1, {}, 0}),
createColumn<Nullable<UInt8>>({0, 1, 1, 0, 1, {}})));
// issue 5849
ASSERT_COLUMN_EQ(
createColumn<UInt8>({0, 1, 1, 1}),
executeFunction(
func_name,
createColumn<UInt8>({0, 123, 0, 41}),
createColumn<Int64>({0, 11, 221, 0})));
// column, const
ASSERT_COLUMN_EQ(
createColumn<Nullable<UInt8>>({1, 1}),
Expand All @@ -101,6 +108,13 @@ try
func_name,
createOnlyNullColumnConst(2),
createColumn<Nullable<UInt8>>({1, 0})));
// issue 5849
ASSERT_COLUMN_EQ(
createColumn<UInt8>({0, 1, 1, 1}),
executeFunction(
func_name,
createColumn<UInt8>({0, 123, 0, 41}),
createColumn<Int64>({0, 11, 221, 0})));
}
CATCH

Expand Down