Skip to content

Commit

Permalink
Prevent joining on nested arrays and complex types (#16349)
Browse files Browse the repository at this point in the history
 #16068 modified DimensionHandlerUtils to accept complex types to be dimensions. This had an unintended side effect of allowing complex types to be joined upon (which wasn't guarded explicitly, it doesn't work).
This PR modifies the IndexedTable to reject building the index on the complex types to prevent joining on complex types. The PR adds back the check in the same place, explicitly.
  • Loading branch information
LakshSingla committed Apr 30, 2024
1 parent fb63520 commit 26d63e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import org.apache.druid.error.InvalidInput;
import org.apache.druid.java.util.common.ISE;
import org.apache.druid.segment.DimensionHandlerUtils;
import org.apache.druid.segment.column.ColumnType;
Expand Down Expand Up @@ -62,6 +63,11 @@ public RowBasedIndexBuilder(ColumnType keyType)
{
this.keyType = keyType;

// Cannot build index on complex types, and non-primitive arrays
if (keyType.is(ValueType.COMPLEX) || keyType.isArray() && !keyType.isPrimitiveArray()) {
throw InvalidInput.exception("Cannot join when the join condition has column of type [%s]", keyType);
}

if (keyType.is(ValueType.LONG)) {
// We're specializing the type even though we don't specialize usage in this class, for two reasons:
// (1) It's still useful to reduce overall memory footprint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.druid.data.input.impl.LongDimensionSchema;
import org.apache.druid.data.input.impl.StringDimensionSchema;
import org.apache.druid.data.input.impl.TimestampSpec;
import org.apache.druid.error.DruidException;
import org.apache.druid.error.DruidExceptionMatcher;
import org.apache.druid.guice.DruidInjectorBuilder;
import org.apache.druid.guice.NestedDataModule;
Expand Down Expand Up @@ -80,6 +81,7 @@
import org.apache.druid.timeline.partition.LinearShardSpec;
import org.hamcrest.CoreMatchers;
import org.junit.internal.matchers.ThrowableMessageMatcher;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand Down Expand Up @@ -5404,6 +5406,19 @@ public void testGroupByRootSingleTypeStringMixed1SparseNotNull()
);
}

@Test
public void testJoinOnNestedColumnThrows()
{
DruidException e = Assertions.assertThrows(DruidException.class, () -> {
testQuery(
"SELECT * FROM druid.nested a INNER JOIN druid.nested b ON a.nester = b.nester",
ImmutableList.of(),
ImmutableList.of()
);
});
Assertions.assertEquals("Cannot join when the join condition has column of type [COMPLEX<json>]", e.getMessage());
}

@Test
public void testScanStringNotNullCast()
{
Expand Down

0 comments on commit 26d63e7

Please sign in to comment.