Jackie-Jiang commented on a change in pull request #7087:
URL: https://github.com/apache/incubator-pinot/pull/7087#discussion_r661841355



##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/merger/AppendMerger.java
##########
@@ -0,0 +1,45 @@
+/**
+ * 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.pinot.segment.local.upsert.merger;
+
+/**
+ * Merges 2 records and returns the merged record.
+ * Append the new value from incoming row to the existing value from 
multi-value field. Then return the merged record.
+ * Append merger allows duplicated records in the multi-value field.
+ */
+public class AppendMerger implements PartialUpsertMerger {
+  AppendMerger() {
+  }
+
+  /**
+   * Append the new value from incoming row to the given multi-value field of 
previous record.
+   */
+  @Override
+  public Object merge(Object previousValue, Object currentValue) {
+    return append((Object[]) previousValue, (Object[]) currentValue);
+  }
+
+  private static Object append(Object[] source, Object[] param) {

Review comment:
       Rename the parameters? `source` and `param` doesn't seem correct

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/merger/UnionMerger.java
##########
@@ -0,0 +1,51 @@
+/**
+ * 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.pinot.segment.local.upsert.merger;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+/**
+ * Merges 2 records and returns the merged record.
+ * Added the new value from incoming row to the existing value from 
multi-value field. Then return the merged record.
+ * Union merger will dedup duplicated records in the multi-value field.
+ */
+public class UnionMerger implements PartialUpsertMerger {
+  UnionMerger() {
+  }
+
+  /**
+   * Union the new value from incoming row to the given multi-value field of 
previous record.
+   */
+  @Override
+  public Object merge(Object previousValue, Object currentValue) {
+    return union((Object[]) previousValue, (Object[]) currentValue);
+  }
+
+  private static Object union(Object[] source, Object[] param) {

Review comment:
       Same here

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java
##########
@@ -371,17 +373,26 @@ static void validatePartialUpsertStrategies(TableConfig 
tableConfig, Schema sche
     List<String> primaryKeyColumns = schema.getPrimaryKeyColumns();
     for (Map.Entry<String, UpsertConfig.Strategy> entry : 
partialUpsertStrategies.entrySet()) {
       String column = entry.getKey();
+      UpsertConfig.Strategy columnStrategy = entry.getValue();
       Preconditions.checkState(!primaryKeyColumns.contains(column), "Merger 
cannot be applied to primary key columns");
 
       FieldSpec fieldSpec = schema.getFieldSpecFor(column);
       Preconditions.checkState(fieldSpec != null, "Merger cannot be applied to 
non-existing column: %s", column);
 
-      if (entry.getValue() == UpsertConfig.Strategy.INCREMENT) {
+      if (columnStrategy == UpsertConfig.Strategy.INCREMENT) {
         
Preconditions.checkState(fieldSpec.getDataType().getStoredType().isNumeric(),
             "INCREMENT merger cannot be applied to non-numeric column: %s", 
column);
         Preconditions.checkState(!schema.getDateTimeNames().contains(column),
             "INCREMENT merger cannot be applied to date time column: %s", 
column);
       }
+
+      if (columnStrategy == UpsertConfig.Strategy.APPEND || columnStrategy == 
UpsertConfig.Strategy.UNION) {

Review comment:
       `else if`?

##########
File path: 
pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java
##########
@@ -371,17 +373,26 @@ static void validatePartialUpsertStrategies(TableConfig 
tableConfig, Schema sche
     List<String> primaryKeyColumns = schema.getPrimaryKeyColumns();
     for (Map.Entry<String, UpsertConfig.Strategy> entry : 
partialUpsertStrategies.entrySet()) {
       String column = entry.getKey();
+      UpsertConfig.Strategy columnStrategy = entry.getValue();
       Preconditions.checkState(!primaryKeyColumns.contains(column), "Merger 
cannot be applied to primary key columns");
 
       FieldSpec fieldSpec = schema.getFieldSpecFor(column);
       Preconditions.checkState(fieldSpec != null, "Merger cannot be applied to 
non-existing column: %s", column);
 
-      if (entry.getValue() == UpsertConfig.Strategy.INCREMENT) {
+      if (columnStrategy == UpsertConfig.Strategy.INCREMENT) {
         
Preconditions.checkState(fieldSpec.getDataType().getStoredType().isNumeric(),
             "INCREMENT merger cannot be applied to non-numeric column: %s", 
column);
         Preconditions.checkState(!schema.getDateTimeNames().contains(column),
             "INCREMENT merger cannot be applied to date time column: %s", 
column);
       }
+
+      if (columnStrategy == UpsertConfig.Strategy.APPEND || columnStrategy == 
UpsertConfig.Strategy.UNION) {
+        Preconditions
+            .checkState(!fieldSpec.isSingleValueField(), "%s merger cannot be 
applied to single-value column: %s",
+                columnStrategy.toString(), column);
+        Preconditions.checkState(!schema.getDateTimeNames().contains(column),

Review comment:
       This is redundant as time cannot be MV




-- 
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: commits-unsubscr...@pinot.apache.org

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



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

Reply via email to