nssalian commented on code in PR #16292: URL: https://github.com/apache/iceberg/pull/16292#discussion_r3574374640
########## arrow/src/main/java/org/apache/iceberg/arrow/vectorized/VectorizedVariantVisitor.java: ########## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.arrow.vectorized; + +import java.util.List; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.iceberg.Schema; +import org.apache.iceberg.parquet.ParquetVariantVisitor; +import org.apache.iceberg.parquet.VectorizedReader; +import org.apache.iceberg.types.Types; +import org.apache.parquet.column.ColumnDescriptor; +import org.apache.parquet.io.InvalidRecordException; +import org.apache.parquet.schema.GroupType; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; + +/** Creates Arrow readers for a variant column's metadata and value leaves. */ +class VectorizedVariantVisitor extends ParquetVariantVisitor<VectorizedReader<?>> { + private final String[] variantGroupPath; + private final MessageType parquetSchema; + private final Schema icebergSchema; + private final BufferAllocator allocator; + private final boolean setArrowValidityVector; + + VectorizedVariantVisitor( + String[] variantGroupPath, + MessageType parquetSchema, + Schema icebergSchema, + BufferAllocator allocator, + boolean setArrowValidityVector) { + this.variantGroupPath = variantGroupPath; + this.parquetSchema = parquetSchema; + this.icebergSchema = icebergSchema; + this.allocator = allocator; + this.setArrowValidityVector = setArrowValidityVector; + } + + @Override + public VectorizedReader<?> metadata(PrimitiveType metadata) { + ColumnDescriptor desc = resolveDescriptor(metadata); + if (desc == null) { + return null; + } + + Types.NestedField field = + Types.NestedField.required(-1, metadata.getName(), Types.BinaryType.get()); + return new VectorizedArrowReader(desc, field, allocator, setArrowValidityVector); + } + + @Override + public VectorizedReader<?> serialized(PrimitiveType value) { + ColumnDescriptor desc = resolveDescriptor(value); + if (desc == null) { + return null; + } + + Types.NestedField field = + Types.NestedField.optional(-1, value.getName(), Types.BinaryType.get()); + return new VectorizedArrowReader(desc, field, allocator, setArrowValidityVector); + } + + @Override + public VectorizedReader<?> variant( + GroupType variant, VectorizedReader<?> metadataResult, VectorizedReader<?> valueResult) { + if (metadataResult instanceof VectorizedArrowReader + && valueResult instanceof VectorizedArrowReader) { + Types.NestedField field = findVariantField(variant); + if (field != null) { + return new VectorizedArrowReader.VectorizedVariantReader( + field, (VectorizedArrowReader) metadataResult, (VectorizedArrowReader) valueResult); + } + } + + return null; + } + + @Override + public VectorizedReader<?> primitive(PrimitiveType primitive) { + return null; + } + + @Override + public VectorizedReader<?> value( + GroupType value, VectorizedReader<?> valueResult, VectorizedReader<?> typedResult) { + return valueResult; Review Comment: Fixed - primitive() and value() (with typedResult != null guard) now throw UnsupportedOperationException. Unshredded path unchanged. Wrote a test TestVectorizedVariantVisitor to cover this. ########## arrow/src/main/java/org/apache/iceberg/arrow/vectorized/VectorizedVariantVisitor.java: ########## @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.arrow.vectorized; + +import java.util.List; +import org.apache.arrow.memory.BufferAllocator; +import org.apache.iceberg.Schema; +import org.apache.iceberg.parquet.ParquetVariantVisitor; +import org.apache.iceberg.parquet.VectorizedReader; +import org.apache.iceberg.types.Types; +import org.apache.parquet.column.ColumnDescriptor; +import org.apache.parquet.io.InvalidRecordException; +import org.apache.parquet.schema.GroupType; +import org.apache.parquet.schema.MessageType; +import org.apache.parquet.schema.PrimitiveType; + +/** Creates Arrow readers for a variant column's metadata and value leaves. */ +class VectorizedVariantVisitor extends ParquetVariantVisitor<VectorizedReader<?>> { + private final String[] variantGroupPath; + private final MessageType parquetSchema; + private final Schema icebergSchema; + private final BufferAllocator allocator; + private final boolean setArrowValidityVector; + + VectorizedVariantVisitor( + String[] variantGroupPath, + MessageType parquetSchema, + Schema icebergSchema, + BufferAllocator allocator, + boolean setArrowValidityVector) { + this.variantGroupPath = variantGroupPath; + this.parquetSchema = parquetSchema; + this.icebergSchema = icebergSchema; + this.allocator = allocator; + this.setArrowValidityVector = setArrowValidityVector; + } + + @Override + public VectorizedReader<?> metadata(PrimitiveType metadata) { + ColumnDescriptor desc = resolveDescriptor(metadata); + if (desc == null) { + return null; + } + + Types.NestedField field = + Types.NestedField.required(-1, metadata.getName(), Types.BinaryType.get()); + return new VectorizedArrowReader(desc, field, allocator, setArrowValidityVector); + } + + @Override + public VectorizedReader<?> serialized(PrimitiveType value) { + ColumnDescriptor desc = resolveDescriptor(value); + if (desc == null) { + return null; + } + + Types.NestedField field = + Types.NestedField.optional(-1, value.getName(), Types.BinaryType.get()); + return new VectorizedArrowReader(desc, field, allocator, setArrowValidityVector); + } + + @Override + public VectorizedReader<?> variant( + GroupType variant, VectorizedReader<?> metadataResult, VectorizedReader<?> valueResult) { + if (metadataResult instanceof VectorizedArrowReader + && valueResult instanceof VectorizedArrowReader) { + Types.NestedField field = findVariantField(variant); + if (field != null) { + return new VectorizedArrowReader.VectorizedVariantReader( + field, (VectorizedArrowReader) metadataResult, (VectorizedArrowReader) valueResult); + } + } + + return null; + } + + @Override + public VectorizedReader<?> primitive(PrimitiveType primitive) { + return null; + } + + @Override + public VectorizedReader<?> value( + GroupType value, VectorizedReader<?> valueResult, VectorizedReader<?> typedResult) { + return valueResult; + } + + @Override + public VectorizedReader<?> object( + GroupType object, VectorizedReader<?> valueResult, List<VectorizedReader<?>> fieldResults) { + return valueResult; Review Comment: Same fix. I added for object() array() to throw unconditionally since they only fire when typed_value is present. Also covered by test TestVectorizedVariantVisitor. -- 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]
