You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@auron.apache.org by "weiqingy (via GitHub)" <gi...@apache.org> on 2026/06/12 06:44:00 UTC

Re: [PR] [AURON #2177] Implement native support for lag window function [auron]

weiqingy commented on code in PR #2199:
URL: https://github.com/apache/auron/pull/2199#discussion_r3401253385


##########
native-engine/datafusion-ext-plans/src/window_exec.rs:
##########
@@ -209,53 +210,38 @@ fn execute_window(
     Ok(exec_ctx
         .clone()
         .output_with_sender("Window", |sender| async move {
-            sender.exclude_time(exec_ctx.baseline_metrics().elapsed_compute());
+            let elapsed_compute = exec_ctx.baseline_metrics().elapsed_compute().clone();
+            sender.exclude_time(&elapsed_compute);
 
             let mut processors = window_ctx
                 .window_exprs
                 .iter()
                 .map(|expr: &WindowExpr| expr.create_processor(&window_ctx))
                 .collect::<Result<Vec<_>>>()?;
 
-            while let Some(mut batch) = input.next().await.transpose()? {
-                let _timer = exec_ctx.baseline_metrics().elapsed_compute().timer();
-                let mut window_cols: Vec<ArrayRef> = processors
-                    .iter_mut()
-                    .map(|processor| processor.process_batch(&window_ctx, &batch))
-                    .collect::<Result<_>>()?;
-
-                if let Some(group_limit) = window_ctx.group_limit {
-                    assert_eq!(window_cols.len(), 1);
-                    let limited = arrow::compute::kernels::cmp::lt_eq(
-                        &window_cols[0],
-                        &Int32Array::new_scalar(group_limit as i32),
-                    )?;
-                    window_cols[0] = arrow::compute::filter(&window_cols[0], &limited)?;
-                    batch = arrow::compute::filter_record_batch(&batch, &limited)?;
+            if window_ctx.requires_full_partition() {

Review Comment:
   This full-partition staging path already exists on master — `requires_full_partition()`, `process_window_batch()`, and the `concat_batches` staging were added when Lead merged, so this part of the diff largely duplicates what's there and will conflict on rebase (the `requires_full_partition()` helpers on `WindowExpr`/`WindowContext` are already defined too). Could you rebase onto current master? The real delta should shrink a lot. It also means the memory/streaming questions on the existing threads can lean on the precedent the merged Lead path already set — full-partition buffering is now the established approach for offset functions, rather than something this PR has to settle.



##########
native-engine/auron-planner/proto/auron.proto:
##########
@@ -129,6 +129,7 @@ enum WindowFunction {
   ROW_NUMBER = 0;
   RANK = 1;
   DENSE_RANK = 2;
+  LAG = 3;

Review Comment:
   `LAG = 3` collides with `LEAD = 3`, which is already on master. Two values sharing the same ordinal in one enum won't compile without `allow_alias`, so on rebase this needs a fresh number (8 is the next free one). Flagging because a textual merge can hide it — the conflict is on the comment/whitespace, not the `= 3`, so it can resolve cleanly and still break the build. (If lag ends up reusing the `LEAD` path per the other comment, this enum entry goes away entirely.)



##########
spark-extension/src/main/scala/org/apache/spark/sql/execution/auron/plan/NativeWindowBase.scala:
##########
@@ -118,6 +124,17 @@ abstract class NativeWindowBase(
             windowExprBuilder.setFuncType(pb.WindowFunctionType.Window)
             windowExprBuilder.setWindowFunc(pb.WindowFunction.DENSE_RANK)
 
+          case e: Lag =>
+            assert(
+              spec.frameSpecification == e.frame,
+              s"window frame not supported: ${spec.frameSpecification}")
+            assert(!lagIgnoreNulls(e), "window function not supported: lag with IGNORE NULLS")
+            windowExprBuilder.setFuncType(pb.WindowFunctionType.Window)
+            windowExprBuilder.setWindowFunc(pb.WindowFunction.LAG)
+            windowExprBuilder.addChildren(NativeConverters.convertExpr(e.input))
+            windowExprBuilder.addChildren(NativeConverters.convertExpr(e.inputOffset))

Review Comment:
   Since this opened in April, native `lead(...)` landed on master — the mirror offset function — and with it `lag` may not need a parallel native path at all. `lag_processor.rs` here is nearly identical to the merged `lead_processor.rs`; the only real difference is `target_idx = row_idx - offset` instead of `+ offset`. Spark models the two as the same thing: `Lag` and `Lead` both extend `FrameLessOffsetWindowFunction`, and `Lag` carries both an `inputOffset()` and a separate derived `offset()` that negates it. The merged Lead case feeds `e.offset` into `WindowFunction.LEAD` → `LeadProcessor` (`row_idx + offset`). So a `Lag` case passing `e.offset` (rather than `e.inputOffset` as here) and mapping to `WindowFunction.LEAD` would reuse `LeadProcessor` and produce correct lag — with no new proto value, planner arm, or processor. Did you consider folding lag into the Lead path? If you'd rather keep them separate (anticipated divergence, readability), that's fair — worth capturi
 ng the rationale, since otherwise it's two copies of the same logic to maintain. Same goes for `lagIgnoreNulls` just above, which duplicates the existing `leadIgnoreNulls` / `invokeNoArg[Boolean]` helper.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@auron.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org