fix bug with expression virtual column indexes on missing columns for expressions that turn null values into not null values (#15959)

This commit is contained in:
Clint Wylie 2024-02-23 15:07:32 -08:00 committed by GitHub
parent b69f89d9f8
commit 6145c8dd01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 0 deletions

View File

@ -207,6 +207,11 @@ public interface Expr extends Cacheable
final ColumnIndexSupplier delegateIndexSupplier = columnIndexSelector.getIndexSupplier(column);
if (delegateIndexSupplier == null) {
// if the column doesn't exist, check to see if the expression evaluates to a non-null result... if so, we might
// need to make a value matcher anyway
if (eval(InputBindings.nilBindings()).valueOrDefault() != null) {
return NoIndexesColumnIndexSupplier.getInstance();
}
return null;
}
final DictionaryEncodedValueIndex<?> delegateRawIndex = delegateIndexSupplier.as(

View File

@ -152,6 +152,7 @@ public abstract class BaseFilterTest extends InitializedNullHandlingTest
new ExpressionVirtualColumn("vdim3-concat", "dim3 + dim3", ColumnType.LONG, TestExprMacroTable.INSTANCE),
new ExpressionVirtualColumn("vdim2-offset", "array_offset(dim2, 1)", ColumnType.STRING, TestExprMacroTable.INSTANCE),
new ExpressionVirtualColumn("nestedArrayLong", "array(arrayLong)", ColumnType.ofArray(ColumnType.LONG_ARRAY), TestExprMacroTable.INSTANCE),
new ExpressionVirtualColumn("fake-nvl", "nvl(fake, 'hello')", ColumnType.STRING, TestExprMacroTable.INSTANCE),
new ListFilteredVirtualColumn("allow-dim0", DefaultDimensionSpec.of("dim0"), ImmutableSet.of("3", "4"), true),
new ListFilteredVirtualColumn("deny-dim0", DefaultDimensionSpec.of("dim0"), ImmutableSet.of("3", "4"), false),
new ListFilteredVirtualColumn("allow-dim2", DefaultDimensionSpec.of("dim2"), ImmutableSet.of("a"), true),

View File

@ -124,6 +124,7 @@ public class EqualityFilterTests
assertFilterMatches(new EqualityFilter("vdim0", ColumnType.LONG, 1L, null), ImmutableList.of("1"));
}
@Test
public void testListFilteredVirtualColumn()
{
@ -407,6 +408,20 @@ public class EqualityFilterTests
}
}
@Test
public void testSingleValueVirtualStringColumnMissingColumnCoalesce()
{
assertFilterMatches(
new EqualityFilter("fake-nvl", ColumnType.STRING, "0", null),
ImmutableList.of()
);
assertFilterMatches(
new EqualityFilter("fake-nvl", ColumnType.STRING, "hello", null),
ImmutableList.of("0", "1", "2", "3", "4", "5")
);
}
@Test
public void testMultiValueStringColumn()
{