Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VirtualColumn related issues in window expressions #15119

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
bd55afd
fixes
kgyrtkirk Oct 4, 2023
5cf1e2c
check for latest rewrite place
kgyrtkirk Oct 4, 2023
c4ff274
Revert "check for latest rewrite place"
kgyrtkirk Oct 4, 2023
89844e9
some stuff
kgyrtkirk Oct 4, 2023
ed5d100
update test output
kgyrtkirk Oct 4, 2023
2a4a3ab
updates to test ouptuts
kgyrtkirk Oct 4, 2023
02aac9d
some stuff
kgyrtkirk Oct 4, 2023
a9877c4
move validator
kgyrtkirk Oct 4, 2023
f104ce4
cleanup
kgyrtkirk Oct 4, 2023
145fe82
fix
kgyrtkirk Oct 4, 2023
761cd68
change test slightly
kgyrtkirk Oct 4, 2023
a10fe7a
add apidoc cleanup warnings
kgyrtkirk Oct 4, 2023
6082df5
cleanup/etc
kgyrtkirk Oct 4, 2023
34a6aeb
instead of telling the story; add a fail with some reason whats the i…
kgyrtkirk Oct 4, 2023
9b74ef5
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 4, 2023
e376ae9
lead-lag fix
kgyrtkirk Oct 4, 2023
1acd53b
add test
kgyrtkirk Oct 5, 2023
a708ef2
remove unnecessary throw
kgyrtkirk Oct 5, 2023
8fa0664
druidexception-trial
kgyrtkirk Oct 5, 2023
b484606
Revert "druidexception-trial"
kgyrtkirk Oct 5, 2023
2858ff6
undo changes to no_grouping; add no_grouping2
kgyrtkirk Oct 5, 2023
2e91d7c
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 6, 2023
9a80c89
add missing assert on resultcount
kgyrtkirk Oct 6, 2023
ee2b35d
rename method; update
kgyrtkirk Oct 9, 2023
4e216b7
introduce enum/etc
kgyrtkirk Oct 9, 2023
5d0fcc0
make resultmatchmode accessible from TestBuilder#expectedResults
kgyrtkirk Oct 9, 2023
0ddd3be
fix dump results to use log
kgyrtkirk Oct 9, 2023
4073f5e
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 10, 2023
47e81d8
Merge remote-tracking branch 'apache/master' into windowing-fix-test-cmp
kgyrtkirk Oct 10, 2023
edea152
fix
kgyrtkirk Oct 10, 2023
de099c6
handle null correctly
kgyrtkirk Oct 10, 2023
5834150
fix virtualcolumnregistry
kgyrtkirk Oct 10, 2023
6e80c83
accept changes from NPE to AGGREGATION_NOT_SUPPORT_TYPE
kgyrtkirk Oct 10, 2023
08d21d0
better match
kgyrtkirk Oct 10, 2023
8b52be7
indent
kgyrtkirk Oct 10, 2023
0369976
try nullx
kgyrtkirk Oct 10, 2023
8b50923
Revert "try nullx"
kgyrtkirk Oct 10, 2023
a4cb14a
fixes/test/etc
kgyrtkirk Oct 10, 2023
1fecd63
undo test changes
kgyrtkirk Oct 10, 2023
8ad2bb9
fix test to have filter
kgyrtkirk Oct 10, 2023
f396de8
update 1 more test
kgyrtkirk Oct 10, 2023
e018b2c
disable feature type based things for MSQ
kgyrtkirk Oct 10, 2023
a74a9fd
fix varianssqlaggtest
kgyrtkirk Oct 10, 2023
185b8e7
use eps in other test
kgyrtkirk Oct 10, 2023
ed1bb89
fix intellij error
kgyrtkirk Oct 10, 2023
91b1be9
add final
kgyrtkirk Oct 11, 2023
df73774
addrss review
kgyrtkirk Oct 11, 2023
7714e2f
update test/string/etc
kgyrtkirk Oct 11, 2023
78d1d31
write concat in 3 lines :D
kgyrtkirk Oct 11, 2023
1f372c3
Merge branch 'windowing-fix-test-cmp' into windowing-fixes-string-min…
kgyrtkirk Oct 11, 2023
3c6934b
Merge remote-tracking branch 'apache/master' into windowing-fixes-str…
kgyrtkirk Oct 11, 2023
35b981d
update sqlTest
kgyrtkirk Oct 11, 2023
a69ecd9
dont create VCR
kgyrtkirk Oct 12, 2023
7c4551b
plannerconfig validate
kgyrtkirk Oct 12, 2023
8937300
Revert "plannerconfig validate"
kgyrtkirk Oct 12, 2023
a79600f
dont swallow exception backtrace
kgyrtkirk Oct 12, 2023
56be2b6
reuse test stuff
kgyrtkirk Oct 12, 2023
7c65c85
Revert "reuse test stuff"
kgyrtkirk Oct 12, 2023
5a15264
Merge commit 'a0fd9ec55c' into windowing-fixes-string-min-max
kgyrtkirk Oct 12, 2023
8a0c3c7
Merge remote-tracking branch 'apache/master' into windowing-fixes-str…
kgyrtkirk Oct 12, 2023
b800180
add exception
kgyrtkirk Oct 13, 2023
4431b7a
move construction phase into separate method
kgyrtkirk Oct 13, 2023
f7f75c7
uncommitted state
kgyrtkirk Oct 16, 2023
f64a615
one fix
kgyrtkirk Oct 16, 2023
41fca50
checkstyle
kgyrtkirk Oct 16, 2023
d51f8f1
cleanup/etc
kgyrtkirk Oct 16, 2023
7d8e568
put back
kgyrtkirk Oct 16, 2023
9904ce9
wat/abc test
kgyrtkirk Oct 16, 2023
6e8731a
Revert "wat/abc test"
kgyrtkirk Oct 16, 2023
b2ac570
weed out prev sol
kgyrtkirk Oct 16, 2023
b0a3e1a
add comment
kgyrtkirk Oct 16, 2023
adeaf59
mark some calls unsupported
kgyrtkirk Oct 16, 2023
35ab748
put them back :facepalm:
kgyrtkirk Oct 16, 2023
24bcd03
zip the two stuff
kgyrtkirk Oct 16, 2023
91077be
blocked by non-existent type; columnselectyorfactorymaker#fromRAC / etc
kgyrtkirk Oct 16, 2023
16fac3e
Revert "blocked by non-existent type; columnselectyorfactorymaker#fro…
kgyrtkirk Oct 16, 2023
77eeb60
ensure no invalid use
kgyrtkirk Oct 16, 2023
4f53973
Merge remote-tracking branch 'apache/master' into windowing-fixes-str…
kgyrtkirk Oct 16, 2023
21ff7f5
checkstyle
kgyrtkirk Oct 16, 2023
15bf039
add Windowing level fix
kgyrtkirk Oct 17, 2023
4d83905
purge out virtualColumns param
kgyrtkirk Oct 17, 2023
a218b3c
working
kgyrtkirk Oct 17, 2023
9bf2c37
cleanup/etc
kgyrtkirk Oct 17, 2023
b034474
cleanup
kgyrtkirk Oct 17, 2023
e1f7ef5
checkstyle fixes
kgyrtkirk Oct 17, 2023
87c6063
remove VCR arg
kgyrtkirk Oct 17, 2023
43df657
add assert
kgyrtkirk Oct 17, 2023
0918a4f
undo+cleanup
kgyrtkirk Oct 18, 2023
462eec6
put back assert; cleanup
kgyrtkirk Oct 18, 2023
854527e
undo enable test
kgyrtkirk Oct 18, 2023
f364c9d
.
kgyrtkirk Oct 18, 2023
d4a077c
update to be at same point as w-f1 branch
kgyrtkirk Oct 19, 2023
73ba4e9
add to opfactory; fix test
kgyrtkirk Oct 19, 2023
6bcb70b
cleanup
kgyrtkirk Oct 19, 2023
da99a8a
cleanup
kgyrtkirk Oct 19, 2023
22bf6da
add test
kgyrtkirk Oct 19, 2023
30d2047
tests
kgyrtkirk Oct 19, 2023
bb033c4
test/etc
kgyrtkirk Oct 19, 2023
216a56d
updates
kgyrtkirk Oct 19, 2023
4d3200f
test/etc
kgyrtkirk Oct 19, 2023
9343248
updates
kgyrtkirk Oct 19, 2023
c66cf33
cleanup; checkstyle
kgyrtkirk Oct 19, 2023
e2203ff
cleanup/etc
kgyrtkirk Oct 20, 2023
ce919f4
checkstyle
kgyrtkirk Oct 20, 2023
b76019c
intellij style
kgyrtkirk Oct 20, 2023
88ee20c
fix test constructor
kgyrtkirk Oct 20, 2023
0919611
review#1
kgyrtkirk Oct 20, 2023
af3424c
remove exception/etc
kgyrtkirk Oct 20, 2023
462796e
Revert "Revert "Revert "Revert "undo build""""
kgyrtkirk Oct 20, 2023
d156022
Revert "Revert "Revert "undo build"""
kgyrtkirk Oct 19, 2023
18f9a38
move/etc
kgyrtkirk Oct 20, 2023
8b7b89c
undo; leave asis
kgyrtkirk Oct 20, 2023
575b153
stuff
kgyrtkirk Oct 20, 2023
11fd787
fix test
kgyrtkirk Oct 20, 2023
247931b
return null instead of default
kgyrtkirk Oct 20, 2023
abe5c06
remove unnecessary stuff; the frame may still contain nulls; regardle…
kgyrtkirk Oct 20, 2023
5257d4a
Merge remote-tracking branch 'apache/master' into windowing-fixes-str…
kgyrtkirk Oct 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.apache.druid.frame.write.columnar;

import org.apache.druid.common.config.NullHandling;
import org.apache.druid.frame.allocation.MemoryAllocator;
import org.apache.druid.frame.write.UnsupportedColumnTypeException;
import org.apache.druid.java.util.common.ISE;
Expand Down Expand Up @@ -167,9 +166,7 @@ private static ComplexFrameColumnWriter makeComplexWriter(

private static boolean hasNullsForNumericWriter(final ColumnCapabilities capabilities)
{
if (NullHandling.replaceWithDefault()) {
return false;
} else if (capabilities == null) {
if (capabilities == null) {
return true;
} else if (capabilities.getType().isNumeric()) {
return capabilities.hasNulls().isMaybeTrue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public Collection<String> getColumnNames()
return viewableColumns == null ? base.getColumnNames() : viewableColumns;
}

public RowsAndColumns getBase()
{
return base;
}

@Override
public int numRows()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,18 @@ public void inspectRuntimeShape(RuntimeShapeInspector inspector)
public ColumnValueSelector makeColumnValueSelector(@Nonnull String columnName)
{
return withColumnAccessor(columnName, columnAccessor -> {
final ColumnType type = columnAccessor.getType();
switch (type.getType()) {
case STRING:
return new StringColumnValueSelector(columnAccessor);
case COMPLEX:
return new ComplexColumnValueSelector(columnAccessor);
default:
return new PassThroughColumnValueSelector(columnAccessor);
if (columnAccessor == null) {
return DimensionSelector.nilSelector();
} else {
final ColumnType type = columnAccessor.getType();
switch (type.getType()) {
case STRING:
return new StringColumnValueSelector(columnAccessor);
case COMPLEX:
return new ComplexColumnValueSelector(columnAccessor);
default:
return new PassThroughColumnValueSelector(columnAccessor);
}
}
});
}
Expand All @@ -156,23 +160,26 @@ public ColumnValueSelector makeColumnValueSelector(@Nonnull String columnName)
@Override
public ColumnCapabilities getColumnCapabilities(String column)
{
return withColumnAccessor(column, columnAccessor ->
new ColumnCapabilitiesImpl()
return withColumnAccessor(column, columnAccessor -> {
if (columnAccessor == null) {
return null;
} else {
return new ColumnCapabilitiesImpl()
.setType(columnAccessor.getType())
.setHasMultipleValues(false)
.setDictionaryEncoded(false)
.setHasBitmapIndexes(false));
.setHasBitmapIndexes(false);
}
});
}

private <T> T withColumnAccessor(String column, Function<ColumnAccessor, T> fn)
{
@Nullable
ColumnAccessor retVal = accessorCache.get(column);
if (retVal == null) {
Column racColumn = rac.findColumn(column);
if (racColumn == null) {
throw DruidException.defensive("Column[%s] not found!", column);
}
retVal = racColumn.toAccessor();
retVal = racColumn == null ? null : racColumn.toAccessor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this code has made me realize that we need to do a containsKey() check in order to actually take advantage of the cache. I.e. if we cache that it was null, we are going to keep asking and overwriting the cache for that column because we are checking the result of .get() instead of .containsKey().

I'm leaving this comment so that we have a shared understanding, not because I'm asking it to be adjusted in this PR.

accessorCache.put(column, retVal);
}
return fn.apply(retVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@
import org.apache.druid.query.rowsandcols.LazilyDecoratedRowsAndColumns;
import org.apache.druid.query.rowsandcols.MapOfColumnsRowsAndColumns;
import org.apache.druid.query.rowsandcols.RowsAndColumnsTestBase;
import java.lang.reflect.Field;
import java.util.function.Function;

import static org.junit.Assert.assertTrue;

public class FrameRowsAndColumnsTest extends RowsAndColumnsTestBase
{

public FrameRowsAndColumnsTest(Class<?> expectedClass)
public FrameRowsAndColumnsTest()
{
super(expectedClass);
super(FrameRowsAndColumns.class);
}

public static Function<MapOfColumnsRowsAndColumns, FrameRowsAndColumns> MAKER = input -> {
Expand All @@ -46,15 +42,6 @@ private static FrameRowsAndColumns buildFrame(MapOfColumnsRowsAndColumns input)

rac.numRows(); // materialize

try {
Field baseField = rac.getClass().getDeclaredField("base");
baseField.setAccessible(true);
Object o = baseField.get(rac);
assertTrue(o instanceof FrameRowsAndColumns);
return (FrameRowsAndColumns) o;
}
catch (Exception e) {
throw new RuntimeException(e);
}
return (FrameRowsAndColumns) rac.getBase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
package org.apache.druid.query.rowsandcols.semantic;

import com.google.common.collect.ImmutableMap;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.DruidExceptionMatcher;
import org.apache.druid.query.aggregation.AggregatorFactory;
import org.apache.druid.query.aggregation.LongSumAggregatorFactory;
import org.apache.druid.query.operator.ColumnWithDirection;
Expand All @@ -33,6 +31,7 @@
import org.apache.druid.query.rowsandcols.column.IntArrayColumn;
import org.apache.druid.query.rowsandcols.column.ObjectArrayColumn;
import org.apache.druid.segment.ColumnSelectorFactory;
import org.apache.druid.segment.DimensionSelector;
import org.apache.druid.segment.column.ColumnType;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -44,8 +43,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
* Place where tests can live that are testing the interactions of multiple semantic interfaces
Expand All @@ -62,15 +61,27 @@ public CombinedSemanticInterfacesTest(
}

@Test
public void testColumnSelectorFactoryNonExistentColumn()
public void testColumnSelectorFactoryMakeColumnValueSelectorNonExistentColumn()
{
RowsAndColumns rac = make(MapOfColumnsRowsAndColumns.fromMap(
ImmutableMap.of(
"some", new IntArrayColumn(new int[] {3, 54, 21, 1, 5, 54, 2, 3, 92}))));
AtomicInteger currRow = new AtomicInteger();
ColumnSelectorFactory csfm = ColumnSelectorFactoryMaker.fromRAC(rac).make(currRow);
DruidException e = assertThrows(DruidException.class, () -> csfm.makeColumnValueSelector("nonexistent"));
assertThat(e, DruidExceptionMatcher.defensive().expectMessageIs("Column[nonexistent] not found!"));

assertEquals(DimensionSelector.nilSelector(), csfm.makeColumnValueSelector("nonexistent"));
}

@Test
public void testColumnSelectorFactoryGetColumnCapabilitiesNonExistentColumn()
{
RowsAndColumns rac = make(MapOfColumnsRowsAndColumns.fromMap(
ImmutableMap.of(
"some", new IntArrayColumn(new int[] {3, 54, 21, 1, 5, 54, 2, 3, 92}))));
AtomicInteger currRow = new AtomicInteger();
ColumnSelectorFactory csfm = ColumnSelectorFactoryMaker.fromRAC(rac).make(currRow);

assertNull(csfm.getColumnCapabilities("nonexistent"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,9 @@ private WindowOperatorQuery toWindowQuery()
VirtualColumns virtualColumns = virtualColumnRegistry.build(Collections.emptySet());
final List<OperatorFactory> operators;

if (!virtualColumns.isEmpty()) {
if (virtualColumns.isEmpty()) {
operators = windowing.getOperators();
} else {
operators = ImmutableList.<OperatorFactory>builder()
.add(new ScanOperatorFactory(
null,
Expand All @@ -1460,8 +1462,6 @@ private WindowOperatorQuery toWindowQuery()
null))
.addAll(windowing.getOperators())
.build();
} else {
operators = windowing.getOperators();
}
return new WindowOperatorQuery(
dataSource,
Expand Down