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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dev/dist
apache-rat-*.jar
venv
dev/release/comet-rm/workdir
spark/benchmarks
25 changes: 2 additions & 23 deletions native/core/src/execution/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use crate::{
use arrow::compute::CastOptions;
use arrow::datatypes::{DataType, Field, Schema, TimeUnit, DECIMAL128_MAX_PRECISION};
use datafusion::functions_aggregate::bit_and_or_xor::{bit_and_udaf, bit_or_udaf, bit_xor_udaf};
use datafusion::functions_aggregate::count::count_udaf;
use datafusion::functions_aggregate::min_max::max_udaf;
use datafusion::functions_aggregate::min_max::min_udaf;
use datafusion::functions_aggregate::sum::sum_udaf;
Expand Down Expand Up @@ -1904,35 +1905,13 @@ impl PhysicalPlanner {
match spark_expr.expr_struct.as_ref().unwrap() {
AggExprStruct::Count(expr) => {
assert!(!expr.children.is_empty());
// Using `count_udaf` from Comet is exceptionally slow for some reason, so
// as a workaround we translate it to `SUM(IF(expr IS NOT NULL, 1, 0))`
// https://github.com/apache/datafusion-comet/issues/744

let children = expr
.children
.iter()
.map(|child| self.create_expr(child, Arc::clone(&schema)))
.collect::<Result<Vec<_>, _>>()?;

// create `IS NOT NULL expr` and join them with `AND` if there are multiple
let not_null_expr: Arc<dyn PhysicalExpr> = children.iter().skip(1).fold(
Arc::new(IsNotNullExpr::new(Arc::clone(&children[0]))) as Arc<dyn PhysicalExpr>,
|acc, child| {
Arc::new(BinaryExpr::new(
acc,
DataFusionOperator::And,
Arc::new(IsNotNullExpr::new(Arc::clone(child))),
))
},
);

let child = Arc::new(IfExpr::new(
not_null_expr,
Arc::new(Literal::new(ScalarValue::Int64(Some(1)))),
Arc::new(Literal::new(ScalarValue::Int64(Some(0)))),
));

AggregateExprBuilder::new(sum_udaf(), vec![child])
AggregateExprBuilder::new(count_udaf(), children)
.schema(schema)
.alias("count")
.with_ignore_nulls(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ object CometAggregateBenchmark extends CometBenchmarkBase {
spark.sql(query).noop()
}

benchmark.addCase(s"SQL Parquet - Comet (Scan) ($aggregateFunction)") { _ =>
withSQLConf(CometConf.COMET_ENABLED.key -> "true") {
spark.sql(query).noop()
}
}
Comment on lines -67 to -71
Copy link
Member Author

Choose a reason for hiding this comment

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

It no longer makes sense to benchmark Comet with Scan vs Scan & Exec configurations, especially for aggregates. Comet scans won't accelerate aggregates.


benchmark.addCase(s"SQL Parquet - Comet (Scan, Exec) ($aggregateFunction)") { _ =>
benchmark.addCase(s"SQL Parquet - Comet ($aggregateFunction)") { _ =>
withSQLConf(
CometConf.COMET_ENABLED.key -> "true",
CometConf.COMET_EXEC_ENABLED.key -> "true") {
Expand Down Expand Up @@ -111,13 +105,7 @@ object CometAggregateBenchmark extends CometBenchmarkBase {
spark.sql(query).noop()
}

benchmark.addCase(s"SQL Parquet - Comet (Scan) ($aggregateFunction)") { _ =>
withSQLConf(CometConf.COMET_ENABLED.key -> "true") {
spark.sql(query).noop()
}
}

benchmark.addCase(s"SQL Parquet - Comet (Scan, Exec) ($aggregateFunction)") { _ =>
benchmark.addCase(s"SQL Parquet - Comet ($aggregateFunction)") { _ =>
withSQLConf(
CometConf.COMET_ENABLED.key -> "true",
CometConf.COMET_EXEC_ENABLED.key -> "true") {
Expand Down Expand Up @@ -153,15 +141,7 @@ object CometAggregateBenchmark extends CometBenchmarkBase {
spark.sql(query).noop()
}

benchmark.addCase(s"SQL Parquet - Comet (Scan) ($aggregateFunction)") { _ =>
withSQLConf(
CometConf.COMET_ENABLED.key -> "true",
CometConf.COMET_MEMORY_OVERHEAD.key -> "1G") {
spark.sql(query).noop()
}
}

benchmark.addCase(s"SQL Parquet - Comet (Scan, Exec) ($aggregateFunction)") { _ =>
benchmark.addCase(s"SQL Parquet - Comet ($aggregateFunction)") { _ =>
withSQLConf(
CometConf.COMET_ENABLED.key -> "true",
CometConf.COMET_EXEC_ENABLED.key -> "true",
Expand Down Expand Up @@ -198,13 +178,7 @@ object CometAggregateBenchmark extends CometBenchmarkBase {
spark.sql(query).noop()
}

benchmark.addCase(s"SQL Parquet - Comet (Scan) ($aggregateFunction)") { _ =>
withSQLConf(CometConf.COMET_ENABLED.key -> "true") {
spark.sql(query).noop()
}
}

benchmark.addCase(s"SQL Parquet - Comet (Scan, Exec) ($aggregateFunction)") { _ =>
benchmark.addCase(s"SQL Parquet - Comet ($aggregateFunction)") { _ =>
withSQLConf(
CometConf.COMET_ENABLED.key -> "true",
CometConf.COMET_EXEC_ENABLED.key -> "true") {
Expand Down
Loading