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

Introduce Comprehensive Pathological Unit Tests for Issue #14409 #14459

Merged
merged 6 commits into from
Nov 24, 2023
Merged
Changes from 4 commits
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
68 changes: 68 additions & 0 deletions cpp/tests/ast/transform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,74 @@ TEST_F(TransformTest, ImbalancedTreeArithmeticDeep)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view(), verbosity);
}

TEST_F(TransformTest, DeeplyNestedArithmeticLogicalExpression)
{
// Test logic for deeply nested arithmetic and logical expressions.
constexpr int64_t kLeftDepthLevel = 100;
constexpr int64_t kRightDepthLevel = 75;
aocsa marked this conversation as resolved.
Show resolved Hide resolved

auto generate_ast_expr = [](int64_t depth_level,
cudf::ast::column_reference col_ref,
cudf::ast::ast_operator root_operator,
bool nested_left_tree) {
auto expressions = std::list<cudf::ast::operation>();
aocsa marked this conversation as resolved.
Show resolved Hide resolved
std::vector<cudf::ast::ast_operator> arithmetic_operators = {cudf::ast::ast_operator::ADD,
cudf::ast::ast_operator::SUB};

auto op = arithmetic_operators[rand() % arithmetic_operators.size()];
aocsa marked this conversation as resolved.
Show resolved Hide resolved
expressions.push_back(cudf::ast::operation(op, col_ref, col_ref));

for (int64_t i = 0; i < depth_level - 1; i++) {
if (i == depth_level - 2) {
op = root_operator;
} else {
op = arithmetic_operators[rand() % arithmetic_operators.size()];
}
if (nested_left_tree) {
expressions.push_back(cudf::ast::operation(op, expressions.back(), col_ref));
} else {
expressions.push_back(cudf::ast::operation(op, col_ref, expressions.back()));
}
}
return expressions;
};

auto c_0 = column_wrapper<int64_t>{0, 0, 0};
auto c_1 = column_wrapper<int32_t>{0, 0, 0};
auto table = cudf::table_view{{c_0, c_1}};

auto expressions = std::list<cudf::ast::operation>();
aocsa marked this conversation as resolved.
Show resolved Hide resolved

auto col_ref_0 = cudf::ast::column_reference(0);
auto col_ref_1 = cudf::ast::column_reference(1);

auto left_expression =
generate_ast_expr(kLeftDepthLevel, col_ref_0, cudf::ast::ast_operator::LESS, false);
auto right_expression =
generate_ast_expr(kRightDepthLevel, col_ref_1, cudf::ast::ast_operator::EQUAL, true);

auto expression_tree = cudf::ast::operation(
cudf::ast::ast_operator::LOGICAL_OR, left_expression.back(), right_expression.back());

// Expression:
// OR(<(-(-(+(-($0, $0), $0), $0), $0), $0), ==($1, -($1, +($1, +($1, -($1, $1))))))
aocsa marked this conversation as resolved.
Show resolved Hide resolved
// ...
// OR(<($L, $0), ==($1, $R))
// true
//
// Breakdown:
// - Left Operand ($L): (-(-(+(-($0, $0), $0), $0), $0), $0)
// - Right Operand ($R): -($1, +($1, +($1, -($1, $1))))
// Explanation:
// If all $1 values and $R values are zeros, the result is true because of the equality check
// combined with the OR operator in OR(<($L, $0), ==($1, $R)).

auto result = cudf::compute_column(table, expression_tree);
auto expected = column_wrapper<bool>{true, true, true};

CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view(), verbosity);
}

TEST_F(TransformTest, MultiLevelTreeComparator)
{
auto c_0 = column_wrapper<int32_t>{3, 20, 1, 50};
Expand Down