-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport] Fix columns with null values in windowing expressions (#15205
) * Fix columns with null values in windowing expressions (#15131) * Trigger Build --------- Co-authored-by: Zoltan Haindrich <[email protected]>
- Loading branch information
1 parent
bdd4e44
commit 36b7537
Showing
7 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
processing/src/test/java/org/apache/druid/query/rowsandcols/column/ColumnAccessorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.query.rowsandcols.column; | ||
|
||
import org.apache.druid.query.rowsandcols.column.accessor.DoubleColumnAccessorBase; | ||
import org.apache.druid.query.rowsandcols.column.accessor.FloatColumnAccessorBase; | ||
import org.apache.druid.query.rowsandcols.column.accessor.LongColumnAccessorBase; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.runners.Parameterized.Parameters; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(Parameterized.class) | ||
public class ColumnAccessorsTest | ||
{ | ||
private TestAccessorShim testAccessor; | ||
|
||
@Parameters | ||
public static List<Object[]> getParameters() | ||
{ | ||
List<Object[]> ret = new ArrayList<>(); | ||
|
||
for (TestAccessorShim accessor : TestAccessorShim.values()) { | ||
ret.add(new Object[] {accessor}); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
enum TestAccessorShim | ||
{ | ||
LONG { | ||
@Override | ||
ColumnAccessor getColumnAccessor(Object value) | ||
{ | ||
Long val = (Long) value; | ||
return new LongColumnAccessorBase() | ||
{ | ||
@Override | ||
public int numRows() | ||
{ | ||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean isNull(int rowNum) | ||
{ | ||
return val == null; | ||
} | ||
|
||
@Override | ||
public long getLong(int rowNum) | ||
{ | ||
return val; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected Object getSomeValue() | ||
{ | ||
return 42L; | ||
} | ||
|
||
|
||
}, | ||
FLOAT { | ||
@Override | ||
ColumnAccessor getColumnAccessor(Object value) | ||
{ | ||
Float val = (Float) value; | ||
return new FloatColumnAccessorBase() | ||
{ | ||
|
||
@Override | ||
public int numRows() | ||
{ | ||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean isNull(int rowNum) | ||
{ | ||
return val == null; | ||
} | ||
|
||
@Override | ||
public float getFloat(int rowNum) | ||
{ | ||
return val; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected Object getSomeValue() | ||
{ | ||
return 42.1F; | ||
} | ||
}, | ||
DOUBLE { | ||
@Override | ||
ColumnAccessor getColumnAccessor(Object value) | ||
{ | ||
Double val = (Double) value; | ||
return new DoubleColumnAccessorBase() | ||
{ | ||
|
||
@Override | ||
public int numRows() | ||
{ | ||
return 1; | ||
} | ||
|
||
@Override | ||
public boolean isNull(int rowNum) | ||
{ | ||
return val == null; | ||
} | ||
|
||
@Override | ||
public double getDouble(int rowNum) | ||
{ | ||
return val; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
protected Object getSomeValue() | ||
{ | ||
return 42.1D; | ||
} | ||
}; | ||
|
||
abstract ColumnAccessor getColumnAccessor(Object val); | ||
|
||
protected abstract Object getSomeValue(); | ||
} | ||
|
||
public ColumnAccessorsTest(TestAccessorShim accessor) | ||
{ | ||
this.testAccessor = accessor; | ||
} | ||
|
||
@Test | ||
public void testSomeValue() | ||
{ | ||
Object expectedValue = testAccessor.getSomeValue(); | ||
ColumnAccessor acc = testAccessor.getColumnAccessor(expectedValue); | ||
|
||
assertFalse(acc.isNull(0)); | ||
assertEquals(expectedValue, acc.getObject(0)); | ||
} | ||
|
||
@Test | ||
public void testNull() | ||
{ | ||
ColumnAccessor acc = testAccessor.getColumnAccessor(null); | ||
|
||
assertTrue(acc.isNull(0)); | ||
assertEquals(null, acc.getObject(0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
sql/src/test/resources/calcite/tests/window/windowed_long_null.sqlTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type: "operatorValidation" | ||
|
||
sql: | | ||
SELECT | ||
l2, | ||
MIN(l2) OVER(partition by l2) | ||
FROM druid.numfoo | ||
WHERE l2 is null or l2 = -1111 or l2 = 0 | ||
|
||
|
||
expectedOperators: | ||
- type: "naiveSort" | ||
columns: | ||
- column: "l2" | ||
direction: "ASC" | ||
- type: "naivePartition" | ||
partitionColumns: [ "l2" ] | ||
- type: "window" | ||
processor: | ||
type: "framedAgg" | ||
frame: { peerType: "ROWS", lowUnbounded: true, lowOffset: 0, uppUnbounded: true, uppOffset: 0 } | ||
aggregations: | ||
- { type: "longMin", name: "w0", fieldName: "l2" } | ||
|
||
expectedResults: | ||
- [null,null] | ||
- [null,null] | ||
- [null,null] | ||
- [null,null] | ||
- [0,0] |