This is an automated email from the ASF dual-hosted git repository.
jerryshao pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/branch-1.3 by this push:
new 68b93801d8 [Cherry-pick to branch-1.3] [#14576] fix(kafka): map
invalid partition counts to argument errors (#14577) (#14605)
68b93801d8 is described below
commit 68b93801d8418bcd77d2dc418ebbba4ee3307814
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Nov 4 19:24:13 2026 +0800
[Cherry-pick to branch-1.3] [#14576] fix(kafka): map invalid partition
counts to argument errors (#14577) (#14605)
**Cherry-pick Information:**
- Original commit: a25d7e7555b23dfda81f911923e5dc41a811457c
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)
Co-authored-by: mchades <[email protected]>
---
.../catalog/kafka/KafkaCatalogOperations.java | 4 ++
.../catalog/kafka/TestKafkaCatalogOperations.java | 60 ++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git
a/catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java
b/catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java
index 85a5feaa29..f234d44fad 100644
---
a/catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java
+++
b/catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java
@@ -86,6 +86,7 @@ import org.apache.kafka.common.Uuid;
import org.apache.kafka.common.config.ConfigException;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.errors.InvalidConfigurationException;
+import org.apache.kafka.common.errors.InvalidPartitionsException;
import org.apache.kafka.common.errors.InvalidReplicationFactorException;
import org.apache.kafka.common.errors.TopicExistsException;
import org.apache.kafka.common.errors.UnknownTopicOrPartitionException;
@@ -292,6 +293,9 @@ public class KafkaCatalogOperations implements
CatalogOperations, SupportsSchema
if (e.getCause() instanceof TopicExistsException) {
throw new TopicAlreadyExistsException(e, "Topic %s already exists",
ident);
+ } else if (e.getCause() instanceof InvalidPartitionsException) {
+ throw ExceptionMessages.illegalArgument("Invalid partition count for
topic " + ident, e);
+
} else if (e.getCause() instanceof InvalidReplicationFactorException) {
throw ExceptionMessages.illegalArgument("Invalid replication factor
for topic " + ident, e);
diff --git
a/catalogs/catalog-kafka/src/test/java/org/apache/gravitino/catalog/kafka/TestKafkaCatalogOperations.java
b/catalogs/catalog-kafka/src/test/java/org/apache/gravitino/catalog/kafka/TestKafkaCatalogOperations.java
index ff492a17ff..f635ebb0bd 100644
---
a/catalogs/catalog-kafka/src/test/java/org/apache/gravitino/catalog/kafka/TestKafkaCatalogOperations.java
+++
b/catalogs/catalog-kafka/src/test/java/org/apache/gravitino/catalog/kafka/TestKafkaCatalogOperations.java
@@ -84,6 +84,7 @@ import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.ListTopicsResult;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.config.TopicConfig;
+import org.apache.kafka.common.errors.InvalidPartitionsException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
@@ -441,6 +442,65 @@ public class TestKafkaCatalogOperations extends
KafkaClusterEmbedded {
exception.getMessage());
}
+ @Test
+ void testCreateTopicWithInvalidPartitionCount() {
+ for (String partitionCount : new String[] {"0", "-2"}) {
+ NameIdentifier ident =
+ NameIdentifier.of(
+ METALAKE_NAME,
+ CATALOG_NAME,
+ DEFAULT_SCHEMA_NAME,
+ "test_create_topic_invalid_partitions_" + partitionCount);
+ Map<String, String> properties =
+ ImmutableMap.of(PARTITION_COUNT, partitionCount, REPLICATION_FACTOR,
"1");
+
+ IllegalArgumentException exception =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> kafkaCatalogOperations.createTopic(ident, null, null,
properties));
+ Assertions.assertTrue(
+ exception.getMessage().contains("Invalid partition count for topic "
+ ident),
+ exception.getMessage());
+ Throwable cause = exception.getCause().getCause();
+ Assertions.assertInstanceOf(InvalidPartitionsException.class, cause);
+
Assertions.assertTrue(exception.getMessage().contains(cause.getMessage()));
+ }
+ }
+
+ @Test
+ void testCreateTopicWithDefaultPartitionCount() {
+ NameIdentifier defaultIdent =
+ NameIdentifier.of(
+ METALAKE_NAME,
+ CATALOG_NAME,
+ DEFAULT_SCHEMA_NAME,
+ "test_create_topic_default_partitions");
+ Topic defaultTopic =
+ kafkaCatalogOperations.createTopic(
+ defaultIdent, null, null, ImmutableMap.of(REPLICATION_FACTOR,
"1"));
+
+ NameIdentifier negativeOneIdent =
+ NameIdentifier.of(
+ METALAKE_NAME,
+ CATALOG_NAME,
+ DEFAULT_SCHEMA_NAME,
+ "test_create_topic_negative_one_partitions");
+ Topic negativeOneTopic =
+ kafkaCatalogOperations.createTopic(
+ negativeOneIdent,
+ null,
+ null,
+ ImmutableMap.of(PARTITION_COUNT, "-1", REPLICATION_FACTOR, "1"));
+
+ String defaultPartitionCount =
defaultTopic.properties().get(PARTITION_COUNT);
+ Assertions.assertTrue(Integer.parseInt(defaultPartitionCount) > 0);
+ Assertions.assertEquals(
+ defaultPartitionCount,
negativeOneTopic.properties().get(PARTITION_COUNT));
+ Assertions.assertEquals(
+ defaultPartitionCount,
+
kafkaCatalogOperations.loadTopic(negativeOneIdent).properties().get(PARTITION_COUNT));
+ }
+
@Test
public void testLoadTopic() {
Topic topic =