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