You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by gi...@apache.org on 2026/08/30 16:28:32 UTC
(seatunnel) branch gh-readonly-queue/dev/pr-11865-a01f5f03e7d9ab93b814e8ab10ba7d37a0d1c618 created (now 9f229ce3e7)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/dev/pr-11865-a01f5f03e7d9ab93b814e8ab10ba7d37a0d1c618
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
at 9f229ce3e7 [Feature] [Connector-V2] [NebulaGraph] Add vertex sink connector (#11865)
This branch includes the following new commits:
new 9f229ce3e7 [Feature] [Connector-V2] [NebulaGraph] Add vertex sink connector (#11865)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(seatunnel) 01/01: [Feature] [Connector-V2] [NebulaGraph] Add vertex sink connector (#11865)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/dev/pr-11865-a01f5f03e7d9ab93b814e8ab10ba7d37a0d1c618
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit 9f229ce3e7f3a2e039fb9e83291d3e171dcf7db9
Author: Goutam Adwant <86...@users.noreply.github.com>
AuthorDate: Sun Aug 30 16:28:21 2026 +0000
[Feature] [Connector-V2] [NebulaGraph] Add vertex sink connector (#11865)
Signed-off-by: goutamadwant <wo...@gmail.com>
---
.github/workflows/labeler/label-scope-conf.yml | 7 +
config/plugin_config | 1 +
.../connectors/changelog/connector-nebulagraph.md | 11 +
docs/en/connectors/sink/NebulaGraph.md | 127 +++++++++++
.../connectors/changelog/connector-nebulagraph.md | 11 +
docs/zh/connectors/sink/NebulaGraph.md | 127 +++++++++++
plugin-mapping.properties | 1 +
.../connector-nebulagraph/pom.xml | 92 ++++++++
.../nebulagraph/client/NebulaGraphClient.java | 27 +++
.../client/SessionPoolNebulaGraphClient.java | 84 ++++++++
.../nebulagraph/config/NebulaGraphSinkConfig.java | 235 +++++++++++++++++++++
.../nebulagraph/config/NebulaGraphSinkOptions.java | 107 ++++++++++
.../nebulagraph/config/NebulaGraphWriteMode.java | 23 ++
.../exception/NebulaGraphConnectorErrorCode.java | 45 ++++
.../exception/NebulaGraphConnectorException.java | 32 +++
.../nebulagraph/sink/NebulaGraphRowConverter.java | 209 ++++++++++++++++++
.../nebulagraph/sink/NebulaGraphSink.java | 56 +++++
.../nebulagraph/sink/NebulaGraphSinkFactory.java | 63 ++++++
.../nebulagraph/sink/NebulaGraphSinkWriter.java | 162 ++++++++++++++
.../sink/NebulaGraphStatementBuilder.java | 173 +++++++++++++++
.../nebulagraph/sink/NebulaGraphVertex.java | 41 ++++
.../nebulagraph/sink/NebulaGraphWriteRequest.java | 41 ++++
.../client/SessionPoolNebulaGraphClientTest.java | 52 +++++
.../config/NebulaGraphSinkConfigTest.java | 112 ++++++++++
.../sink/NebulaGraphSinkWriterTest.java | 187 ++++++++++++++++
.../sink/NebulaGraphStatementBuilderTest.java | 121 +++++++++++
seatunnel-connectors-v2/pom.xml | 1 +
seatunnel-dist/pom.xml | 6 +
seatunnel-dist/release-docs/LICENSE | 2 +
.../connector-nebulagraph-e2e/pom.xml | 58 +++++
.../e2e/connector/nebulagraph/NebulaGraphIT.java | 201 ++++++++++++++++++
.../nebulagraph/fake_to_nebulagraph_insert.conf | 65 ++++++
.../nebulagraph/fake_to_nebulagraph_update.conf | 57 +++++
seatunnel-e2e/seatunnel-connector-v2-e2e/pom.xml | 1 +
34 files changed, 2538 insertions(+)
diff --git a/.github/workflows/labeler/label-scope-conf.yml b/.github/workflows/labeler/label-scope-conf.yml
index 54c0f3db0a..f405ddbf5e 100644
--- a/.github/workflows/labeler/label-scope-conf.yml
+++ b/.github/workflows/labeler/label-scope-conf.yml
@@ -254,6 +254,13 @@ neo4j:
- changed-files:
- any-glob-to-any-file: seatunnel-connectors-v2/connector-neo4j/**
- all-globs-to-all-files: '!seatunnel-connectors-v2/connector-!(neo4j)/**'
+nebulagraph:
+ - all:
+ - changed-files:
+ - any-glob-to-any-file:
+ - seatunnel-connectors-v2/connector-nebulagraph/**
+ - seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/**
+ - all-globs-to-all-files: '!seatunnel-connectors-v2/connector-!(nebulagraph)/**'
openmldb:
- all:
- changed-files:
diff --git a/config/plugin_config b/config/plugin_config
index 875e405d46..55b27d764e 100644
--- a/config/plugin_config
+++ b/config/plugin_config
@@ -79,6 +79,7 @@ connector-kudu
connector-maxcompute
connector-couchbase
connector-mongodb
+connector-nebulagraph
connector-neo4j
connector-openmldb
connector-pulsar
diff --git a/docs/en/connectors/changelog/connector-nebulagraph.md b/docs/en/connectors/changelog/connector-nebulagraph.md
new file mode 100644
index 0000000000..d2eeeabc9e
--- /dev/null
+++ b/docs/en/connectors/changelog/connector-nebulagraph.md
@@ -0,0 +1,11 @@
+---
+title: NebulaGraph
+---
+
+<details><summary> Change Log </summary>
+
+| Change | Commit | Version |
+|--------|--------|---------|
+| [Feature][Connector-V2] Add NebulaGraph vertex sink | - | Next |
+
+</details>
diff --git a/docs/en/connectors/sink/NebulaGraph.md b/docs/en/connectors/sink/NebulaGraph.md
new file mode 100644
index 0000000000..2c043d051a
--- /dev/null
+++ b/docs/en/connectors/sink/NebulaGraph.md
@@ -0,0 +1,127 @@
+import ChangeLog from '../changelog/connector-nebulagraph.md';
+
+# NebulaGraph
+
+> NebulaGraph sink connector
+
+## Support Those Engines
+
+> Spark<br/>
+> Flink<br/>
+> SeaTunnel Zeta<br/>
+
+## Description
+
+The NebulaGraph sink writes SeaTunnel rows as vertices under one existing tag. This first connector scope supports NebulaGraph 3.5 or later because it uses parameterized DML, which was introduced in NebulaGraph 3.5.
+
+The target space and tag must exist before the job starts. Source reads, edge writes, schema creation, and delete handling are not included in this version.
+
+## Key Features
+
+- [x] [batch](../../introduction/concepts/connector-v2-features.md)
+- [ ] [exactly-once](../../introduction/concepts/connector-v2-features.md)
+- [ ] [cdc](../../introduction/concepts/connector-v2-features.md)
+- [ ] [support multiple table write](../../introduction/concepts/connector-v2-features.md)
+
+## Options
+
+| name | type | required | default value | description |
+|------|------|----------|---------------|-------------|
+| hosts | list | yes | - | NebulaGraph graphd addresses in `host:port` form. Bracketed IPv6 addresses are also supported. |
+| username | string | yes | - | NebulaGraph username. |
+| password | string | yes | - | NebulaGraph password. |
+| space | string | yes | - | Existing NebulaGraph space. |
+| tag | string | yes | - | Existing vertex tag. |
+| vid_field | string | yes | - | Input field used as the vertex ID. |
+| write_fields | list | no | all fields except `vid_field` | Input fields written as tag properties. |
+| write_mode | enum | no | `INSERT` | `INSERT` or `UPDATE`. |
+| batch_size | int | no | 500 | Number of vertices in each nGQL request. |
+| timeout_millis | int | no | 30000 | Connection, socket, and session wait timeout in milliseconds. |
+| max_retries | int | no | 0 | Retries after the initial write attempt. |
+| retry_interval_millis | int | no | 1000 | Delay between retries in milliseconds. |
+| common-options | | no | - | Sink common options. |
+
+### write_mode [enum]
+
+- `INSERT` accepts only `INSERT` rows and sends `INSERT VERTEX IF NOT EXISTS`. A replay does not overwrite an existing vertex.
+- `UPDATE` accepts `INSERT` and `UPDATE_AFTER` rows, ignores `UPDATE_BEFORE`, and sends `UPDATE VERTEX`. The vertex must already exist.
+
+`DELETE` rows are rejected in both modes.
+
+### common options
+
+Sink plugin common parameters, see [Sink Common Options](../common-options/sink-common-options.md) for details.
+
+## Supported Types
+
+The vertex ID may be a `STRING`, `TINYINT`, `SMALLINT`, `INT`, or `BIGINT`. It must not be null.
+
+| SeaTunnel property type | NebulaGraph parameter value |
+|-------------------------|-----------------------------|
+| STRING | string |
+| BOOLEAN | boolean |
+| BYTES | binary |
+| TINYINT / SMALLINT / INT / BIGINT | integer |
+| FLOAT / DOUBLE | floating point |
+| DATE | date |
+| TIME | time |
+| TIMESTAMP | datetime |
+
+Other property types are rejected during sink initialization.
+
+## Write Guarantees and Limits
+
+- The sink provides at-least-once delivery. It flushes on `batch_size`, checkpoint preparation, and writer close.
+- `max_retries` defaults to `0` because retrying a request after an ambiguous network failure can repeat a write. Enable retries only when the selected write mode is safe for the job.
+- Each sink block writes vertices to one tag. Use separate sink blocks for different tags.
+- Space, tag, and property names must use letters, digits, or underscores and must not start with a digit.
+- The connector uses the default NebulaGraph Thrift socket transport. TLS and HTTP/2 transport options are not exposed in this version.
+
+## Task Example
+
+Create the space and tag before running the job, for example:
+
+```ngql
+CREATE SPACE IF NOT EXISTS examples(vid_type = FIXED_STRING(64));
+USE examples;
+CREATE TAG IF NOT EXISTS person(name string, age int);
+```
+
+After the schema is available on graphd, the following job writes two vertices:
+
+```hocon
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ row.num = 2
+ schema = {
+ fields {
+ id = string
+ name = string
+ age = int
+ }
+ }
+ }
+}
+
+sink {
+ NebulaGraph {
+ hosts = ["localhost:9669"]
+ username = "root"
+ password = "nebula"
+ space = "examples"
+ tag = "person"
+ vid_field = "id"
+ write_fields = ["name", "age"]
+ write_mode = "INSERT"
+ }
+}
+```
+
+## Changelog
+
+<ChangeLog />
diff --git a/docs/zh/connectors/changelog/connector-nebulagraph.md b/docs/zh/connectors/changelog/connector-nebulagraph.md
new file mode 100644
index 0000000000..7f556b3dba
--- /dev/null
+++ b/docs/zh/connectors/changelog/connector-nebulagraph.md
@@ -0,0 +1,11 @@
+---
+title: NebulaGraph
+---
+
+<details><summary> Change Log </summary>
+
+| 变更 | 提交 | 版本 |
+|------|------|------|
+| [Feature][Connector-V2] 添加 NebulaGraph 顶点 Sink | - | Next |
+
+</details>
diff --git a/docs/zh/connectors/sink/NebulaGraph.md b/docs/zh/connectors/sink/NebulaGraph.md
new file mode 100644
index 0000000000..d9201fcd49
--- /dev/null
+++ b/docs/zh/connectors/sink/NebulaGraph.md
@@ -0,0 +1,127 @@
+import ChangeLog from '../changelog/connector-nebulagraph.md';
+
+# NebulaGraph
+
+> NebulaGraph 数据写入连接器
+
+## 引擎支持
+
+> Spark<br/>
+> Flink<br/>
+> SeaTunnel Zeta<br/>
+
+## 描述
+
+NebulaGraph sink 将 SeaTunnel 数据行作为顶点写入一个已经存在的 Tag。首个版本使用参数化 DML,因此支持 NebulaGraph 3.5 及以上版本。
+
+作业启动前必须创建目标 Space 和 Tag。当前版本不包含 Source、边写入、Schema 创建和删除处理。
+
+## 主要特性
+
+- [x] [批处理](../../introduction/concepts/connector-v2-features.md)
+- [ ] [精确一次](../../introduction/concepts/connector-v2-features.md)
+- [ ] [CDC](../../introduction/concepts/connector-v2-features.md)
+- [ ] [支持多表写入](../../introduction/concepts/connector-v2-features.md)
+
+## 选项
+
+| 名称 | 类型 | 必填 | 默认值 | 说明 |
+|------|------|------|--------|------|
+| hosts | list | 是 | - | `host:port` 格式的 graphd 地址列表,也支持带方括号的 IPv6 地址。 |
+| username | string | 是 | - | NebulaGraph 用户名。 |
+| password | string | 是 | - | NebulaGraph 密码。 |
+| space | string | 是 | - | 已存在的 Space。 |
+| tag | string | 是 | - | 已存在的顶点 Tag。 |
+| vid_field | string | 是 | - | 用作顶点 ID 的输入字段。 |
+| write_fields | list | 否 | 除 `vid_field` 外的全部字段 | 写入 Tag 属性的输入字段。 |
+| write_mode | enum | 否 | `INSERT` | 可选值为 `INSERT` 或 `UPDATE`。 |
+| batch_size | int | 否 | 500 | 每个 nGQL 请求包含的顶点数。 |
+| timeout_millis | int | 否 | 30000 | 连接、socket 和 session 等待超时时间,单位为毫秒。 |
+| max_retries | int | 否 | 0 | 首次写入失败后的重试次数。 |
+| retry_interval_millis | int | 否 | 1000 | 重试间隔,单位为毫秒。 |
+| common-options | | 否 | - | Sink 通用选项。 |
+
+### write_mode [enum]
+
+- `INSERT` 只接收 `INSERT` 行,并执行 `INSERT VERTEX IF NOT EXISTS`。重放数据不会覆盖已经存在的顶点。
+- `UPDATE` 接收 `INSERT` 和 `UPDATE_AFTER` 行,忽略 `UPDATE_BEFORE`,并执行 `UPDATE VERTEX`。目标顶点必须已经存在。
+
+两种模式都会拒绝 `DELETE` 行。
+
+### 通用选项
+
+Sink 插件通用参数请参考 [Sink 通用选项](../common-options/sink-common-options.md)。
+
+## 支持的数据类型
+
+顶点 ID 支持 `STRING`、`TINYINT`、`SMALLINT`、`INT` 和 `BIGINT`,并且不能为 null。
+
+| SeaTunnel 属性类型 | NebulaGraph 参数值 |
+|--------------------|--------------------|
+| STRING | 字符串 |
+| BOOLEAN | 布尔值 |
+| BYTES | 二进制 |
+| TINYINT / SMALLINT / INT / BIGINT | 整数 |
+| FLOAT / DOUBLE | 浮点数 |
+| DATE | date |
+| TIME | time |
+| TIMESTAMP | datetime |
+
+其他属性类型会在 Sink 初始化时被拒绝。
+
+## 写入语义和限制
+
+- Sink 提供 at-least-once 语义,在达到 `batch_size`、准备 checkpoint 和关闭 writer 时刷新数据。
+- `max_retries` 默认为 `0`,因为网络结果不明确时重试可能会重复写入。只有在当前写入模式对作业安全时才应启用重试。
+- 每个 Sink 配置块只向一个 Tag 写入顶点。不同 Tag 请使用不同的 Sink 配置块。
+- Space、Tag 和属性名称只能包含字母、数字或下划线,并且不能以数字开头。
+- 当前版本使用 NebulaGraph 默认的 Thrift socket,不提供 TLS 和 HTTP/2 配置。
+
+## 任务示例
+
+运行作业前先创建 Space 和 Tag,例如:
+
+```ngql
+CREATE SPACE IF NOT EXISTS examples(vid_type = FIXED_STRING(64));
+USE examples;
+CREATE TAG IF NOT EXISTS person(name string, age int);
+```
+
+Schema 在 graphd 上生效后,可以运行以下作业:
+
+```hocon
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ row.num = 2
+ schema = {
+ fields {
+ id = string
+ name = string
+ age = int
+ }
+ }
+ }
+}
+
+sink {
+ NebulaGraph {
+ hosts = ["localhost:9669"]
+ username = "root"
+ password = "nebula"
+ space = "examples"
+ tag = "person"
+ vid_field = "id"
+ write_fields = ["name", "age"]
+ write_mode = "INSERT"
+ }
+}
+```
+
+## 变更日志
+
+<ChangeLog />
diff --git a/plugin-mapping.properties b/plugin-mapping.properties
index 841086a450..4ef59376d1 100644
--- a/plugin-mapping.properties
+++ b/plugin-mapping.properties
@@ -60,6 +60,7 @@ seatunnel.source.IoTDB = connector-iotdb
seatunnel.sink.IoTDB = connector-iotdb
seatunnel.source.IoTDBv2 = connector-iotdb-v2
seatunnel.sink.IoTDBv2 = connector-iotdb-v2
+seatunnel.sink.NebulaGraph = connector-nebulagraph
seatunnel.source.Neo4j = connector-neo4j
seatunnel.sink.Neo4j = connector-neo4j
seatunnel.source.FtpFile = connector-file-ftp
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/pom.xml b/seatunnel-connectors-v2/connector-nebulagraph/pom.xml
new file mode 100644
index 0000000000..dd39024f14
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/pom.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>seatunnel-connectors-v2</artifactId>
+ <version>${revision}</version>
+ </parent>
+
+ <artifactId>connector-nebulagraph</artifactId>
+ <name>SeaTunnel : Connectors V2 : NebulaGraph</name>
+
+ <properties>
+ <nebula-java.version>3.8.4</nebula-java.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.vesoft</groupId>
+ <artifactId>client</artifactId>
+ <version>${nebula-java.version}</version>
+ <!-- The sink uses the graph SessionPool over the default Thrift socket only. -->
+ <exclusions>
+ <exclusion>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.bouncycastle</groupId>
+ <artifactId>bcpkix-jdk15on</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.locationtech.jts</groupId>
+ <artifactId>jts-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>com.squareup.okhttp3</groupId>
+ <artifactId>okhttp</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.mortbay.jetty.alpn</groupId>
+ <artifactId>alpn-boot</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/NebulaGraphClient.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/NebulaGraphClient.java
new file mode 100644
index 0000000000..2705af00d9
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/NebulaGraphClient.java
@@ -0,0 +1,27 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.client;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.Map;
+
+public interface NebulaGraphClient extends Closeable {
+
+ void execute(String statement, Map<String, Object> parameters) throws IOException;
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClient.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClient.java
new file mode 100644
index 0000000000..6dea3b8afc
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClient.java
@@ -0,0 +1,84 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.client;
+
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import com.vesoft.nebula.client.graph.SessionPool;
+import com.vesoft.nebula.client.graph.SessionPoolConfig;
+import com.vesoft.nebula.client.graph.data.ResultSet;
+
+import java.io.IOException;
+import java.util.Map;
+
+public final class SessionPoolNebulaGraphClient implements NebulaGraphClient {
+
+ private final SessionPool sessionPool;
+
+ public SessionPoolNebulaGraphClient(NebulaGraphSinkConfig config) {
+ SessionPoolConfig poolConfig =
+ new SessionPoolConfig(
+ config.getHosts(),
+ config.getSpace(),
+ config.getUsername(),
+ config.getPassword())
+ .setMinSessionSize(1)
+ .setMaxSessionSize(1)
+ .setTimeout(config.getTimeoutMillis())
+ .setWaitTime(config.getTimeoutMillis())
+ .setRetryTimes(config.getMaxRetries())
+ .setIntervalTime(
+ config.getMaxRetries() == 0 ? 0 : config.getRetryIntervalMillis())
+ .setReconnect(true);
+ try {
+ this.sessionPool = new SessionPool(poolConfig);
+ } catch (RuntimeException e) {
+ throw new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.CONNECT_FAILED,
+ "Unable to initialize a NebulaGraph session pool for space '"
+ + config.getSpace()
+ + "'.",
+ e);
+ }
+ }
+
+ @Override
+ public void execute(String statement, Map<String, Object> parameters) throws IOException {
+ try {
+ ResultSet result = sessionPool.execute(statement, parameters);
+ if (!result.isSucceeded()) {
+ throw new IOException(
+ "NebulaGraph rejected the write with code "
+ + result.getErrorCode()
+ + ": "
+ + result.getErrorMessage());
+ }
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException("NebulaGraph write request failed.", e);
+ }
+ }
+
+ @Override
+ public void close() {
+ sessionPool.close();
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfig.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfig.java
new file mode 100644
index 0000000000..2a2892b0a8
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfig.java
@@ -0,0 +1,235 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.config;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import com.vesoft.nebula.client.graph.data.HostAddress;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+public final class NebulaGraphSinkConfig implements Serializable {
+
+ private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
+
+ private final List<HostAddress> hosts;
+ private final String username;
+ private final String password;
+ private final String space;
+ private final String tag;
+ private final String vidField;
+ private final List<String> writeFields;
+ private final NebulaGraphWriteMode writeMode;
+ private final int batchSize;
+ private final int timeoutMillis;
+ private final int maxRetries;
+ private final int retryIntervalMillis;
+
+ private NebulaGraphSinkConfig(ReadonlyConfig config) {
+ this.hosts = parseHosts(config.get(NebulaGraphSinkOptions.HOSTS));
+ this.username = requireNotBlank(config.get(NebulaGraphSinkOptions.USERNAME), "username");
+ this.password = requireNotBlank(config.get(NebulaGraphSinkOptions.PASSWORD), "password");
+ this.space = requireIdentifier(config.get(NebulaGraphSinkOptions.SPACE), "space");
+ this.tag = requireIdentifier(config.get(NebulaGraphSinkOptions.TAG), "tag");
+ this.vidField = requireNotBlank(config.get(NebulaGraphSinkOptions.VID_FIELD), "vid_field");
+ this.writeFields =
+ parseWriteFields(config.getOptional(NebulaGraphSinkOptions.WRITE_FIELDS));
+ this.writeMode = config.get(NebulaGraphSinkOptions.WRITE_MODE);
+ this.batchSize =
+ requirePositive(config.get(NebulaGraphSinkOptions.BATCH_SIZE), "batch_size");
+ this.timeoutMillis =
+ requirePositive(
+ config.get(NebulaGraphSinkOptions.TIMEOUT_MILLIS), "timeout_millis");
+ this.maxRetries =
+ requireNonNegative(config.get(NebulaGraphSinkOptions.MAX_RETRIES), "max_retries");
+ this.retryIntervalMillis =
+ requireNonNegative(
+ config.get(NebulaGraphSinkOptions.RETRY_INTERVAL_MILLIS),
+ "retry_interval_millis");
+ }
+
+ public static NebulaGraphSinkConfig of(ReadonlyConfig config) {
+ return new NebulaGraphSinkConfig(config);
+ }
+
+ private static List<HostAddress> parseHosts(List<String> values) {
+ if (values == null || values.isEmpty()) {
+ throw invalid("Option 'hosts' must contain at least one graphd address.");
+ }
+ List<HostAddress> result = new ArrayList<>(values.size());
+ for (String value : values) {
+ result.add(parseHost(value));
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ static HostAddress parseHost(String value) {
+ String address = requireNotBlank(value, "hosts").trim();
+ String host;
+ String portText;
+ if (address.startsWith("[")) {
+ int bracket = address.indexOf(']');
+ if (bracket <= 1
+ || bracket + 1 >= address.length()
+ || address.charAt(bracket + 1) != ':') {
+ throw invalid("Invalid graphd address '" + value + "'. Expected [ipv6]:port.");
+ }
+ host = address.substring(1, bracket);
+ portText = address.substring(bracket + 2);
+ } else {
+ int separator = address.lastIndexOf(':');
+ if (separator <= 0
+ || separator == address.length() - 1
+ || address.indexOf(':') != separator) {
+ throw invalid("Invalid graphd address '" + value + "'. Expected host:port.");
+ }
+ host = address.substring(0, separator).trim();
+ portText = address.substring(separator + 1).trim();
+ }
+
+ int port;
+ try {
+ port = Integer.parseInt(portText);
+ } catch (NumberFormatException e) {
+ throw invalid("Invalid port in graphd address '" + value + "'.", e);
+ }
+ if (host.isEmpty() || port < 1 || port > 65535) {
+ throw invalid("Invalid graphd address '" + value + "'. Port must be in [1, 65535].");
+ }
+ return new HostAddress(host, port);
+ }
+
+ private static List<String> parseWriteFields(java.util.Optional<List<String>> optional) {
+ if (!optional.isPresent()) {
+ return Collections.emptyList();
+ }
+ List<String> values = optional.get();
+ if (values.isEmpty()) {
+ throw invalid("Option 'write_fields' must not be empty when it is configured.");
+ }
+ Set<String> seen = new HashSet<>();
+ List<String> result = new ArrayList<>(values.size());
+ for (String value : values) {
+ String field = requireIdentifier(value, "write_fields");
+ if (!seen.add(field)) {
+ throw invalid("Option 'write_fields' contains duplicate field '" + field + "'.");
+ }
+ result.add(field);
+ }
+ return Collections.unmodifiableList(result);
+ }
+
+ private static String requireIdentifier(String value, String option) {
+ String identifier = requireNotBlank(value, option);
+ if (!IDENTIFIER.matcher(identifier).matches()) {
+ throw invalid(
+ "Option '"
+ + option
+ + "' must use a simple NebulaGraph identifier containing letters, digits, or underscores: "
+ + identifier);
+ }
+ return identifier;
+ }
+
+ private static String requireNotBlank(String value, String option) {
+ if (value == null || value.trim().isEmpty()) {
+ throw invalid("Option '" + option + "' must not be blank.");
+ }
+ return value.trim();
+ }
+
+ private static int requirePositive(int value, String option) {
+ if (value < 1) {
+ throw invalid("Option '" + option + "' must be greater than 0, but was " + value + ".");
+ }
+ return value;
+ }
+
+ private static int requireNonNegative(int value, String option) {
+ if (value < 0) {
+ throw invalid("Option '" + option + "' must be at least 0, but was " + value + ".");
+ }
+ return value;
+ }
+
+ private static NebulaGraphConnectorException invalid(String message) {
+ return new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.INVALID_CONFIG, message);
+ }
+
+ private static NebulaGraphConnectorException invalid(String message, Throwable cause) {
+ return new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.INVALID_CONFIG, message, cause);
+ }
+
+ public List<HostAddress> getHosts() {
+ return hosts;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getSpace() {
+ return space;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public String getVidField() {
+ return vidField;
+ }
+
+ public List<String> getWriteFields() {
+ return writeFields;
+ }
+
+ public NebulaGraphWriteMode getWriteMode() {
+ return writeMode;
+ }
+
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ public int getTimeoutMillis() {
+ return timeoutMillis;
+ }
+
+ public int getMaxRetries() {
+ return maxRetries;
+ }
+
+ public int getRetryIntervalMillis() {
+ return retryIntervalMillis;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkOptions.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkOptions.java
new file mode 100644
index 0000000000..4cac50aae2
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkOptions.java
@@ -0,0 +1,107 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.config;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+
+import java.util.List;
+
+public final class NebulaGraphSinkOptions {
+
+ public static final String CONNECTOR_IDENTITY = "NebulaGraph";
+
+ public static final Option<List<String>> HOSTS =
+ Options.key("hosts")
+ .listType()
+ .noDefaultValue()
+ .withDescription(
+ "NebulaGraph graphd addresses in host:port form, for example [\"graphd-1:9669\", \"graphd-2:9669\"].");
+
+ public static final Option<String> USERNAME =
+ Options.key("username")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("NebulaGraph username.");
+
+ public static final Option<String> PASSWORD =
+ Options.key("password")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("NebulaGraph password.");
+
+ public static final Option<String> SPACE =
+ Options.key("space")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Existing NebulaGraph space to write to.");
+
+ public static final Option<String> TAG =
+ Options.key("tag")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Existing NebulaGraph vertex tag to write to.");
+
+ public static final Option<String> VID_FIELD =
+ Options.key("vid_field")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Input field used as the NebulaGraph vertex ID.");
+
+ public static final Option<List<String>> WRITE_FIELDS =
+ Options.key("write_fields")
+ .listType()
+ .noDefaultValue()
+ .withDescription(
+ "Input fields written as tag properties. By default all fields except vid_field are written.");
+
+ public static final Option<NebulaGraphWriteMode> WRITE_MODE =
+ Options.key("write_mode")
+ .enumType(NebulaGraphWriteMode.class)
+ .defaultValue(NebulaGraphWriteMode.INSERT)
+ .withDescription(
+ "Vertex write mode. INSERT uses INSERT VERTEX IF NOT EXISTS; UPDATE only changes an existing vertex.");
+
+ public static final Option<Integer> BATCH_SIZE =
+ Options.key("batch_size")
+ .intType()
+ .defaultValue(500)
+ .withDescription("Number of vertices buffered in each nGQL request.");
+
+ public static final Option<Integer> TIMEOUT_MILLIS =
+ Options.key("timeout_millis")
+ .intType()
+ .defaultValue(30000)
+ .withDescription(
+ "Connection, socket, and session wait timeout in milliseconds.");
+
+ public static final Option<Integer> MAX_RETRIES =
+ Options.key("max_retries")
+ .intType()
+ .defaultValue(0)
+ .withDescription(
+ "Retries after the initial write attempt. The default is 0 to avoid hidden re-execution after an ambiguous write result.");
+
+ public static final Option<Integer> RETRY_INTERVAL_MILLIS =
+ Options.key("retry_interval_millis")
+ .intType()
+ .defaultValue(1000)
+ .withDescription("Delay between NebulaGraph client retries in milliseconds.");
+
+ private NebulaGraphSinkOptions() {}
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphWriteMode.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphWriteMode.java
new file mode 100644
index 0000000000..7dc3d4c662
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphWriteMode.java
@@ -0,0 +1,23 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.config;
+
+public enum NebulaGraphWriteMode {
+ INSERT,
+ UPDATE
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorErrorCode.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorErrorCode.java
new file mode 100644
index 0000000000..3e55f6da33
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorErrorCode.java
@@ -0,0 +1,45 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum NebulaGraphConnectorErrorCode implements SeaTunnelErrorCode {
+ INVALID_CONFIG("NEBULAGRAPH-01", "NebulaGraph connector configuration is invalid"),
+ UNSUPPORTED_DATA_TYPE("NEBULAGRAPH-02", "SeaTunnel data type is not supported"),
+ CONNECT_FAILED("NEBULAGRAPH-03", "Failed to connect to NebulaGraph"),
+ WRITE_FAILED("NEBULAGRAPH-04", "Failed to write to NebulaGraph");
+
+ private final String code;
+ private final String description;
+
+ NebulaGraphConnectorErrorCode(String code, String description) {
+ this.code = code;
+ this.description = description;
+ }
+
+ @Override
+ public String getCode() {
+ return code;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorException.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorException.java
new file mode 100644
index 0000000000..80cd19bb0b
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/exception/NebulaGraphConnectorException.java
@@ -0,0 +1,32 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class NebulaGraphConnectorException extends SeaTunnelRuntimeException {
+
+ public NebulaGraphConnectorException(NebulaGraphConnectorErrorCode errorCode, String message) {
+ super(errorCode, message);
+ }
+
+ public NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode errorCode, String message, Throwable cause) {
+ super(errorCode, message, cause);
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphRowConverter.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphRowConverter.java
new file mode 100644
index 0000000000..fa1788c9df
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphRowConverter.java
@@ -0,0 +1,209 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.api.table.type.SqlType;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphWriteMode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import com.vesoft.nebula.Date;
+import com.vesoft.nebula.DateTime;
+import com.vesoft.nebula.Time;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+final class NebulaGraphRowConverter {
+
+ private final SeaTunnelRowType rowType;
+ private final int vidIndex;
+ private final List<String> propertyNames;
+ private final List<Integer> propertyIndexes;
+
+ NebulaGraphRowConverter(NebulaGraphSinkConfig config, SeaTunnelRowType rowType) {
+ this.rowType = rowType;
+ this.vidIndex = fieldIndex(rowType, config.getVidField(), "vid_field");
+ validateVidType(rowType.getFieldType(vidIndex), config.getVidField());
+
+ List<String> configuredFields = config.getWriteFields();
+ if (configuredFields.isEmpty()) {
+ configuredFields = new ArrayList<>(Arrays.asList(rowType.getFieldNames()));
+ configuredFields.remove(config.getVidField());
+ }
+ if (config.getWriteMode() == NebulaGraphWriteMode.UPDATE && configuredFields.isEmpty()) {
+ throw invalid("UPDATE mode requires at least one property field.");
+ }
+
+ this.propertyNames = new ArrayList<>(configuredFields.size());
+ this.propertyIndexes = new ArrayList<>(configuredFields.size());
+ for (String field : configuredFields) {
+ int index = fieldIndex(rowType, field, "write_fields");
+ validatePropertyType(rowType.getFieldType(index), field);
+ propertyNames.add(field);
+ propertyIndexes.add(index);
+ }
+ }
+
+ NebulaGraphVertex convert(SeaTunnelRow row) {
+ if (row.getArity() != rowType.getTotalFields()) {
+ throw invalid(
+ "Input row arity "
+ + row.getArity()
+ + " does not match the configured schema arity "
+ + rowType.getTotalFields()
+ + ".");
+ }
+ Object vid = convertVid(row.getField(vidIndex));
+ Map<String, Object> properties = new LinkedHashMap<>();
+ for (int i = 0; i < propertyNames.size(); i++) {
+ int index = propertyIndexes.get(i);
+ properties.put(
+ propertyNames.get(i),
+ convertProperty(rowType.getFieldType(index), row.getField(index)));
+ }
+ return new NebulaGraphVertex(vid, properties);
+ }
+
+ List<String> getPropertyNames() {
+ return new ArrayList<>(propertyNames);
+ }
+
+ private Object convertVid(Object value) {
+ if (value == null) {
+ throw invalid("The vertex ID field must not be null.");
+ }
+ SqlType sqlType = rowType.getFieldType(vidIndex).getSqlType();
+ if (sqlType == SqlType.STRING) {
+ return (String) value;
+ }
+ return ((Number) value).longValue();
+ }
+
+ private static Object convertProperty(SeaTunnelDataType<?> dataType, Object value) {
+ if (value == null) {
+ return null;
+ }
+ switch (dataType.getSqlType()) {
+ case STRING:
+ case BOOLEAN:
+ case BYTES:
+ return value;
+ case TINYINT:
+ case SMALLINT:
+ case INT:
+ case BIGINT:
+ return ((Number) value).longValue();
+ case FLOAT:
+ case DOUBLE:
+ return ((Number) value).doubleValue();
+ case DATE:
+ LocalDate date = (LocalDate) value;
+ return new Date(
+ (short) date.getYear(),
+ (byte) date.getMonthValue(),
+ (byte) date.getDayOfMonth());
+ case TIME:
+ LocalTime time = (LocalTime) value;
+ return new Time(
+ (byte) time.getHour(),
+ (byte) time.getMinute(),
+ (byte) time.getSecond(),
+ time.getNano() / 1000);
+ case TIMESTAMP:
+ LocalDateTime timestamp = (LocalDateTime) value;
+ return new DateTime(
+ (short) timestamp.getYear(),
+ (byte) timestamp.getMonthValue(),
+ (byte) timestamp.getDayOfMonth(),
+ (byte) timestamp.getHour(),
+ (byte) timestamp.getMinute(),
+ (byte) timestamp.getSecond(),
+ timestamp.getNano() / 1000);
+ default:
+ throw unsupported(dataType.getSqlType(), "property");
+ }
+ }
+
+ private static int fieldIndex(SeaTunnelRowType rowType, String field, String option) {
+ int index = rowType.indexOf(field, false);
+ if (index < 0) {
+ throw invalid(
+ "Option '"
+ + option
+ + "' references unknown field '"
+ + field
+ + "'. Available fields are "
+ + Arrays.toString(rowType.getFieldNames())
+ + ".");
+ }
+ return index;
+ }
+
+ private static void validateVidType(SeaTunnelDataType<?> dataType, String field) {
+ SqlType type = dataType.getSqlType();
+ if (type != SqlType.STRING
+ && type != SqlType.TINYINT
+ && type != SqlType.SMALLINT
+ && type != SqlType.INT
+ && type != SqlType.BIGINT) {
+ throw unsupported(type, "vertex ID field '" + field + "'");
+ }
+ }
+
+ private static void validatePropertyType(SeaTunnelDataType<?> dataType, String field) {
+ switch (dataType.getSqlType()) {
+ case STRING:
+ case BOOLEAN:
+ case BYTES:
+ case TINYINT:
+ case SMALLINT:
+ case INT:
+ case BIGINT:
+ case FLOAT:
+ case DOUBLE:
+ case DATE:
+ case TIME:
+ case TIMESTAMP:
+ return;
+ default:
+ throw unsupported(dataType.getSqlType(), "property field '" + field + "'");
+ }
+ }
+
+ private static NebulaGraphConnectorException invalid(String message) {
+ return new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.INVALID_CONFIG, message);
+ }
+
+ private static NebulaGraphConnectorException unsupported(SqlType type, String context) {
+ return new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.UNSUPPORTED_DATA_TYPE,
+ "SeaTunnel type " + type + " is not supported for NebulaGraph " + context + ".");
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSink.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSink.java
new file mode 100644
index 0000000000..79b94202ce
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSink.java
@@ -0,0 +1,56 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.api.sink.SinkWriter;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSimpleSink;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkOptions;
+
+import java.io.IOException;
+import java.util.Optional;
+
+public class NebulaGraphSink extends AbstractSimpleSink<SeaTunnelRow, Void> {
+
+ private final NebulaGraphSinkConfig config;
+ private final CatalogTable catalogTable;
+
+ public NebulaGraphSink(NebulaGraphSinkConfig config, CatalogTable catalogTable) {
+ this.config = config;
+ this.catalogTable = catalogTable;
+ }
+
+ @Override
+ public String getPluginName() {
+ return NebulaGraphSinkOptions.CONNECTOR_IDENTITY;
+ }
+
+ @Override
+ public AbstractSinkWriter<SeaTunnelRow, Void> createWriter(SinkWriter.Context context)
+ throws IOException {
+ return new NebulaGraphSinkWriter(config, catalogTable.getSeaTunnelRowType());
+ }
+
+ @Override
+ public Optional<CatalogTable> getWriteCatalogTable() {
+ return Optional.of(catalogTable);
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkFactory.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkFactory.java
new file mode 100644
index 0000000000..85e37cd9e4
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkFactory.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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.api.configuration.util.OptionRule;
+import org.apache.seatunnel.api.table.connector.TableSink;
+import org.apache.seatunnel.api.table.factory.Factory;
+import org.apache.seatunnel.api.table.factory.TableSinkFactory;
+import org.apache.seatunnel.api.table.factory.TableSinkFactoryContext;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkOptions;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(Factory.class)
+public class NebulaGraphSinkFactory implements TableSinkFactory {
+
+ @Override
+ public String factoryIdentifier() {
+ return NebulaGraphSinkOptions.CONNECTOR_IDENTITY;
+ }
+
+ @Override
+ public TableSink createSink(TableSinkFactoryContext context) {
+ NebulaGraphSinkConfig config = NebulaGraphSinkConfig.of(context.getOptions());
+ return () -> new NebulaGraphSink(config, context.getCatalogTable());
+ }
+
+ @Override
+ public OptionRule optionRule() {
+ return OptionRule.builder()
+ .required(
+ NebulaGraphSinkOptions.HOSTS,
+ NebulaGraphSinkOptions.USERNAME,
+ NebulaGraphSinkOptions.PASSWORD,
+ NebulaGraphSinkOptions.SPACE,
+ NebulaGraphSinkOptions.TAG,
+ NebulaGraphSinkOptions.VID_FIELD)
+ .optional(
+ NebulaGraphSinkOptions.WRITE_FIELDS,
+ NebulaGraphSinkOptions.WRITE_MODE,
+ NebulaGraphSinkOptions.BATCH_SIZE,
+ NebulaGraphSinkOptions.TIMEOUT_MILLIS,
+ NebulaGraphSinkOptions.MAX_RETRIES,
+ NebulaGraphSinkOptions.RETRY_INTERVAL_MILLIS)
+ .build();
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriter.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriter.java
new file mode 100644
index 0000000000..db81339aa7
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriter.java
@@ -0,0 +1,162 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.client.NebulaGraphClient;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.client.SessionPoolNebulaGraphClient;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphWriteMode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+public class NebulaGraphSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void> {
+
+ private final NebulaGraphSinkConfig config;
+ private final NebulaGraphClient client;
+ private final NebulaGraphRowConverter converter;
+ private final NebulaGraphStatementBuilder statementBuilder;
+ private final List<NebulaGraphVertex> buffer;
+
+ private boolean failed;
+ private boolean closed;
+
+ public NebulaGraphSinkWriter(NebulaGraphSinkConfig config, SeaTunnelRowType rowType) {
+ this(config, rowType, null);
+ }
+
+ NebulaGraphSinkWriter(
+ NebulaGraphSinkConfig config, SeaTunnelRowType rowType, NebulaGraphClient client) {
+ this.config = config;
+ this.converter = new NebulaGraphRowConverter(config, rowType);
+ this.statementBuilder =
+ new NebulaGraphStatementBuilder(
+ config.getTag(), converter.getPropertyNames(), config.getWriteMode());
+ this.buffer = new ArrayList<>(config.getBatchSize());
+ this.client = client == null ? new SessionPoolNebulaGraphClient(config) : client;
+ }
+
+ @Override
+ public void write(SeaTunnelRow row) throws IOException {
+ ensureWritable();
+ RowKind rowKind = row.getRowKind();
+ if (rowKind == RowKind.DELETE) {
+ throw unsupportedRowKind(rowKind);
+ }
+ if (config.getWriteMode() == NebulaGraphWriteMode.INSERT && rowKind != RowKind.INSERT) {
+ throw unsupportedRowKind(rowKind);
+ }
+ if (rowKind == RowKind.UPDATE_BEFORE) {
+ return;
+ }
+
+ buffer.add(converter.convert(row));
+ if (buffer.size() >= config.getBatchSize()) {
+ flush();
+ }
+ }
+
+ @Override
+ public Optional<Void> prepareCommit() {
+ try {
+ ensureWritable();
+ flush();
+ return Optional.empty();
+ } catch (IOException e) {
+ throw new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.WRITE_FAILED,
+ "Failed to flush the NebulaGraph sink before commit.",
+ e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ if (closed) {
+ return;
+ }
+ IOException failure = null;
+ if (!failed) {
+ try {
+ flush();
+ } catch (IOException e) {
+ failure = e;
+ }
+ }
+ try {
+ client.close();
+ } catch (IOException e) {
+ if (failure == null) {
+ failure = e;
+ } else {
+ failure.addSuppressed(e);
+ }
+ } finally {
+ closed = true;
+ }
+ if (failure != null) {
+ throw failure;
+ }
+ }
+
+ private void flush() throws IOException {
+ if (buffer.isEmpty()) {
+ return;
+ }
+ NebulaGraphWriteRequest request = statementBuilder.build(buffer);
+ try {
+ client.execute(request.getStatement(), request.getParameters());
+ buffer.clear();
+ } catch (IOException | RuntimeException e) {
+ failed = true;
+ throw new IOException(
+ "Failed to write "
+ + buffer.size()
+ + " vertices to NebulaGraph tag '"
+ + config.getTag()
+ + "'. The writer will not retry this batch during close.",
+ e);
+ }
+ }
+
+ private void ensureWritable() throws IOException {
+ if (closed) {
+ throw new IOException("NebulaGraph sink writer is already closed.");
+ }
+ if (failed) {
+ throw new IOException("NebulaGraph sink writer is in a failed state.");
+ }
+ }
+
+ private IOException unsupportedRowKind(RowKind rowKind) {
+ return new IOException(
+ "Row kind "
+ + rowKind
+ + " is not supported in NebulaGraph "
+ + config.getWriteMode()
+ + " mode.");
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilder.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilder.java
new file mode 100644
index 0000000000..b030b06c76
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilder.java
@@ -0,0 +1,173 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphWriteMode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+final class NebulaGraphStatementBuilder {
+
+ private static final Pattern IDENTIFIER = Pattern.compile("[A-Za-z_][A-Za-z0-9_]*");
+
+ private final String quotedTag;
+ private final List<String> propertyNames;
+ private final NebulaGraphWriteMode writeMode;
+
+ NebulaGraphStatementBuilder(
+ String tag, List<String> propertyNames, NebulaGraphWriteMode writeMode) {
+ this.quotedTag = quoteIdentifier(tag);
+ this.propertyNames =
+ propertyNames.stream()
+ .map(NebulaGraphStatementBuilder::validateIdentifier)
+ .collect(Collectors.toList());
+ this.writeMode = writeMode;
+ }
+
+ NebulaGraphWriteRequest build(List<NebulaGraphVertex> vertices) {
+ if (vertices.isEmpty()) {
+ throw new IllegalArgumentException(
+ "Cannot build a NebulaGraph request for an empty batch.");
+ }
+ if (writeMode == NebulaGraphWriteMode.INSERT) {
+ return buildInsert(vertices);
+ }
+ return buildUpdate(vertices);
+ }
+
+ private NebulaGraphWriteRequest buildInsert(List<NebulaGraphVertex> vertices) {
+ Map<String, Object> parameters = new LinkedHashMap<>();
+ List<String> values = new ArrayList<>(vertices.size());
+ for (int row = 0; row < vertices.size(); row++) {
+ NebulaGraphVertex vertex = vertices.get(row);
+
+ List<String> propertyParameters = new ArrayList<>(propertyNames.size());
+ for (int field = 0; field < propertyNames.size(); field++) {
+ String parameter = parameterName(row, field);
+ parameters.put(parameter, vertex.getProperties().get(propertyNames.get(field)));
+ propertyParameters.add("$" + parameter);
+ }
+ values.add(
+ formatVid(vertex.getVid()) + ":(" + String.join(",", propertyParameters) + ")");
+ }
+
+ String properties =
+ propertyNames.stream()
+ .map(NebulaGraphStatementBuilder::quoteIdentifier)
+ .collect(Collectors.joining(","));
+ String statement =
+ "INSERT VERTEX IF NOT EXISTS "
+ + quotedTag
+ + " ("
+ + properties
+ + ") VALUES "
+ + String.join(",", values);
+ return new NebulaGraphWriteRequest(statement, parameters);
+ }
+
+ private NebulaGraphWriteRequest buildUpdate(List<NebulaGraphVertex> vertices) {
+ Map<String, Object> parameters = new LinkedHashMap<>();
+ List<String> statements = new ArrayList<>(vertices.size());
+ for (int row = 0; row < vertices.size(); row++) {
+ NebulaGraphVertex vertex = vertices.get(row);
+
+ List<String> assignments = new ArrayList<>(propertyNames.size());
+ for (int field = 0; field < propertyNames.size(); field++) {
+ String property = propertyNames.get(field);
+ String parameter = parameterName(row, field);
+ parameters.put(parameter, vertex.getProperties().get(property));
+ assignments.add(quoteIdentifier(property) + "=$" + parameter);
+ }
+ statements.add(
+ "UPDATE VERTEX ON "
+ + quotedTag
+ + " "
+ + formatVid(vertex.getVid())
+ + " SET "
+ + String.join(",", assignments));
+ }
+ return new NebulaGraphWriteRequest(String.join(";", statements), parameters);
+ }
+
+ private static String parameterName(int row, int field) {
+ return "value_" + row + "_" + field;
+ }
+
+ private static String formatVid(Object vid) {
+ if (vid instanceof Number) {
+ return Long.toString(((Number) vid).longValue());
+ }
+ String value = (String) vid;
+ StringBuilder escaped = new StringBuilder(value.length() + 2);
+ escaped.append('"');
+ for (int i = 0; i < value.length(); i++) {
+ char character = value.charAt(i);
+ switch (character) {
+ case '\\':
+ escaped.append("\\\\");
+ break;
+ case '"':
+ escaped.append("\\\"");
+ break;
+ case '\n':
+ escaped.append("\\n");
+ break;
+ case '\r':
+ escaped.append("\\r");
+ break;
+ case '\t':
+ escaped.append("\\t");
+ break;
+ case '\b':
+ escaped.append("\\b");
+ break;
+ case '\f':
+ escaped.append("\\f");
+ break;
+ default:
+ if (Character.isISOControl(character)) {
+ throw new IllegalArgumentException(
+ "NebulaGraph string vertex IDs must not contain unsupported control characters.");
+ }
+ escaped.append(character);
+ }
+ }
+ return escaped.append('"').toString();
+ }
+
+ private static String quoteIdentifier(String identifier) {
+ return "`" + validateIdentifier(identifier) + "`";
+ }
+
+ private static String validateIdentifier(String identifier) {
+ if (identifier == null || !IDENTIFIER.matcher(identifier).matches()) {
+ throw new NebulaGraphConnectorException(
+ NebulaGraphConnectorErrorCode.INVALID_CONFIG,
+ "NebulaGraph tag and property names must contain only letters, digits, or underscores and must not start with a digit: "
+ + identifier);
+ }
+ return identifier;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphVertex.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphVertex.java
new file mode 100644
index 0000000000..1d4fbd90a8
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphVertex.java
@@ -0,0 +1,41 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+final class NebulaGraphVertex {
+
+ private final Object vid;
+ private final Map<String, Object> properties;
+
+ NebulaGraphVertex(Object vid, Map<String, Object> properties) {
+ this.vid = vid;
+ this.properties = Collections.unmodifiableMap(new LinkedHashMap<>(properties));
+ }
+
+ Object getVid() {
+ return vid;
+ }
+
+ Map<String, Object> getProperties() {
+ return properties;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphWriteRequest.java b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphWriteRequest.java
new file mode 100644
index 0000000000..af9ce3d5c3
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/main/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphWriteRequest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+final class NebulaGraphWriteRequest {
+
+ private final String statement;
+ private final Map<String, Object> parameters;
+
+ NebulaGraphWriteRequest(String statement, Map<String, Object> parameters) {
+ this.statement = statement;
+ this.parameters = Collections.unmodifiableMap(new LinkedHashMap<>(parameters));
+ }
+
+ String getStatement() {
+ return statement;
+ }
+
+ Map<String, Object> getParameters() {
+ return parameters;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClientTest.java b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClientTest.java
new file mode 100644
index 0000000000..f5ba4f343f
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/client/SessionPoolNebulaGraphClientTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.client;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class SessionPoolNebulaGraphClientTest {
+
+ @Test
+ void reportsConnectionFailureWithTheReducedRuntimeDependencies() {
+ Map<String, Object> values = new HashMap<>();
+ values.put("hosts", Arrays.asList("127.0.0.1:1"));
+ values.put("username", "root");
+ values.put("password", "nebula");
+ values.put("space", "test");
+ values.put("tag", "person");
+ values.put("vid_field", "id");
+ values.put("timeout_millis", 10);
+ values.put("max_retries", 0);
+
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () ->
+ new SessionPoolNebulaGraphClient(
+ NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(values))));
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfigTest.java b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfigTest.java
new file mode 100644
index 0000000000..2898df4667
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/config/NebulaGraphSinkConfigTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.config;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import org.junit.jupiter.api.Test;
+
+import com.vesoft.nebula.client.graph.data.HostAddress;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class NebulaGraphSinkConfigTest {
+
+ @Test
+ void parsesHostNamesAndBracketedIpv6Addresses() {
+ HostAddress hostname = NebulaGraphSinkConfig.parseHost("graphd:9669");
+ HostAddress ipv6 = NebulaGraphSinkConfig.parseHost("[2001:db8::1]:9669");
+
+ assertEquals("graphd", hostname.getHost());
+ assertEquals(9669, hostname.getPort());
+ assertEquals("2001:db8::1", ipv6.getHost());
+ assertEquals(9669, ipv6.getPort());
+ }
+
+ @Test
+ void rejectsMalformedAddresses() {
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.parseHost("2001:db8::1:9669"));
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.parseHost("graphd:70000"));
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.parseHost("graphd"));
+ }
+
+ @Test
+ void validatesNumericOptionsAndIdentifiers() {
+ Map<String, Object> invalidBatchSize = validValues();
+ invalidBatchSize.put("batch_size", 0);
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(invalidBatchSize)));
+
+ Map<String, Object> invalidTag = validValues();
+ invalidTag.put("tag", "person; DROP SPACE test");
+ NebulaGraphConnectorException exception =
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(invalidTag)));
+ assertTrue(exception.getMessage().contains("tag"));
+
+ Map<String, Object> invalidSpace = validValues();
+ invalidSpace.put("space", "test` MATCH (v) RETURN v");
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(invalidSpace)));
+ }
+
+ @Test
+ void rejectsDuplicateWriteFields() {
+ Map<String, Object> values = validValues();
+ values.put("write_fields", Arrays.asList("name", "name"));
+
+ NebulaGraphConnectorException exception =
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () -> NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(values)));
+ assertTrue(exception.getMessage().contains("duplicate"));
+ }
+
+ static NebulaGraphSinkConfig validConfig(Map<String, Object> overrides) {
+ Map<String, Object> values = validValues();
+ values.putAll(overrides);
+ return NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(values));
+ }
+
+ private static Map<String, Object> validValues() {
+ Map<String, Object> values = new HashMap<>();
+ values.put("hosts", Arrays.asList("graphd:9669"));
+ values.put("username", "root");
+ values.put("password", "nebula");
+ values.put("space", "test");
+ values.put("tag", "person");
+ values.put("vid_field", "id");
+ return values;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriterTest.java b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriterTest.java
new file mode 100644
index 0000000000..61c2b7c048
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphSinkWriterTest.java
@@ -0,0 +1,187 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.RowKind;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.client.NebulaGraphClient;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class NebulaGraphSinkWriterTest {
+
+ private static final SeaTunnelRowType ROW_TYPE =
+ new SeaTunnelRowType(
+ new String[] {"id", "name", "age"},
+ new SeaTunnelDataType<?>[] {
+ BasicType.STRING_TYPE, BasicType.STRING_TYPE, BasicType.INT_TYPE
+ });
+
+ @Test
+ void flushesAtBatchBoundaryAndCheckpoint() throws Exception {
+ RecordingClient client = new RecordingClient();
+ NebulaGraphSinkConfig config = config(Collections.singletonMap("batch_size", 2));
+ NebulaGraphSinkWriter writer = new NebulaGraphSinkWriter(config, ROW_TYPE, client);
+
+ writer.write(row("p1", "Alice", 31));
+ assertEquals(0, client.statements.size());
+ writer.write(row("p2", "Bob", 29));
+ assertEquals(1, client.statements.size());
+
+ writer.write(row("p3", "Carol", 42));
+ writer.prepareCommit();
+ assertEquals(2, client.statements.size());
+ assertEquals(42L, client.parameters.get(1).get("value_0_1"));
+ writer.close();
+ }
+
+ @Test
+ void rejectsNullVertexIdsBeforeWriting() throws Exception {
+ RecordingClient client = new RecordingClient();
+ NebulaGraphSinkWriter writer =
+ new NebulaGraphSinkWriter(config(Collections.emptyMap()), ROW_TYPE, client);
+
+ assertThrows(
+ NebulaGraphConnectorException.class, () -> writer.write(row(null, "Alice", 31)));
+ assertEquals(0, client.statements.size());
+ writer.close();
+ }
+
+ @Test
+ void insertModeRejectsChangelogRows() throws Exception {
+ RecordingClient client = new RecordingClient();
+ NebulaGraphSinkWriter writer =
+ new NebulaGraphSinkWriter(config(Collections.emptyMap()), ROW_TYPE, client);
+ SeaTunnelRow update = row("p1", "Alice", 32);
+ update.setRowKind(RowKind.UPDATE_AFTER);
+
+ IOException exception = assertThrows(IOException.class, () -> writer.write(update));
+ assertTrue(exception.getMessage().contains("UPDATE_AFTER"));
+ writer.close();
+ }
+
+ @Test
+ void updateModeIgnoresBeforeImageAndWritesAfterImage() throws Exception {
+ Map<String, Object> options = new HashMap<>();
+ options.put("write_mode", "UPDATE");
+ options.put("batch_size", 1);
+ RecordingClient client = new RecordingClient();
+ NebulaGraphSinkWriter writer = new NebulaGraphSinkWriter(config(options), ROW_TYPE, client);
+ SeaTunnelRow before = row("p1", "Alice", 31);
+ before.setRowKind(RowKind.UPDATE_BEFORE);
+ SeaTunnelRow after = row("p1", "Alice", 32);
+ after.setRowKind(RowKind.UPDATE_AFTER);
+
+ writer.write(before);
+ writer.write(after);
+
+ assertEquals(1, client.statements.size());
+ assertTrue(client.statements.get(0).startsWith("UPDATE VERTEX"));
+ assertEquals(32L, client.parameters.get(0).get("value_0_1"));
+ writer.close();
+ }
+
+ @Test
+ void failedBatchIsNotRetriedDuringClose() throws Exception {
+ RecordingClient client = new RecordingClient();
+ client.failure = new IOException("connection reset");
+ NebulaGraphSinkWriter writer =
+ new NebulaGraphSinkWriter(
+ config(Collections.singletonMap("batch_size", 1)), ROW_TYPE, client);
+
+ assertThrows(IOException.class, () -> writer.write(row("p1", "Alice", 31)));
+ writer.close();
+
+ assertEquals(1, client.executeCount);
+ assertTrue(client.closed);
+ }
+
+ @Test
+ void rejectsUnsupportedPropertyTypeBeforeClientUse() {
+ SeaTunnelRowType decimalRowType =
+ new SeaTunnelRowType(
+ new String[] {"id", "amount"},
+ new SeaTunnelDataType<?>[] {BasicType.STRING_TYPE, new DecimalType(10, 2)});
+ RecordingClient client = new RecordingClient();
+
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () ->
+ new NebulaGraphSinkWriter(
+ config(Collections.emptyMap()), decimalRowType, client));
+ assertEquals(0, client.executeCount);
+ }
+
+ private static NebulaGraphSinkConfig config(Map<String, Object> overrides) {
+ Map<String, Object> values = new HashMap<>();
+ values.put("hosts", Arrays.asList("graphd:9669"));
+ values.put("username", "root");
+ values.put("password", "nebula");
+ values.put("space", "test");
+ values.put("tag", "person");
+ values.put("vid_field", "id");
+ values.putAll(overrides);
+ return NebulaGraphSinkConfig.of(ReadonlyConfig.fromMap(values));
+ }
+
+ private static SeaTunnelRow row(String id, String name, int age) {
+ return new SeaTunnelRow(new Object[] {id, name, age});
+ }
+
+ private static final class RecordingClient implements NebulaGraphClient {
+ private final List<String> statements = new ArrayList<>();
+ private final List<Map<String, Object>> parameters = new ArrayList<>();
+ private IOException failure;
+ private int executeCount;
+ private boolean closed;
+
+ @Override
+ public void execute(String statement, Map<String, Object> parameters) throws IOException {
+ executeCount++;
+ if (failure != null) {
+ throw failure;
+ }
+ statements.add(statement);
+ this.parameters.add(new HashMap<>(parameters));
+ }
+
+ @Override
+ public void close() {
+ closed = true;
+ }
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilderTest.java b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilderTest.java
new file mode 100644
index 0000000000..b9635caf10
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-nebulagraph/src/test/java/org/apache/seatunnel/connectors/seatunnel/nebulagraph/sink/NebulaGraphStatementBuilderTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.nebulagraph.sink;
+
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.config.NebulaGraphWriteMode;
+import org.apache.seatunnel.connectors.seatunnel.nebulagraph.exception.NebulaGraphConnectorException;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class NebulaGraphStatementBuilderTest {
+
+ @Test
+ void buildsParameterizedBatchInsert() {
+ NebulaGraphStatementBuilder builder =
+ new NebulaGraphStatementBuilder(
+ "person", Arrays.asList("name", "age"), NebulaGraphWriteMode.INSERT);
+
+ NebulaGraphWriteRequest request =
+ builder.build(Arrays.asList(vertex("p1", "Alice", 31L), vertex("p2", "Bob", 29L)));
+
+ assertEquals(
+ "INSERT VERTEX IF NOT EXISTS `person` (`name`,`age`) VALUES "
+ + "\"p1\":($value_0_0,$value_0_1),\"p2\":($value_1_0,$value_1_1)",
+ request.getStatement());
+ assertEquals(31L, request.getParameters().get("value_0_1"));
+ assertFalse(request.getParameters().containsKey("vid_0"));
+ assertFalse(request.getStatement().contains("Alice"));
+ }
+
+ @Test
+ void buildsParameterizedBatchUpdate() {
+ NebulaGraphStatementBuilder builder =
+ new NebulaGraphStatementBuilder(
+ "person", Arrays.asList("name", "age"), NebulaGraphWriteMode.UPDATE);
+
+ NebulaGraphWriteRequest request =
+ builder.build(Arrays.asList(vertex("p1", "Alice", 31L), vertex("p2", "Bob", 29L)));
+
+ assertEquals(
+ "UPDATE VERTEX ON `person` \"p1\" SET `name`=$value_0_0,`age`=$value_0_1;"
+ + "UPDATE VERTEX ON `person` \"p2\" SET `name`=$value_1_0,`age`=$value_1_1",
+ request.getStatement());
+ assertEquals("Bob", request.getParameters().get("value_1_0"));
+ }
+
+ @Test
+ void escapesStringVertexIdsAndFormatsIntegerVertexIds() {
+ NebulaGraphStatementBuilder builder =
+ new NebulaGraphStatementBuilder(
+ "person", Arrays.asList("name", "age"), NebulaGraphWriteMode.INSERT);
+
+ NebulaGraphWriteRequest request =
+ builder.build(
+ Arrays.asList(vertex("quote\"slash\\line\n", "Alice", 31L), vertex(42L)));
+
+ assertEquals(
+ "INSERT VERTEX IF NOT EXISTS `person` (`name`,`age`) VALUES "
+ + "\"quote\\\"slash\\\\line\\n\":($value_0_0,$value_0_1),"
+ + "42:($value_1_0,$value_1_1)",
+ request.getStatement());
+ }
+
+ @Test
+ void rejectsUnsupportedControlCharactersInVertexIds() {
+ NebulaGraphStatementBuilder builder =
+ new NebulaGraphStatementBuilder(
+ "person", Arrays.asList("name", "age"), NebulaGraphWriteMode.INSERT);
+
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> builder.build(Arrays.asList(vertex("person\u0000", "Alice", 31L))));
+ }
+
+ @Test
+ void rejectsUnsafePropertyNames() {
+ assertThrows(
+ NebulaGraphConnectorException.class,
+ () ->
+ new NebulaGraphStatementBuilder(
+ "person",
+ Arrays.asList("name`, admin=true; --"),
+ NebulaGraphWriteMode.INSERT));
+ }
+
+ private static NebulaGraphVertex vertex(String vid, String name, long age) {
+ Map<String, Object> properties = new LinkedHashMap<>();
+ properties.put("name", name);
+ properties.put("age", age);
+ return new NebulaGraphVertex(vid, properties);
+ }
+
+ private static NebulaGraphVertex vertex(long vid) {
+ Map<String, Object> properties = new LinkedHashMap<>();
+ properties.put("name", "Alice");
+ properties.put("age", 31L);
+ return new NebulaGraphVertex(vid, properties);
+ }
+}
diff --git a/seatunnel-connectors-v2/pom.xml b/seatunnel-connectors-v2/pom.xml
index 19e563e438..694c90ad6c 100644
--- a/seatunnel-connectors-v2/pom.xml
+++ b/seatunnel-connectors-v2/pom.xml
@@ -52,6 +52,7 @@
<module>connector-elasticsearch</module>
<module>connector-iotdb</module>
<module>connector-iotdb-v2</module>
+ <module>connector-nebulagraph</module>
<module>connector-neo4j</module>
<module>connector-redis</module>
<module>connector-datahub</module>
diff --git a/seatunnel-dist/pom.xml b/seatunnel-dist/pom.xml
index d5e16abebe..7354811388 100644
--- a/seatunnel-dist/pom.xml
+++ b/seatunnel-dist/pom.xml
@@ -476,6 +476,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-nebulagraph</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-neo4j</artifactId>
diff --git a/seatunnel-dist/release-docs/LICENSE b/seatunnel-dist/release-docs/LICENSE
index e18dd28818..822d334be8 100644
--- a/seatunnel-dist/release-docs/LICENSE
+++ b/seatunnel-dist/release-docs/LICENSE
@@ -227,6 +227,8 @@ The text of each license is the standard Apache 2.0 license.
(Apache License, Version 2.0) Apache Commons IO (commons-io:commons-io:2.11.0 - http://commons.apache.org/proper/commons-io/)
(Apache License, Version 2.0) Apache Commons Lang (org.apache.commons:commons-lang3:3.5 - http://commons.apache.org/proper/commons-lang/)
(The Apache Software License, Version 2.0) Commons Pool (commons-pool:commons-pool:1.6 - http://commons.apache.org/pool/)
+ (The Apache Software License, Version 2.0) Apache Commons Pool (org.apache.commons:commons-pool2:2.2 - https://commons.apache.org/proper/commons-pool/)
+ (Apache-2.0) NebulaGraph Java Client (com.vesoft:client:3.8.4 - https://github.com/vesoft-inc/nebula-java)
(Apache License, Version 2.0) config (com.typesafe:config:1.3.3 - https://github.com/lightbend/config)
(The Apache Software License, Version 2.0) Flink : Formats : Avro (org.apache.flink:flink-avro:1.13.6 - https://flink.apache.org/flink-formats/flink-avro)
(The Apache Software License, Version 2.0) Flink : Formats : Csv (org.apache.flink:flink-csv:1.13.6 - https://flink.apache.org/flink-formats/flink-csv)
diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/pom.xml b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/pom.xml
new file mode 100644
index 0000000000..1414006c7c
--- /dev/null
+++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>seatunnel-connector-v2-e2e</artifactId>
+ <version>${revision}</version>
+ </parent>
+
+ <artifactId>connector-nebulagraph-e2e</artifactId>
+ <name>SeaTunnel : E2E : Connector V2 : NebulaGraph</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-nebulagraph</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-fake</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <version>${testcontainer.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/java/org/apache/seatunnel/e2e/connector/nebulagraph/NebulaGraphIT.java b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/java/org/apache/seatunnel/e2e/connector/nebulagraph/NebulaGraphIT.java
new file mode 100644
index 0000000000..cd687c6e03
--- /dev/null
+++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/java/org/apache/seatunnel/e2e/connector/nebulagraph/NebulaGraphIT.java
@@ -0,0 +1,201 @@
+/*
+ * 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.seatunnel.e2e.connector.nebulagraph;
+
+import org.apache.seatunnel.e2e.common.TestResource;
+import org.apache.seatunnel.e2e.common.TestSuiteBase;
+import org.apache.seatunnel.e2e.common.container.TestContainer;
+
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.TestTemplate;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.utility.DockerImageName;
+
+import com.vesoft.nebula.client.graph.NebulaPoolConfig;
+import com.vesoft.nebula.client.graph.data.HostAddress;
+import com.vesoft.nebula.client.graph.data.ResultSet;
+import com.vesoft.nebula.client.graph.net.NebulaPool;
+import com.vesoft.nebula.client.graph.net.Session;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class NebulaGraphIT extends TestSuiteBase implements TestResource {
+
+ private static final String VERSION = "v3.8.0";
+
+ private GenericContainer<?> metad;
+ private GenericContainer<?> storaged;
+ private GenericContainer<?> graphd;
+ private NebulaPool adminPool;
+ private Session adminSession;
+
+ @BeforeAll
+ @Override
+ public void startUp() throws Exception {
+ metad =
+ new GenericContainer<>(DockerImageName.parse("vesoft/nebula-metad:" + VERSION))
+ .withNetwork(NETWORK)
+ .withNetworkAliases("metad0")
+ .withExposedPorts(19559)
+ .withCommand(
+ "--meta_server_addrs=metad0:9559",
+ "--local_ip=metad0",
+ "--ws_ip=metad0",
+ "--port=9559",
+ "--ws_http_port=19559",
+ "--data_path=/data/meta",
+ "--logtostderr=true")
+ .waitingFor(Wait.forHttp("/status").forPort(19559))
+ .withStartupTimeout(Duration.ofMinutes(3));
+ storaged =
+ new GenericContainer<>(DockerImageName.parse("vesoft/nebula-storaged:" + VERSION))
+ .withNetwork(NETWORK)
+ .withNetworkAliases("storaged0")
+ .withCommand(
+ "--meta_server_addrs=metad0:9559",
+ "--local_ip=storaged0",
+ "--ws_ip=storaged0",
+ "--port=9779",
+ "--ws_http_port=19779",
+ "--data_path=/data/storage",
+ "--logtostderr=true");
+ graphd =
+ new GenericContainer<>(DockerImageName.parse("vesoft/nebula-graphd:" + VERSION))
+ .withNetwork(NETWORK)
+ .withNetworkAliases("graphd")
+ .withExposedPorts(9669, 19669)
+ .withCommand(
+ "--meta_server_addrs=metad0:9559",
+ "--local_ip=graphd",
+ "--ws_ip=graphd",
+ "--port=9669",
+ "--ws_http_port=19669",
+ "--logtostderr=true")
+ .waitingFor(Wait.forHttp("/status").forPort(19669))
+ .withStartupTimeout(Duration.ofMinutes(3));
+
+ metad.start();
+ // Storaged waits for host registration, so it cannot use an HTTP startup wait here.
+ storaged.start();
+ graphd.start();
+
+ adminPool = new NebulaPool();
+ NebulaPoolConfig poolConfig = new NebulaPoolConfig().setMaxConnSize(1).setTimeout(30000);
+ assertTrue(
+ adminPool.init(
+ Arrays.asList(
+ new HostAddress(graphd.getHost(), graphd.getMappedPort(9669))),
+ poolConfig));
+ adminSession = adminPool.getSession("root", "nebula", false);
+ execute("ADD HOSTS \"storaged0\":9779");
+
+ Awaitility.await()
+ .atMost(90, TimeUnit.SECONDS)
+ .pollInterval(2, TimeUnit.SECONDS)
+ .until(() -> execute("SHOW HOSTS").toString().contains("ONLINE"));
+
+ execute("CREATE SPACE IF NOT EXISTS seatunnel(vid_type = FIXED_STRING(64))");
+ Awaitility.await()
+ .atMost(30, TimeUnit.SECONDS)
+ .pollInterval(1, TimeUnit.SECONDS)
+ .until(() -> succeeds("USE seatunnel"));
+ execute("CREATE TAG IF NOT EXISTS person(name string, age int)");
+ Awaitility.await()
+ .atMost(30, TimeUnit.SECONDS)
+ .pollInterval(1, TimeUnit.SECONDS)
+ .until(() -> succeeds("DESCRIBE TAG person"));
+ }
+
+ @TestTemplate
+ public void writesAndUpdatesVertices(TestContainer container)
+ throws IOException, InterruptedException {
+ execute("DELETE VERTEX \"person-1\", \"person-2\"");
+
+ Container.ExecResult insert =
+ container.executeJob("/nebulagraph/fake_to_nebulagraph_insert.conf");
+ assertEquals(0, insert.getExitCode(), insert.getStderr());
+
+ ResultSet inserted =
+ execute(
+ "FETCH PROP ON person \"person-1\" "
+ + "YIELD properties(vertex).name AS name, properties(vertex).age AS age");
+ assertEquals("Alice", inserted.rowValues(0).get("name").asString());
+ assertEquals(30L, inserted.rowValues(0).get("age").asLong());
+
+ Container.ExecResult update =
+ container.executeJob("/nebulagraph/fake_to_nebulagraph_update.conf");
+ assertEquals(0, update.getExitCode(), update.getStderr());
+
+ ResultSet updated =
+ execute(
+ "FETCH PROP ON person \"person-1\" "
+ + "YIELD properties(vertex).age AS age");
+ assertEquals(31L, updated.rowValues(0).get("age").asLong());
+ }
+
+ @AfterAll
+ @Override
+ public void tearDown() {
+ if (adminSession != null) {
+ adminSession.release();
+ }
+ if (adminPool != null) {
+ adminPool.close();
+ }
+ if (graphd != null) {
+ graphd.stop();
+ }
+ if (storaged != null) {
+ storaged.stop();
+ }
+ if (metad != null) {
+ metad.stop();
+ }
+ }
+
+ private ResultSet execute(String statement) {
+ try {
+ ResultSet result = adminSession.execute(statement);
+ if (!result.isSucceeded()) {
+ throw new IllegalStateException(
+ "NebulaGraph command failed: " + result.getErrorMessage());
+ }
+ return result;
+ } catch (Exception e) {
+ throw new IllegalStateException("Unable to execute NebulaGraph command.", e);
+ }
+ }
+
+ private boolean succeeds(String statement) {
+ try {
+ return adminSession.execute(statement).isSucceeded();
+ } catch (Exception e) {
+ return false;
+ }
+ }
+}
diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_insert.conf b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_insert.conf
new file mode 100644
index 0000000000..e56e7e7b3f
--- /dev/null
+++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_insert.conf
@@ -0,0 +1,65 @@
+#
+# 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.
+#
+
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ rows = [
+ {
+ kind = INSERT
+ fields = {
+ id = "person-1"
+ name = "Alice"
+ age = 30
+ }
+ },
+ {
+ kind = INSERT
+ fields = {
+ id = "person-2"
+ name = "Bob"
+ age = 29
+ }
+ }
+ ]
+ schema = {
+ fields {
+ id = string
+ name = string
+ age = int
+ }
+ }
+ }
+}
+
+sink {
+ NebulaGraph {
+ hosts = ["graphd:9669"]
+ username = "root"
+ password = "nebula"
+ space = "seatunnel"
+ tag = "person"
+ vid_field = "id"
+ write_fields = ["name", "age"]
+ write_mode = "INSERT"
+ batch_size = 2
+ }
+}
diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_update.conf b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_update.conf
new file mode 100644
index 0000000000..a354c975d6
--- /dev/null
+++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-nebulagraph-e2e/src/test/resources/nebulagraph/fake_to_nebulagraph_update.conf
@@ -0,0 +1,57 @@
+#
+# 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.
+#
+
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ rows = [
+ {
+ kind = INSERT
+ fields = {
+ id = "person-1"
+ name = "Alice"
+ age = 31
+ }
+ }
+ ]
+ schema = {
+ fields {
+ id = string
+ name = string
+ age = int
+ }
+ }
+ }
+}
+
+sink {
+ NebulaGraph {
+ hosts = ["graphd:9669"]
+ username = "root"
+ password = "nebula"
+ space = "seatunnel"
+ tag = "person"
+ vid_field = "id"
+ write_fields = ["name", "age"]
+ write_mode = "UPDATE"
+ batch_size = 1
+ }
+}
diff --git a/seatunnel-e2e/seatunnel-connector-v2-e2e/pom.xml b/seatunnel-e2e/seatunnel-connector-v2-e2e/pom.xml
index ab91ca5eba..27e2487aa2 100644
--- a/seatunnel-e2e/seatunnel-connector-v2-e2e/pom.xml
+++ b/seatunnel-e2e/seatunnel-connector-v2-e2e/pom.xml
@@ -98,6 +98,7 @@
<module>connector-aerospike-e2e</module>
<module>connector-sensorsdata-e2e</module>
<module>connector-hugegraph-e2e</module>
+ <module>connector-nebulagraph-e2e</module>
<module>connector-fluss-e2e</module>
<module>connector-lance-e2e</module>
<module>connector-bigquery-e2e</module>