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 5 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
65 changes: 65 additions & 0 deletions cpp/tests/ast/transform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,71 @@ 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 left_depth_level = 100;
constexpr int64_t right_depth_level = 75;

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

auto op = arithmetic_operator;
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_operator;
}
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 col_ref_0 = cudf::ast::column_reference(0);
auto col_ref_1 = cudf::ast::column_reference(1);

auto left_expression =
generate_ast_expr(left_depth_level, col_ref_0, cudf::ast::ast_operator::LESS, cudf::ast::ast_operator::ADD, false);
auto right_expression =
generate_ast_expr(right_depth_level, col_ref_1, cudf::ast::ast_operator::EQUAL, cudf::ast::ast_operator::SUB, 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))))))
// ...
// 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
Loading