imply-cheddar commented on code in PR #13458: URL: https://github.com/apache/druid/pull/13458#discussion_r1040154981
########## processing/src/main/java/org/apache/druid/query/rowsandcols/DefaultGroupPartitioner.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.druid.query.rowsandcols; + +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.query.rowsandcols.column.Column; +import org.apache.druid.query.rowsandcols.column.ColumnAccessor; + +import java.util.List; + +@SuppressWarnings("unused") +public class DefaultGroupPartitioner implements GroupPartitioner +{ + private final RowsAndColumns rac; + + public DefaultGroupPartitioner( + RowsAndColumns rac + ) + { + this.rac = rac; + } + + @Override + public int[] computeGroupings(List<String> columns) + { + int[] retVal = new int[rac.numRows()]; + + for (String column : columns) { + final Column theCol = rac.findColumn(column); + if (theCol == null) { + // The column doesn't exist. In this case, we assume it's always the same value: null. If it's always + // the same, then it doesn't impact grouping at all and can be entirely skipped. + continue; + } + final ColumnAccessor accessor = theCol.toAccessor(); + + int currGroup = 0; + int prevGroupVal = 0; + for (int i = 1; i < retVal.length; ++i) { + if (retVal[i] == prevGroupVal) { Review Comment: `retVal[i]` will always be 0 for the first column that is walked. For the second column, it will only be all-zero if all of the values of the first column were the same. Basically, the algorithm is computing the groupings one column at a time, and the value of retVal up until then is the grouping of all of the previous columns. This check is validating that we are still in an equivalency group based on all of the previous columns (if row `i` and row `i-1` are different based on the previous columns, then the value of our new column doesn't matter, row `i` and row `i-1` will be part of different groupings) -- 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]
