From 5426936c4fd92e0887e3fb432c34ddfbad452d36 Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Mon, 9 Sep 2024 17:32:55 +0800 Subject: [PATCH 1/2] fix window function lag typo error --- .../org/apache/gluten/expression/WindowFunctionsBuilder.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluten-substrait/src/main/scala/org/apache/gluten/expression/WindowFunctionsBuilder.scala b/gluten-substrait/src/main/scala/org/apache/gluten/expression/WindowFunctionsBuilder.scala index 831e3199733d..c1c3051f7fb7 100644 --- a/gluten-substrait/src/main/scala/org/apache/gluten/expression/WindowFunctionsBuilder.scala +++ b/gluten-substrait/src/main/scala/org/apache/gluten/expression/WindowFunctionsBuilder.scala @@ -31,7 +31,7 @@ object WindowFunctionsBuilder { val substraitFunc = windowFunc match { // Handle lag with negative inputOffset, e.g., converts lag(c1, -1) to lead(c1, 1). // Spark uses `-inputOffset` as `offset` for Lag function. - case lag: Lag if lag.offset.eval(EmptyRow).asInstanceOf[Int] > 0 => + case lag: Lag if lag.offset.eval(EmptyRow).asInstanceOf[Int] < 0 => Some(LEAD) // Handle lead with negative offset, e.g., converts lead(c1, -1) to lag(c1, 1). case lead: Lead if lead.offset.eval(EmptyRow).asInstanceOf[Int] < 0 => From 171b7a420e45baa6ff4709482eaaa3946f8e2f7a Mon Sep 17 00:00:00 2001 From: zhaokuo Date: Mon, 9 Sep 2024 20:04:37 +0800 Subject: [PATCH 2/2] add ut --- .../execution/WindowFunctionsValidateSuite.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/backends-velox/src/test/scala/org/apache/gluten/execution/WindowFunctionsValidateSuite.scala b/backends-velox/src/test/scala/org/apache/gluten/execution/WindowFunctionsValidateSuite.scala index 04d0d2c56b94..b0f38c74fe0b 100644 --- a/backends-velox/src/test/scala/org/apache/gluten/execution/WindowFunctionsValidateSuite.scala +++ b/backends-velox/src/test/scala/org/apache/gluten/execution/WindowFunctionsValidateSuite.scala @@ -19,6 +19,18 @@ package org.apache.gluten.execution class WindowFunctionsValidateSuite extends FunctionsValidateSuite { test("lag/lead window function with negative input offset") { + runQueryAndCompare( + "select l_suppkey,lag(l_orderkey, -2) over" + + " (partition by l_suppkey order by l_orderkey) from lineitem") { + checkGlutenOperatorMatch[WindowExecTransformer] + } + + runQueryAndCompare( + "select l_suppkey, lead(l_orderkey, -2) over" + + " (partition by l_suppkey order by l_orderkey) from lineitem") { + checkGlutenOperatorMatch[WindowExecTransformer] + } + runQueryAndCompare( "select lag(l_orderkey, -2) over" + " (partition by l_suppkey order by l_orderkey) from lineitem") { @@ -26,7 +38,7 @@ class WindowFunctionsValidateSuite extends FunctionsValidateSuite { } runQueryAndCompare( - "select lead(l_orderkey, -2) over" + + "select lag(l_orderkey, 2) over" + " (partition by l_suppkey order by l_orderkey) from lineitem") { checkGlutenOperatorMatch[WindowExecTransformer] }