apache / apache/arrow

[C++][Gandiva] InExpression for Decimal128 segfaults.

Open
#43,198 2 comments 0 reactions 0 assignees View on GitHub
Component: C++ Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

### Describe the bug, including details regarding any error messages, version, and platform.

```cpp
TEST_F(TestIn, TestInDecimal) {
int test = 5;
while(test--) {
int32_t precision = 38;
int32_t scale = 5;
auto decimal_type = std::make_shared(precision, scale);

// schema for input fields
auto field0 = field("f0", arrow::decimal(precision, scale));
auto schema = arrow::schema({field0});

// Build In f0 + f1 in (6, 11)
auto node_f0 = TreeExprBuilder::MakeField(field0);

gandiva::DecimalScalar128 d0("6", precision, scale);
gandiva::DecimalScalar128 d1("12", precision, scale);
gandiva::DecimalScalar128 d2("11", precision, scale);
std::unordered_set in_constants({d0, d1, d2});
auto in_expr = TreeExprBuilder::MakeInExpressionDecimal(node_f0, in_constants);
auto condition = TreeExprBuilder::MakeCondition(in_expr);

std::shared_ptr filter;
auto status = Filter::Make(schema, condition, TestConfiguration(), &filter);
EXPECT_TRUE(status.ok());

// Create a row-batch with some sample data
int num_records = 5;
auto values0 = MakeDecimalVector({"1", "2", "0", "-6", "6"});
auto array0 =
MakeArrowArrayDecimal(decimal_type, values0, {true, true, true, false, true});
// expected output (indices for which condition matches)
auto exp = MakeArrowArrayUint16({4});

// prepare input record batch
auto in_batch = arrow::RecordBatch::Make(schema, num_records, {array0});

std::shared_ptr selection_vector;
status = SelectionVector::MakeInt16(num_records, pool_, &selection_vector);
EXPECT_TRUE(status.ok());

// Evaluate expression
status = filter->Evaluate(*in_batch, selection_vector);
EXPECT_TRUE(status.ok());

// Validate results
EXPECT_ARROW_ARRAY_EQUALS(exp, selection_vector->ToArray());
}
}
```

**running this test multiple times in a loop segfaults,**

**cause** : in function

```cpp
bool gdv_fn_in_expr_lookup_decimal(int64_t ptr, int64_t value_high, int64_t value_low,
int32_t precision, int32_t scale, bool in_validity) {
if (!in_validity) {
return false;
}
gandiva::DecimalScalar128 value(value_high, value_low, precision, scale);
gandiva::InHolder* holder =
reinterpret_cast*>(ptr);
return holder->HasValue(value);
}
```

here the data value pointed by ptr for InHolder getting corrupted.

### Component(s)

C++ C++ - Gandiva

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.