clintropolis commented on code in PR #13652:
URL: https://github.com/apache/druid/pull/13652#discussion_r1066514667
##########
processing/src/main/java/org/apache/druid/query/rowsandcols/ArrayListRowsAndColumns.java:
##########
@@ -118,8 +188,309 @@ public <T> T as(Class<? extends T> clazz)
@Nullable
@Override
+ @SuppressWarnings("unchecked")
public <T> T as(Class<T> clazz)
{
+ if (ClusteredGroupPartitioner.class.equals(clazz)) {
+ return (T) new ClusteredGroupPartitioner()
Review Comment:
nit: maybe getting close to threshold to make these internal classes to make
the `as` method itself not be huge as we have done in other places
##########
processing/src/main/java/org/apache/druid/query/rowsandcols/ArrayListRowsAndColumns.java:
##########
@@ -118,8 +188,309 @@ public <T> T as(Class<? extends T> clazz)
@Nullable
@Override
+ @SuppressWarnings("unchecked")
public <T> T as(Class<T> clazz)
{
+ if (ClusteredGroupPartitioner.class.equals(clazz)) {
+ return (T) new ClusteredGroupPartitioner()
+ {
+ @Override
+ public int[] computeBoundaries(List<String> columns)
+ {
+ if (numRows() == 0) {
+ return new int[]{};
+ }
+
+ boolean allInSignature = true;
+ for (String column : columns) {
+ if (!rowSignature.contains(column)) {
+ allInSignature = false;
+ }
+ }
+
+ if (allInSignature) {
+ return computeBoundariesAllInSignature(columns);
+ } else {
+ return computeBoundariesSomeAppended(columns);
+ }
+ }
+
+ /**
+ * Computes boundaries assuming all columns are defined as in the
signature. Given that
+ * ArrayListRowsAndColumns is a fundamentally row-oriented data
structure, using a row-oriented
+ * algorithm should prove better than the column-oriented
implementation in DefaultClusteredGroupPartitioner
+ *
+ * @param columns the columns to partition on as in {@link
#computeBoundaries(List)}
+ * @return the partition boundaries as in {@link
#computeBoundaries(List)}
+ */
+ private int[] computeBoundariesAllInSignature(List<String> columns)
+ {
+ ArrayList<Comparator<Object>> comparators = new
ArrayList<>(columns.size());
+ ArrayList<Function<RowType, Object>> adapters = new
ArrayList<>(columns.size());
+ for (String column : columns) {
+ final Optional<ColumnType> columnType =
rowSignature.getColumnType(column);
+ if (columnType.isPresent()) {
+
comparators.add(Comparator.nullsFirst(columnType.get().getStrategy()));
Review Comment:
nit: could also use `getNullableStrategy`, though it doesn't matter
--
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]