diff --git a/src/codegen/projector.cc b/src/codegen/projector.cc index 8fe21028969f9..14311bc330eaf 100644 --- a/src/codegen/projector.cc +++ b/src/codegen/projector.cc @@ -148,14 +148,15 @@ Status Projector::AllocArrayData(const DataTypePtr &type, int num_records, } arrow::Status astatus; - auto null_bitmap = std::make_shared(pool_); - astatus = null_bitmap->Resize(arrow::BitUtil::BytesForBits(num_records)); + std::shared_ptr null_bitmap; + int64_t size = arrow::BitUtil::BytesForBits(num_records); + astatus = arrow::AllocateResizableBuffer(pool_, size, &null_bitmap); GANDIVA_RETURN_ARROW_NOT_OK(astatus); - auto data = std::make_shared(pool_); + std::shared_ptr data; const auto &fw_type = dynamic_cast(*type); int64_t data_len = arrow::BitUtil::BytesForBits(num_records * fw_type.bit_width()); - astatus = data->Resize(data_len); + astatus = arrow::AllocateResizableBuffer(pool_, data_len, &data); GANDIVA_RETURN_ARROW_NOT_OK(astatus); *array_data = arrow::ArrayData::Make(type, num_records, {null_bitmap, data}); diff --git a/src/precompiled/arithmetic_ops.cc b/src/precompiled/arithmetic_ops.cc index 756ccf969b80a..9d13498857dec 100644 --- a/src/precompiled/arithmetic_ops.cc +++ b/src/precompiled/arithmetic_ops.cc @@ -44,10 +44,10 @@ extern "C" { DATE_TYPES(INNER, NAME, OP) \ INNER(NAME, boolean, OP) -#define BINARY_GENERIC_OP(NAME, IN_TYPE1, IN_TYPE2, OUT_TYPE, OP) \ +#define MOD_OP(NAME, IN_TYPE1, IN_TYPE2, OUT_TYPE) \ FORCE_INLINE \ OUT_TYPE NAME##_##IN_TYPE1##_##IN_TYPE2(IN_TYPE1 left, IN_TYPE2 right) { \ - return left OP right; \ + return (right == 0 ? left : left % right); \ } // Symmetric binary fns : left, right params and return type are same. @@ -60,8 +60,8 @@ NUMERIC_TYPES(BINARY_SYMMETRIC, subtract, -) NUMERIC_TYPES(BINARY_SYMMETRIC, multiply, *) NUMERIC_TYPES(BINARY_SYMMETRIC, divide, /) -BINARY_GENERIC_OP(mod, int64, int32, int32, %) -BINARY_GENERIC_OP(mod, int64, int64, int64, %) +MOD_OP(mod, int64, int32, int32) +MOD_OP(mod, int64, int64, int64) // Relational binary fns : left, right params are same, return is bool. #define BINARY_RELATIONAL(NAME, TYPE, OP) \ diff --git a/src/precompiled/arithmetic_ops_test.cc b/src/precompiled/arithmetic_ops_test.cc index e5c397dec72ab..fc46464f4a21d 100644 --- a/src/precompiled/arithmetic_ops_test.cc +++ b/src/precompiled/arithmetic_ops_test.cc @@ -33,4 +33,6 @@ TEST(TestArithmeticOps, TestIsDistinctFrom) { EXPECT_EQ(is_not_distinct_from_int32_int32(1000, true, 1000, true), true); } +TEST(TestArithmeticOps, TestMod) { EXPECT_EQ(mod_int64_int32(10, 0), 10); } + } // namespace gandiva diff --git a/src/precompiled/types.h b/src/precompiled/types.h index 30bac6c31814e..cd97dc745efe8 100644 --- a/src/precompiled/types.h +++ b/src/precompiled/types.h @@ -117,6 +117,8 @@ int64 date_trunc_Week_timestamp(timestamp); int32 mem_compare(const char *left, int32 left_len, const char *right, int32 right_len); +int32 mod_int64_int32(int64 left, int32 right); + } // extern "C" #endif // PRECOMPILED_TYPES_H