You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@parquet.apache.org by GitBox <gi...@apache.org> on 2021/01/04 10:55:47 UTC

[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #847: [PARQUET-1951] Allow different strategies to combine key values when …

gszadovszky commented on a change in pull request #847:
URL: https://github.com/apache/parquet-mr/pull/847#discussion_r551240027



##########
File path: parquet-tools/src/main/java/org/apache/parquet/tools/command/MergeCommand.java
##########
@@ -41,6 +46,21 @@
           "   <output> is the destination parquet file"
   };
 
+  private static final String DEFAULT_KEY_VALUE_MERGE_STRATEGY = new DefaultKeyValueMetadataMergeStrategy().getClass().getName();

Review comment:
       You do not need to instantiate an object to get its class. Simply use `DefaultKeyValueMetadataMergeStrategy.class`

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/KeyValueMetadataMergeStrategy.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.parquet.schema.MessageType;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Set;
+
+import static java.util.Collections.unmodifiableMap;
+
+/**
+ * Strategy to merge metadata. Possible implementations:
+ * 1) Expect metadata to be exactly identical. Otherwise throw error (this is the default strategy implementation)
+ * 2) Custom strategy to merge metadata if the values are not identical. Example: concatenate values.
+ */
+public interface KeyValueMetadataMergeStrategy extends Serializable {
+  /**
+   * @param keyValueMetaData the merged app specific metadata
+   *
+   * @throws NullPointerException if keyValueMetaData is {@code null}
+   */
+  Map<String, String> merge(Map<String, Set<String>> keyValueMetaData);

Review comment:
       I think, this interface does not support all types of the potential merge strategy implementations. For example if you would like to use the value which is common in the most files you cannot do it because you only have the distinct values. What do you think about using a `List<String>` instead of a `Set<String>`?

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/DefaultKeyValueMetadataMergeStrategy.java
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ *  Default strategy to throw errors in metadata if there are multiple values for a given key in metadata.
+ */
+public class DefaultKeyValueMetadataMergeStrategy implements KeyValueMetadataMergeStrategy {

Review comment:
       I do not really like the naming of this class. This is the default implementation, it's fine but the name should suggest what it does. I'm quite sure there is a better naming but what about `StrictKeyValueMetadataMergeStrategy`?




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

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