Skip to content

Commit f4bc04d

Browse files
author
Sonam Mandal
authored
Add validation for * column for non-COUNT function in star tree config (#17008)
* Add validation for * column for non-COUNT function in star tree config * Add validation for aggregationConfig in startree config and related tests
1 parent e258c7d commit f4bc04d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

pinot-segment-local/src/main/java/org/apache/pinot/segment/local/utils/TableConfigUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,9 @@ private static void validateStarTreeIndexConfigs(List<StarTreeIndexConfig> starT
13311331
String column = columnPair.getColumn();
13321332
if (!column.equals(AggregationFunctionColumnPair.STAR)) {
13331333
referencedColumns.add(column);
1334+
} else if (columnPair.getFunctionType() != AggregationFunctionType.COUNT) {
1335+
throw new IllegalStateException("Non-COUNT function set the column as '*' in the functionColumnPair: "
1336+
+ functionColumnPair + ". Please configure an actual column for the function");
13341337
}
13351338
}
13361339
}
@@ -1357,6 +1360,10 @@ private static void validateStarTreeIndexConfigs(List<StarTreeIndexConfig> starT
13571360
String column = columnPair.getColumn();
13581361
if (!column.equals(AggregationFunctionColumnPair.STAR)) {
13591362
referencedColumns.add(column);
1363+
} else if (columnPair.getFunctionType() != AggregationFunctionType.COUNT) {
1364+
throw new IllegalStateException("Non-COUNT function set the column as '*' in the aggregationConfig for "
1365+
+ "function: " + aggregationConfig.getAggregationFunction()
1366+
+ ". Please configure an actual column for the function");
13601367
}
13611368
}
13621369
}

pinot-segment-local/src/test/java/org/apache/pinot/segment/local/utils/TableConfigUtilsTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,31 @@ public void testValidateIndexingConfig() {
16321632
fail("Should not fail for valid StarTreeIndex config column name");
16331633
}
16341634

1635+
// Test using * as the column for the COUNT aggregation
1636+
starTreeIndexConfig =
1637+
new StarTreeIndexConfig(List.of("myCol"), List.of("myCol"), List.of("COUNT__*"), null, 1);
1638+
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
1639+
.setStarTreeIndexConfigs(List.of(starTreeIndexConfig))
1640+
.build();
1641+
try {
1642+
TableConfigUtils.validate(tableConfig, schema);
1643+
} catch (Exception e) {
1644+
fail("Should not fail for valid StarTreeIndex function column pair with COUNT__*");
1645+
}
1646+
1647+
// Test using * as the column for a non-COUNT aggregation
1648+
starTreeIndexConfig =
1649+
new StarTreeIndexConfig(List.of("myCol"), List.of("myCol"), List.of("SUM__*"), null, 1);
1650+
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
1651+
.setStarTreeIndexConfigs(List.of(starTreeIndexConfig))
1652+
.build();
1653+
try {
1654+
TableConfigUtils.validate(tableConfig, schema);
1655+
fail("Should not fail for invalid StarTreeIndex function column pair with SUM__*");
1656+
} catch (Exception e) {
1657+
// expected
1658+
}
1659+
16351660
starTreeIndexConfig = new StarTreeIndexConfig(List.of("myCol2"), List.of("myCol"), List.of("SUM__myCol"), null, 1);
16361661
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
16371662
.setStarTreeIndexConfigs(List.of(starTreeIndexConfig))
@@ -1690,6 +1715,29 @@ public void testValidateIndexingConfig() {
16901715
// expected
16911716
}
16921717

1718+
starTreeIndexConfig = new StarTreeIndexConfig(List.of("myCol"), null, null,
1719+
List.of(new StarTreeAggregationConfig("*", "COUNT")), 1);
1720+
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
1721+
.setStarTreeIndexConfigs(List.of(starTreeIndexConfig))
1722+
.build();
1723+
try {
1724+
TableConfigUtils.validate(tableConfig, schema);
1725+
} catch (Exception e) {
1726+
fail("Should not fail for valid StarTreeIndex config with aggregation config for COUNT on '*' column");
1727+
}
1728+
1729+
starTreeIndexConfig = new StarTreeIndexConfig(List.of("myCol"), null, null,
1730+
List.of(new StarTreeAggregationConfig("*", "SUM")), 1);
1731+
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)
1732+
.setStarTreeIndexConfigs(List.of(starTreeIndexConfig))
1733+
.build();
1734+
try {
1735+
TableConfigUtils.validate(tableConfig, schema);
1736+
fail("Should fail for invalid StarTreeIndex config with aggregation config for SUM on '*' column");
1737+
} catch (Exception e) {
1738+
// expected
1739+
}
1740+
16931741
starTreeIndexConfig =
16941742
new StarTreeIndexConfig(List.of("multiValCol"), List.of("multiValCol"), List.of("SUM__multiValCol"), null, 1);
16951743
tableConfig = new TableConfigBuilder(TableType.OFFLINE).setTableName(TABLE_NAME)

0 commit comments

Comments
 (0)