This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new ed68364086 [Improve][Connector-V2][InfluxDB] Support OptionRule
validation for InfluxDBSinkFactory (#13049)
ed68364086 is described below
commit ed683640863fafd617695061093638636e0b9e0b
Author: erica1111-prog <[email protected]>
AuthorDate: Tue Nov 24 08:23:17 2026 +0000
[Improve][Connector-V2][InfluxDB] Support OptionRule validation for
InfluxDBSinkFactory (#13049)
---
.../influxdb/sink/InfluxDBSinkFactory.java | 4 +
.../seatunnel/influxdb/InfluxDBFactoryTest.java | 119 +++++++++++++++++++++
2 files changed, 123 insertions(+)
diff --git
a/seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkFactory.java
b/seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkFactory.java
index ad2b726155..8c71520fb5 100644
---
a/seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkFactory.java
+++
b/seatunnel-connectors-v2/connector-influxdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/influxdb/sink/InfluxDBSinkFactory.java
@@ -18,6 +18,7 @@
package org.apache.seatunnel.connectors.seatunnel.influxdb.sink;
import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.configuration.util.ConfigValidator;
import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.api.options.SinkConnectorCommonOptions;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
@@ -69,6 +70,9 @@ public class InfluxDBSinkFactory implements TableSinkFactory {
public TableSink createSink(TableSinkFactoryContext context) {
ReadonlyConfig config = context.getOptions();
CatalogTable catalogTable = context.getCatalogTable();
+
+ ConfigValidator.of(config).validate(optionRule());
+
if
(!config.getOptional(InfluxDBSinkOptions.KEY_MEASUREMENT).isPresent()) {
Map<String, String> map = config.toMap();
map.put(
diff --git
a/seatunnel-connectors-v2/connector-influxdb/src/test/java/org/apache/seatunnel/connectors/seatunnel/influxdb/InfluxDBFactoryTest.java
b/seatunnel-connectors-v2/connector-influxdb/src/test/java/org/apache/seatunnel/connectors/seatunnel/influxdb/InfluxDBFactoryTest.java
index 2d0404b8a1..2bd621b8a3 100644
---
a/seatunnel-connectors-v2/connector-influxdb/src/test/java/org/apache/seatunnel/connectors/seatunnel/influxdb/InfluxDBFactoryTest.java
+++
b/seatunnel-connectors-v2/connector-influxdb/src/test/java/org/apache/seatunnel/connectors/seatunnel/influxdb/InfluxDBFactoryTest.java
@@ -17,12 +17,30 @@
package org.apache.seatunnel.connectors.seatunnel.influxdb;
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.configuration.util.ConfigValidator;
+import org.apache.seatunnel.api.configuration.util.OptionValidationException;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.catalog.TableIdentifier;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.connector.TableSink;
+import org.apache.seatunnel.api.table.factory.TableSinkFactoryContext;
+import org.apache.seatunnel.api.table.type.BasicType;
+import
org.apache.seatunnel.connectors.seatunnel.influxdb.config.InfluxDBSinkOptions;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.config.SinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.influxdb.sink.InfluxDBSink;
import
org.apache.seatunnel.connectors.seatunnel.influxdb.sink.InfluxDBSinkFactory;
import
org.apache.seatunnel.connectors.seatunnel.influxdb.source.InfluxDBSourceFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
class InfluxDBFactoryTest {
@Test
@@ -30,4 +48,105 @@ class InfluxDBFactoryTest {
Assertions.assertNotNull((new InfluxDBSourceFactory()).optionRule());
Assertions.assertNotNull((new InfluxDBSinkFactory()).optionRule());
}
+
+ @Test
+ void testSinkOptionRuleSuccess() {
+ Map<String, Object> map = new HashMap<>();
+ map.put(InfluxDBSinkOptions.URL.key(), "http://localhost:8086");
+ map.put(InfluxDBSinkOptions.DATABASES.key(), "test_db");
+ map.put(InfluxDBSinkOptions.USERNAME.key(), "admin");
+ map.put(InfluxDBSinkOptions.PASSWORD.key(), "123456");
+
+ ReadonlyConfig config = ReadonlyConfig.fromMap(map);
+ Assertions.assertDoesNotThrow(
+ () ->
+ ConfigValidator.of(config)
+ .validate((new
InfluxDBSinkFactory()).optionRule()));
+ }
+
+ @Test
+ void testSinkOptionRuleMissingRequired() {
+ Map<String, Object> map = new HashMap<>();
+ map.put(InfluxDBSinkOptions.URL.key(), "http://localhost:8086");
+
+ ReadonlyConfig config = ReadonlyConfig.fromMap(map);
+ Assertions.assertThrows(
+ OptionValidationException.class,
+ () ->
+ ConfigValidator.of(config)
+ .validate((new
InfluxDBSinkFactory()).optionRule()));
+ }
+
+ @Test
+ void testSinkOptionRuleBundledFailed() {
+ Map<String, Object> map = new HashMap<>();
+ map.put(InfluxDBSinkOptions.URL.key(), "http://localhost:8086");
+ map.put(InfluxDBSinkOptions.DATABASES.key(), "test_db");
+ map.put(InfluxDBSinkOptions.USERNAME.key(), "admin");
+
+ ReadonlyConfig config = ReadonlyConfig.fromMap(map);
+ Assertions.assertThrows(
+ OptionValidationException.class,
+ () ->
+ ConfigValidator.of(config)
+ .validate((new
InfluxDBSinkFactory()).optionRule()));
+ }
+
+ @Test
+ void testCreateSinkValidationFailed() {
+ Map<String, Object> map = new HashMap<>();
+ map.put(InfluxDBSinkOptions.URL.key(), "http://localhost:8086");
+ map.put(InfluxDBSinkOptions.DATABASES.key(), "test_db");
+ map.put(InfluxDBSinkOptions.USERNAME.key(), "admin");
+
+ ReadonlyConfig config = ReadonlyConfig.fromMap(map);
+ CatalogTable catalogTable = createMockCatalogTable();
+ TableSinkFactoryContext context =
+ new TableSinkFactoryContext(
+ catalogTable, config,
Thread.currentThread().getContextClassLoader());
+
+ InfluxDBSinkFactory factory = new InfluxDBSinkFactory();
+ Assertions.assertThrows(OptionValidationException.class, () ->
factory.createSink(context));
+ }
+
+ @Test
+ void testCreateSinkWithDefaultMeasurementSuccess() throws Exception {
+ Map<String, Object> map = new HashMap<>();
+ map.put(InfluxDBSinkOptions.URL.key(), "http://localhost:8086");
+ map.put(InfluxDBSinkOptions.DATABASES.key(), "test_db");
+
+ ReadonlyConfig config = ReadonlyConfig.fromMap(map);
+ CatalogTable catalogTable = createMockCatalogTable();
+ TableSinkFactoryContext context =
+ new TableSinkFactoryContext(
+ catalogTable, config,
Thread.currentThread().getContextClassLoader());
+
+ InfluxDBSinkFactory factory = new InfluxDBSinkFactory();
+ TableSink<?, ?, ?, ?> tableSink =
+ Assertions.assertDoesNotThrow(() ->
factory.createSink(context));
+ Assertions.assertNotNull(tableSink);
+
+ InfluxDBSink influxDBSink = (InfluxDBSink) tableSink.createSink();
+ Field sinkConfigField =
InfluxDBSink.class.getDeclaredField("sinkConfig");
+ sinkConfigField.setAccessible(true);
+ SinkConfig sinkConfig = (SinkConfig) sinkConfigField.get(influxDBSink);
+
+ Assertions.assertEquals(
+ catalogTable.getTableId().toTablePath().getFullName(),
sinkConfig.getMeasurement());
+ }
+
+ private CatalogTable createMockCatalogTable() {
+ TableSchema tableSchema =
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.of(
+ "id", BasicType.INT_TYPE, (Long) null,
true, null, null))
+ .build();
+ return CatalogTable.of(
+ TableIdentifier.of("default", "default_db",
"test_measurement"),
+ tableSchema,
+ Collections.emptyMap(),
+ Collections.emptyList(),
+ "");
+ }
}