clintropolis commented on code in PR #13619: URL: https://github.com/apache/druid/pull/13619#discussion_r1063199567
########## processing/src/main/java/org/apache/druid/query/rowsandcols/semantic/NaiveSortMaker.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.semantic; + +import com.google.common.collect.Lists; +import org.apache.druid.query.operator.ColumnWithDirection; +import org.apache.druid.query.rowsandcols.RowsAndColumns; + +import java.util.ArrayList; + +/** + * A NaiveSorter sorts a stream of data in-place. In the worst case, that means it needs to buffer up all + * RowsAndColumns received before it can return anything. This semantic interface is setup to allow an + * implementation of RowsAndColumns to know that it is pre-sorted and potentially return sorted data early. + * <p> + * The default implementation cannot actually do this, however, so it is up to the specific concrete RowsAndColumns + * classes to provide their own implementations that can do this. + */ +public interface NaiveSortMaker +{ + static NaiveSortMaker fromRAC(RowsAndColumns rac) + { + NaiveSortMaker retVal = rac.as(NaiveSortMaker.class); + if (retVal == null) { + retVal = new DefaultNaiveSortMaker(rac); + } + return retVal; + } + + interface NaiveSorter + { + /** + * Adds more data to the sort. This method can optionally return a RowsAndColumns object. If it does return + * a RowsAndColumns object, any data included in the return is assumed to be in sorted-order. + * + * @param rac the data to include in the sort + * @return optionally, a RowsAndColumns object of data that is known to be in sorted order, null if nothing yet. + */ + RowsAndColumns moreData(RowsAndColumns rac); + + /** + * Indicate that there is no more data coming. + * + * @return A RowsAndColumns object of sorted data that has not been returned already from {@link #moreData} calls. + */ + RowsAndColumns complete(); + } + + /** + * Makes the NaiveSorter that will actually do the sort. This method uses {@code List<OrderByColumnSpec>} to avoid + * littering the code with extra objects for the same thing. {@code OrderByColumnSpec} is only used to identify Review Comment: ah, I see that maybe you were originally using one of the other "order by" things, specifically the group by version? I guess the 'none' probably makes the scan query order by inappropriate too? anyway, javadocs are stale ########## processing/src/main/java/org/apache/druid/query/operator/ColumnWithDirection.java: ########## @@ -0,0 +1,109 @@ +/* + * 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.operator; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +public class ColumnWithDirection Review Comment: sort of sad to have another one of these (`ScanQuery.OrderBy`, `OrderByColumnSpec` of the group by query). It would be nice to standardize these someday... ########## processing/src/main/java/org/apache/druid/query/rowsandcols/ConcatRowsAndColumns.java: ########## @@ -0,0 +1,241 @@ +/* + * 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 org.apache.druid.segment.column.ColumnType; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.Map; + +public class ConcatRowsAndColumns implements RowsAndColumns Review Comment: nit: javadocs ########## processing/src/main/java/org/apache/druid/query/rowsandcols/RearrangedRowsAndColumns.java: ########## @@ -0,0 +1,147 @@ +/* + * 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.IAE; +import org.apache.druid.query.rowsandcols.column.Column; +import org.apache.druid.query.rowsandcols.column.ColumnAccessor; +import org.apache.druid.query.rowsandcols.column.ColumnAccessorBasedColumn; +import org.apache.druid.segment.column.ColumnType; + +import javax.annotation.Nullable; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; + +public class RearrangedRowsAndColumns implements RowsAndColumns Review Comment: why "rearranged" instead of "sorted"? I don't really care, just curious 😅 also javadocs -- 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]
