Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public InternalRow copy() {
row.update(i, getArray(i).copy());
} else if (pdt instanceof PhysicalMapType) {
row.update(i, getMap(i).copy());
} else if (pdt instanceof PhysicalVariantType) {
row.update(i, getVariant(i));
} else {
throw new RuntimeException("Not implemented. " + dt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public InternalRow copy() {
row.update(i, getArray(i).copy());
} else if (dt instanceof MapType) {
row.update(i, getMap(i).copy());
} else if (dt instanceof VariantType) {
row.update(i, getVariant(i));
} else {
throw new RuntimeException("Not implemented. " + dt);
}
Expand Down Expand Up @@ -217,6 +219,8 @@ public Object get(int ordinal, DataType dataType) {
return getStruct(ordinal, structType.fields().length);
} else if (dataType instanceof MapType) {
return getMap(ordinal);
} else if (dataType instanceof VariantType) {
return getVariant(ordinal);
} else {
throw new SparkUnsupportedOperationException(
"_LEGACY_ERROR_TEMP_3192", Map.of("dt", dataType.toString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2025,4 +2025,39 @@ class ColumnarBatchSuite extends SparkFunSuite {
}
}
}

testVector("[SPARK-55552] Variant", 3, VariantType) {
column =>
val valueChild = column.getChild(0)
val metadataChild = column.getChild(1)

column.putNotNull(0)
valueChild.appendByteArray(Array[Byte](1, 2, 3), 0, 3)
metadataChild.appendByteArray(Array[Byte](10, 11), 0, 2)

column.putNotNull(1)
valueChild.appendByteArray(Array[Byte](4, 5), 0, 2)
metadataChild.appendByteArray(Array[Byte](12, 13, 14), 0, 3)

column.putNull(2)
valueChild.appendNull()
metadataChild.appendNull()

val batchRow = new ColumnarBatchRow(Array(column))
(0 until 3).foreach { i =>
batchRow.rowId = i
val batchRowCopy = batchRow.copy()
if (i < 2) {
assert(!batchRow.isNullAt(0))
assert(!batchRowCopy.isNullAt(0))
val original = batchRow.getVariant(0)
val copied = batchRowCopy.get(0, VariantType).asInstanceOf[VariantVal]
assert(java.util.Arrays.equals(original.getValue, copied.getValue))
assert(java.util.Arrays.equals(original.getMetadata, copied.getMetadata))
} else {
assert(batchRow.isNullAt(0))
assert(batchRowCopy.isNullAt(0))
}
}
}
}