Copilot commented on code in PR #14977:
URL: https://github.com/apache/gravitino/pull/14977#discussion_r4579774784


##########
catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java:
##########
@@ -460,6 +496,47 @@ public void close() throws IOException {
     }
   }
 
+  @VisibleForTesting
+  Map<String, String> enrichTableTopicLinkageProperties(
+      String topicName, Map<String, String> rawProperties) {
+    Map<String, String> enriched =
+        rawProperties == null ? Maps.newHashMap() : 
Maps.newHashMap(rawProperties);
+    
enriched.keySet().removeAll(KafkaTopicPropertiesMetadata.RESERVED_TABLE_TOPIC_LINKAGE_KEYS);
+
+    String enabled = 
enriched.get(KafkaTopicPropertiesMetadata.AUTOMQ_TABLE_TOPIC_ENABLE);
+    if (enabled == null || !"true".equalsIgnoreCase(enabled.trim())) {
+      return enriched;
+    }
+
+    String namespace = 
enriched.get(KafkaTopicPropertiesMetadata.AUTOMQ_TABLE_TOPIC_NAMESPACE);
+    if (namespace == null || namespace.trim().isEmpty()) {
+      namespace = 
catalogConfig.get(KafkaCatalogPropertiesMetadata.TABLE_TOPIC_DEFAULT_NAMESPACE);
+    }
+    if (namespace == null || namespace.trim().isEmpty()) {
+      namespace = "default";
+    } else {
+      namespace = namespace.trim();
+    }
+
+    String icebergCatalog =
+        
catalogConfig.get(KafkaCatalogPropertiesMetadata.TABLE_TOPIC_ICEBERG_CATALOG);
+    enriched.put(KafkaTopicPropertiesMetadata.TABLE_TOPIC_ENABLED, "true");
+    enriched.put(KafkaTopicPropertiesMetadata.TABLE_TOPIC_ICEBERG_NAMESPACE, 
namespace);
+    enriched.put(KafkaTopicPropertiesMetadata.TABLE_TOPIC_ICEBERG_TABLE, 
topicName);
+
+    if (icebergCatalog != null && !icebergCatalog.trim().isEmpty()) {
+      String trimmedCatalog = icebergCatalog.trim();
+      enriched.put(KafkaTopicPropertiesMetadata.TABLE_TOPIC_ICEBERG_CATALOG, 
trimmedCatalog);
+      enriched.put(
+          KafkaTopicPropertiesMetadata.TABLE_TOPIC_ICEBERG_IDENT,
+          trimmedCatalog + "." + namespace + "." + topicName);

Review Comment:
   Issue #14969 requires 
`<metalake>.<iceberg_catalog>.<namespace>.<topic_name>`, but this identifier 
omits the metalake even when the target catalog is configured. It therefore 
does not provide the requested full Gravitino table identifier. Include 
`info.namespace().level(0)` and align the MCP fallback in 
`mcp-server/mcp_server/tools/topic.py:277–281`, documentation, and test 
expectations with that format.



##########
catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaCatalogOperations.java:
##########
@@ -460,6 +496,47 @@ public void close() throws IOException {
     }
   }
 
+  @VisibleForTesting
+  Map<String, String> enrichTableTopicLinkageProperties(
+      String topicName, Map<String, String> rawProperties) {
+    Map<String, String> enriched =
+        rawProperties == null ? Maps.newHashMap() : 
Maps.newHashMap(rawProperties);
+    
enriched.keySet().removeAll(KafkaTopicPropertiesMetadata.RESERVED_TABLE_TOPIC_LINKAGE_KEYS);
+
+    String enabled = 
enriched.get(KafkaTopicPropertiesMetadata.AUTOMQ_TABLE_TOPIC_ENABLE);
+    if (enabled == null || !"true".equalsIgnoreCase(enabled.trim())) {
+      return enriched;
+    }
+
+    String namespace = 
enriched.get(KafkaTopicPropertiesMetadata.AUTOMQ_TABLE_TOPIC_NAMESPACE);
+    if (namespace == null || namespace.trim().isEmpty()) {
+      namespace = 
catalogConfig.get(KafkaCatalogPropertiesMetadata.TABLE_TOPIC_DEFAULT_NAMESPACE);
+    }

Review Comment:
   The catalog default namespace affects only the returned linkage, not the 
configuration sent to AutoMQ. With `table-topic.default-namespace=analytics` 
and no topic namespace, the broker is not configured to use `analytics`, so the 
reported linkage can point to the wrong table. Apply the fallback to 
`automq.table.topic.namespace` when creating/enabling a Table Topic, and derive 
loaded and post-alter linkage from the effective broker configuration.



##########
catalogs/catalog-kafka/src/main/java/org/apache/gravitino/catalog/kafka/KafkaTopicPropertiesMetadata.java:
##########
@@ -19,42 +19,363 @@
 package org.apache.gravitino.catalog.kafka;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 import org.apache.gravitino.connector.BasePropertiesMetadata;
 import org.apache.gravitino.connector.PropertyEntry;
 
+/** Property definitions and Table Topic validation rules for Kafka catalog 
topics. */
 public class KafkaTopicPropertiesMetadata extends BasePropertiesMetadata {
+  /** Number of partitions configured for the topic. */
   public static final String PARTITION_COUNT = "partition-count";
+
+  /** Replication factor configured for the topic. */
   public static final String REPLICATION_FACTOR = "replication-factor";
 
+  /** Persisted AutoMQ Table Topic enablement flag. */
+  public static final String AUTOMQ_TABLE_TOPIC_ENABLE = 
"automq.table.topic.enable";
+
+  /** AutoMQ Table Topic Iceberg commit interval in milliseconds. */
+  public static final String AUTOMQ_TABLE_TOPIC_COMMIT_INTERVAL_MS =
+      "automq.table.topic.commit.interval.ms";
+
+  /** Target Iceberg namespace (schema) configured on the AutoMQ Table Topic. 
*/
+  public static final String AUTOMQ_TABLE_TOPIC_NAMESPACE = 
"automq.table.topic.namespace";
+
+  /** AutoMQ Table Topic schema evolution mode. */
+  public static final String AUTOMQ_TABLE_TOPIC_SCHEMA_TYPE = 
"automq.table.topic.schema.type";
+
+  /** Comma-separated primary key column names for Iceberg equality deletes 
and upserts. */
+  public static final String AUTOMQ_TABLE_TOPIC_ID_COLUMNS = 
"automq.table.topic.id.columns";
+
+  /** Iceberg partition transform expressions for the materialized Table 
Topic. */
+  public static final String AUTOMQ_TABLE_TOPIC_PARTITION_BY = 
"automq.table.topic.partition.by";
+
+  /** AutoMQ Table Topic upsert enablement flag. */
+  public static final String AUTOMQ_TABLE_TOPIC_UPSERT_ENABLE = 
"automq.table.topic.upsert.enable";
+
+  /** Field name carrying the CDC operation code for AutoMQ Table Topic 
materialization. */
+  public static final String AUTOMQ_TABLE_TOPIC_CDC_FIELD = 
"automq.table.topic.cdc.field";
+
+  /** Deserialization error tolerance policy for AutoMQ Table Topic ingestion. 
*/
+  public static final String AUTOMQ_TABLE_TOPIC_ERRORS_TOLERANCE =
+      "automq.table.topic.errors.tolerance";
+
+  /** Synthetic read-only property indicating whether Table Topic 
materialization is enabled. */
+  public static final String TABLE_TOPIC_ENABLED = "table-topic.enabled";
+
+  /** Synthetic read-only property carrying the linked Iceberg catalog name. */
+  public static final String TABLE_TOPIC_ICEBERG_CATALOG = 
"table-topic.iceberg-catalog";
+
+  /** Synthetic read-only property carrying the resolved target Iceberg 
namespace. */
+  public static final String TABLE_TOPIC_ICEBERG_NAMESPACE = 
"table-topic.iceberg-namespace";
+
+  /** Synthetic read-only property carrying the target Iceberg table name. */
+  public static final String TABLE_TOPIC_ICEBERG_TABLE = 
"table-topic.iceberg-table";
+
+  /** Synthetic read-only property carrying the qualified linked Iceberg table 
identifier. */
+  public static final String TABLE_TOPIC_ICEBERG_IDENT = 
"table-topic.iceberg-ident";
+
+  /** Set of synthetic read-only Table Topic linkage keys managed by 
Gravitino. */
+  public static final Set<String> RESERVED_TABLE_TOPIC_LINKAGE_KEYS =
+      ImmutableSet.of(
+          TABLE_TOPIC_ENABLED,
+          TABLE_TOPIC_ICEBERG_CATALOG,
+          TABLE_TOPIC_ICEBERG_NAMESPACE,
+          TABLE_TOPIC_ICEBERG_TABLE,
+          TABLE_TOPIC_ICEBERG_IDENT);
+
+  /** Supported AutoMQ Table Topic schema evolution modes. */
+  public enum TableTopicSchemaType {
+    /** Schemaless payload ingestion without external schema registry 
enforcement. */
+    SCHEMALESS,
+    /** Schema-driven ingestion derived from attached record schemas. */
+    SCHEMA,
+    /** Subject naming strategy based on the record name. */
+    RECORD_NAME,
+    /** Subject naming strategy based on the topic name. */
+    TOPIC_NAME
+  }
+
+  /** Supported AutoMQ Table Topic deserialization error tolerance policies. */
+  public enum TableTopicErrorsTolerance {
+    /** Fail immediately on record conversion errors. */
+    NONE,
+    /** Tolerate and skip invalid records during ingestion. */
+    ALL
+  }
+
   private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;
 
   static {
     List<PropertyEntry<?>> propertyEntries =
-        ImmutableList.of(
-            PropertyEntry.integerOptionalPropertyEntry(
-                PARTITION_COUNT,
-                "The number of partitions for the topic, if not specified, "
-                    + "will use the num.partitions property in the broker",
-                false /* immutable */,
-                null /* default value */,
-                false /* hidden */),
-            // TODO: make REPLICATION_FACTOR mutable if needed
-            PropertyEntry.shortOptionalPropertyEntry(
-                REPLICATION_FACTOR,
-                "The number of replications for the topic, if not specified, "
-                    + "will use the default.replication.factor property in the 
broker",
-                true /* immutable */,
-                null /* default value */,
-                false /* hidden */));
+        ImmutableList.<PropertyEntry<?>>builder()
+            .add(
+                PropertyEntry.integerOptionalPropertyEntry(
+                    PARTITION_COUNT,
+                    "The number of partitions for the topic, if not specified, 
"
+                        + "will use the num.partitions property in the broker",
+                    false /* immutable */,
+                    null /* default value */,
+                    false /* hidden */),
+                // TODO: make REPLICATION_FACTOR mutable if needed
+                PropertyEntry.shortOptionalPropertyEntry(
+                    REPLICATION_FACTOR,
+                    "The number of replications for the topic, if not 
specified, "
+                        + "will use the default.replication.factor property in 
the broker",
+                    true /* immutable */,
+                    null /* default value */,
+                    false /* hidden */),
+                strictBooleanPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_ENABLE,
+                    "Whether to materialize this Kafka topic as an AutoMQ 
Table Topic in Iceberg"),
+                positiveLongPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_COMMIT_INTERVAL_MS,
+                    "Commit interval in milliseconds for materializing AutoMQ 
Table Topic records"),
+                nonBlankStringPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_NAMESPACE,
+                    "Target Iceberg namespace (schema) for the materialized 
AutoMQ Table Topic"),
+                PropertyEntry.enumPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_SCHEMA_TYPE,
+                    "Schema mode for AutoMQ Table Topic conversion 
(schemaless, schema,"
+                        + " record_name, or topic_name)",
+                    false /* required */,
+                    false /* immutable */,
+                    TableTopicSchemaType.class,
+                    null /* default value */,
+                    false /* hidden */,
+                    false /* reserved */),
+                columnListPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_ID_COLUMNS,
+                    "Comma-separated primary key column names for Iceberg 
equality deletes and"
+                        + " upserts"),
+                nonBlankStringPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_PARTITION_BY,
+                    "Iceberg partition transform expressions for the 
materialized Table Topic"),
+                strictBooleanPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_UPSERT_ENABLE,
+                    "Whether upsert mode is enabled for the materialized 
AutoMQ Table Topic"),
+                nonBlankStringPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_CDC_FIELD,
+                    "Field name carrying the CDC operation code for AutoMQ 
Table Topic"
+                        + " materialization"),
+                PropertyEntry.enumPropertyEntry(
+                    AUTOMQ_TABLE_TOPIC_ERRORS_TOLERANCE,
+                    "Error tolerance policy when converting records for an 
AutoMQ Table Topic"
+                        + " (none or all)",
+                    false /* required */,
+                    false /* immutable */,
+                    TableTopicErrorsTolerance.class,
+                    null /* default value */,
+                    false /* hidden */,
+                    false /* reserved */),
+                PropertyEntry.stringReservedPropertyEntry(
+                    TABLE_TOPIC_ENABLED,
+                    "Synthetic read-only flag indicating whether AutoMQ Table 
Topic"
+                        + " materialization is enabled",
+                    false /* hidden */),
+                PropertyEntry.stringReservedPropertyEntry(
+                    TABLE_TOPIC_ICEBERG_CATALOG,
+                    "Synthetic read-only name of the linked Iceberg catalog 
configured on the"
+                        + " Kafka catalog",
+                    false /* hidden */),
+                PropertyEntry.stringReservedPropertyEntry(
+                    TABLE_TOPIC_ICEBERG_NAMESPACE,
+                    "Synthetic read-only Iceberg namespace resolved for the 
Table Topic",
+                    false /* hidden */),
+                PropertyEntry.stringReservedPropertyEntry(
+                    TABLE_TOPIC_ICEBERG_TABLE,
+                    "Synthetic read-only Iceberg table name linked to the 
Table Topic",
+                    false /* hidden */),
+                PropertyEntry.stringReservedPropertyEntry(
+                    TABLE_TOPIC_ICEBERG_IDENT,
+                    "Synthetic read-only qualified Iceberg identifier linked 
to the Table Topic",
+                    false /* hidden */))
+            .build();
 
     PROPERTIES_METADATA = Maps.uniqueIndex(propertyEntries, 
PropertyEntry::getName);
   }
 
+  /**
+   * Validates AutoMQ Table Topic property values and cross-property 
constraints.
+   *
+   * @param properties topic properties to validate; null or empty maps are 
accepted as no-ops
+   */
+  public static void validateTableTopicProperties(Map<String, String> 
properties) {
+    if (properties == null || properties.isEmpty()) {
+      return;
+    }
+
+    for (Map.Entry<String, String> entry : properties.entrySet()) {
+      String key = entry.getKey();
+      if (RESERVED_TABLE_TOPIC_LINKAGE_KEYS.contains(key)) {
+        continue;
+      }
+      PropertyEntry<?> propertyEntry = PROPERTIES_METADATA.get(key);
+      if (propertyEntry != null && key.startsWith("automq.table.topic.")) {
+        propertyEntry.decode(entry.getValue());
+      }
+    }
+
+    String tableTopicEnable = properties.get(AUTOMQ_TABLE_TOPIC_ENABLE);
+    boolean tableTopicDisabled =
+        tableTopicEnable != null && 
"false".equalsIgnoreCase(tableTopicEnable.trim());

Review Comment:
   An absent enable flag is treated as enabled for this constraint, although 
linkage enrichment treats it as disabled. After removing 
`automq.table.topic.enable` and `id.columns` while leaving 
`upsert.enable=true`, a subsequent unrelated alteration fails because the 
temporary validation override protects only the removal request. Treat an 
absent enable flag as disabled consistently so the resulting topic remains 
alterable.



-- 
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]

Reply via email to