diff --git a/cpp/src/gandiva/dex.h b/cpp/src/gandiva/dex.h index 2998c2131769..23ebf1bcace5 100644 --- a/cpp/src/gandiva/dex.h +++ b/cpp/src/gandiva/dex.h @@ -211,6 +211,34 @@ class GANDIVA_EXPORT LiteralDex : public Dex { LiteralHolder holder_; }; +/// Decomposed CASE with an ordered list of conditions and results. +class GANDIVA_EXPORT CaseDex : public Dex { + public: + CaseDex(const ValueValidityPairVector& conditions, + const ValueValidityPairVector& results, ValueValidityPairPtr else_vv, + DataTypePtr result_type, int local_bitmap_idx) + : conditions_(conditions), + results_(results), + else_vv_(else_vv), + result_type_(result_type), + local_bitmap_idx_(local_bitmap_idx) {} + + void Accept(DexVisitor& visitor) override { visitor.Visit(*this); } + + const ValueValidityPairVector& conditions() const { return conditions_; } + const ValueValidityPairVector& results() const { return results_; } + const ValueValidityPair& else_vv() const { return *else_vv_; } + const DataTypePtr& result_type() const { return result_type_; } + int local_bitmap_idx() const { return local_bitmap_idx_; } + + private: + ValueValidityPairVector conditions_; + ValueValidityPairVector results_; + ValueValidityPairPtr else_vv_; + DataTypePtr result_type_; + int local_bitmap_idx_; +}; + /// decomposed if-else expression. class GANDIVA_EXPORT IfDex : public Dex { public: diff --git a/cpp/src/gandiva/dex_visitor.h b/cpp/src/gandiva/dex_visitor.h index 4115df7ffb22..5fdb9fdd479a 100644 --- a/cpp/src/gandiva/dex_visitor.h +++ b/cpp/src/gandiva/dex_visitor.h @@ -37,6 +37,7 @@ class NonNullableFuncDex; class NullableNeverFuncDex; class NullableInternalFuncDex; class IfDex; +class CaseDex; class BooleanAndDex; class BooleanOrDex; template @@ -58,6 +59,7 @@ class GANDIVA_EXPORT DexVisitor { virtual void Visit(const NullableNeverFuncDex& dex) = 0; virtual void Visit(const NullableInternalFuncDex& dex) = 0; virtual void Visit(const IfDex& dex) = 0; + virtual void Visit(const CaseDex& dex) = 0; virtual void Visit(const BooleanAndDex& dex) = 0; virtual void Visit(const BooleanOrDex& dex) = 0; virtual void Visit(const InExprDexBase& dex) = 0; @@ -84,6 +86,7 @@ class GANDIVA_EXPORT DexDefaultVisitor : public DexVisitor { VISIT_DCHECK(NullableNeverFuncDex) VISIT_DCHECK(NullableInternalFuncDex) VISIT_DCHECK(IfDex) + VISIT_DCHECK(CaseDex) VISIT_DCHECK(BooleanAndDex) VISIT_DCHECK(BooleanOrDex) VISIT_DCHECK(InExprDexBase) diff --git a/cpp/src/gandiva/expr_decomposer.cc b/cpp/src/gandiva/expr_decomposer.cc index 921829db6a95..11914acfd330 100644 --- a/cpp/src/gandiva/expr_decomposer.cc +++ b/cpp/src/gandiva/expr_decomposer.cc @@ -159,6 +159,30 @@ Status ExprDecomposer::Visit(const IfNode& node) { return Status::OK(); } +Status ExprDecomposer::Visit(const CaseNode& node) { + ValueValidityPairVector conditions; + ValueValidityPairVector results; + for (size_t i = 0; i < node.conditions().size(); ++i) { + nested_if_else_ = false; + ARROW_RETURN_NOT_OK(node.conditions()[i]->Accept(*this)); + conditions.push_back(result()); + nested_if_else_ = false; + ARROW_RETURN_NOT_OK(node.results()[i]->Accept(*this)); + results.push_back(result()); + } + nested_if_else_ = false; + ARROW_RETURN_NOT_OK(node.else_node()->Accept(*this)); + auto else_vv = result(); + nested_if_else_ = false; + + int local_bitmap_idx = annotator_.AddLocalBitMap(); + auto validity_dex = std::make_shared(local_bitmap_idx); + auto value_dex = std::make_shared(conditions, results, else_vv, + node.return_type(), local_bitmap_idx); + result_ = std::make_shared(validity_dex, value_dex); + return Status::OK(); +} + // Decompose a BooleanNode Status ExprDecomposer::Visit(const BooleanNode& node) { // decompose the children. diff --git a/cpp/src/gandiva/expr_decomposer.h b/cpp/src/gandiva/expr_decomposer.h index 90a27744b362..1c3601a3a128 100644 --- a/cpp/src/gandiva/expr_decomposer.h +++ b/cpp/src/gandiva/expr_decomposer.h @@ -63,6 +63,7 @@ class GANDIVA_EXPORT ExprDecomposer : public NodeVisitor { Status Visit(const FieldNode& node) override; Status Visit(const FunctionNode& node) override; Status Visit(const IfNode& node) override; + Status Visit(const CaseNode& node) override; Status Visit(const LiteralNode& node) override; Status Visit(const BooleanNode& node) override; Status Visit(const InExpressionNode& node) override; diff --git a/cpp/src/gandiva/expr_validator.cc b/cpp/src/gandiva/expr_validator.cc index 27b27fbe25ad..e263938b78b3 100644 --- a/cpp/src/gandiva/expr_validator.cc +++ b/cpp/src/gandiva/expr_validator.cc @@ -135,6 +135,27 @@ Status ExprValidator::Visit(const IfNode& node) { return Status::OK(); } +Status ExprValidator::Visit(const CaseNode& node) { + ARROW_RETURN_IF( + node.conditions().empty() || node.conditions().size() != node.results().size(), + Status::ExpressionValidationError("CASE requires matching conditions and results")); + for (size_t i = 0; i < node.conditions().size(); ++i) { + const auto& condition = node.conditions()[i]; + const auto& result = node.results()[i]; + ARROW_RETURN_NOT_OK(condition->Accept(*this)); + ARROW_RETURN_NOT_OK(result->Accept(*this)); + ARROW_RETURN_IF(!condition->return_type()->Equals(arrow::boolean()), + Status::ExpressionValidationError("CASE condition must be boolean")); + ARROW_RETURN_IF(!result->return_type()->Equals(node.return_type()), + Status::ExpressionValidationError("CASE result types must match")); + } + ARROW_RETURN_NOT_OK(node.else_node()->Accept(*this)); + ARROW_RETURN_IF( + !node.else_node()->return_type()->Equals(node.return_type()), + Status::ExpressionValidationError("CASE ELSE type must match result type")); + return Status::OK(); +} + Status ExprValidator::Visit(const LiteralNode& node) { auto llvm_type = types_->IRType(node.return_type()->id()); ARROW_RETURN_IF(llvm_type == nullptr, diff --git a/cpp/src/gandiva/expr_validator.h b/cpp/src/gandiva/expr_validator.h index 8a423fc93b02..8ab9f209a37d 100644 --- a/cpp/src/gandiva/expr_validator.h +++ b/cpp/src/gandiva/expr_validator.h @@ -57,6 +57,7 @@ class ExprValidator : public NodeVisitor { Status Visit(const FieldNode& node) override; Status Visit(const FunctionNode& node) override; Status Visit(const IfNode& node) override; + Status Visit(const CaseNode& node) override; Status Visit(const LiteralNode& node) override; Status Visit(const BooleanNode& node) override; Status Visit(const InExpressionNode& node) override; diff --git a/cpp/src/gandiva/llvm_generator.cc b/cpp/src/gandiva/llvm_generator.cc index e910352189ff..4f9d68d11ddf 100644 --- a/cpp/src/gandiva/llvm_generator.cc +++ b/cpp/src/gandiva/llvm_generator.cc @@ -902,6 +902,57 @@ void LLVMGenerator::Visitor::Visit(const NullableInternalFuncDex& dex) { ClearLocalBitMapIfNotValid(dex.local_bitmap_idx(), result_valid); } +void LLVMGenerator::Visitor::Visit(const CaseDex& dex) { + auto* builder = ir_builder(); + auto* types = generator_->types(); + auto* context = generator_->context(); + auto* merge = llvm::BasicBlock::Create(*context, "case.merge", function_); + std::vector values; + std::vector predecessors; + + auto emit_result = [&](const ValueValidityPair& pair) { + auto value = BuildValueAndValidity(pair); + if (value == nullptr) return false; + ClearLocalBitMapIfNotValid(dex.local_bitmap_idx(), value->validity()); + values.push_back(value); + predecessors.push_back(builder->GetInsertBlock()); + builder->CreateBr(merge); + return true; + }; + + for (size_t i = 0; i < dex.conditions().size(); ++i) { + auto condition = BuildValueAndValidity(*dex.conditions()[i]); + if (condition == nullptr) return; + auto* matched = builder->CreateAnd(condition->data(), condition->validity()); + auto* then_bb = llvm::BasicBlock::Create(*context, "case.then", function_); + auto* next_bb = llvm::BasicBlock::Create(*context, "case.next", function_); + builder->CreateCondBr(matched, then_bb, next_bb); + builder->SetInsertPoint(then_bb); + if (!emit_result(*dex.results()[i])) return; + builder->SetInsertPoint(next_bb); + } + if (!emit_result(dex.else_vv())) return; + + builder->SetInsertPoint(merge); + auto* value_phi = builder->CreatePHI(types->IRType(dex.result_type()->id()), + values.size(), "case.value"); + llvm::PHINode* length_phi = nullptr; + if (arrow::is_binary_like(dex.result_type()->id())) { + length_phi = builder->CreatePHI(types->i32_type(), values.size(), "case.length"); + } + for (size_t i = 0; i < values.size(); ++i) { + value_phi->addIncoming(values[i]->data(), predecessors[i]); + if (length_phi != nullptr) { + length_phi->addIncoming(values[i]->length(), predecessors[i]); + } + } + if (dex.result_type()->id() == arrow::Type::DECIMAL) { + result_ = generator_->BuildDecimalLValue(value_phi, dex.result_type()); + } else { + result_ = std::make_shared(value_phi, length_phi); + } +} + void LLVMGenerator::Visitor::Visit(const IfDex& dex) { ADD_VISITOR_TRACE("visit IfExpression"); llvm::IRBuilder<>* builder = ir_builder(); diff --git a/cpp/src/gandiva/llvm_generator.h b/cpp/src/gandiva/llvm_generator.h index 6cf7a9fef06e..4f23c7093277 100644 --- a/cpp/src/gandiva/llvm_generator.h +++ b/cpp/src/gandiva/llvm_generator.h @@ -137,6 +137,7 @@ class GANDIVA_EXPORT LLVMGenerator { void Visit(const NullableNeverFuncDex& dex) override; void Visit(const NullableInternalFuncDex& dex) override; void Visit(const IfDex& dex) override; + void Visit(const CaseDex& dex) override; void Visit(const BooleanAndDex& dex) override; void Visit(const BooleanOrDex& dex) override; void Visit(const InExprDexBase& dex) override; diff --git a/cpp/src/gandiva/node.h b/cpp/src/gandiva/node.h index 858c65704898..605b9db6d42d 100644 --- a/cpp/src/gandiva/node.h +++ b/cpp/src/gandiva/node.h @@ -194,6 +194,38 @@ class GANDIVA_EXPORT IfNode : public Node { NodePtr else_node_; }; +/// \brief An ordered, flat list of CASE conditions and results. +class GANDIVA_EXPORT CaseNode : public Node { + public: + CaseNode(const NodeVector& conditions, const NodeVector& results, NodePtr else_node, + DataTypePtr result_type) + : Node(result_type), + conditions_(conditions), + results_(results), + else_node_(else_node) {} + + Status Accept(NodeVisitor& visitor) const override { return visitor.Visit(*this); } + + const NodeVector& conditions() const { return conditions_; } + const NodeVector& results() const { return results_; } + const NodePtr& else_node() const { return else_node_; } + + std::string ToString() const override { + std::stringstream ss; + ss << "case"; + for (size_t i = 0; i < conditions_.size(); ++i) { + ss << " when " << conditions_[i]->ToString() << " then " << results_[i]->ToString(); + } + ss << " else " << else_node_->ToString() << " end"; + return ss.str(); + } + + private: + NodeVector conditions_; + NodeVector results_; + NodePtr else_node_; +}; + /// \brief Node in the expression tree, representing an and/or boolean expression. class GANDIVA_EXPORT BooleanNode : public Node { public: diff --git a/cpp/src/gandiva/node_visitor.h b/cpp/src/gandiva/node_visitor.h index 8f233f5b77c0..23bb56223a7d 100644 --- a/cpp/src/gandiva/node_visitor.h +++ b/cpp/src/gandiva/node_visitor.h @@ -30,6 +30,7 @@ namespace gandiva { class FieldNode; class FunctionNode; class IfNode; +class CaseNode; class LiteralNode; class BooleanNode; template @@ -43,6 +44,7 @@ class GANDIVA_EXPORT NodeVisitor { virtual Status Visit(const FieldNode& node) = 0; virtual Status Visit(const FunctionNode& node) = 0; virtual Status Visit(const IfNode& node) = 0; + virtual Status Visit(const CaseNode& node) = 0; virtual Status Visit(const LiteralNode& node) = 0; virtual Status Visit(const BooleanNode& node) = 0; virtual Status Visit(const InExpressionNode& node) = 0; diff --git a/cpp/src/gandiva/tests/if_expr_test.cc b/cpp/src/gandiva/tests/if_expr_test.cc index 54b6d43b4df1..b8e66876f8ec 100644 --- a/cpp/src/gandiva/tests/if_expr_test.cc +++ b/cpp/src/gandiva/tests/if_expr_test.cc @@ -375,4 +375,157 @@ TEST_F(TestIfExpr, TestBigNested) { EXPECT_ARROW_ARRAY_EQUALS(exp, outputs.at(0)); } +TEST_F(TestIfExpr, FlatCaseOrderNullsAndNestedBranches) { + auto input = field("a", int32()); + auto schema = arrow::schema({input}); + auto a = TreeExprBuilder::MakeField(input); + auto positive = TreeExprBuilder::MakeFunction( + "greater_than", {a, TreeExprBuilder::MakeLiteral(int32_t{0})}, boolean()); + auto nested = TreeExprBuilder::MakeIf( + positive, a, TreeExprBuilder::MakeLiteral(int32_t{-1}), int32()); + auto null_value = TreeExprBuilder::MakeNull(int32()); + auto node = TreeExprBuilder::MakeCase( + {TreeExprBuilder::MakeNull(boolean()), positive, + TreeExprBuilder::MakeLiteral(true)}, + {TreeExprBuilder::MakeLiteral(int32_t{99}), nested, null_value}, + TreeExprBuilder::MakeLiteral(int32_t{88}), int32()); + auto baseline = TreeExprBuilder::MakeIf( + TreeExprBuilder::MakeNull(boolean()), TreeExprBuilder::MakeLiteral(int32_t{99}), + TreeExprBuilder::MakeIf(positive, nested, null_value, int32()), int32()); + for (bool optimize : {false, true}) { + auto config = ConfigurationBuilder().build(optimize); + std::shared_ptr projector; + ASSERT_OK(Projector::Make( + schema, + {TreeExprBuilder::MakeExpression(node, field("flat", int32())), + TreeExprBuilder::MakeExpression(baseline, field("nested", int32()))}, + config, &projector)); + auto batch = arrow::RecordBatch::Make( + schema, 4, {MakeArrowArrayInt32({10, -1, 0, 5}, {true, true, true, false})}); + arrow::ArrayVector outputs; + ASSERT_OK(projector->Evaluate(*batch, pool_, &outputs)); + EXPECT_ARROW_ARRAY_EQUALS(outputs[0], outputs[1]); + EXPECT_ARROW_ARRAY_EQUALS( + MakeArrowArrayInt32({10, 0, 0, 0}, {true, false, false, false}), outputs[0]); + } +} + +TEST_F(TestIfExpr, FlatCaseShortCircuitsConditionsAndResults) { + auto input = field("a", int32()); + auto schema = arrow::schema({input}); + auto a = TreeExprBuilder::MakeField(input); + auto divide = TreeExprBuilder::MakeFunction( + "divide", {a, TreeExprBuilder::MakeLiteral(int32_t{0})}, int32()); + auto throwing_condition = + TreeExprBuilder::MakeFunction("equal", {divide, a}, boolean()); + auto node = + TreeExprBuilder::MakeCase({TreeExprBuilder::MakeLiteral(false), + TreeExprBuilder::MakeLiteral(true), throwing_condition}, + {divide, a, divide}, divide, int32()); + for (bool optimize : {false, true}) { + std::shared_ptr projector; + ASSERT_OK(Projector::Make( + schema, {TreeExprBuilder::MakeExpression(node, field("out", int32()))}, + ConfigurationBuilder().build(optimize), &projector)); + auto array = MakeArrowArrayInt32({10, -1, 0, 5}, {true, true, true, false}); + auto batch = arrow::RecordBatch::Make(schema, 4, {array}); + arrow::ArrayVector outputs; + ASSERT_OK(projector->Evaluate(*batch, pool_, &outputs)); + EXPECT_ARROW_ARRAY_EQUALS(array, outputs[0]); + } +} + +TEST_F(TestIfExpr, FlatCaseLarge) { + auto input = field("a", int32()); + auto schema = arrow::schema({input}); + auto a = TreeExprBuilder::MakeField(input); + NodeVector conditions; + NodeVector results; + constexpr int32_t branches = 5000; + for (int32_t i = 0; i < branches; ++i) { + conditions.push_back(TreeExprBuilder::MakeFunction( + "equal", {a, TreeExprBuilder::MakeLiteral(i)}, boolean())); + results.push_back(TreeExprBuilder::MakeLiteral(i + 10)); + } + auto node = TreeExprBuilder::MakeCase(conditions, results, + TreeExprBuilder::MakeNull(int32()), int32()); + for (bool optimize : {false, true}) { + std::shared_ptr projector; + ASSERT_OK(Projector::Make( + schema, {TreeExprBuilder::MakeExpression(node, field("out", int32()))}, + ConfigurationBuilder().build(optimize), &projector)); + auto batch = arrow::RecordBatch::Make( + schema, 5, + {MakeArrowArrayInt32({0, 2500, branches - 1, branches, 0}, + {true, true, true, true, false})}); + arrow::ArrayVector outputs; + ASSERT_OK(projector->Evaluate(*batch, pool_, &outputs)); + EXPECT_ARROW_ARRAY_EQUALS(MakeArrowArrayInt32({10, 2510, branches + 9, 0, 0}, + {true, true, true, false, false}), + outputs[0]); + } +} + +TEST_F(TestIfExpr, FlatCaseStringAndDecimal) { + for (const auto& type : {arrow::utf8(), arrow::decimal128(20, 2)}) { + auto condition_field = field("condition", boolean()); + auto then_field = field("then", type); + auto else_field = field("else", type); + auto schema = arrow::schema({condition_field, then_field, else_field}); + auto condition = TreeExprBuilder::MakeField(condition_field); + auto then_node = TreeExprBuilder::MakeField(then_field); + auto else_node = TreeExprBuilder::MakeField(else_field); + auto inner = TreeExprBuilder::MakeCase({condition}, {then_node}, else_node, type); + auto node = + TreeExprBuilder::MakeCase({condition, TreeExprBuilder::MakeNull(boolean())}, + {inner, then_node}, else_node, type); + auto baseline = TreeExprBuilder::MakeIf(condition, then_node, else_node, type); + auto conditions = + MakeArrowArrayBool({true, false, false, true}, {true, true, false, true}); + auto then_array = + arrow::ArrayFromJSON(type, "[\"123.45\", \"-54.32\", \"12.00\", null]"); + auto else_array = arrow::ArrayFromJSON(type, "[\"0.00\", \"98.76\", null, \"1.00\"]"); + auto expected = arrow::ArrayFromJSON(type, "[\"123.45\", \"98.76\", null, null]"); + for (bool optimize : {false, true}) { + std::shared_ptr projector; + ASSERT_OK(Projector::Make( + schema, + {TreeExprBuilder::MakeExpression(node, field("flat", type)), + TreeExprBuilder::MakeExpression(baseline, field("nested", type))}, + ConfigurationBuilder().build(optimize), &projector)); + auto batch = + arrow::RecordBatch::Make(schema, 4, {conditions, then_array, else_array}); + arrow::ArrayVector outputs; + ASSERT_OK(projector->Evaluate(*batch, pool_, &outputs)); + EXPECT_ARROW_ARRAY_EQUALS(expected, outputs[0]); + EXPECT_ARROW_ARRAY_EQUALS(outputs[1], outputs[0]); + } + } +} + +TEST_F(TestIfExpr, FlatCaseHasOneMerge) { + auto input = field("a", int32()); + auto schema = arrow::schema({input}); + auto a = TreeExprBuilder::MakeField(input); + NodeVector conditions; + NodeVector results; + for (int32_t i = 0; i < 10; ++i) { + conditions.push_back(TreeExprBuilder::MakeFunction( + "equal", {a, TreeExprBuilder::MakeLiteral(i)}, boolean())); + results.push_back(TreeExprBuilder::MakeLiteral(i + 1)); + } + auto node = TreeExprBuilder::MakeCase(conditions, results, a, int32()); + auto config = ConfigurationBuilder().build(false); + config->set_dump_ir(true); + std::shared_ptr projector; + ASSERT_OK(Projector::Make( + schema, {TreeExprBuilder::MakeExpression(node, field("out", int32()))}, config, + &projector)); + const auto& ir = projector->DumpIR(); + auto phi = ir.find("case.value = phi i32"); + ASSERT_NE(std::string::npos, phi); + EXPECT_EQ(std::string::npos, ir.find("case.value = phi i32", phi + 1)); + EXPECT_EQ(std::string::npos, ir.find("res_value = phi")); +} + } // namespace gandiva diff --git a/cpp/src/gandiva/tests/projector_build_validation_test.cc b/cpp/src/gandiva/tests/projector_build_validation_test.cc index 1ed4c77a074a..5f9068101bc1 100644 --- a/cpp/src/gandiva/tests/projector_build_validation_test.cc +++ b/cpp/src/gandiva/tests/projector_build_validation_test.cc @@ -284,4 +284,25 @@ TEST_F(ValidationTestProjector, TestAndBooleanArgType) { EXPECT_TRUE(status.IsExpressionValidationError()); } +TEST_F(ValidationTestProjector, TestCaseTypes) { + auto input = field("a", int32()); + auto schema = arrow::schema({input}); + auto value = TreeExprBuilder::MakeField(input); + auto truth = TreeExprBuilder::MakeLiteral(true); + auto null_value = TreeExprBuilder::MakeNull(int32()); + for (const auto& node : + {TreeExprBuilder::MakeCase({value}, {value}, null_value, int32()), + TreeExprBuilder::MakeCase({truth}, {truth}, null_value, int32()), + TreeExprBuilder::MakeCase({truth}, {value}, truth, int32())}) { + std::shared_ptr projector; + auto expression = TreeExprBuilder::MakeExpression(node, field("out", int32())); + EXPECT_TRUE(Projector::Make(schema, {expression}, TestConfiguration(), &projector) + .IsExpressionValidationError()); + } + EXPECT_EQ(nullptr, TreeExprBuilder::MakeCase({}, {}, null_value, int32())); + EXPECT_EQ(nullptr, TreeExprBuilder::MakeCase({truth}, {}, null_value, int32())); + EXPECT_EQ(nullptr, TreeExprBuilder::MakeCase({nullptr}, {value}, null_value, int32())); + EXPECT_EQ(nullptr, TreeExprBuilder::MakeCase({truth}, {nullptr}, null_value, int32())); +} + } // namespace gandiva diff --git a/cpp/src/gandiva/tree_expr_builder.cc b/cpp/src/gandiva/tree_expr_builder.cc index 122013a1dbe9..fc78b7d9498e 100644 --- a/cpp/src/gandiva/tree_expr_builder.cc +++ b/cpp/src/gandiva/tree_expr_builder.cc @@ -132,6 +132,20 @@ NodePtr TreeExprBuilder::MakeIf(NodePtr condition, NodePtr then_node, NodePtr el return std::make_shared(condition, then_node, else_node, result_type); } +NodePtr TreeExprBuilder::MakeCase(const NodeVector& conditions, const NodeVector& results, + NodePtr else_node, DataTypePtr result_type) { + if (conditions.empty() || conditions.size() != results.size() || else_node == nullptr || + result_type == nullptr) { + return nullptr; + } + for (size_t i = 0; i < conditions.size(); ++i) { + if (conditions[i] == nullptr || results[i] == nullptr) { + return nullptr; + } + } + return std::make_shared(conditions, results, else_node, result_type); +} + NodePtr TreeExprBuilder::MakeAnd(const NodeVector& children) { return std::make_shared(BooleanNode::AND, children); } diff --git a/cpp/src/gandiva/tree_expr_builder.h b/cpp/src/gandiva/tree_expr_builder.h index 94a4a1793400..168f71ee9818 100644 --- a/cpp/src/gandiva/tree_expr_builder.h +++ b/cpp/src/gandiva/tree_expr_builder.h @@ -68,6 +68,10 @@ class GANDIVA_EXPORT TreeExprBuilder { static NodePtr MakeIf(NodePtr condition, NodePtr then_node, NodePtr else_node, DataTypePtr result_type); + /// \brief Build a CASE expression with first-match semantics. + static NodePtr MakeCase(const NodeVector& conditions, const NodeVector& results, + NodePtr else_node, DataTypePtr result_type); + /// \brief create a node with a boolean AND expression. static NodePtr MakeAnd(const NodeVector& children);