xiangfu0 commented on code in PR #18411: URL: https://github.com/apache/pinot/pull/18411#discussion_r3185126696
########## pinot-controller/src/test/java/org/apache/pinot/controller/api/resources/DeprecatedTableConfigValidationUtilsTest.java: ########## @@ -0,0 +1,63 @@ +/** + * 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.pinot.controller.api.resources; + +import com.fasterxml.jackson.databind.JsonNode; +import org.apache.pinot.spi.utils.JsonUtils; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.expectThrows; + + +public class DeprecatedTableConfigValidationUtilsTest { + + @Test + public void testRejectsDeprecatedConfigsWithArrayAndMapPaths() + throws Exception { + JsonNode tableConfigJson = JsonUtils.stringToJsonNode("{" + + "\"segmentsConfig\":{\"segmentPushType\":\"APPEND\",\"minimizeDataMovement\":false}," + + "\"tableIndexConfig\":{\"createInvertedIndexDuringSegmentGeneration\":false}," + + "\"fieldConfigList\":[{\"name\":\"c1\",\"indexType\":\"INVERTED\"}]," + + "\"instanceAssignmentConfigMap\":{\"CONSUMING\":{\"replicaGroupPartitionConfig\":" + + "{\"minimizeDataMovement\":false}}}}"); + + IllegalStateException e = expectThrows(IllegalStateException.class, + () -> DeprecatedTableConfigValidationUtils.validateNoDeprecatedConfigs(tableConfigJson, "realtime")); + assertTrue(e.getMessage().contains("realtime.segmentsConfig.segmentPushType")); + assertTrue(e.getMessage().contains("realtime.segmentsConfig.minimizeDataMovement")); + assertTrue(e.getMessage().contains("realtime.tableIndexConfig.createInvertedIndexDuringSegmentGeneration")); + assertTrue(e.getMessage().contains("realtime.fieldConfigList[0].indexType")); + assertTrue( + e.getMessage().contains("realtime.instanceAssignmentConfigMap.CONSUMING.replicaGroupPartitionConfig" + + ".minimizeDataMovement")); Review Comment: Addressed in df5e6363b3. The whole rule list is now annotation-driven (`@DeprecatedConfig` on getters), so the test reads the discovered rules back out of `DeprecatedTableConfigValidationUtils.rulesForTesting()` and runs a parameterized `testEveryRuleFiresOnSyntheticInput` via TestNG `@DataProvider`. Coverage tracks the rule list 1:1 — adding a new `@DeprecatedConfig` automatically gets a test case without editing this file. Currently 16 rule cases × 1 assertion each, all green. ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/DeprecatedTableConfigValidationUtils.java: ########## @@ -0,0 +1,137 @@ +/** + * 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.pinot.controller.api.resources; + +import com.fasterxml.jackson.databind.JsonNode; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Nullable; + + +/** + * Validates raw table-config JSON for deprecated properties that must not be accepted on table creation paths. + * + * <p>This utility operates on the input JSON instead of the deserialized {@code TableConfig} so it can reject + * explicitly provided deprecated keys even when they carry default or false-y values.</p> + */ +public final class DeprecatedTableConfigValidationUtils { + private DeprecatedTableConfigValidationUtils() { + } + + private static final String WILDCARD = "*"; + + private static final List<DeprecatedConfigRule> DEPRECATED_CONFIG_RULES = List.of( + new DeprecatedConfigRule("Use 'ingestionConfig.batchIngestionConfig.segmentIngestionFrequency' instead.", + "segmentsConfig", "segmentPushFrequency"), + new DeprecatedConfigRule("Use 'ingestionConfig.batchIngestionConfig.segmentIngestionType' instead.", + "segmentsConfig", "segmentPushType"), + new DeprecatedConfigRule("Use 'segmentsConfig.replication' instead.", "segmentsConfig", "replicasPerPartition"), + new DeprecatedConfigRule("Use 'segmentAssignmentConfigMap' instead.", "segmentsConfig", + "segmentAssignmentStrategy"), + new DeprecatedConfigRule("Use 'segmentAssignmentConfigMap' instead.", "segmentsConfig", + "replicaGroupStrategyConfig"), + new DeprecatedConfigRule("Use 'instanceAssignmentConfigMap' instead.", "segmentsConfig", "minimizeDataMovement"), + new DeprecatedConfigRule("Use 'ingestionConfig.streamIngestionConfig.streamConfigMaps' instead.", + "tableIndexConfig", "streamConfigs"), + new DeprecatedConfigRule("Use 'tableIndexConfig.jsonIndexConfigs' instead.", "tableIndexConfig", + "jsonIndexColumns"), + new DeprecatedConfigRule("Remove this field; it is ignored.", "tableIndexConfig", + "createInvertedIndexDuringSegmentGeneration"), + new DeprecatedConfigRule("Use 'routing.segmentPrunerTypes' and 'routing.instanceSelectorType' instead.", + "routing", "routingTableBuilderName"), + new DeprecatedConfigRule("Use 'fieldConfigList[].indexTypes' instead.", "fieldConfigList", WILDCARD, + "indexType"), + new DeprecatedConfigRule("Use 'upsertConfig.snapshot' instead.", "upsertConfig", "enableSnapshot"), + new DeprecatedConfigRule("Use 'upsertConfig.preload' instead.", "upsertConfig", "enablePreload"), + new DeprecatedConfigRule( + "Use 'ingestionConfig.streamIngestionConfig.parallelSegmentConsumptionPolicy' instead.", + "upsertConfig", "allowPartialUpsertConsumptionDuringCommit"), + new DeprecatedConfigRule("Use 'dedupConfig.preload' instead.", "dedupConfig", "enablePreload"), + new DeprecatedConfigRule( + "Use 'ingestionConfig.streamIngestionConfig.parallelSegmentConsumptionPolicy' instead.", + "dedupConfig", "allowDedupConsumptionDuringCommit"), + new DeprecatedConfigRule("Remove this field; it will be removed in a future release.", + "instanceAssignmentConfigMap", WILDCARD, "replicaGroupPartitionConfig", "minimizeDataMovement")); + + public static void validateNoDeprecatedConfigs(JsonNode tableConfigJson) { + validateNoDeprecatedConfigs(tableConfigJson, null); + } + + public static void validateNoDeprecatedConfigs(JsonNode tableConfigJson, @Nullable String rootPathPrefix) { + List<String> violations = new ArrayList<>(); + for (DeprecatedConfigRule deprecatedConfigRule : DEPRECATED_CONFIG_RULES) { + deprecatedConfigRule.collectMatches(tableConfigJson, rootPathPrefix, violations); + } + if (!violations.isEmpty()) { + throw new IllegalStateException( Review Comment: Fixed in fbc259ab81 — `validateOnCreate` and `validateOnUpdate` both now throw `IllegalArgumentException` (was `IllegalStateException` in the original commit). Caller-side rewrap in the controller is unchanged. -- 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]
