likun666661 commented on code in PR #50372:
URL: https://github.com/apache/arrow/pull/50372#discussion_r3593098493


##########
cpp/src/gandiva/projector.cc:
##########
@@ -283,6 +288,10 @@ Status Projector::ValidateArrayDataCapacity(const 
arrow::ArrayData& array_data,
 
 const std::string& Projector::DumpIR() { return llvm_generator_->ir(); }
 
+const std::string& Projector::DumpUnoptimizedIR() {

Review Comment:
   Implemented option 3. `DumpUnoptimizedIR()` now returns 
`Result<std::string>` and returns `Invalid` when IR dumping is disabled or the 
projector was built from cache. I also added a cache-hit regression test that 
verifies the error path instead of DCHECKing.



##########
cpp/src/gandiva/tests/projector_test.cc:
##########
@@ -388,6 +434,226 @@ TEST_F(TestProjector, TestAllIntTypes) {
   TestArithmeticOpsForType<arrow::Int64Type, int64_t>(pool_);
 }
 
+TEST_F(TestProjector, TestCommonSubexpressionEliminationIR) {
+  auto field0 = arrow::field("cse_f0", arrow::int32());
+  auto field1 = arrow::field("cse_f1", arrow::int32());
+  auto schema = arrow::schema({field0, field1});
+
+  auto left_sum = TreeExprBuilder::MakeFunction(
+      "add", {TreeExprBuilder::MakeField(field0), 
TreeExprBuilder::MakeField(field1)},
+      arrow::int32());
+  auto right_sum = TreeExprBuilder::MakeFunction(
+      "add", {TreeExprBuilder::MakeField(field0), 
TreeExprBuilder::MakeField(field1)},
+      arrow::int32());
+  auto square =
+      TreeExprBuilder::MakeFunction("multiply", {left_sum, right_sum}, 
arrow::int32());
+  auto expr =
+      TreeExprBuilder::MakeExpression(square, arrow::field("cse_out", 
arrow::int32()));
+
+  auto configuration = std::make_shared<Configuration>(

Review Comment:
   Done. I removed all assertions against `DumpIR()` and LLVM's final optimized 
instruction shape. The tests now only inspect the pre-optimization IR for the 
folding structure and validate the produced arrays at runtime.



##########
cpp/src/gandiva/filter.cc:
##########
@@ -45,10 +46,13 @@ Status Filter::Make(SchemaPtr schema, ConditionPtr 
condition,
   ARROW_RETURN_IF(configuration == nullptr,
                   Status::Invalid("Configuration cannot be null"));
 
+  auto folded_condition =

Review Comment:
   Added `TestFilter.TestCommonSubexpressionFoldAndCache`. It evaluates a 
condition containing three equivalent predicates, verifies the selected rows, 
then builds the equivalent single-predicate condition and checks that it hits 
the folded cache key and produces the same result.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to