This is an automated email from the ASF dual-hosted git repository.

karan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 26d63e7b65b Prevent joining on nested arrays and complex types (#16349)
26d63e7b65b is described below

commit 26d63e7b65b164746a634517fe4fa16263fbd8c8
Author: Laksh Singla <[email protected]>
AuthorDate: Tue Apr 30 11:36:53 2024 +0530

    Prevent joining on nested arrays and complex types (#16349)
    
     #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.
---
 .../druid/segment/join/table/RowBasedIndexBuilder.java    |  6 ++++++
 .../druid/sql/calcite/CalciteNestedDataQueryTest.java     | 15 +++++++++++++++
 2 files changed, 21 insertions(+)

diff --git 
a/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexBuilder.java
 
b/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexBuilder.java
index 5574f607e83..732039befc4 100644
--- 
a/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexBuilder.java
+++ 
b/processing/src/main/java/org/apache/druid/segment/join/table/RowBasedIndexBuilder.java
@@ -26,6 +26,7 @@ import it.unimi.dsi.fastutil.ints.IntSortedSet;
 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;
@@ -62,6 +63,11 @@ public class RowBasedIndexBuilder
   {
     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.
diff --git 
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java
 
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java
index e93a602296d..eda86289d29 100644
--- 
a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java
+++ 
b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java
@@ -32,6 +32,7 @@ import org.apache.druid.data.input.impl.DimensionsSpec;
 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;
@@ -80,6 +81,7 @@ import org.apache.druid.timeline.DataSegment;
 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;
@@ -5404,6 +5406,19 @@ public class CalciteNestedDataQueryTest extends 
BaseCalciteQueryTest
     );
   }
 
+  @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()
   {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to