diff --git a/ydb/library/yql/providers/generic/provider/ut/pushdown/pushdown_ut.cpp b/ydb/library/yql/providers/generic/provider/ut/pushdown/pushdown_ut.cpp index 937b5b0c60a4..0c7add0a2ac7 100644 --- a/ydb/library/yql/providers/generic/provider/ut/pushdown/pushdown_ut.cpp +++ b/ydb/library/yql/providers/generic/provider/ut/pushdown/pushdown_ut.cpp @@ -372,7 +372,7 @@ Y_UNIT_TEST_SUITE_F(PushdownTest, TPushdownFixture) { R"ast( (Coalesce (!= (Member $row '"col_optional_uint64") (Member $row '"col_uint32")) - (Bool '"true") + (Bool '"false") ) )ast", R"proto( @@ -388,6 +388,44 @@ Y_UNIT_TEST_SUITE_F(PushdownTest, TPushdownFixture) { )proto"); } + Y_UNIT_TEST(TrueCoalesce) { + AssertFilter( + // Note that R"ast()ast" is empty string! + R"ast( + (Coalesce + (!= (Member $row '"col_optional_uint64") (Member $row '"col_uint32")) + (Bool '"true") + ) + )ast", + R"proto( + coalesce { + operands { + comparison { + operation: NE + left_value { + column: "col_optional_uint64" + } + right_value { + column: "col_uint32" + } + } + } + operands { + bool_expression { + typed_value { + type { + type_id: BOOL + } + value { + bool_value: true + } + } + } + } + } + )proto"); + } + Y_UNIT_TEST(CmpInt16AndInt32) { AssertFilter( // Note that R"ast()ast" is empty string! @@ -421,7 +459,7 @@ Y_UNIT_TEST_SUITE_F(PushdownTest, TPushdownFixture) { (< (Unwrap (/ (Int64 '42) (Member $row '"col_int64"))) (Int64 '10)) (>= (Member $row '"col_uint32") (- (Uint32 '15) (Uint32 '1))) ) - (Bool '"true") + (Bool '"false") ) )ast", R"proto( @@ -515,7 +553,7 @@ Y_UNIT_TEST_SUITE_F(PushdownTest, TPushdownFixture) { (< (Unwrap (/ (Int64 '42) (Member $row '"col_int64"))) (Int64 '10)) (>= (Member $row '"col_uint32") (Uint32 '15)) ) - (Bool '"true") + (Bool '"false") ) )ast", R"proto( @@ -600,7 +638,7 @@ Y_UNIT_TEST_SUITE_F(PushdownTest, TPushdownFixture) { (Member $row '"col_utf8") (Member $row '"col_optional_utf8") ) - (Bool '"true") + (Bool '"false") ) )ast"); } diff --git a/ydb/library/yql/providers/generic/provider/yql_generic_predicate_pushdown.cpp b/ydb/library/yql/providers/generic/provider/yql_generic_predicate_pushdown.cpp index a3dd9ff1fe44..e08e09c9a545 100644 --- a/ydb/library/yql/providers/generic/provider/yql_generic_predicate_pushdown.cpp +++ b/ydb/library/yql/providers/generic/provider/yql_generic_predicate_pushdown.cpp @@ -69,6 +69,7 @@ namespace NYql { } // data + MATCH_ATOM(Bool, BOOL, bool, bool); MATCH_ATOM(Int8, INT8, int32, i8); MATCH_ATOM(Uint8, UINT8, uint32, ui8); MATCH_ATOM(Int16, INT16, int32, i16); @@ -140,9 +141,7 @@ namespace NYql { if (depth == 0) { auto value = coalesce.Value().Maybe(); if (value && TStringBuf(value.Cast().Literal()) == "false"sv) { - if (!SerializePredicate(TExprBase(coalesce.Predicate()), proto, arg, err, 0)) { - return false; - } + return SerializePredicate(TExprBase(coalesce.Predicate()), proto, arg, err, 0); } } @@ -259,8 +258,9 @@ namespace NYql { return SerializePredicate(TExprBase(just.Cast().Input()), proto, arg, err, depth + 1); } - err << "unknown predicate: " << predicate.Raw()->Content(); - return false; + // Try to serialize predicate as boolean expression + // For example single bool value TRUE in COALESCE or IF + return SerializeExpression(predicate, proto->mutable_bool_expression()->mutable_value(), arg, err); } } @@ -271,7 +271,7 @@ namespace NYql { TString FormatValue(const Ydb::TypedValue& value) { switch (value.value().value_case()) { case Ydb::Value::kBoolValue: - return ToString(value.value().bool_value()); + return value.value().bool_value() ? "TRUE" : "FALSE"; case Ydb::Value::kInt32Value: return ToString(value.value().int32_value()); case Ydb::Value::kUint32Value: