rahil-c commented on code in PR #18328:
URL: https://github.com/apache/hudi/pull/18328#discussion_r2998509460
##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/io/storage/row/HoodieRowParquetWriteSupport.java:
##########
@@ -305,6 +306,40 @@ private ValueWriter makeWriter(HoodieSchema schema,
DataType dataType) {
}
recordConsumer.addBinary(Binary.fromReusedByteArray(fixedLengthBytes,
0, numBytes));
};
+ } else if (dataType instanceof ArrayType
+ && resolvedSchema != null
+ && resolvedSchema.getType() == HoodieSchemaType.VECTOR) {
+ HoodieSchema.Vector vectorSchema = (HoodieSchema.Vector) resolvedSchema;
+ int dimension = vectorSchema.getDimension();
+ HoodieSchema.Vector.VectorElementType elemType =
vectorSchema.getVectorElementType();
+ int bufferSize = Math.multiplyExact(dimension,
elemType.getElementSize());
+ ByteBuffer buffer =
ByteBuffer.allocate(bufferSize).order(HoodieSchema.VectorLogicalType.VECTOR_BYTE_ORDER);
+ return (row, ordinal) -> {
+ ArrayData array = row.getArray(ordinal);
+ ValidationUtils.checkArgument(array.numElements() == dimension,
+ () -> String.format("Vector dimension mismatch: schema expects %d
elements but got %d", dimension, array.numElements()));
+ buffer.clear();
+ switch (elemType) {
+ case FLOAT:
+ for (int i = 0; i < dimension; i++) {
+ buffer.putFloat(array.getFloat(i));
+ }
+ break;
+ case DOUBLE:
+ for (int i = 0; i < dimension; i++) {
+ buffer.putDouble(array.getDouble(i));
+ }
+ break;
+ case INT8:
+ for (int i = 0; i < dimension; i++) {
+ buffer.put(array.getByte(i));
+ }
+ break;
+ default:
+ throw new UnsupportedOperationException("Unsupported vector
element type: " + elemType);
+ }
+ recordConsumer.addBinary(Binary.fromReusedByteArray(buffer.array()));
Review Comment:
left a comment in the pr for this
--
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]