Skip to content

Conversation

@ttnghia
Copy link
Collaborator

@ttnghia ttnghia commented Oct 13, 2025

This optimizes min_by and max_by aggregations by avoiding data copy and replacing the expensive operations (min/max on structs column) by the much cheaper ones (argmin/argmax on the input ordering column then gather).

@ttnghia ttnghia self-assigned this Oct 13, 2025
Copilot AI review requested due to automatic review settings October 13, 2025 20:05
@ttnghia ttnghia added SQL part of the SQL/Dataframe plugin performance A performance related task/issue improve labels Oct 13, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR reimplements the min_by and max_by aggregation functions by switching from a struct-based approach to using CUDF's argMin and argMax operations. The new implementation is more efficient as it directly finds the index of the minimum/maximum ordering value and then gathers the corresponding value.

Key changes:

  • Replaced struct-based aggregation with argMin/argMax operations
  • Introduced a new GpuGather expression for extracting values by index
  • Simplified the aggregation logic by eliminating complex struct creation and extraction

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
dataExtractors.scala Adds new GpuGather expression for gathering values by indices
aggregateFunctions.scala Reimplements min_by/max_by using argMin/argMax operations instead of struct-based approach

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 2217 to 2227
override lazy val initialValues: Seq[Expression] = Seq(GpuLiteral(null, valueExpr.dataType))

override lazy val initialValues: Seq[Expression] = Seq(
GpuLiteral(null, valueExpr.dataType), GpuLiteral(null, orderingExpr.dataType))
// The ordering column is used as input for reduction/groupby to find the argmin/argmax index.
override lazy val inputProjection: Seq[Expression] = Seq(orderingExpr)
override lazy val updateAggregates: Seq[CudfAggregate] = Seq(cudfArgMinMaxAggregate)

override lazy val inputProjection: Seq[Expression] = Seq(
createStructExpression(orderingExpr, valueExpr))
override lazy val updateAggregates: Seq[CudfAggregate] = Seq(cudfMaxMinByAggregate)
override lazy val postUpdate: Seq[Expression] = extractChildren
// Extract the extremum value from argmin/argmax index.
override lazy val postUpdate: Seq[Expression] =
Seq(GpuGather(bufferValue, cudfArgMinMaxAggregate.attr))

override lazy val preMerge: Seq[Expression] = Seq(
createStructExpression(bufferOrdering, bufferValue))
override lazy val mergeAggregates: Seq[CudfAggregate] = Seq(cudfMaxMinByAggregate)
override lazy val postMerge: Seq[Expression] = extractChildren
override lazy val mergeAggregates: Seq[CudfAggregate] = Seq(cudfArgMinMaxAggregate)
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

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

The GpuGather operation is being called with bufferValue as the values column, but bufferValue is not being populated during the update phase. The initialValues only initializes it with null, and there's no mechanism to collect the actual values that correspond to the ordering column indices.

Copilot uses AI. Check for mistakes.
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
Signed-off-by: Nghia Truong <[email protected]>
@abellina abellina self-requested a review October 31, 2025 20:29
@nvauto
Copy link
Collaborator

nvauto commented Nov 17, 2025

NOTE: release/25.12 has been created from main. Please retarget your PR to release/25.12 if it should be included in the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improve performance A performance related task/issue SQL part of the SQL/Dataframe plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants