Skip to content

Commit fc3e6e9

Browse files
authored
feat: Add support for abs (#2689)
1 parent cf56fc1 commit fc3e6e9

File tree

13 files changed

+1027
-92
lines changed

13 files changed

+1027
-92
lines changed

.github/workflows/pr_build_linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ jobs:
134134
org.apache.comet.CometCastSuite
135135
org.apache.comet.CometExpressionSuite
136136
org.apache.comet.CometExpressionCoverageSuite
137+
org.apache.comet.CometMathExpressionSuite
137138
org.apache.comet.CometNativeSuite
138139
org.apache.comet.CometSparkSessionExtensionsSuite
139140
org.apache.comet.CometStringExpressionSuite

.github/workflows/pr_build_macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ jobs:
9999
org.apache.comet.CometCastSuite
100100
org.apache.comet.CometExpressionSuite
101101
org.apache.comet.CometExpressionCoverageSuite
102+
org.apache.comet.CometMathExpressionSuite
102103
org.apache.comet.CometNativeSuite
103104
org.apache.comet.CometSparkSessionExtensionsSuite
104105
org.apache.comet.CometStringExpressionSuite

docs/source/user-guide/latest/configs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ These settings can be used to determine which parts of the plan are accelerated
164164
<!--BEGIN:CONFIG_TABLE[enable_expr]-->
165165
| Config | Description | Default Value |
166166
|--------|-------------|---------------|
167+
| `spark.comet.expression.Abs.enabled` | Enable Comet acceleration for `Abs` | true |
167168
| `spark.comet.expression.Acos.enabled` | Enable Comet acceleration for `Acos` | true |
168169
| `spark.comet.expression.Add.enabled` | Enable Comet acceleration for `Add` | true |
169170
| `spark.comet.expression.Alias.enabled` | Enable Comet acceleration for `Alias` | true |

docs/source/user-guide/latest/expressions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ incompatible expressions.
119119

120120
| Expression | SQL | Spark-Compatible? | Compatibility Notes |
121121
|----------------|-----------|-------------------|-----------------------------------|
122+
| Abs | `abs` | Yes | |
122123
| Acos | `acos` | Yes | |
123124
| Add | `+` | Yes | |
124125
| Asin | `asin` | Yes | |

native/core/src/execution/planner.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -674,19 +674,6 @@ impl PhysicalPlanner {
674674
let op = DataFusionOperator::BitwiseShiftLeft;
675675
Ok(Arc::new(BinaryExpr::new(left, op, right)))
676676
}
677-
// https://github.com/apache/datafusion-comet/issues/666
678-
// ExprStruct::Abs(expr) => {
679-
// let child = self.create_expr(expr.child.as_ref().unwrap(), Arc::clone(&input_schema))?;
680-
// let return_type = child.data_type(&input_schema)?;
681-
// let args = vec![child];
682-
// let eval_mode = from_protobuf_eval_mode(expr.eval_mode)?;
683-
// let comet_abs = Arc::new(ScalarUDF::new_from_impl(Abs::new(
684-
// eval_mode,
685-
// return_type.to_string(),
686-
// )?));
687-
// let expr = ScalarFunctionExpr::new("abs", comet_abs, args, return_type);
688-
// Ok(Arc::new(expr))
689-
// }
690677
ExprStruct::CaseWhen(case_when) => {
691678
let when_then_pairs = case_when
692679
.when

native/proto/src/proto/expr.proto

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ message Expr {
7070
IfExpr if = 44;
7171
NormalizeNaNAndZero normalize_nan_and_zero = 45;
7272
TruncTimestamp truncTimestamp = 47;
73-
Abs abs = 49;
7473
Subquery subquery = 50;
7574
UnboundReference unbound = 51;
7675
BloomFilterMightContain bloom_filter_might_contain = 52;
@@ -351,11 +350,6 @@ message TruncTimestamp {
351350
string timezone = 3;
352351
}
353352

354-
message Abs {
355-
Expr child = 1;
356-
EvalMode eval_mode = 2;
357-
}
358-
359353
message Subquery {
360354
int64 id = 1;
361355
DataType datatype = 2;

native/spark-expr/src/comet_scalar_funcs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use crate::hash_funcs::*;
19+
use crate::math_funcs::abs::abs;
1920
use crate::math_funcs::checked_arithmetic::{checked_add, checked_div, checked_mul, checked_sub};
2021
use crate::math_funcs::modulo_expr::spark_modulo;
2122
use crate::{
@@ -180,6 +181,10 @@ pub fn create_comet_physical_fun_with_eval_mode(
180181
let func = Arc::new(spark_modulo);
181182
make_comet_scalar_udf!("spark_modulo", func, without data_type, fail_on_error)
182183
}
184+
"abs" => {
185+
let func = Arc::new(abs);
186+
make_comet_scalar_udf!("abs", func, without data_type)
187+
}
183188
_ => registry.udf(fun_name).map_err(|e| {
184189
DataFusionError::Execution(format!(
185190
"Function {fun_name} not found in the registry: {e}",

0 commit comments

Comments
 (0)