FrankChen021 commented on code in PR #19301:
URL: https://github.com/apache/druid/pull/19301#discussion_r3141459735
##########
processing/src/main/java/org/apache/druid/query/operator/window/value/WindowValueProcessorBase.java:
##########
@@ -108,4 +112,59 @@ public List<String> getOutputColumnNames()
{
return Collections.singletonList(outputColumn);
}
+
+ /**
+ * Computes first or last value for each row respecting the given window
frame. For each row, selects
+ * either the first or last element of the frame. Entries for rows where the
frame is empty are left as null.
+ *
+ * @param first if true, selects the first element of the frame; if false,
selects the last
+ */
+ static void computeFirstOrLastValueFramed(
+ final RowsAndColumns rac,
+ final ColumnAccessor accessor,
+ final WindowFrame frame,
+ final Object[] results,
+ final boolean first
+ )
+ {
+ final int numRows = accessor.numRows();
+ final WindowFrame.Rows rowsFrame = frame.unwrap(WindowFrame.Rows.class);
+ if (rowsFrame != null) {
+ final int lower = rowsFrame.getLowerOffsetClamped(numRows);
+ final int upper = rowsFrame.getUpperOffsetClamped(numRows);
+ for (int i = 0; i < numRows; i++) {
+ final int frameLower = Math.max(0, i + lower);
+ final int frameUpper = Math.min(numRows - 1, i + upper);
+ if (frameLower <= frameUpper) {
+ results[i] = accessor.getObject(first ? frameLower : frameUpper);
+ }
+ }
+ return;
+ }
+
+ final WindowFrame.Groups groupsFrame =
frame.unwrap(WindowFrame.Groups.class);
Review Comment:
[P1] Bounded RANGE frames still execute with GROUPS semantics
The new framed path treats every non-ROWS frame as `WindowFrame.Groups`, and
`Windowing` maps Calcite's `isRows == false` windows into that representation.
That is not correct for bounded SQL RANGE frames, which must use value-distance
on the ORDER BY expression. Queries like `FIRST_VALUE(x) OVER (ORDER BY t RANGE
BETWEEN 1 PRECEDING AND CURRENT ROW)` will still return wrong answers even
though this PR now enables framed FIRST_VALUE/LAST_VALUE.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]