adityavaish commented on code in PR #7830:
URL: https://github.com/apache/datafusion-comet/pull/7830#discussion_r4778656841


##########
spark/src/main/java/org/apache/comet/vector/CometPlainVector.java:
##########
@@ -170,20 +187,23 @@ public byte[] getBinary(int rowId) {
     if (isNullAt(rowId)) return null;
     long offset;
     int length;
-    if (offsetBufferAddress != -1) {
-      if (isLargeVarWidth) {
+    switch (vectorKind) {
+      case VARIABLE_WIDTH:
+        int intOffset = Platform.getInt(null, offsetBufferAddress + rowId * 
4L);
+        offset = intOffset;
+        length = Platform.getInt(null, offsetBufferAddress + (rowId + 1L) * 
4L) - intOffset;
+        break;
+      case LARGE_VARIABLE_WIDTH:
         offset = Platform.getLong(null, offsetBufferAddress + rowId * 8L);
         length = (int) (Platform.getLong(null, offsetBufferAddress + (rowId + 
1L) * 8L) - offset);
-      } else {
-        offset = Platform.getInt(null, offsetBufferAddress + rowId * 4L);
-        length = Platform.getInt(null, offsetBufferAddress + (rowId + 1L) * 
4L) - (int) offset;
-      }
-    } else if (valueVector instanceof BaseFixedWidthVector) {
-      BaseFixedWidthVector fixedWidthVector = (BaseFixedWidthVector) 
valueVector;
-      length = fixedWidthVector.getTypeWidth();
-      offset = rowId * length;
-    } else {
-      throw new IllegalStateException("Unsupported binary vector type: " + 
valueVector.getName());
+        break;
+      case FIXED_WIDTH:
+        BaseFixedWidthVector fixedWidthVector = (BaseFixedWidthVector) 
valueVector;
+        length = fixedWidthVector.getTypeWidth();
+        offset = (long) rowId * length;

Review Comment:
   Updated the PR description to drop the hot-path `instanceof` claim and 
explicitly document the `(long) rowId * length` 2 GiB offset-overflow fix (kept 
per @sunchao's verification across the 2 GiB boundary). Switching both getters 
to `if / else if / else` in `3d4619ac2` also made their bracing style 
consistent.
   
   <sub>Auto-replied by the [GitHub Copilot app](https://gh.io/app)</sub>



##########
spark/src/main/java/org/apache/comet/vector/CometPlainVector.java:
##########
@@ -136,32 +148,37 @@ public double getDouble(int rowId) {
   @Override
   public UTF8String getUTF8String(int rowId) {
     if (isNullAt(rowId)) return null;
-    if (offsetBufferAddress != -1) {
-      long offset;
-      int length;
-      if (isLargeVarWidth) {
-        offset = Platform.getLong(null, offsetBufferAddress + rowId * 8L);
-        length = (int) (Platform.getLong(null, offsetBufferAddress + (rowId + 
1L) * 8L) - offset);
-      } else {
-        offset = Platform.getInt(null, offsetBufferAddress + rowId * 4L);
-        length = Platform.getInt(null, offsetBufferAddress + (rowId + 1L) * 
4L) - (int) offset;
-      }
-      return UTF8String.fromAddress(null, valueBufferAddress + offset, length);
-    } else if (isBaseFixedWidthVector) {
-      BaseFixedWidthVector fixedWidthVector = (BaseFixedWidthVector) 
valueVector;
-      int length = fixedWidthVector.getTypeWidth();
-      int offset = rowId * length;
-      byte[] result = new byte[length];
-      Platform.copyMemory(
-          null, valueBufferAddress + offset, result, 
Platform.BYTE_ARRAY_OFFSET, length);
-
-      if (!isUuid) {
-        return UTF8String.fromBytes(result);
-      } else {
-        return UTF8String.fromString(convertToUuid(result).toString());
-      }
-    } else {
-      throw new IllegalStateException("Unsupported UTF8 vector type: " + 
valueVector.getName());
+    switch (vectorKind) {

Review Comment:
   Good point—replaced `switch (vectorKind)` in both `getUTF8String` and 
`getBinary` with `if / else if / else` direct reference comparisons (`==`) 
starting with `VectorKind.VARIABLE_WIDTH` in `3d4619ac2` (merged in 
`f7e1b1318`). Verified with `javap -c` that javac emits no `$SwitchMap` / 
`ordinal()` lookup or synthetic class—the common `VARIABLE_WIDTH` path is a 
single `getfield` + `getstatic` + `if_acmpne`.
   
   <sub>Auto-replied by the [GitHub Copilot app](https://gh.io/app)</sub>



##########
spark/src/main/java/org/apache/comet/vector/CometPlainVector.java:
##########
@@ -57,24 +64,29 @@ public CometPlainVector(ValueVector vector) {
 
   public CometPlainVector(ValueVector vector, boolean isUuid) {
     super(vector, vector.getField(), isUuid);
-    // NullType doesn't have data buffer.
     if (vector instanceof NullVector) {
-      this.valueBufferAddress = -1;
-    } else {
+      // NullType doesn't have a data buffer.
+      this.vectorKind = VectorKind.NULL;
+      this.valueBufferAddress = -1L;
+      this.offsetBufferAddress = -1L;
+    } else if (vector instanceof BaseFixedWidthVector) {
+      this.vectorKind = VectorKind.FIXED_WIDTH;
+      this.valueBufferAddress = vector.getDataBuffer().memoryAddress();
+      this.offsetBufferAddress = -1L;
+    } else if (vector instanceof BaseVariableWidthVector) {
+      this.vectorKind = VectorKind.VARIABLE_WIDTH;
       this.valueBufferAddress = vector.getDataBuffer().memoryAddress();
-    }
-    isBaseFixedWidthVector = valueVector instanceof BaseFixedWidthVector;
-    if (vector instanceof BaseVariableWidthVector) {
       this.offsetBufferAddress =
           ((BaseVariableWidthVector) vector).getOffsetBuffer().memoryAddress();
-      this.isLargeVarWidth = false;
     } else if (vector instanceof BaseLargeVariableWidthVector) {
+      this.vectorKind = VectorKind.LARGE_VARIABLE_WIDTH;
+      this.valueBufferAddress = vector.getDataBuffer().memoryAddress();
       this.offsetBufferAddress =
           ((BaseLargeVariableWidthVector) 
vector).getOffsetBuffer().memoryAddress();
-      this.isLargeVarWidth = true;
     } else {
-      this.offsetBufferAddress = -1;
-      this.isLargeVarWidth = false;
+      this.vectorKind = VectorKind.OTHER;
+      this.valueBufferAddress = vector.getDataBuffer().memoryAddress();
+      this.offsetBufferAddress = -1L;
     }

Review Comment:
   Refactored in `3d4619ac2`: extracted `vectorKindOf(ValueVector)` so the 
constructor computes `vectorKind` first and assigns `valueBufferAddress` and 
`offsetBufferAddress` once each. Also updated the PR description to state 
accurately that `-1L` is still stored when a kind has no buffer, while dispatch 
checks now use `vectorKind`.
   
   <sub>Auto-replied by the [GitHub Copilot app](https://gh.io/app)</sub>



-- 
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