wgtmac commented on code in PR #3700:
URL: https://github.com/apache/parquet-java/pull/3700#discussion_r3695123488
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/FileMetaData.java:
##########
@@ -118,4 +122,23 @@ public InternalFileDecryptor getFileDecryptor() {
public EncryptionType getEncryptionType() {
return encryptionType;
}
+
+ /**
+ * @return the parsed writer version, or {@code null} if {@code createdBy}
is null, empty, or unparseable
+ */
+ @JsonIgnore
+ public ParsedVersion getWriterVersion() {
Review Comment:
This adds the cached value, but no production call site uses it yet. Please
migrate the callers listed in the issue, especially footer stats, page stats,
reader init, rewrite, and lazy encrypted metadata paths.
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/FileMetaData.java:
##########
@@ -42,6 +44,7 @@ public enum EncryptionType {
private final MessageType schema;
private final Map<String, String> keyValueMetaData;
Review Comment:
This cached field is `transient final`. After Java deserialization it will
stay `null` even when `createdBy` is valid. Recompute lazily in
`getWriterVersion()`, or add serialization handling and tests.
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/FileMetaData.java:
##########
@@ -118,4 +122,23 @@ public InternalFileDecryptor getFileDecryptor() {
public EncryptionType getEncryptionType() {
return encryptionType;
}
+
+ /**
+ * @return the parsed writer version, or {@code null} if {@code createdBy}
is null, empty, or unparseable
+ */
+ @JsonIgnore
+ public ParsedVersion getWriterVersion() {
+ return writerVersion;
+ }
+
+ private static ParsedVersion parseVersion(String createdBy) {
+ if (createdBy == null || createdBy.isEmpty()) {
+ return null;
+ }
+ try {
+ return VersionParser.parse(createdBy);
+ } catch (RuntimeException | VersionParser.VersionParseException e) {
+ return null;
+ }
Review Comment:
Returning `null` loses the difference between missing `createdBy` and parse
failure. `CorruptStatistics` currently logs different warnings for these cases.
Preserve the parse failure state, or keep enough context for migrated callers
to preserve existing behavior.
##########
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/metadata/FileMetaDataTest.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.hadoop.metadata;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Collections;
+import org.apache.parquet.schema.MessageType;
+import org.apache.parquet.schema.PrimitiveType;
+import org.apache.parquet.schema.Type;
+import org.junit.jupiter.api.Test;
+
+class FileMetaDataTest {
+
+ private static final MessageType SCHEMA = new MessageType(
+ "test", new PrimitiveType(Type.Repetition.REQUIRED,
PrimitiveType.PrimitiveTypeName.INT32, "id"));
+
+ @Test
+ void validCreatedByIsParsed() {
+ FileMetaData meta =
+ new FileMetaData(SCHEMA, Collections.emptyMap(), "parquet-mr version
1.12.0 (build abc123)");
+
+ assertThat(meta.getWriterVersion()).isNotNull();
Review Comment:
These tests only cover the getter. They do not prove the repeated parsing
problem is fixed. Please add coverage for at least one migrated production path
using the cached `ParsedVersion` instead of reparsing `createdBy`.
--
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]