Fix lead/lag to be usable without offset (#15057)

This commit is contained in:
Zoltan Haindrich 2023-10-04 14:08:46 +02:00 committed by GitHub
parent c888ac5d61
commit 90e4b25620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View File

@ -88,9 +88,9 @@ public class Windowing
private static final ImmutableMap<String, ProcessorMaker> KNOWN_WINDOW_FNS = ImmutableMap
.<String, ProcessorMaker>builder()
.put("LAG", (agg) ->
new WindowOffsetProcessor(agg.getColumn(0), agg.getOutputName(), -agg.getConstantInt(1)))
new WindowOffsetProcessor(agg.getColumn(0), agg.getOutputName(), -agg.getConstantInt(1, 1)))
.put("LEAD", (agg) ->
new WindowOffsetProcessor(agg.getColumn(0), agg.getOutputName(), agg.getConstantInt(1)))
new WindowOffsetProcessor(agg.getColumn(0), agg.getOutputName(), agg.getConstantInt(1, 1)))
.put("FIRST_VALUE", (agg) ->
new WindowFirstProcessor(agg.getColumn(0), agg.getOutputName()))
.put("LAST_VALUE", (agg) ->

View File

@ -0,0 +1,50 @@
type: "operatorValidation"
sql: |
SELECT
dim1,
LAG(dim1,2) OVER (),
LAG(dim1) OVER (),
LAG(dim1,0) OVER (),
LEAD(dim1,0) OVER (),
LEAD(dim1) OVER (),
LEAD(dim1,2) OVER ()
FROM foo
WHERE length(dim1) > 1
GROUP BY dim1
expectedOperators:
- type: "naivePartition"
partitionColumns: []
- type: "window"
processor:
type: "composing"
processors:
- type: "offset"
inputColumn: "d0"
outputColumn: "w0"
offset: -2
- type: "offset"
inputColumn: "d0"
outputColumn: "w1"
offset: -1
- type: "offset"
inputColumn: "d0"
outputColumn: "w2"
offset: 0
- type: "offset"
inputColumn: "d0"
outputColumn: "w3"
offset: 0
- type: "offset"
inputColumn: "d0"
outputColumn: "w4"
offset: 1
- type: "offset"
inputColumn: "d0"
outputColumn: "w5"
offset: 2
expectedResults:
- ["10.1",null,null,"10.1","10.1","abc","def"]
- ["abc",null,"10.1","abc","abc","def",null]
- ["def","10.1","abc","def","def",null,null]