LakshSingla commented on code in PR #16885:
URL: https://github.com/apache/druid/pull/16885#discussion_r1719338773


##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -159,7 +144,7 @@ private void validate(final Memory region)
     }
 
     final byte typeCode = region.getByte(0);
-    final byte expectedTypeCode = asArray ? 
FrameColumnWriters.TYPE_STRING_ARRAY : FrameColumnWriters.TYPE_STRING;
+    final byte expectedTypeCode = FrameColumnWriters.TYPE_STRING;

Review Comment:
   nit: Can remove this 



##########
processing/src/test/java/org/apache/druid/query/operator/window/RowsAndColumnsHelper.java:
##########
@@ -280,6 +281,17 @@ public void validate(String msgBase, Column col)
           } else {
             Assert.assertEquals(msg, ((Long) expectedVal).longValue(), 
accessor.getLong(i));
           }
+        } else if (expectedVal instanceof Object[]) {
+          Object actualVal = accessor.getObject(i);
+          if (expectedNulls[i]) {
+            Assert.assertEquals(msg, 0, actualVal);

Review Comment:
   Question: Does this check mean that if the row value is null (in expected), 
then actual val should be 0? 



##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -709,3 +694,87 @@ public void close()
     }
   }
 }
+
+/**
+ * Reader for {@link ColumnType#STRING_ARRAY}.
+ */
+class StringArrayFrameColumnReader extends StringFrameColumnReader
+{
+  StringArrayFrameColumnReader(int columnNumber)
+  {
+    super(columnNumber);
+  }
+
+  @Override
+  public Column readRACColumn(Frame frame)
+  {
+    final Memory memory = frame.region(columnNumber);
+    validate(memory);
+
+    // we expect the memory to be stored as if there are multi values

Review Comment:
   ```suggestion
       // String arrays always store multiple values per row. 
   ```



##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -709,3 +694,87 @@ public void close()
     }
   }
 }
+
+/**
+ * Reader for {@link ColumnType#STRING_ARRAY}.
+ */
+class StringArrayFrameColumnReader extends StringFrameColumnReader

Review Comment:
   Should just create a separate class like its done for other Array readers. 



##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -709,3 +694,87 @@ public void close()
     }
   }
 }
+
+/**
+ * Reader for {@link ColumnType#STRING_ARRAY}.
+ */
+class StringArrayFrameColumnReader extends StringFrameColumnReader
+{
+  StringArrayFrameColumnReader(int columnNumber)
+  {
+    super(columnNumber);
+  }
+
+  @Override
+  public Column readRACColumn(Frame frame)
+  {
+    final Memory memory = frame.region(columnNumber);
+    validate(memory);
+
+    // we expect the memory to be stored as if there are multi values
+    assert isMultiValue(memory);
+    final long positionOfLengths = 
getStartOfStringLengthSection(frame.numRows(), true);
+    final long positionOfPayloads = getStartOfStringDataSection(memory, 
frame.numRows(), true);
+
+    StringFrameColumn frameCol = new StringFrameColumn(
+        frame,
+        true,
+        memory,
+        positionOfLengths,
+        positionOfPayloads,
+        true
+    );
+
+    return new ColumnAccessorBasedColumn(frameCol);
+  }
+
+  @Override
+  public ColumnPlus readColumn(final Frame frame)
+  {
+    final Memory memory = frame.region(columnNumber);
+    validate(memory);
+
+    // we expect the memory to be stored as if there are multi values
+    assert isMultiValue(memory);
+    final long startOfStringLengthSection = 
getStartOfStringLengthSection(frame.numRows(), true);
+    final long startOfStringDataSection = getStartOfStringDataSection(memory, 
frame.numRows(), true);
+
+    final BaseColumn baseColumn = new StringArrayFrameColumn(
+        frame,
+        true,
+        memory,
+        startOfStringLengthSection,
+        startOfStringDataSection
+    );
+
+    return new ColumnPlus(
+        baseColumn,
+        new ColumnCapabilitiesImpl().setType(ColumnType.STRING_ARRAY)
+                                    .setHasMultipleValues(false)
+                                    .setDictionaryEncoded(false)
+                                    .setHasBitmapIndexes(false)
+                                    .setHasSpatialIndexes(false)
+                                    
.setHasNulls(ColumnCapabilities.Capable.UNKNOWN),

Review Comment:
   These should be the defaults, can remove them afaict 



##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -170,7 +155,7 @@ private void validate(final Memory region)
     }
   }
 
-  private static boolean isMultiValue(final Memory memory)
+  static boolean isMultiValue(final Memory memory)

Review Comment:
   Should make this and other methods/variables  protected 
   ```suggestion
     protected static boolean isMultiValue(final Memory memory)
   ```



##########
processing/src/main/java/org/apache/druid/frame/read/columnar/StringFrameColumnReader.java:
##########
@@ -709,3 +694,87 @@ public void close()
     }
   }
 }
+
+/**
+ * Reader for {@link ColumnType#STRING_ARRAY}.
+ */
+class StringArrayFrameColumnReader extends StringFrameColumnReader
+{
+  StringArrayFrameColumnReader(int columnNumber)
+  {
+    super(columnNumber);
+  }
+
+  @Override
+  public Column readRACColumn(Frame frame)
+  {
+    final Memory memory = frame.region(columnNumber);
+    validate(memory);
+
+    // we expect the memory to be stored as if there are multi values
+    assert isMultiValue(memory);
+    final long positionOfLengths = 
getStartOfStringLengthSection(frame.numRows(), true);
+    final long positionOfPayloads = getStartOfStringDataSection(memory, 
frame.numRows(), true);
+
+    StringFrameColumn frameCol = new StringFrameColumn(
+        frame,
+        true,
+        memory,
+        positionOfLengths,
+        positionOfPayloads,
+        true
+    );
+
+    return new ColumnAccessorBasedColumn(frameCol);
+  }
+
+  @Override
+  public ColumnPlus readColumn(final Frame frame)
+  {
+    final Memory memory = frame.region(columnNumber);
+    validate(memory);
+
+    // we expect the memory to be stored as if there are multi values
+    assert isMultiValue(memory);
+    final long startOfStringLengthSection = 
getStartOfStringLengthSection(frame.numRows(), true);
+    final long startOfStringDataSection = getStartOfStringDataSection(memory, 
frame.numRows(), true);
+
+    final BaseColumn baseColumn = new StringArrayFrameColumn(
+        frame,
+        true,
+        memory,
+        startOfStringLengthSection,
+        startOfStringDataSection
+    );
+
+    return new ColumnPlus(
+        baseColumn,
+        new ColumnCapabilitiesImpl().setType(ColumnType.STRING_ARRAY)
+                                    .setHasMultipleValues(false)
+                                    .setDictionaryEncoded(false)
+                                    .setHasBitmapIndexes(false)
+                                    .setHasSpatialIndexes(false)
+                                    
.setHasNulls(ColumnCapabilities.Capable.UNKNOWN),
+        frame.numRows()
+    );
+  }
+
+  private void validate(final Memory region)
+  {
+    // Check if column is big enough for a header
+    if (region.getCapacity() < StringFrameColumnWriter.DATA_OFFSET) {
+      throw DruidException.defensive("Column[%s] is not big enough for a 
header", columnNumber);
+    }
+
+    final byte typeCode = region.getByte(0);
+    final byte expectedTypeCode = FrameColumnWriters.TYPE_STRING_ARRAY;

Review Comment:
   assignment not required



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to