This is an automated email from the ASF dual-hosted git repository.
clintropolis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 1a5e0f9f4a1 fix: msq compaction for non-time ordered rollup tables
(#20801)
1a5e0f9f4a1 is described below
commit 1a5e0f9f4a187f44e1381ee7b806dbf425f437b0
Author: Clint Wylie <[email protected]>
AuthorDate: Fri Oct 30 13:44:17 2026 -0700
fix: msq compaction for non-time ordered rollup tables (#20801)
---
.../druid/msq/indexing/MSQCompactionRunner.java | 6 +++
.../msq/indexing/MSQCompactionRunnerTest.java | 57 ++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git
a/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQCompactionRunner.java
b/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQCompactionRunner.java
index 52e73052a60..9af2fe652ed 100644
---
a/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQCompactionRunner.java
+++
b/multi-stage-query/src/main/java/org/apache/druid/msq/indexing/MSQCompactionRunner.java
@@ -471,6 +471,12 @@ public class MSQCompactionRunner implements
CompactionRunner
} else {
colType = ColumnType.fromCapabilities(vc.capabilities(inspector,
vc.getOutputName()));
}
+ } else if (ColumnHolder.TIME_COLUMN_NAME.equals(dimension)) {
+ // A group-by output cannot be named __time, and getColumnMappings()
maps TIME_VIRTUAL_COLUMN back to it for
+ // every group-by. A query granularity would have put a virtual column
above that does the renaming; without
+ // one the column is read as it is, under the name the mapping expects.
+ dimensions.add(new DefaultDimensionSpec(ColumnHolder.TIME_COLUMN_NAME,
TIME_VIRTUAL_COLUMN, ColumnType.LONG));
+ continue;
}
dimensions.add(new DefaultDimensionSpec(dimension, dimension, colType));
}
diff --git
a/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQCompactionRunnerTest.java
b/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQCompactionRunnerTest.java
index cf3d841d7d6..a4ef3826396 100644
---
a/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQCompactionRunnerTest.java
+++
b/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQCompactionRunnerTest.java
@@ -630,6 +630,63 @@ public class MSQCompactionRunnerTest
Assertions.assertEquals(expectedDimensionSpec,
groupByQuery.getDimensions());
}
+ @Test
+ public void testTimeAmongTheDimensionsIsGroupedUnderTheVirtualTimeColumn()
throws JsonProcessingException
+ {
+ // A schema that is not sorted by time carries __time among its
dimensions. Naming an output __time is a
+ // restriction of group-by rather than of scan, so this only arises for a
layout that compacts by grouping, and
+ // without a query granularity there is no granularity virtual column to
do the renaming.
+ final List<DimensionSchema> dimensions =
+ ImmutableList.of(STRING_DIMENSION, new
LongDimensionSchema(ColumnHolder.TIME_COLUMN_NAME));
+
+ final CompactionTask task = createCompactionTask(
+ new DynamicPartitionsSpec(3, null),
+ null,
+ Collections.emptyMap(),
+ null,
+ null
+ );
+
+ final CombinedDataSchema dataSchema = new CombinedDataSchema(
+ DATA_SOURCE,
+ new TimestampSpec(TIMESTAMP_COLUMN, null, null),
+
DimensionsSpec.builder().setDimensions(dimensions).setForceSegmentSortByTime(false).build(),
+ AGGREGATORS.toArray(new AggregatorFactory[0]),
+ new UniformGranularitySpec(
+ SEGMENT_GRANULARITY.getDefaultGranularity(),
+ // no query granularity, so nothing else renames __time
+ null,
+ Collections.singletonList(COMPACTION_INTERVAL)
+ ),
+ null,
+ null,
+ null
+ );
+
+ final GroupByQuery groupByQuery = (GroupByQuery) Iterables.getOnlyElement(
+ MSQ_COMPACTION_RUNNER.createMsqControllerTasks(
+ task,
+ Map.of(new
MultipleIntervalSegmentSpec(List.of(COMPACTION_INTERVAL)), dataSchema)
+ )
+ ).getQuerySpec().getQuery();
+
+ Assertions.assertTrue(
+ groupByQuery.getDimensions()
+ .stream()
+ .anyMatch(
+ dim ->
ColumnHolder.TIME_COLUMN_NAME.equals(dim.getDimension())
+ &&
MSQCompactionRunner.TIME_VIRTUAL_COLUMN.equals(dim.getOutputName())
+ ),
+ groupByQuery.getDimensions()::toString
+ );
+ Assertions.assertTrue(
+ groupByQuery.getDimensions()
+ .stream()
+ .noneMatch(dim ->
ColumnHolder.TIME_COLUMN_NAME.equals(dim.getOutputName())),
+ groupByQuery.getDimensions()::toString
+ );
+ }
+
@Test
public void testCompactionConfigWithProjectionsProducesCorrectSpec() throws
JsonProcessingException
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]