rdblue commented on code in PR #12139:
URL: https://github.com/apache/iceberg/pull/12139#discussion_r1943800768


##########
parquet/src/main/java/org/apache/iceberg/parquet/ParquetVariantReaders.java:
##########
@@ -0,0 +1,409 @@
+/*
+ * 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.parquet;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.stream.Streams;
+import org.apache.iceberg.parquet.ParquetValueReaders.PrimitiveReader;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.variants.ShreddedObject;
+import org.apache.iceberg.variants.Variant;
+import org.apache.iceberg.variants.VariantMetadata;
+import org.apache.iceberg.variants.VariantObject;
+import org.apache.iceberg.variants.VariantValue;
+import org.apache.iceberg.variants.Variants;
+import org.apache.iceberg.variants.Variants.PhysicalType;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.column.page.PageReadStore;
+
+public class ParquetVariantReaders {
+  private ParquetVariantReaders() {}
+
+  public interface VariantValueReader extends ParquetValueReader<VariantValue> 
{
+    @Override
+    default VariantValue read(VariantValue reuse) {
+      throw new UnsupportedOperationException("Variants must be read using 
read(VariantMetadata)");

Review Comment:
   Yes, I considered using the existing `ParquetValueReader` interface with 
different type parameters. The problem that this is solving doesn't fit well 
with reusing this though. The need for a new `read` method is to pass the root 
variant's `VariantMetadata` down to children because its dictionary is used for 
all of the object field names in the current value structure.
   
   To pass `VariantMetadata` down, we could use 
`ParquetValueReader<VariantMetadata>` but then the `read` method would return 
`VariantMetadata`. To overcome that, we could use `Variant` to pass metadata 
into read and a value back out, but then each value is wrapped in an 
unnecessary `Variant` that needs to be removed (same with other cleverness, 
like `OneOf<VariantMetadata, VariantValue>`). The only workable option is to 
parameterize by `Object` and pass whatever we want.
   
   If we were to parameterize by object there's a second problem, which is that 
using the `reuse` value for that purpose is actually violating the contract of 
the `read` method. So my rationale was that as long as we are changing the 
contract, we should just state what we are changing the contract to by adding a 
new interface that encapsulates it.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to