| 112 | } |
| 113 | |
| 114 | void TestDecimalSql::Verify(DecimalTypeUtil::Op op, const DecimalScalar128& x, |
| 115 | const DecimalScalar128& y, |
| 116 | const DecimalScalar128& expected_result, |
| 117 | bool expected_overflow) { |
| 118 | auto t1 = std::make_shared<arrow::Decimal128Type>(x.precision(), x.scale()); |
| 119 | auto t2 = std::make_shared<arrow::Decimal128Type>(y.precision(), y.scale()); |
| 120 | bool overflow = false; |
| 121 | int64_t context = 0; |
| 122 | |
| 123 | Decimal128TypePtr out_type; |
| 124 | ARROW_EXPECT_OK(DecimalTypeUtil::GetResultType(op, {t1, t2}, &out_type)); |
| 125 | |
| 126 | arrow::BasicDecimal128 out_value; |
| 127 | std::string op_name; |
| 128 | switch (op) { |
| 129 | case DecimalTypeUtil::kOpAdd: |
| 130 | op_name = "add"; |
| 131 | out_value = decimalops::Add(x, y, out_type->precision(), out_type->scale()); |
| 132 | break; |
| 133 | |
| 134 | case DecimalTypeUtil::kOpSubtract: |
| 135 | op_name = "subtract"; |
| 136 | out_value = decimalops::Subtract(x, y, out_type->precision(), out_type->scale()); |
| 137 | break; |
| 138 | |
| 139 | case DecimalTypeUtil::kOpMultiply: |
| 140 | op_name = "multiply"; |
| 141 | out_value = |
| 142 | decimalops::Multiply(x, y, out_type->precision(), out_type->scale(), &overflow); |
| 143 | break; |
| 144 | |
| 145 | case DecimalTypeUtil::kOpDivide: |
| 146 | op_name = "divide"; |
| 147 | out_value = decimalops::Divide(context, x, y, out_type->precision(), |
| 148 | out_type->scale(), &overflow); |
| 149 | break; |
| 150 | |
| 151 | case DecimalTypeUtil::kOpMod: |
| 152 | op_name = "mod"; |
| 153 | out_value = decimalops::Mod(context, x, y, out_type->precision(), out_type->scale(), |
| 154 | &overflow); |
| 155 | break; |
| 156 | |
| 157 | default: |
| 158 | // not implemented. |
| 159 | ASSERT_FALSE(true); |
| 160 | } |
| 161 | EXPECT_DECIMAL_EQ(op_name, x, y, expected_result, expected_overflow, |
| 162 | DecimalScalar128(out_value, out_type->precision(), out_type->scale()), |
| 163 | overflow); |
| 164 | } |
| 165 | |
| 166 | void TestDecimalSql::VerifyAllSign(DecimalTypeUtil::Op op, const DecimalScalar128& left, |
| 167 | const DecimalScalar128& right, |