wgtmac commented on code in PR #3243:
URL: https://github.com/apache/parquet-java/pull/3243#discussion_r2328926038


##########
parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveComparator.java:
##########
@@ -206,6 +206,34 @@ public String toString() {
         }
       };
 
+  /*
+   * This comparator is for comparing two timestamps represented as int96 
binary.
+   * It is a two level comparison.
+   * Days (last 4 bytes compared as unsigned Little endian int32),

Review Comment:
   ```suggestion
      * Days (last 4 bytes compared as unsigned little endian int32),
   ```



##########
parquet-column/src/main/java/org/apache/parquet/ValidInt96Stats.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.parquet;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.parquet.VersionParser.ParsedVersion;
+import org.apache.parquet.VersionParser.VersionParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Not all parquet writers populate the int96 statistics correctly. For 
example: arrow-rs
+ * 
https://github.com/apache/arrow-rs/blob/3ed9aedabc9e5a90170e43ff818f24a29eafb35b/parquet/src/file/statistics.rs#L212-L215
+ * This class is used to detect whether a file was written with a version that 
has correct int96 statistics.
+ */
+public class ValidInt96Stats {
+  private static final AtomicBoolean alreadyLogged = new AtomicBoolean(false);
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ValidInt96Stats.class);
+
+  /**
+   * Decides if the statistics from a file created by createdBy (the 
created_by field from parquet format)
+   * should be trusted for INT96 columns.
+   *
+   * @param createdBy  the created-by string from a file footer
+   * @return true if the statistics are valid and can be trusted, false 
otherwise
+   */
+  public static boolean hasValidInt96Stats(String createdBy) {
+    if (Strings.isNullOrEmpty(createdBy)) {
+      warnOnce("Cannot verify INT96 statistics because created_by is null or 
empty");

Review Comment:
   What is the convention for it? `created_by`, `createdBy` or `created-by`?



##########
parquet-column/src/main/java/org/apache/parquet/ValidInt96Stats.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.parquet;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.parquet.VersionParser.ParsedVersion;
+import org.apache.parquet.VersionParser.VersionParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Not all parquet writers populate the int96 statistics correctly. For 
example: arrow-rs
+ * 
https://github.com/apache/arrow-rs/blob/3ed9aedabc9e5a90170e43ff818f24a29eafb35b/parquet/src/file/statistics.rs#L212-L215
+ * This class is used to detect whether a file was written with a version that 
has correct int96 statistics.
+ */
+public class ValidInt96Stats {
+  private static final AtomicBoolean alreadyLogged = new AtomicBoolean(false);
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ValidInt96Stats.class);
+
+  /**
+   * Decides if the statistics from a file created by createdBy (the 
created_by field from parquet format)
+   * should be trusted for INT96 columns.
+   *
+   * @param createdBy  the created-by string from a file footer
+   * @return true if the statistics are valid and can be trusted, false 
otherwise
+   */
+  public static boolean hasValidInt96Stats(String createdBy) {
+    if (Strings.isNullOrEmpty(createdBy)) {
+      warnOnce("Cannot verify INT96 statistics because created_by is null or 
empty");
+      return false;
+    }
+
+    try {
+      ParsedVersion version = VersionParser.parse(createdBy);
+      if ("parquet-mr".equals(version.application)) {

Review Comment:
   I recall that @rdblue has an opinion in maintaining an allow-list here.



##########
parquet-column/src/main/java/org/apache/parquet/ValidInt96Stats.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.parquet;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.parquet.VersionParser.ParsedVersion;
+import org.apache.parquet.VersionParser.VersionParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Not all parquet writers populate the int96 statistics correctly. For 
example: arrow-rs
+ * 
https://github.com/apache/arrow-rs/blob/3ed9aedabc9e5a90170e43ff818f24a29eafb35b/parquet/src/file/statistics.rs#L212-L215
+ * This class is used to detect whether a file was written with a version that 
has correct int96 statistics.
+ */
+public class ValidInt96Stats {
+  private static final AtomicBoolean alreadyLogged = new AtomicBoolean(false);
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ValidInt96Stats.class);
+
+  /**
+   * Decides if the statistics from a file created by createdBy (the 
created_by field from parquet format)
+   * should be trusted for INT96 columns.
+   *
+   * @param createdBy  the created-by string from a file footer
+   * @return true if the statistics are valid and can be trusted, false 
otherwise
+   */
+  public static boolean hasValidInt96Stats(String createdBy) {
+    if (Strings.isNullOrEmpty(createdBy)) {
+      warnOnce("Cannot verify INT96 statistics because created_by is null or 
empty");
+      return false;
+    }
+
+    try {
+      ParsedVersion version = VersionParser.parse(createdBy);
+      if ("parquet-mr".equals(version.application)) {
+        return version.version != null && version.version.compareTo("1.15.0") 
> 0;
+      }
+      if ("parquet-mr compatible Photon".equals(version.application)) {
+        return true;
+      }
+    } catch (RuntimeException | VersionParseException e) {
+      warnParseErrorOnce(createdBy, e);
+    }
+    return false;
+  }
+
+  private static void warnParseErrorOnce(String createdBy, Throwable e) {
+    if (!alreadyLogged.getAndSet(true)) {

Review Comment:
   If it is running in a service, we are unable to log warnings for different 
jobs.



##########
parquet-column/src/main/java/org/apache/parquet/ValidInt96Stats.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.parquet;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.parquet.VersionParser.ParsedVersion;
+import org.apache.parquet.VersionParser.VersionParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Not all parquet writers populate the int96 statistics correctly. For 
example: arrow-rs
+ * 
https://github.com/apache/arrow-rs/blob/3ed9aedabc9e5a90170e43ff818f24a29eafb35b/parquet/src/file/statistics.rs#L212-L215
+ * This class is used to detect whether a file was written with a version that 
has correct int96 statistics.
+ */
+public class ValidInt96Stats {
+  private static final AtomicBoolean alreadyLogged = new AtomicBoolean(false);
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(ValidInt96Stats.class);
+
+  /**
+   * Decides if the statistics from a file created by createdBy (the 
created_by field from parquet format)
+   * should be trusted for INT96 columns.
+   *
+   * @param createdBy  the created-by string from a file footer
+   * @return true if the statistics are valid and can be trusted, false 
otherwise
+   */
+  public static boolean hasValidInt96Stats(String createdBy) {
+    if (Strings.isNullOrEmpty(createdBy)) {
+      warnOnce("Cannot verify INT96 statistics because created_by is null or 
empty");
+      return false;
+    }
+
+    try {
+      ParsedVersion version = VersionParser.parse(createdBy);
+      if ("parquet-mr".equals(version.application)) {
+        return version.version != null && version.version.compareTo("1.15.0") 
> 0;

Review Comment:
   ```suggestion
           return version.version != null && 
version.version.compareTo("1.16.0") > 0;
   ```
   
   1.16 has been released.



##########
parquet-hadoop/src/main/java/org/apache/parquet/format/converter/ParquetMetadataConverter.java:
##########
@@ -762,12 +772,12 @@ public List<PageEncodingStats> 
convertEncodingStats(EncodingStats stats) {
     return formatStats;
   }
 
-  public static Statistics 
toParquetStatistics(org.apache.parquet.column.statistics.Statistics stats) {
-    return toParquetStatistics(stats, 
ParquetProperties.DEFAULT_STATISTICS_TRUNCATE_LENGTH);
+  public Statistics toParquetStatistics(String createdBy, 
org.apache.parquet.column.statistics.Statistics stats) {

Review Comment:
   Isn't it a breaking change?



##########
parquet-column/src/main/java/org/apache/parquet/schema/PrimitiveComparator.java:
##########
@@ -206,6 +206,34 @@ public String toString() {
         }
       };
 
+  /*
+   * This comparator is for comparing two timestamps represented as int96 
binary.
+   * It is a two level comparison.
+   * Days (last 4 bytes compared as unsigned Little endian int32),
+   * Nanoseconds (first 8 bytes compared as unsigned little endian int64)
+   */
+  static final PrimitiveComparator<Binary> 
BINARY_AS_INT96_TIMESTAMP_COMPARATOR = new BinaryComparator() {
+    @Override
+    int compareBinary(Binary b1, Binary b2) {
+      ByteBuffer bb1 = b1.toByteBuffer().slice();

Review Comment:
   Should we check if their lengths are exactly 12 before anything? I recall 
that `BINARY_AS_FLOAT16_COMPARATOR` did 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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to