This is an automated email from the ASF dual-hosted git repository.
cwylie pushed a commit to branch 34.0.0
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/34.0.0 by this push:
new 55a3bc0aafa Throw error if duplicated projection names are found
(#18233) (#18280)
55a3bc0aafa is described below
commit 55a3bc0aafa29edd06954451b16f3ab8709c7e58
Author: Lucas Capistrant <[email protected]>
AuthorDate: Fri Jul 18 04:26:14 2025 -0500
Throw error if duplicated projection names are found (#18233) (#18280)
* Throw error if duplicated projection names are found
* update to use DruidException
Co-authored-by: Cece Mei <[email protected]>
---
.../incremental/OnheapIncrementalIndex.java | 8 +++
.../incremental/OnheapIncrementalIndexTest.java | 81 ++++++++++++++++++++--
2 files changed, 85 insertions(+), 4 deletions(-)
diff --git
a/processing/src/main/java/org/apache/druid/segment/incremental/OnheapIncrementalIndex.java
b/processing/src/main/java/org/apache/druid/segment/incremental/OnheapIncrementalIndex.java
index b73004bad80..53cf321f8e0 100644
---
a/processing/src/main/java/org/apache/druid/segment/incremental/OnheapIncrementalIndex.java
+++
b/processing/src/main/java/org/apache/druid/segment/incremental/OnheapIncrementalIndex.java
@@ -143,6 +143,14 @@ public class OnheapIncrementalIndex extends
IncrementalIndex
// initialize them all with 0 rows
AggregateProjectionMetadata.Schema schema =
projectionSpec.toMetadataSchema();
aggregateProjections.add(new AggregateProjectionMetadata(schema, 0));
+ if (projections.containsKey(projectionSpec.getName())) {
+ throw DruidException.forPersona(DruidException.Persona.USER)
+ .ofCategory(DruidException.Category.INVALID_INPUT)
+ .build(
+ "Found duplicate projection[%s], please remove
and resubmit the ingestion.",
+ projectionSpec.getName()
+ );
+ }
final OnHeapAggregateProjection projection = new
OnHeapAggregateProjection(
projectionSpec,
diff --git
a/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexTest.java
b/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexTest.java
index fa577b702f1..4d0cb647712 100644
---
a/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexTest.java
+++
b/processing/src/test/java/org/apache/druid/segment/incremental/OnheapIncrementalIndexTest.java
@@ -52,6 +52,76 @@ public class OnheapIncrementalIndexTest
Assert.assertEquals(spec,
MAPPER.readValue(MAPPER.writeValueAsString(spec),
OnheapIncrementalIndex.Spec.class));
}
+ @Test
+ public void testProjectionHappyPath()
+ {
+ // arrange
+ DimensionsSpec dimensionsSpec = DimensionsSpec.builder()
+
.setDimensions(ImmutableList.of(
+ new
StringDimensionSchema("string"),
+ new
LongDimensionSchema("long")
+ ))
+ .build();
+ AggregatorFactory aggregatorFactory = new
DoubleSumAggregatorFactory("double", "double");
+ AggregateProjectionSpec projectionSpec = new AggregateProjectionSpec(
+ "proj",
+ VirtualColumns.EMPTY,
+ ImmutableList.of(new StringDimensionSchema("string")),
+ new AggregatorFactory[]{
+ new LongSumAggregatorFactory("sum_long", "long"),
+ new DoubleSumAggregatorFactory("double", "double")
+ }
+ );
+ // act & assert
+ IncrementalIndex index = IndexBuilder.create()
+
.schema(IncrementalIndexSchema.builder()
+
.withDimensionsSpec(dimensionsSpec)
+
.withRollup(true)
+
.withMetrics(aggregatorFactory)
+
.withProjections(ImmutableList.of(projectionSpec))
+
.build())
+ .buildIncrementalIndex();
+ Assert.assertNotNull(index.getProjection("proj"));
+ }
+
+ @Test
+ public void testProjectionDuplicatedName()
+ {
+ // arrange
+ DimensionsSpec dimensionsSpec = DimensionsSpec.EMPTY;
+ AggregatorFactory aggregatorFactory = new
DoubleSumAggregatorFactory("double", "double");
+ AggregateProjectionSpec projectionSpec1 = new AggregateProjectionSpec(
+ "proj",
+ VirtualColumns.EMPTY,
+ ImmutableList.of(),
+ new AggregatorFactory[]{new DoubleSumAggregatorFactory("double",
"double")}
+ );
+ AggregateProjectionSpec projectionSpec2 = new AggregateProjectionSpec(
+ "proj",
+ VirtualColumns.EMPTY,
+ ImmutableList.of(),
+ new AggregatorFactory[]{new DoubleSumAggregatorFactory("double",
"double")}
+ );
+ // act & assert
+ DruidException e = Assert.assertThrows(
+ DruidException.class,
+ () -> IndexBuilder.create()
+ .schema(IncrementalIndexSchema.builder()
+
.withDimensionsSpec(dimensionsSpec)
+ .withRollup(true)
+
.withMetrics(aggregatorFactory)
+
.withProjections(ImmutableList.of(
+ projectionSpec1,
+ projectionSpec2
+ ))
+ .build())
+ .buildIncrementalIndex()
+ );
+ Assert.assertEquals(DruidException.Persona.USER, e.getTargetPersona());
+ Assert.assertEquals(DruidException.Category.INVALID_INPUT,
e.getCategory());
+ Assert.assertEquals("Found duplicate projection[proj], please remove and
resubmit the ingestion.", e.getMessage());
+ }
+
@Test
public void testSpecEqualsAndHashCode()
{
@@ -226,8 +296,11 @@ public class OnheapIncrementalIndexTest
ImmutableList.of(
new
StringDimensionSchema("string")
),
- new
AggregatorFactory[] {
- new
LongSumAggregatorFactory("sum_double", "sum_double")
+ new
AggregatorFactory[]{
+ new
LongSumAggregatorFactory(
+
"sum_double",
+
"sum_double"
+ )
}
)
)
@@ -272,7 +345,7 @@ public class OnheapIncrementalIndexTest
ImmutableList.of(
new
StringDimensionSchema("string")
),
- new
AggregatorFactory[] {
+ new
AggregatorFactory[]{
new
LongSumAggregatorFactory("sum_long", "long"),
new
DoubleSumAggregatorFactory("sum_double", "double")
}
@@ -322,7 +395,7 @@ public class OnheapIncrementalIndexTest
ImmutableList.of(
new
LongDimensionSchema("long")
),
- new
AggregatorFactory[] {
+ new
AggregatorFactory[]{
new
LongSumAggregatorFactory("v0_sum", "v0")
}
)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]