Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/source/user-guide/latest/compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ the [Comet Supported Expressions Guide](expressions.md) for more information on

### Math Expressions

- **Ceil, Floor**: Incorrect results for Decimal type inputs.
[#1729](https://github.com/apache/datafusion-comet/issues/1729)
- **Tan**: `tan(-0.0)` produces `0.0` instead of `-0.0`.
[#1897](https://github.com/apache/datafusion-comet/issues/1897)

Expand Down
84 changes: 42 additions & 42 deletions docs/source/user-guide/latest/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,48 +121,48 @@ Expressions that are not Spark-compatible will fall back to Spark by default and

## Math Expressions

| Expression | SQL | Spark-Compatible? | Compatibility Notes |
| -------------- | --------- | ----------------- | ----------------------------------------------------------------------------------------------------------- |
| Abs | `abs` | Yes | |
| Acos | `acos` | Yes | |
| Add | `+` | Yes | |
| Asin | `asin` | Yes | |
| Atan | `atan` | Yes | |
| Atan2 | `atan2` | Yes | |
| BRound | `bround` | Yes | |
| Ceil | `ceil` | No | Incorrect results for Decimal type inputs ([#1729](https://github.com/apache/datafusion-comet/issues/1729)) |
| Cos | `cos` | Yes | |
| Cosh | `cosh` | Yes | |
| Cot | `cot` | Yes | |
| Divide | `/` | Yes | |
| Exp | `exp` | Yes | |
| Expm1 | `expm1` | Yes | |
| Floor | `floor` | No | Incorrect results for Decimal type inputs ([#1729](https://github.com/apache/datafusion-comet/issues/1729)) |
| Hex | `hex` | Yes | |
| IntegralDivide | `div` | Yes | |
| IsNaN | `isnan` | Yes | |
| Log | `log` | Yes | |
| Log2 | `log2` | Yes | |
| Log10 | `log10` | Yes | |
| Multiply | `*` | Yes | |
| Pow | `power` | Yes | |
| Rand | `rand` | Yes | |
| Randn | `randn` | Yes | |
| Remainder | `%` | Yes | |
| Round | `round` | Yes | |
| Signum | `signum` | Yes | |
| Sin | `sin` | Yes | |
| Sinh | `sinh` | Yes | |
| Sqrt | `sqrt` | Yes | |
| Subtract | `-` | Yes | |
| Tan | `tan` | No | tan(-0.0) produces incorrect result ([#1897](https://github.com/apache/datafusion-comet/issues/1897)) |
| Tanh | `tanh` | Yes | |
| TryAdd | `try_add` | Yes | Only integer inputs are supported |
| TryDivide | `try_div` | Yes | Only integer inputs are supported |
| TryMultiply | `try_mul` | Yes | Only integer inputs are supported |
| TrySubtract | `try_sub` | Yes | Only integer inputs are supported |
| UnaryMinus | `-` | Yes | |
| Unhex | `unhex` | Yes | |
| Expression | SQL | Spark-Compatible? | Compatibility Notes |
| -------------- | --------- | ----------------- | ----------------------------------------------------------------------------------------------------- |
| Abs | `abs` | Yes | |
| Acos | `acos` | Yes | |
| Add | `+` | Yes | |
| Asin | `asin` | Yes | |
| Atan | `atan` | Yes | |
| Atan2 | `atan2` | Yes | |
| BRound | `bround` | Yes | |
| Ceil | `ceil` | Yes | |
| Cos | `cos` | Yes | |
| Cosh | `cosh` | Yes | |
| Cot | `cot` | Yes | |
| Divide | `/` | Yes | |
| Exp | `exp` | Yes | |
| Expm1 | `expm1` | Yes | |
| Floor | `floor` | Yes | |
| Hex | `hex` | Yes | |
| IntegralDivide | `div` | Yes | |
| IsNaN | `isnan` | Yes | |
| Log | `log` | Yes | |
| Log2 | `log2` | Yes | |
| Log10 | `log10` | Yes | |
| Multiply | `*` | Yes | |
| Pow | `power` | Yes | |
| Rand | `rand` | Yes | |
| Randn | `randn` | Yes | |
| Remainder | `%` | Yes | |
| Round | `round` | Yes | |
| Signum | `signum` | Yes | |
| Sin | `sin` | Yes | |
| Sinh | `sinh` | Yes | |
| Sqrt | `sqrt` | Yes | |
| Subtract | `-` | Yes | |
| Tan | `tan` | No | tan(-0.0) produces incorrect result ([#1897](https://github.com/apache/datafusion-comet/issues/1897)) |
| Tanh | `tanh` | Yes | |
| TryAdd | `try_add` | Yes | Only integer inputs are supported |
| TryDivide | `try_div` | Yes | Only integer inputs are supported |
| TryMultiply | `try_mul` | Yes | Only integer inputs are supported |
| TrySubtract | `try_sub` | Yes | Only integer inputs are supported |
| UnaryMinus | `-` | Yes | |
| Unhex | `unhex` | Yes | |

## Hashing Functions

Expand Down
20 changes: 8 additions & 12 deletions native/spark-expr/src/math_funcs/ceil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ mod test {
Ok(())
}

// https://github.com/apache/datafusion-comet/issues/1729
#[test]
#[ignore]
fn test_ceil_decimal128_array() -> Result<()> {
let array = Decimal128Array::from(vec![
Some(12345), // 123.45
Expand All @@ -174,16 +172,16 @@ mod test {
])
.with_precision_and_scale(5, 2)?;
let args = vec![ColumnarValue::Array(Arc::new(array))];
let ColumnarValue::Array(result) = spark_ceil(&args, &DataType::Decimal128(5, 2))? else {
let ColumnarValue::Array(result) = spark_ceil(&args, &DataType::Decimal128(4, 0))? else {
unreachable!()
};
let expected = Decimal128Array::from(vec![
Some(12400), // 124.00
Some(12500), // 125.00
Some(-12900), // -129.00
Some(124), // 124.00
Some(125), // 125.00
Some(-129), // -129.00
Comment thread
kazuyukitanimura marked this conversation as resolved.
None,
])
.with_precision_and_scale(5, 2)?;
.with_precision_and_scale(4, 0)?;
let actual = result.as_any().downcast_ref::<Decimal128Array>().unwrap();
assert_eq!(actual, &expected);
Ok(())
Expand Down Expand Up @@ -225,21 +223,19 @@ mod test {
Ok(())
}

// https://github.com/apache/datafusion-comet/issues/1729
#[test]
#[ignore]
fn test_ceil_decimal128_scalar() -> Result<()> {
let args = vec![ColumnarValue::Scalar(ScalarValue::Decimal128(
Some(567),
3,
1,
))]; // 56.7
let ColumnarValue::Scalar(ScalarValue::Decimal128(Some(result), 3, 1)) =
spark_ceil(&args, &DataType::Decimal128(3, 1))?
let ColumnarValue::Scalar(ScalarValue::Decimal128(Some(result), 3, 0)) =
spark_ceil(&args, &DataType::Decimal128(3, 0))?
else {
unreachable!()
};
assert_eq!(result, 570); // 57.0
assert_eq!(result, 57); // 57.0
Ok(())
}
}
20 changes: 8 additions & 12 deletions native/spark-expr/src/math_funcs/floor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,7 @@ mod test {
Ok(())
}

// https://github.com/apache/datafusion-comet/issues/1729
#[test]
#[ignore]
fn test_floor_decimal128_array() -> Result<()> {
let array = Decimal128Array::from(vec![
Some(12345), // 123.45
Expand All @@ -174,16 +172,16 @@ mod test {
])
.with_precision_and_scale(5, 2)?;
let args = vec![ColumnarValue::Array(Arc::new(array))];
let ColumnarValue::Array(result) = spark_floor(&args, &DataType::Decimal128(5, 2))? else {
let ColumnarValue::Array(result) = spark_floor(&args, &DataType::Decimal128(4, 0))? else {
unreachable!()
};
let expected = Decimal128Array::from(vec![
Some(12300), // 123.00
Some(12500), // 125.00
Some(-13000), // -130.00
Some(123), // 123.00
Some(125), // 125.00
Some(-130), // -130.00
None,
])
.with_precision_and_scale(5, 2)?;
.with_precision_and_scale(4, 0)?;
let actual = result.as_any().downcast_ref::<Decimal128Array>().unwrap();
assert_eq!(actual, &expected);
Ok(())
Expand Down Expand Up @@ -225,21 +223,19 @@ mod test {
Ok(())
}

// https://github.com/apache/datafusion-comet/issues/1729
#[test]
#[ignore]
fn test_floor_decimal128_scalar() -> Result<()> {
let args = vec![ColumnarValue::Scalar(ScalarValue::Decimal128(
Some(567),
3,
1,
))]; // 56.7
let ColumnarValue::Scalar(ScalarValue::Decimal128(Some(result), 3, 1)) =
spark_floor(&args, &DataType::Decimal128(3, 1))?
let ColumnarValue::Scalar(ScalarValue::Decimal128(Some(result), 3, 0)) =
spark_floor(&args, &DataType::Decimal128(3, 0))?
else {
unreachable!()
};
assert_eq!(result, 560); // 56.0
assert_eq!(result, 56); // 56.0
Ok(())
}
}
24 changes: 0 additions & 24 deletions spark/src/main/scala/org/apache/comet/serde/math.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ object CometAtan2 extends CometExpressionSerde[Atan2] {
}

object CometCeil extends CometExpressionSerde[Ceil] {

override def getSupportLevel(expr: Ceil): SupportLevel = {
expr.child.dataType match {
case _: DecimalType =>
Incompatible(
Some(
"Incorrect results for Decimal type inputs" +
" (https://github.com/apache/datafusion-comet/issues/1729)"))
case _ => Compatible()
}
}

override def convert(
expr: Ceil,
inputs: Seq[Attribute],
Expand All @@ -70,18 +58,6 @@ object CometCeil extends CometExpressionSerde[Ceil] {
}

object CometFloor extends CometExpressionSerde[Floor] {

override def getSupportLevel(expr: Floor): SupportLevel = {
expr.child.dataType match {
case _: DecimalType =>
Incompatible(
Some(
"Incorrect results for Decimal type inputs" +
" (https://github.com/apache/datafusion-comet/issues/1729)"))
case _ => Compatible()
}
}

override def convert(
expr: Floor,
inputs: Seq[Attribute],
Expand Down
9 changes: 4 additions & 5 deletions spark/src/test/resources/sql-tests/expressions/math/ceil.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@
-- specific language governing permissions and limitations
-- under the License.

-- Config: spark.comet.expression.Ceil.allowIncompatible=true
-- ConfigMatrix: parquet.enable.dictionary=false,true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be nice to add a decimal column to the SQL test data so that decimal ceil/floor is tested through the SQL file framework too. Something like adding a decimal(5,2) column to the test table

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

statement
CREATE TABLE test_ceil(f float, d double) USING parquet
CREATE TABLE test_ceil(f float, d double, dec DECIMAL(5, 2)) USING parquet

statement
INSERT INTO test_ceil VALUES (1.1, 1.1), (-1.1, -1.1), (0.0, 0.0), (1.0, 1.0), (NULL, NULL), (cast('NaN' as float), cast('NaN' as double)), (cast('Infinity' as float), cast('Infinity' as double))
INSERT INTO test_ceil VALUES (1.1, 1.1, 1.10), (-1.1, -1.1, -1.10), (0.0, 0.0, 0.00), (1.0, 1.0, 1.00), (NULL, NULL, NULL), (cast('NaN' as float), cast('NaN' as double), NULL), (cast('Infinity' as float), cast('Infinity' as double), NULL)

query
SELECT ceil(f), ceil(d) FROM test_ceil
SELECT ceil(f), ceil(d), ceil(dec) FROM test_ceil

-- literal arguments
query
SELECT ceil(1.1), ceil(-1.1), ceil(0.0), ceil(NULL)
SELECT ceil(1.1), ceil(-1.1), ceil(0.0), ceil(NULL), ceil(cast(1.10 as DECIMAL(5, 2))), ceil(cast(-1.10 as DECIMAL(5, 2)))
Loading
Loading