Skip to content

Commit

Permalink
changed the logic, modified nullifwhenprimitive function
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhawvipul committed Jun 22, 2024
1 parent d82ffbf commit b658eac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 202 deletions.
1 change: 0 additions & 1 deletion core/src/execution/datafusion/expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod avg_decimal;
pub mod bloom_filter_might_contain;
pub mod correlation;
pub mod covariance;
pub mod modulo;
pub mod negative;
pub mod stats;
pub mod stddev;
Expand Down
191 changes: 0 additions & 191 deletions core/src/execution/datafusion/expressions/modulo.rs

This file was deleted.

10 changes: 2 additions & 8 deletions core/src/execution/datafusion/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ use crate::{
},
};

use super::expressions::{abs::CometAbsFunc, modulo::ModuloExpr, EvalMode};
use super::expressions::{abs::CometAbsFunc, EvalMode};

// For clippy error on type_complexity.
type ExecResult<T> = Result<T, ExecutionError>;
Expand Down Expand Up @@ -681,13 +681,7 @@ impl PhysicalPlanner {
data_type,
)))
}
_ => {
// Improves compatibility with Spark
if op == DataFusionOperator::Modulo {
return Ok(Arc::new(ModuloExpr::new(left, right)));
}
Ok(Arc::new(BinaryExpr::new(left, op, right)))
}
_ => Ok(Arc::new(BinaryExpr::new(left, op, right))),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,15 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim

def nullIfWhenPrimitive(expression: Expression): Expression = if (isPrimitive(expression)) {
val zero = Literal.default(expression.dataType)
If(EqualTo(expression, zero), Literal.create(null, expression.dataType), expression)
val negZero = Literal.create(-0.0, DoubleType)
if (expression.dataType == DoubleType) {
If(
Or(EqualTo(expression, zero), EqualTo(expression, negZero)),
Literal.create(null, expression.dataType),
expression)
} else {
If(EqualTo(expression, zero), Literal.create(null, expression.dataType), expression)
}
} else {
expression
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,9 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {

test("remainder") {
withTempDir { dir =>
val df = Seq((21840, -0.0)).toDF("c90", "c1")
val df =
Seq((21840, -0.0), (21840, 5.0))
.toDF("c90", "c1")
val path = new Path(dir.toURI.toString, "remainder_test.parquet").toString
df.write.mode("overwrite").parquet(path)

Expand Down

0 comments on commit b658eac

Please sign in to comment.