Skip to content

Commit

Permalink
Remove coalesce usage from pivot transform
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease committed Aug 12, 2024
1 parent f1b43b2 commit 7f4ffdd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 6 additions & 9 deletions vegafusion-runtime/src/transform/pivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::transform::aggregate::make_agg_expr_for_col_expr;
use crate::transform::TransformTrait;
use async_trait::async_trait;
use datafusion_expr::{expr::Sort, lit, when, Expr};
use datafusion_functions::expr_fn::coalesce;
use datafusion_functions_aggregate::expr_fn::min;
use std::sync::Arc;
use vegafusion_common::arrow::array::StringArray;
Expand Down Expand Up @@ -170,17 +169,15 @@ async fn pivot_case(
for pivot_val in pivot_vec.iter() {
let predicate_expr = unescaped_col(&tx.field).eq(lit(pivot_val.as_str()));
let value_expr = unescaped_col(tx.value.as_str());
let agg_col = when(predicate_expr, value_expr).otherwise(lit(ScalarValue::Null))?;
let agg_col = when(predicate_expr, value_expr).otherwise(if fill_zero {
// Replace null with zero for certain aggregates
lit(0)
} else {
lit(ScalarValue::Null)
})?;

let agg_expr = make_agg_expr_for_col_expr(agg_col, &agg_op, &dataframe.schema_df()?)?;

// Replace null with zero for certain aggregates
let agg_expr = if fill_zero {
coalesce(vec![agg_expr, lit(0.0)])
} else {
agg_expr
};

// Compute pivot column name, replacing null placeholder with "null"
let col_name = if pivot_val == NULL_PLACEHOLDER_NAME {
NULL_NAME
Expand Down
1 change: 0 additions & 1 deletion vegafusion-sql/src/compile/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ fn translate_aggregate_function(
within_group: vec![],
parameters: FunctionArguments::None,
});
println!("{}", fn_expr.to_string());
Ok(fn_expr)
} else if let Some(transformer) = dialect.aggregate_transformers.get(fun_name) {
// Supported through AST transformation
Expand Down

0 comments on commit 7f4ffdd

Please sign in to comment.