egalpin commented on code in PR #10234: URL: https://github.com/apache/pinot/pull/10234#discussion_r1103667183
########## pinot-segment-local/src/main/java/org/apache/pinot/segment/local/upsert/ComparisonColumns.java: ########## @@ -0,0 +1,51 @@ +package org.apache.pinot.segment.local.upsert; + +import com.google.common.base.Preconditions; +import java.util.Map; +import javax.annotation.Nonnull; + + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ComparisonColumns implements Comparable { + private ComparisonColumns _other = null; + private final Map<String, ComparisonColumn> _comparisonColumns; + + public ComparisonColumns(Map<String, ComparisonColumn> comparisonColumns) { + _comparisonColumns = comparisonColumns; + } + + public Map<String, ComparisonColumn> getComparisonColumns() { + return _comparisonColumns; + } + + public ComparisonColumns getOther() { + return _other; + } + + @Override + public int compareTo(@Nonnull Object other) { + + Preconditions.checkState(other instanceof ComparisonColumns, + "ComparisonColumns is only Comparable with another instance of ComparisonColumns"); + + /* Capture other for later use in {@link RecordInfo#getComparisonValue()} */ + _other = (ComparisonColumns) other; + for (Map.Entry<String, ComparisonColumn> columnEntry : _comparisonColumns.entrySet()) { + ComparisonColumn comparisonColumn = columnEntry.getValue(); + // "this" may only 1 non-null value at most. _other may have all non-null values, however. + if (comparisonColumn.isNull) { + continue; + } + + ComparisonColumn otherComparisonColumn = _other.getComparisonColumns().get(comparisonColumn.columnName); + if (otherComparisonColumn == null) { + // This can happen if a new column is added to the list of coparisonColumns. We want o support that without + // requiring a server restart, so handle the null here. + return 1; + } + return comparisonColumn.comparisonValue.compareTo(otherComparisonColumn.comparisonValue); + } + + return -1; Review Comment: Note to self: to maintain existing behaviour where the existing comparisonColumn is null and so to is the inbound comparisonColumn (which allows upsert due to compareTo returning 0 in such a case), if all inbound comparisonColumns are null, do one last check to see if all those same columns in the existing set of ComparisonColumns are also null. If so, return 0. If not, return -1 -- 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