Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyPA committed Nov 8, 2024
1 parent aebfa7a commit 022e3cc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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!
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -140,9 +141,7 @@ namespace NYql {
if (depth == 0) {
auto value = coalesce.Value().Maybe<TCoBool>();
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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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:
Expand Down

0 comments on commit 022e3cc

Please sign in to comment.