rdblue commented on a change in pull request #3210:
URL: https://github.com/apache/iceberg/pull/3210#discussion_r720429581



##########
File path: core/src/main/java/org/apache/iceberg/JacksonSerializationUtil.java
##########
@@ -0,0 +1,156 @@
+/*
+ * 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;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.iceberg.expressions.ResidualEvaluator;
+
+/**
+ * Util methods to help Jackson serialization of Iceberg objects, useful in 
systems like Presto and Trino.
+ */
+public class JacksonSerializationUtil {
+
+  private JacksonSerializationUtil() {
+  }
+
+  public static FileScanTask createFileScanTask(DataFile file, DeleteFile[] 
deletes, String schemaString,
+                                                String specString, 
ResidualEvaluator residuals) {
+    return new BaseFileScanTask(file, deletes, schemaString, specString, 
residuals);
+  }
+
+  public static DataFile createDataFile(int specId, FileContent content, 
String filePath, FileFormat format,
+                                        PartitionData partitionData, long 
fileSizeInBytes, long recordCount,
+                                        Map<Integer, Long> columnSizes, 
Map<Integer, Long> valueCounts,
+                                        Map<Integer, Long> nullValueCounts, 
Map<Integer, Long> nanValueCounts,
+                                        Map<Integer, ByteBuffer> lowerBounds, 
Map<Integer, ByteBuffer> upperBounds,
+                                        List<Long> splitOffsets, int[] 
equalityFieldIds, Integer sortOrderId,
+                                        ByteBuffer keyMetadata) {
+    return new GenericDataFile(specId, content, filePath, format, 
partitionData, fileSizeInBytes, recordCount,
+        columnSizes, valueCounts, nullValueCounts, nanValueCounts, 
lowerBounds, upperBounds, splitOffsets,
+        equalityFieldIds, sortOrderId, keyMetadata);
+  }
+
+  public static DeleteFile createDeleteFile(int specId, FileContent content, 
String filePath, FileFormat format,
+                                            PartitionData partitionData, long 
fileSizeInBytes, long recordCount,
+                                            Map<Integer, Long> columnSizes, 
Map<Integer, Long> valueCounts,
+                                            Map<Integer, Long> 
nullValueCounts, Map<Integer, Long> nanValueCounts,
+                                            Map<Integer, ByteBuffer> 
lowerBounds, Map<Integer, ByteBuffer> upperBounds,
+                                            List<Long> splitOffsets, int[] 
equalityFieldIds, Integer sortOrderId,
+                                            ByteBuffer keyMetadata) {
+    return new GenericDeleteFile(specId, content, filePath, format, 
partitionData, fileSizeInBytes, recordCount,
+        columnSizes, valueCounts, nullValueCounts, nanValueCounts, 
lowerBounds, upperBounds, splitOffsets,
+        equalityFieldIds, sortOrderId, keyMetadata);
+  }
+
+  public static List<byte[]> partitionDataToBytesMap(PartitionData partition) {

Review comment:
       The spec is used in deserialization to convert bytes to values. Why not 
also use it to convert values to bytes rather than `instanceof` checks? Then 
you'd know whether a value matches the assumptions at serialization time rather 
than potentially deserializing incorrectly. For example, if I have an long in 
the partition that should be an int serializing 8 bytes but deserializing just 
the first 4 is a silent error.




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