mirror of https://github.com/apache/druid.git
Fix lead/lag to be usable without offset (#15057)
This commit is contained in:
parent
c888ac5d61
commit
90e4b25620
|
@ -88,9 +88,9 @@ public class Windowing
|
||||||
private static final ImmutableMap<String, ProcessorMaker> KNOWN_WINDOW_FNS = ImmutableMap
|
private static final ImmutableMap<String, ProcessorMaker> KNOWN_WINDOW_FNS = ImmutableMap
|
||||||
.<String, ProcessorMaker>builder()
|
.<String, ProcessorMaker>builder()
|
||||||
.put("LAG", (agg) ->
|
.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) ->
|
.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) ->
|
.put("FIRST_VALUE", (agg) ->
|
||||||
new WindowFirstProcessor(agg.getColumn(0), agg.getOutputName()))
|
new WindowFirstProcessor(agg.getColumn(0), agg.getOutputName()))
|
||||||
.put("LAST_VALUE", (agg) ->
|
.put("LAST_VALUE", (agg) ->
|
||||||
|
|
|
@ -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]
|
Loading…
Reference in New Issue