diff --git a/velox/experimental/cudf/exec/ToCudf.cpp b/velox/experimental/cudf/exec/ToCudf.cpp index 5abebaf62a81..879fb8287034 100644 --- a/velox/experimental/cudf/exec/ToCudf.cpp +++ b/velox/experimental/cudf/exec/ToCudf.cpp @@ -133,6 +133,10 @@ bool CompileState::compile(bool allowCpuFallback) { // Check projects separately. if (projectPlanNode) { + if (projectPlanNode->sources()[0]->outputType()->size() == 0 || + projectPlanNode->outputType()->size() == 0) { + return false; + } if (!canBeEvaluatedByCudf( projectPlanNode->projections(), ctx->task->queryCtx().get())) { return false; @@ -155,6 +159,12 @@ bool CompileState::compile(bool allowCpuFallback) { return false; } + if (aggregationPlanNode->sources()[0]->outputType()->size() == 0) { + // We cannot hande RowVectors with a length but no data. + // This is the case with count(*) global (without groupby) + return false; + } + // Use the centralized canBeEvaluatedByCudf function which includes // expression expansion return canBeEvaluatedByCudf( diff --git a/velox/experimental/cudf/tests/AggregationTest.cpp b/velox/experimental/cudf/tests/AggregationTest.cpp index 4a5af4211d86..729646f6126b 100644 --- a/velox/experimental/cudf/tests/AggregationTest.cpp +++ b/velox/experimental/cudf/tests/AggregationTest.cpp @@ -422,6 +422,22 @@ TEST_F(AggregationTest, avgPartialFinalGlobal) { assertQuery(op, "SELECT avg(c1), avg(c2), avg(c4), avg(c5) FROM tmp"); } +TEST_F(AggregationTest, countStarGlobal) { + auto vectors = makeVectors(rowType_, 10, 100); + + createDuckDbTable(vectors); + + auto op = PlanBuilder() + .values(vectors) + .filter("c0 > 10") + .project({}) + .partialAggregation({}, {"count(*)"}) + .finalAggregation() + .planNode(); + + assertQuery(op, "SELECT count(*) FROM tmp WHERE c0 > 10"); +} + TEST_F(AggregationTest, countSingleGroupBy) { auto vectors = makeVectors(rowType_, 10, 100); createDuckDbTable(vectors);