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/09/01 10:45:51 UTC
(seatunnel) 01/01: [Feature][Connector-V2] Add Deep Lake sink connector (#11852)
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-11852-be53a1d3d1e3becba7d4386516b7de14fdc0aa7e
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
commit e171b290516c0be548165d7a5cd1937d6bcbd08f
Author: Goutam Adwant <86...@users.noreply.github.com>
AuthorDate: Tue Sep 1 10:45:25 2026 +0000
[Feature][Connector-V2] Add Deep Lake sink connector (#11852)
Signed-off-by: goutamadwant <wo...@gmail.com>
Signed-off-by: Goutam Adwant <wo...@gmail.com>
---
.github/workflows/labeler/label-scope-conf.yml | 5 +
config/plugin_config | 1 +
docs/en/connectors/changelog/connector-deeplake.md | 6 +
docs/en/connectors/sink/DeepLake.md | 122 ++++++++
docs/zh/connectors/changelog/connector-deeplake.md | 6 +
docs/zh/connectors/sink/DeepLake.md | 122 ++++++++
plugin-mapping.properties | 1 +
seatunnel-connectors-v2/connector-deeplake/pom.xml | 48 +++
.../seatunnel/deeplake/client/DeepLakeClient.java | 118 ++++++++
.../seatunnel/deeplake/client/DeepLakeSql.java | 160 ++++++++++
.../deeplake/config/DeepLakeSinkConfig.java | 123 ++++++++
.../deeplake/config/DeepLakeSinkOptions.java | 83 ++++++
.../exception/DeepLakeConnectorErrorCode.java | 44 +++
.../exception/DeepLakeConnectorException.java | 32 ++
.../deeplake/sink/DeepLakeRowConverter.java | 87 ++++++
.../seatunnel/deeplake/sink/DeepLakeSink.java | 56 ++++
.../deeplake/sink/DeepLakeSinkFactory.java | 80 +++++
.../deeplake/sink/DeepLakeSinkWriter.java | 163 +++++++++++
.../seatunnel/deeplake/client/DeepLakeSqlTest.java | 114 ++++++++
.../deeplake/sink/DeepLakeSinkFactoryTest.java | 81 ++++++
.../deeplake/sink/DeepLakeSinkWriterTest.java | 324 +++++++++++++++++++++
seatunnel-connectors-v2/pom.xml | 1 +
seatunnel-dist/pom.xml | 6 +
23 files changed, 1783 insertions(+)
diff --git a/.github/workflows/labeler/label-scope-conf.yml b/.github/workflows/labeler/label-scope-conf.yml
index 9fec74b421..1130483132 100644
--- a/.github/workflows/labeler/label-scope-conf.yml
+++ b/.github/workflows/labeler/label-scope-conf.yml
@@ -99,6 +99,11 @@ salesforce:
- changed-files:
- any-glob-to-any-file: seatunnel-connectors-v2/connector-salesforce/**
- all-globs-to-all-files: '!seatunnel-connectors-v2/connector-!(salesforce)/**'
+deeplake:
+ - all:
+ - changed-files:
+ - any-glob-to-any-file: seatunnel-connectors-v2/connector-deeplake/**
+ - all-globs-to-all-files: '!seatunnel-connectors-v2/connector-!(deeplake)/**'
cdc:
- all:
- changed-files:
diff --git a/config/plugin_config b/config/plugin_config
index cec3f3ceff..a2e8bd3cc7 100644
--- a/config/plugin_config
+++ b/config/plugin_config
@@ -106,6 +106,7 @@ connector-web3j
connector-milvus
connector-activemq
connector-prometheus
+connector-deeplake
connector-sls
connector-qdrant
connector-typesense
diff --git a/docs/en/connectors/changelog/connector-deeplake.md b/docs/en/connectors/changelog/connector-deeplake.md
new file mode 100644
index 0000000000..97ff142816
--- /dev/null
+++ b/docs/en/connectors/changelog/connector-deeplake.md
@@ -0,0 +1,6 @@
+<details><summary> Change Log </summary>
+
+| Change | Commit | Version |
+|--------|--------|---------|
+
+</details>
diff --git a/docs/en/connectors/sink/DeepLake.md b/docs/en/connectors/sink/DeepLake.md
new file mode 100644
index 0000000000..3175164dfe
--- /dev/null
+++ b/docs/en/connectors/sink/DeepLake.md
@@ -0,0 +1,122 @@
+import ChangeLog from '../changelog/connector-deeplake.md';
+
+# DeepLake
+
+> Deep Lake sink connector
+
+## Support These Engines
+
+> Spark<br/>
+> Flink<br/>
+> SeaTunnel Zeta<br/>
+
+## Key Features
+
+- [ ] [exactly-once](../../introduction/concepts/connector-v2-features.md)
+- [ ] [cdc](../../introduction/concepts/connector-v2-features.md)
+- [x] [batch](../../introduction/concepts/connector-v2-features.md)
+- [x] [stream](../../introduction/concepts/connector-v2-features.md)
+- [x] [support multiple table write](../../introduction/concepts/connector-v2-features.md)
+- [ ] [timer flush](../../introduction/concepts/connector-v2-features.md)
+
+## Description
+
+The DeepLake sink appends SeaTunnel rows to a table hosted by the Deep Lake managed service. It uses the Deep Lake REST SQL API and does not require Python or a native Deep Lake client on SeaTunnel workers.
+
+This connector supports managed workspaces reachable through the REST API. Local Deep Lake datasets and Python-only storage paths are not supported.
+
+The sink accepts append-only input. `UPDATE_BEFORE`, `UPDATE_AFTER`, and `DELETE` rows fail instead of being silently appended with incorrect CDC semantics.
+
+## Sink Options
+
+| Name | Type | Required | Default | Description |
+|------|------|----------|---------|-------------|
+| api_url | string | no | `https://api.deeplake.ai` | Deep Lake REST API base URL. |
+| api_key | string | yes | - | Deep Lake API key. Keep this value outside source control. |
+| org_id | string | yes | - | Activeloop organization ID sent with each request. |
+| workspace | string | yes | - | Workspace containing the destination table. |
+| table | string | no | upstream table name | Destination table. |
+| batch_size | int | no | `100` | Maximum rows sent to the batch query endpoint in one request. |
+| connect_timeout_ms | int | no | `10000` | HTTP connection timeout in milliseconds. |
+| socket_timeout_ms | int | no | `60000` | HTTP socket timeout in milliseconds. |
+| schema_save_mode | enum | no | `CREATE_SCHEMA_WHEN_NOT_EXIST` | Schema handling mode. Supported values are `CREATE_SCHEMA_WHEN_NOT_EXIST`, `ERROR_WHEN_SCHEMA_NOT_EXIST`, and `IGNORE`. |
+| multi_table_sink_replica | int | no | `1` | Parallel replica count for multi-table sink writing. |
+
+### schema_save_mode
+
+- `CREATE_SCHEMA_WHEN_NOT_EXIST`: sends `CREATE TABLE IF NOT EXISTS ... USING deeplake` before writing.
+- `ERROR_WHEN_SCHEMA_NOT_EXIST`: validates the table with an empty query and fails when it is unavailable.
+- `IGNORE`: assumes the table already exists and skips schema validation.
+
+`RECREATE_SCHEMA` is rejected because dropping a managed dataset is destructive and unsafe when multiple sink writers start concurrently.
+
+## Data Type Mapping
+
+| SeaTunnel Data Type | Deep Lake SQL Type |
+|---------------------|--------------------|
+| BOOLEAN | BOOLEAN |
+| TINYINT | SMALLINT |
+| SMALLINT | SMALLINT |
+| INT | INTEGER |
+| BIGINT | BIGINT |
+| FLOAT | REAL |
+| DOUBLE | DOUBLE PRECISION |
+| DECIMAL | NUMERIC(precision, scale) |
+| STRING | TEXT |
+| BYTES | BYTEA |
+| DATE | DATE |
+| TIME | TIME |
+| TIMESTAMP | TIMESTAMP |
+| TIMESTAMP_TZ | TIMESTAMPTZ |
+| FLOAT_VECTOR | FLOAT4[] |
+| BINARY_VECTOR | BYTEA |
+| ARRAY | corresponding supported Deep Lake element type array |
+
+`FLOAT16_VECTOR`, `BFLOAT16_VECTOR`, `SPARSE_FLOAT_VECTOR`, `MAP`, `ROW`, and arrays containing `BYTES` or `BINARY_VECTOR` are not supported in this first version. The connector fails during SQL generation rather than converting these values with a loss of precision or structure.
+
+## Delivery Semantics
+
+Rows are buffered in memory and written through Deep Lake's parameterized batch query endpoint. The buffer is cleared only after a successful HTTP response and is flushed when it reaches `batch_size`, on checkpoint preparation, and when an active writer closes. After a failed write, the writer becomes terminal and closing it does not retry the ambiguous batch.
+
+The connector provides at-least-once delivery. A task failure after Deep Lake accepts a request but before SeaTunnel records the checkpoint can cause the batch to be sent again. A stable primary key can detect duplicates but does not make retries exactly-once. Deduplicate before or after this sink when duplicate rows are not acceptable.
+
+The connector maps each input field to the Deep Lake column with the same name. It does not generate a synthetic record ID. Define a primary key in the upstream schema when the destination needs a stable application-level identifier.
+
+## Task Example
+
+```hocon
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ row.num = 10
+ schema = {
+ fields {
+ document_id = bigint
+ content = string
+ score = double
+ }
+ }
+ plugin_output = "documents"
+ }
+}
+
+sink {
+ DeepLake {
+ plugin_input = "documents"
+ api_key = "${DEEPLAKE_API_KEY}"
+ org_id = "${DEEPLAKE_ORG_ID}"
+ workspace = "research"
+ table = "documents"
+ batch_size = 100
+ schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
+ }
+}
+```
+
+## Changelog
+
+<ChangeLog />
diff --git a/docs/zh/connectors/changelog/connector-deeplake.md b/docs/zh/connectors/changelog/connector-deeplake.md
new file mode 100644
index 0000000000..97ff142816
--- /dev/null
+++ b/docs/zh/connectors/changelog/connector-deeplake.md
@@ -0,0 +1,6 @@
+<details><summary> Change Log </summary>
+
+| Change | Commit | Version |
+|--------|--------|---------|
+
+</details>
diff --git a/docs/zh/connectors/sink/DeepLake.md b/docs/zh/connectors/sink/DeepLake.md
new file mode 100644
index 0000000000..b73a75cd0c
--- /dev/null
+++ b/docs/zh/connectors/sink/DeepLake.md
@@ -0,0 +1,122 @@
+import ChangeLog from '../changelog/connector-deeplake.md';
+
+# DeepLake
+
+> Deep Lake Sink 连接器
+
+## 支持引擎
+
+> Spark<br/>
+> Flink<br/>
+> SeaTunnel Zeta<br/>
+
+## 主要特性
+
+- [ ] [精确一次](../../introduction/concepts/connector-v2-features.md)
+- [ ] [CDC](../../introduction/concepts/connector-v2-features.md)
+- [x] [批处理](../../introduction/concepts/connector-v2-features.md)
+- [x] [流处理](../../introduction/concepts/connector-v2-features.md)
+- [x] [支持多表写入](../../introduction/concepts/connector-v2-features.md)
+- [ ] [定时刷新](../../introduction/concepts/connector-v2-features.md)
+
+## 描述
+
+DeepLake Sink 将 SeaTunnel 数据追加写入 Deep Lake 托管服务中的表。连接器使用 Deep Lake REST SQL API,SeaTunnel Worker 不需要安装 Python 或原生 Deep Lake 客户端。
+
+当前仅支持可通过 REST API 访问的托管 Workspace,不支持本地 Deep Lake 数据集或仅限 Python 的存储路径。
+
+该连接器只接受追加数据。遇到 `UPDATE_BEFORE`、`UPDATE_AFTER` 或 `DELETE` 时会直接失败,避免将 CDC 记录错误地追加到目标表。
+
+## Sink 参数
+
+| 名称 | 类型 | 是否必填 | 默认值 | 描述 |
+|------|------|----------|--------|------|
+| api_url | string | 否 | `https://api.deeplake.ai` | Deep Lake REST API 地址。 |
+| api_key | string | 是 | - | Deep Lake API Key,请勿提交到源码仓库。 |
+| org_id | string | 是 | - | 每个请求携带的 Activeloop 组织 ID。 |
+| workspace | string | 是 | - | 目标表所在的 Workspace。 |
+| table | string | 否 | 上游表名 | 目标表名。 |
+| batch_size | int | 否 | `100` | 单次批量请求最多写入的行数。 |
+| connect_timeout_ms | int | 否 | `10000` | HTTP 连接超时时间,单位为毫秒。 |
+| socket_timeout_ms | int | 否 | `60000` | HTTP Socket 超时时间,单位为毫秒。 |
+| schema_save_mode | enum | 否 | `CREATE_SCHEMA_WHEN_NOT_EXIST` | Schema 处理方式。支持 `CREATE_SCHEMA_WHEN_NOT_EXIST`、`ERROR_WHEN_SCHEMA_NOT_EXIST` 和 `IGNORE`。 |
+| multi_table_sink_replica | int | 否 | `1` | 多表写入的并行副本数。 |
+
+### schema_save_mode
+
+- `CREATE_SCHEMA_WHEN_NOT_EXIST`:写入前执行 `CREATE TABLE IF NOT EXISTS ... USING deeplake`。
+- `ERROR_WHEN_SCHEMA_NOT_EXIST`:使用空查询验证目标表,不存在时失败。
+- `IGNORE`:假设目标表已存在并跳过 Schema 验证。
+
+不支持 `RECREATE_SCHEMA`,因为删除托管数据集具有破坏性,并且多个 Sink Writer 并发启动时不安全。
+
+## 数据类型映射
+
+| SeaTunnel 数据类型 | Deep Lake SQL 类型 |
+|-------------------|--------------------|
+| BOOLEAN | BOOLEAN |
+| TINYINT | SMALLINT |
+| SMALLINT | SMALLINT |
+| INT | INTEGER |
+| BIGINT | BIGINT |
+| FLOAT | REAL |
+| DOUBLE | DOUBLE PRECISION |
+| DECIMAL | NUMERIC(precision, scale) |
+| STRING | TEXT |
+| BYTES | BYTEA |
+| DATE | DATE |
+| TIME | TIME |
+| TIMESTAMP | TIMESTAMP |
+| TIMESTAMP_TZ | TIMESTAMPTZ |
+| FLOAT_VECTOR | FLOAT4[] |
+| BINARY_VECTOR | BYTEA |
+| ARRAY | 对应受支持 Deep Lake 元素类型的数组 |
+
+首个版本不支持 `FLOAT16_VECTOR`、`BFLOAT16_VECTOR`、`SPARSE_FLOAT_VECTOR`、`MAP`、`ROW`,也不支持包含 `BYTES` 或 `BINARY_VECTOR` 的数组。SQL 生成阶段会直接失败,不会以精度或结构损失的方式转换这些数据。
+
+## 交付语义
+
+数据先缓存在内存中,再通过 Deep Lake 参数化批量查询接口写入。只有 HTTP 请求成功后才清空缓存;达到 `batch_size`、准备 Checkpoint 和关闭正常 Writer 时都会刷新缓存。写入失败后 Writer 会进入终止状态,关闭时不会重试结果不明确的批次。
+
+连接器提供至少一次交付。Deep Lake 已接受请求但 SeaTunnel 尚未记录 Checkpoint 时,如果任务失败,恢复后可能再次发送同一批数据。稳定的主键可以发现重复数据,但不能让重试变成精确一次语义。无法接受重复数据时,应在写入前或写入后去重。
+
+连接器按同名列映射每个输入字段,不会生成合成记录 ID。目标表需要稳定的业务标识时,应在上游 schema 中定义主键。
+
+## 任务示例
+
+```hocon
+env {
+ parallelism = 1
+ job.mode = "BATCH"
+}
+
+source {
+ FakeSource {
+ row.num = 10
+ schema = {
+ fields {
+ document_id = bigint
+ content = string
+ score = double
+ }
+ }
+ plugin_output = "documents"
+ }
+}
+
+sink {
+ DeepLake {
+ plugin_input = "documents"
+ api_key = "${DEEPLAKE_API_KEY}"
+ org_id = "${DEEPLAKE_ORG_ID}"
+ workspace = "research"
+ table = "documents"
+ batch_size = 100
+ schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
+ }
+}
+```
+
+## 更新日志
+
+<ChangeLog />
diff --git a/plugin-mapping.properties b/plugin-mapping.properties
index 53ded4c36b..d0253dcb4d 100644
--- a/plugin-mapping.properties
+++ b/plugin-mapping.properties
@@ -163,6 +163,7 @@ seatunnel.source.SNMP = connector-snmp
seatunnel.source.Python = connector-python
seatunnel.source.Prometheus = connector-prometheus
seatunnel.sink.Prometheus = connector-prometheus
+seatunnel.sink.DeepLake = connector-deeplake
seatunnel.source.Qdrant = connector-qdrant
seatunnel.sink.Qdrant = connector-qdrant
seatunnel.source.Sls = connector-sls
diff --git a/seatunnel-connectors-v2/connector-deeplake/pom.xml b/seatunnel-connectors-v2/connector-deeplake/pom.xml
new file mode 100644
index 0000000000..f0f7123b0c
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/pom.xml
@@ -0,0 +1,48 @@
+<?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-deeplake</artifactId>
+ <name>SeaTunnel : Connectors V2 : Deep Lake</name>
+
+ <properties>
+ <httpclient.version>4.5.13</httpclient.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>${httpclient.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeClient.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeClient.java
new file mode 100644
index 0000000000..5b74225acc
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeClient.java
@@ -0,0 +1,118 @@
+/*
+ * 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.deeplake.client;
+
+import org.apache.seatunnel.common.utils.JsonUtils;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorException;
+
+import org.apache.http.HttpHeaders;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class DeepLakeClient implements Closeable {
+
+ static final String ORGANIZATION_HEADER = "X-Activeloop-Org-Id";
+
+ private final DeepLakeSinkConfig config;
+ private final CloseableHttpClient httpClient;
+ private final String queryUrl;
+ private final String batchQueryUrl;
+
+ public DeepLakeClient(DeepLakeSinkConfig config) {
+ this.config = config;
+ RequestConfig requestConfig =
+ RequestConfig.custom()
+ .setConnectTimeout(config.getConnectTimeoutMs())
+ .setConnectionRequestTimeout(config.getConnectTimeoutMs())
+ .setSocketTimeout(config.getSocketTimeoutMs())
+ .build();
+ this.httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
+ String workspace = encodePathSegment(config.getWorkspace());
+ this.queryUrl = config.getApiUrl() + "/workspaces/" + workspace + "/tables/query";
+ this.batchQueryUrl = queryUrl + "/batch";
+ }
+
+ public void execute(String query) {
+ Map<String, Object> body = new LinkedHashMap<>();
+ body.put("query", query);
+ post(queryUrl, body);
+ }
+
+ public void executeBatch(String query, List<List<Object>> rows) {
+ Map<String, Object> body = new LinkedHashMap<>();
+ body.put("query", query);
+ body.put("params_batch", rows);
+ post(batchQueryUrl, body);
+ }
+
+ private void post(String url, Map<String, Object> body) {
+ HttpPost request = new HttpPost(url);
+ request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + config.getApiKey());
+ request.setHeader(ORGANIZATION_HEADER, config.getOrgId());
+ request.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
+ request.setEntity(
+ new StringEntity(JsonUtils.toJsonString(body), ContentType.APPLICATION_JSON));
+
+ try (CloseableHttpResponse response = httpClient.execute(request)) {
+ int status = response.getStatusLine().getStatusCode();
+ String responseBody =
+ response.getEntity() == null
+ ? ""
+ : EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
+ if (status < 200 || status >= 300) {
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.REQUEST_FAILED,
+ "Deep Lake request failed with HTTP "
+ + status
+ + (responseBody.isEmpty() ? "" : ": " + responseBody));
+ }
+ } catch (IOException e) {
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.REQUEST_FAILED, "Deep Lake request failed", e);
+ }
+ }
+
+ private static String encodePathSegment(String value) {
+ try {
+ return URLEncoder.encode(value, StandardCharsets.UTF_8.name()).replace("+", "%20");
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Invalid Deep Lake workspace", e);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ httpClient.close();
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSql.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSql.java
new file mode 100644
index 0000000000..a2956571a0
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSql.java
@@ -0,0 +1,160 @@
+/*
+ * 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.deeplake.client;
+
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PrimaryKey;
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorException;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** Builds parameterized Deep Lake SQL and validates the supported SeaTunnel type mapping. */
+public final class DeepLakeSql {
+
+ private DeepLakeSql() {}
+
+ public static String createTableSql(String workspace, String table, CatalogTable catalogTable) {
+ List<Column> schemaColumns = catalogTable.getTableSchema().getColumns();
+ List<String> columns = new ArrayList<>(schemaColumns.size() + 1);
+ for (Column column : schemaColumns) {
+ String definition =
+ quoteIdentifier(column.getName()) + " " + toDeepLakeType(column.getDataType());
+ if (!column.isNullable()) {
+ definition += " NOT NULL";
+ }
+ columns.add(definition);
+ }
+
+ PrimaryKey primaryKey = catalogTable.getTableSchema().getPrimaryKey();
+ if (primaryKey != null && !primaryKey.getColumnNames().isEmpty()) {
+ String keys =
+ primaryKey.getColumnNames().stream()
+ .map(DeepLakeSql::quoteIdentifier)
+ .collect(Collectors.joining(", "));
+ columns.add("PRIMARY KEY (" + keys + ")");
+ }
+
+ return "CREATE TABLE IF NOT EXISTS "
+ + qualifiedTable(workspace, table)
+ + " ("
+ + String.join(", ", columns)
+ + ") USING deeplake";
+ }
+
+ public static String insertSql(String workspace, String table, SeaTunnelRowType rowType) {
+ List<String> columns = new ArrayList<>(rowType.getTotalFields());
+ List<String> parameters = new ArrayList<>(rowType.getTotalFields());
+ for (int i = 0; i < rowType.getTotalFields(); i++) {
+ // Validate every field even when the sink writes to a pre-existing table.
+ toDeepLakeType(rowType.getFieldType(i));
+ columns.add(quoteIdentifier(rowType.getFieldName(i)));
+ String parameter = "$" + (i + 1);
+ switch (rowType.getFieldType(i).getSqlType()) {
+ case FLOAT_VECTOR:
+ parameter += "::float4[]";
+ break;
+ case BINARY_VECTOR:
+ case BYTES:
+ parameter = "decode(" + parameter + ", 'base64')";
+ break;
+ default:
+ break;
+ }
+ parameters.add(parameter);
+ }
+ return "INSERT INTO "
+ + qualifiedTable(workspace, table)
+ + " ("
+ + String.join(", ", columns)
+ + ") VALUES ("
+ + String.join(", ", parameters)
+ + ")";
+ }
+
+ static String toDeepLakeType(SeaTunnelDataType<?> type) {
+ return toDeepLakeType(type, false);
+ }
+
+ private static String toDeepLakeType(SeaTunnelDataType<?> type, boolean arrayElement) {
+ switch (type.getSqlType()) {
+ case BOOLEAN:
+ return "BOOLEAN";
+ case TINYINT:
+ case SMALLINT:
+ return "SMALLINT";
+ case INT:
+ return "INTEGER";
+ case BIGINT:
+ return "BIGINT";
+ case FLOAT:
+ return "REAL";
+ case DOUBLE:
+ return "DOUBLE PRECISION";
+ case DECIMAL:
+ DecimalType decimalType = (DecimalType) type;
+ return "NUMERIC("
+ + decimalType.getPrecision()
+ + ", "
+ + decimalType.getScale()
+ + ")";
+ case STRING:
+ return "TEXT";
+ case BYTES:
+ case BINARY_VECTOR:
+ if (arrayElement) {
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.UNSUPPORTED_DATA_TYPE,
+ "DeepLake sink does not support binary values inside arrays");
+ }
+ return "BYTEA";
+ case DATE:
+ return "DATE";
+ case TIME:
+ return "TIME";
+ case TIMESTAMP:
+ return "TIMESTAMP";
+ case TIMESTAMP_TZ:
+ return "TIMESTAMPTZ";
+ case FLOAT_VECTOR:
+ return "FLOAT4[]";
+ case ARRAY:
+ ArrayType<?, ?> arrayType = (ArrayType<?, ?>) type;
+ return toDeepLakeType(arrayType.getElementType(), true) + "[]";
+ default:
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.UNSUPPORTED_DATA_TYPE,
+ "DeepLake sink does not support " + type.getSqlType());
+ }
+ }
+
+ public static String qualifiedTable(String workspace, String table) {
+ return quoteIdentifier(workspace) + "." + quoteIdentifier(table);
+ }
+
+ public static String quoteIdentifier(String identifier) {
+ return "\"" + identifier.replace("\"", "\"\"") + "\"";
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkConfig.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkConfig.java
new file mode 100644
index 0000000000..6a5b138c29
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkConfig.java
@@ -0,0 +1,123 @@
+/*
+ * 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.deeplake.config;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+
+import java.io.Serializable;
+
+public class DeepLakeSinkConfig implements Serializable {
+
+ private final String apiUrl;
+ private final String apiKey;
+ private final String orgId;
+ private final String workspace;
+ private final String table;
+ private final int batchSize;
+ private final int connectTimeoutMs;
+ private final int socketTimeoutMs;
+ private final SchemaSaveMode schemaSaveMode;
+
+ public DeepLakeSinkConfig(ReadonlyConfig config, CatalogTable catalogTable) {
+ this.apiUrl = removeTrailingSlash(config.get(DeepLakeSinkOptions.API_URL));
+ this.apiKey = config.get(DeepLakeSinkOptions.API_KEY);
+ this.orgId = config.get(DeepLakeSinkOptions.ORG_ID);
+ this.workspace = config.get(DeepLakeSinkOptions.WORKSPACE);
+ this.table =
+ config.getOptional(DeepLakeSinkOptions.TABLE)
+ .orElse(catalogTable.getTableId().getTableName());
+ this.batchSize = config.get(DeepLakeSinkOptions.BATCH_SIZE);
+ this.connectTimeoutMs = config.get(DeepLakeSinkOptions.CONNECT_TIMEOUT_MS);
+ this.socketTimeoutMs = config.get(DeepLakeSinkOptions.SOCKET_TIMEOUT_MS);
+ this.schemaSaveMode = config.get(DeepLakeSinkOptions.SCHEMA_SAVE_MODE);
+
+ requireNonBlank(apiUrl, "api_url");
+ requireNonBlank(apiKey, "api_key");
+ requireNonBlank(orgId, "org_id");
+ requireNonBlank(workspace, "workspace");
+ requireNonBlank(table, "table");
+ requirePositive(batchSize, "batch_size");
+ requirePositive(connectTimeoutMs, "connect_timeout_ms");
+ requirePositive(socketTimeoutMs, "socket_timeout_ms");
+ if (schemaSaveMode == SchemaSaveMode.RECREATE_SCHEMA) {
+ throw new IllegalArgumentException(
+ "schema_save_mode RECREATE_SCHEMA is not supported by the DeepLake sink");
+ }
+ }
+
+ private static String removeTrailingSlash(String value) {
+ if (value == null) {
+ return null;
+ }
+ int end = value.length();
+ while (end > 0 && value.charAt(end - 1) == '/') {
+ end--;
+ }
+ return value.substring(0, end);
+ }
+
+ private static void requireNonBlank(String value, String option) {
+ if (value == null || value.trim().isEmpty()) {
+ throw new IllegalArgumentException(option + " must not be blank");
+ }
+ }
+
+ private static void requirePositive(int value, String option) {
+ if (value <= 0) {
+ throw new IllegalArgumentException(option + " must be greater than zero");
+ }
+ }
+
+ public String getApiUrl() {
+ return apiUrl;
+ }
+
+ public String getApiKey() {
+ return apiKey;
+ }
+
+ public String getOrgId() {
+ return orgId;
+ }
+
+ public String getWorkspace() {
+ return workspace;
+ }
+
+ public String getTable() {
+ return table;
+ }
+
+ public int getBatchSize() {
+ return batchSize;
+ }
+
+ public int getConnectTimeoutMs() {
+ return connectTimeoutMs;
+ }
+
+ public int getSocketTimeoutMs() {
+ return socketTimeoutMs;
+ }
+
+ public SchemaSaveMode getSchemaSaveMode() {
+ return schemaSaveMode;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkOptions.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkOptions.java
new file mode 100644
index 0000000000..b8a0cd77be
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/config/DeepLakeSinkOptions.java
@@ -0,0 +1,83 @@
+/*
+ * 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.deeplake.config;
+
+import org.apache.seatunnel.api.configuration.Option;
+import org.apache.seatunnel.api.configuration.Options;
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+
+public final class DeepLakeSinkOptions {
+
+ public static final String CONNECTOR_IDENTITY = "DeepLake";
+
+ public static final Option<String> API_URL =
+ Options.key("api_url")
+ .stringType()
+ .defaultValue("https://api.deeplake.ai")
+ .withDescription("Deep Lake REST API base URL.");
+
+ public static final Option<String> API_KEY =
+ Options.key("api_key")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Deep Lake API key.");
+
+ public static final Option<String> ORG_ID =
+ Options.key("org_id")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Activeloop organization ID.");
+
+ public static final Option<String> WORKSPACE =
+ Options.key("workspace")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Deep Lake workspace containing the destination table.");
+
+ public static final Option<String> TABLE =
+ Options.key("table")
+ .stringType()
+ .noDefaultValue()
+ .withDescription("Destination table. Defaults to the input table name.");
+
+ public static final Option<Integer> BATCH_SIZE =
+ Options.key("batch_size")
+ .intType()
+ .defaultValue(100)
+ .withDescription("Maximum number of rows sent in one batch request.");
+
+ public static final Option<Integer> CONNECT_TIMEOUT_MS =
+ Options.key("connect_timeout_ms")
+ .intType()
+ .defaultValue(10000)
+ .withDescription("HTTP connection timeout in milliseconds.");
+
+ public static final Option<Integer> SOCKET_TIMEOUT_MS =
+ Options.key("socket_timeout_ms")
+ .intType()
+ .defaultValue(60000)
+ .withDescription("HTTP socket timeout in milliseconds.");
+
+ public static final Option<SchemaSaveMode> SCHEMA_SAVE_MODE =
+ Options.key("schema_save_mode")
+ .enumType(SchemaSaveMode.class)
+ .defaultValue(SchemaSaveMode.CREATE_SCHEMA_WHEN_NOT_EXIST)
+ .withDescription("Controls whether the destination table is created.");
+
+ private DeepLakeSinkOptions() {}
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorErrorCode.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorErrorCode.java
new file mode 100644
index 0000000000..0dbf836fc2
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorErrorCode.java
@@ -0,0 +1,44 @@
+/*
+ * 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.deeplake.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
+
+public enum DeepLakeConnectorErrorCode implements SeaTunnelErrorCode {
+ REQUEST_FAILED("DEEPLAKE-01", "Deep Lake request failed"),
+ UNSUPPORTED_ROW_KIND("DEEPLAKE-02", "Deep Lake sink received an unsupported row kind"),
+ UNSUPPORTED_DATA_TYPE("DEEPLAKE-03", "Deep Lake sink received an unsupported data type");
+
+ private final String code;
+ private final String description;
+
+ DeepLakeConnectorErrorCode(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-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorException.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorException.java
new file mode 100644
index 0000000000..9bf6628f31
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/exception/DeepLakeConnectorException.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.deeplake.exception;
+
+import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
+
+public class DeepLakeConnectorException extends SeaTunnelRuntimeException {
+
+ public DeepLakeConnectorException(DeepLakeConnectorErrorCode errorCode, String message) {
+ super(errorCode, message);
+ }
+
+ public DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode errorCode, String message, Throwable cause) {
+ super(errorCode, message, cause);
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeRowConverter.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeRowConverter.java
new file mode 100644
index 0000000000..2336314727
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeRowConverter.java
@@ -0,0 +1,87 @@
+/*
+ * 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.deeplake.sink;
+
+import org.apache.seatunnel.api.table.type.ArrayType;
+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.common.utils.VectorUtils;
+
+import java.lang.reflect.Array;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.List;
+
+final class DeepLakeRowConverter {
+
+ private DeepLakeRowConverter() {}
+
+ static List<Object> convert(SeaTunnelRow row, SeaTunnelRowType rowType) {
+ List<Object> values = new ArrayList<>(rowType.getTotalFields());
+ for (int i = 0; i < rowType.getTotalFields(); i++) {
+ values.add(convertValue(row.getField(i), rowType.getFieldType(i)));
+ }
+ return values;
+ }
+
+ private static Object convertValue(Object value, SeaTunnelDataType<?> type) {
+ if (value == null) {
+ return null;
+ }
+ switch (type.getSqlType()) {
+ case BYTES:
+ return Base64.getEncoder().encodeToString((byte[]) value);
+ case BINARY_VECTOR:
+ return Base64.getEncoder().encodeToString(readBytes((ByteBuffer) value));
+ case FLOAT_VECTOR:
+ ByteBuffer vectorBuffer = ((ByteBuffer) value).duplicate();
+ vectorBuffer.rewind();
+ Float[] vector = VectorUtils.toFloatArray(vectorBuffer);
+ List<Float> vectorValues = new ArrayList<>(vector.length);
+ for (Float item : vector) {
+ vectorValues.add(item);
+ }
+ return vectorValues;
+ case ARRAY:
+ SeaTunnelDataType<?> elementType = ((ArrayType<?, ?>) type).getElementType();
+ int length = Array.getLength(value);
+ List<Object> arrayValues = new ArrayList<>(length);
+ for (int i = 0; i < length; i++) {
+ arrayValues.add(convertValue(Array.get(value, i), elementType));
+ }
+ return arrayValues;
+ case DATE:
+ case TIME:
+ case TIMESTAMP:
+ case TIMESTAMP_TZ:
+ return value.toString();
+ default:
+ return value;
+ }
+ }
+
+ private static byte[] readBytes(ByteBuffer buffer) {
+ ByteBuffer copy = buffer.duplicate();
+ copy.rewind();
+ byte[] bytes = new byte[copy.remaining()];
+ copy.get(bytes);
+ return bytes;
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSink.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSink.java
new file mode 100644
index 0000000000..de758bed20
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSink.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.deeplake.sink;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.sink.SinkWriter;
+import org.apache.seatunnel.api.sink.SupportMultiTableSink;
+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.deeplake.config.DeepLakeSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkOptions;
+
+import java.util.Optional;
+
+public class DeepLakeSink extends AbstractSimpleSink<SeaTunnelRow, Void>
+ implements SupportMultiTableSink {
+
+ private final CatalogTable catalogTable;
+ private final DeepLakeSinkConfig config;
+
+ public DeepLakeSink(ReadonlyConfig readonlyConfig, CatalogTable catalogTable) {
+ this.catalogTable = catalogTable;
+ this.config = new DeepLakeSinkConfig(readonlyConfig, catalogTable);
+ }
+
+ @Override
+ public String getPluginName() {
+ return DeepLakeSinkOptions.CONNECTOR_IDENTITY;
+ }
+
+ @Override
+ public DeepLakeSinkWriter createWriter(SinkWriter.Context context) {
+ return new DeepLakeSinkWriter(catalogTable, config);
+ }
+
+ @Override
+ public Optional<CatalogTable> getWriteCatalogTable() {
+ return Optional.of(catalogTable);
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactory.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactory.java
new file mode 100644
index 0000000000..dc1867ef36
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactory.java
@@ -0,0 +1,80 @@
+/*
+ * 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.deeplake.sink;
+
+import org.apache.seatunnel.api.configuration.util.Condition;
+import org.apache.seatunnel.api.configuration.util.ConditionOperator;
+import org.apache.seatunnel.api.configuration.util.Conditions;
+import org.apache.seatunnel.api.configuration.util.OptionRule;
+import org.apache.seatunnel.api.options.SinkConnectorCommonOptions;
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+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.deeplake.config.DeepLakeSinkOptions;
+
+import com.google.auto.service.AutoService;
+
+@AutoService(Factory.class)
+public class DeepLakeSinkFactory implements TableSinkFactory {
+
+ @Override
+ public String factoryIdentifier() {
+ return DeepLakeSinkOptions.CONNECTOR_IDENTITY;
+ }
+
+ @Override
+ public TableSink createSink(TableSinkFactoryContext context) {
+ return () -> new DeepLakeSink(context.getOptions(), context.getCatalogTable());
+ }
+
+ @Override
+ public OptionRule optionRule() {
+ return OptionRule.builder()
+ .required(
+ DeepLakeSinkOptions.API_KEY,
+ Conditions.notBlank(DeepLakeSinkOptions.API_KEY))
+ .required(
+ DeepLakeSinkOptions.ORG_ID, Conditions.notBlank(DeepLakeSinkOptions.ORG_ID))
+ .required(
+ DeepLakeSinkOptions.WORKSPACE,
+ Conditions.notBlank(DeepLakeSinkOptions.WORKSPACE))
+ .optional(
+ DeepLakeSinkOptions.API_URL,
+ Conditions.notBlank(DeepLakeSinkOptions.API_URL))
+ .optional(DeepLakeSinkOptions.TABLE, Conditions.notBlank(DeepLakeSinkOptions.TABLE))
+ .optional(
+ DeepLakeSinkOptions.BATCH_SIZE,
+ Conditions.greaterThan(DeepLakeSinkOptions.BATCH_SIZE, 0))
+ .optional(
+ DeepLakeSinkOptions.CONNECT_TIMEOUT_MS,
+ Conditions.greaterThan(DeepLakeSinkOptions.CONNECT_TIMEOUT_MS, 0))
+ .optional(
+ DeepLakeSinkOptions.SOCKET_TIMEOUT_MS,
+ Conditions.greaterThan(DeepLakeSinkOptions.SOCKET_TIMEOUT_MS, 0))
+ .optional(
+ DeepLakeSinkOptions.SCHEMA_SAVE_MODE,
+ Condition.of(
+ DeepLakeSinkOptions.SCHEMA_SAVE_MODE,
+ ConditionOperator.NOT_EQUAL,
+ SchemaSaveMode.RECREATE_SCHEMA))
+ .optional(SinkConnectorCommonOptions.MULTI_TABLE_SINK_REPLICA)
+ .build();
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriter.java b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriter.java
new file mode 100644
index 0000000000..9ec95f05d2
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/main/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriter.java
@@ -0,0 +1,163 @@
+/*
+ * 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.deeplake.sink;
+
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+import org.apache.seatunnel.api.sink.SupportMultiTableSinkWriter;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+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.deeplake.client.DeepLakeClient;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.client.DeepLakeSql;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorErrorCode;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorException;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/** Buffers append-only rows and writes parameterized batches to a Deep Lake table. */
+public class DeepLakeSinkWriter extends AbstractSinkWriter<SeaTunnelRow, Void>
+ implements SupportMultiTableSinkWriter<Void> {
+
+ private final DeepLakeClient client;
+ private final SeaTunnelRowType rowType;
+ private final int batchSize;
+ private final String insertSql;
+ private final List<List<Object>> rows;
+ private boolean failed;
+
+ public DeepLakeSinkWriter(CatalogTable catalogTable, DeepLakeSinkConfig config) {
+ this.rowType = catalogTable.getSeaTunnelRowType();
+ this.batchSize = config.getBatchSize();
+ this.insertSql = DeepLakeSql.insertSql(config.getWorkspace(), config.getTable(), rowType);
+ this.rows = new ArrayList<>(batchSize);
+ this.client = new DeepLakeClient(config);
+
+ try {
+ if (config.getSchemaSaveMode() == SchemaSaveMode.CREATE_SCHEMA_WHEN_NOT_EXIST) {
+ client.execute(
+ DeepLakeSql.createTableSql(
+ config.getWorkspace(), config.getTable(), catalogTable));
+ } else if (config.getSchemaSaveMode() == SchemaSaveMode.ERROR_WHEN_SCHEMA_NOT_EXIST) {
+ client.execute(
+ "SELECT 1 FROM "
+ + DeepLakeSql.qualifiedTable(
+ config.getWorkspace(), config.getTable())
+ + " LIMIT 0");
+ }
+ } catch (RuntimeException | Error e) {
+ try {
+ client.close();
+ } catch (IOException closeError) {
+ e.addSuppressed(closeError);
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public void write(SeaTunnelRow element) {
+ ensureActive();
+ if (element.getRowKind() != RowKind.INSERT) {
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.UNSUPPORTED_ROW_KIND,
+ "DeepLake sink supports append-only input, but received "
+ + element.getRowKind());
+ }
+ try {
+ rows.add(DeepLakeRowConverter.convert(element, rowType));
+ if (rows.size() >= batchSize) {
+ flush();
+ }
+ } catch (RuntimeException | Error e) {
+ failed = true;
+ throw e;
+ }
+ }
+
+ @Override
+ public Optional<Void> prepareCommit() {
+ ensureActive();
+ flush();
+ return Optional.empty();
+ }
+
+ void flush() {
+ ensureActive();
+ if (rows.isEmpty()) {
+ return;
+ }
+ try {
+ client.executeBatch(insertSql, rows);
+ } catch (RuntimeException | Error e) {
+ failed = true;
+ throw e;
+ }
+ rows.clear();
+ }
+
+ private void ensureActive() {
+ if (failed) {
+ throw new DeepLakeConnectorException(
+ DeepLakeConnectorErrorCode.REQUEST_FAILED,
+ "DeepLake sink writer cannot continue after a failed write");
+ }
+ }
+
+ int bufferedRows() {
+ return rows.size();
+ }
+
+ @Override
+ public void close() throws IOException {
+ Throwable primary = null;
+ if (!failed) {
+ try {
+ flush();
+ } catch (Throwable t) {
+ primary = t;
+ }
+ }
+ try {
+ client.close();
+ } catch (Throwable t) {
+ if (primary == null) {
+ primary = t;
+ } else {
+ primary.addSuppressed(t);
+ }
+ }
+ if (primary instanceof IOException) {
+ throw (IOException) primary;
+ }
+ if (primary instanceof RuntimeException) {
+ throw (RuntimeException) primary;
+ }
+ if (primary instanceof Error) {
+ throw (Error) primary;
+ }
+ if (primary != null) {
+ throw new IOException(primary);
+ }
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSqlTest.java b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSqlTest.java
new file mode 100644
index 0000000000..7bb254ff86
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/client/DeepLakeSqlTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.deeplake.client;
+
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.catalog.PrimaryKey;
+import org.apache.seatunnel.api.table.catalog.TableIdentifier;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.VectorType;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorException;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class DeepLakeSqlTest {
+
+ @Test
+ void buildsCreateAndInsertStatementsForSupportedTypes() {
+ CatalogTable table = catalogTable();
+
+ assertEquals(
+ "CREATE TABLE IF NOT EXISTS \"research\".\"documents\" "
+ + "(\"document_id\" BIGINT NOT NULL, \"content\" TEXT, \"embedding\" FLOAT4[], "
+ + "\"payload\" BYTEA, \"score\" NUMERIC(12, 4), PRIMARY KEY (\"document_id\")) "
+ + "USING deeplake",
+ DeepLakeSql.createTableSql("research", "documents", table));
+ assertEquals(
+ "INSERT INTO \"research\".\"documents\" "
+ + "(\"document_id\", \"content\", \"embedding\", \"payload\", \"score\") "
+ + "VALUES ($1, $2, $3::float4[], decode($4, 'base64'), $5)",
+ DeepLakeSql.insertSql("research", "documents", table.getSeaTunnelRowType()));
+ }
+
+ @Test
+ void quotesWorkspaceTableAndColumnIdentifiers() {
+ assertEquals("\"team\"\"one\"", DeepLakeSql.quoteIdentifier("team\"one"));
+ assertEquals(
+ "\"team\"\"one\".\"docs\"\"2026\"",
+ DeepLakeSql.qualifiedTable("team\"one", "docs\"2026"));
+ }
+
+ @Test
+ void rejectsVectorEncodingsThatCannotBeRepresentedWithoutConversion() {
+ assertThrows(
+ DeepLakeConnectorException.class,
+ () -> DeepLakeSql.toDeepLakeType(VectorType.VECTOR_FLOAT16_TYPE));
+ }
+
+ @Test
+ void rejectsBinaryValuesInsideArrays() {
+ assertThrows(
+ DeepLakeConnectorException.class,
+ () ->
+ DeepLakeSql.toDeepLakeType(
+ new ArrayType<>(byte[][].class, PrimitiveByteArrayType.INSTANCE)));
+ }
+
+ static CatalogTable catalogTable() {
+ List<Column> columns =
+ Arrays.asList(
+ column("document_id", BasicType.LONG_TYPE, false),
+ column("content", BasicType.STRING_TYPE, true),
+ column("embedding", VectorType.VECTOR_FLOAT_TYPE, true),
+ column("payload", PrimitiveByteArrayType.INSTANCE, true),
+ column("score", new DecimalType(12, 4), true));
+ TableSchema schema =
+ TableSchema.builder()
+ .columns(columns)
+ .primaryKey(
+ PrimaryKey.of(
+ "pk_documents", Collections.singletonList("document_id")))
+ .build();
+ return CatalogTable.of(
+ TableIdentifier.of("deeplake", "research", "documents"),
+ schema,
+ Collections.emptyMap(),
+ Collections.emptyList(),
+ "Deep Lake documents");
+ }
+
+ private static Column column(
+ String name,
+ org.apache.seatunnel.api.table.type.SeaTunnelDataType<?> dataType,
+ boolean nullable) {
+ return PhysicalColumn.builder().name(name).dataType(dataType).nullable(nullable).build();
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactoryTest.java b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactoryTest.java
new file mode 100644
index 0000000000..a16c2458e7
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkFactoryTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.deeplake.sink;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.configuration.util.ConfigValidator;
+import org.apache.seatunnel.api.configuration.util.OptionValidationException;
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkOptions;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class DeepLakeSinkFactoryTest {
+
+ private static final DeepLakeSinkFactory FACTORY = new DeepLakeSinkFactory();
+
+ @Test
+ void exposesExpectedIdentifierAndAcceptsValidOptions() {
+ assertEquals("DeepLake", FACTORY.factoryIdentifier());
+ assertDoesNotThrow(() -> validate(requiredOptions()));
+ }
+
+ @Test
+ void rejectsMissingRequiredOptions() {
+ for (String option : new String[] {"api_key", "org_id", "workspace"}) {
+ Map<String, Object> config = requiredOptions();
+ config.remove(option);
+ assertThrows(OptionValidationException.class, () -> validate(config));
+ }
+ }
+
+ @Test
+ void rejectsInvalidOptionalValues() {
+ Map<String, Object> blankApiUrl = requiredOptions();
+ blankApiUrl.put(DeepLakeSinkOptions.API_URL.key(), " ");
+ assertThrows(OptionValidationException.class, () -> validate(blankApiUrl));
+
+ Map<String, Object> zeroBatchSize = requiredOptions();
+ zeroBatchSize.put(DeepLakeSinkOptions.BATCH_SIZE.key(), 0);
+ assertThrows(OptionValidationException.class, () -> validate(zeroBatchSize));
+
+ Map<String, Object> recreateSchema = requiredOptions();
+ recreateSchema.put(
+ DeepLakeSinkOptions.SCHEMA_SAVE_MODE.key(), SchemaSaveMode.RECREATE_SCHEMA.name());
+ assertThrows(OptionValidationException.class, () -> validate(recreateSchema));
+ }
+
+ private static Map<String, Object> requiredOptions() {
+ Map<String, Object> config = new HashMap<>();
+ config.put(DeepLakeSinkOptions.API_KEY.key(), "test-api-key");
+ config.put(DeepLakeSinkOptions.ORG_ID.key(), "test-org");
+ config.put(DeepLakeSinkOptions.WORKSPACE.key(), "research");
+ return config;
+ }
+
+ private static void validate(Map<String, Object> config) {
+ ConfigValidator.of(ReadonlyConfig.fromMap(config)).validate(FACTORY.optionRule());
+ }
+}
diff --git a/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriterTest.java b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriterTest.java
new file mode 100644
index 0000000000..b68efd3116
--- /dev/null
+++ b/seatunnel-connectors-v2/connector-deeplake/src/test/java/org/apache/seatunnel/connectors/seatunnel/deeplake/sink/DeepLakeSinkWriterTest.java
@@ -0,0 +1,324 @@
+/*
+ * 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.deeplake.sink;
+
+import org.apache.seatunnel.api.configuration.ReadonlyConfig;
+import org.apache.seatunnel.api.sink.SchemaSaveMode;
+import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.catalog.TableIdentifier;
+import org.apache.seatunnel.api.table.catalog.TableSchema;
+import org.apache.seatunnel.api.table.type.ArrayType;
+import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
+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.api.table.type.VectorType;
+import org.apache.seatunnel.common.utils.VectorUtils;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkConfig;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.config.DeepLakeSinkOptions;
+import org.apache.seatunnel.connectors.seatunnel.deeplake.exception.DeepLakeConnectorException;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+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 java.util.concurrent.atomic.AtomicInteger;
+
+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 DeepLakeSinkWriterTest {
+
+ private HttpServer server;
+ private String apiUrl;
+ private final List<String> requestBodies = Collections.synchronizedList(new ArrayList<>());
+ private final List<String> requestPaths = Collections.synchronizedList(new ArrayList<>());
+ private final AtomicInteger responseStatus = new AtomicInteger(204);
+
+ @BeforeEach
+ void setUp() throws IOException {
+ server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ server.createContext("/workspaces/research/tables/query", this::handleRequest);
+ server.start();
+ apiUrl = "http://127.0.0.1:" + server.getAddress().getPort();
+ }
+
+ @AfterEach
+ void tearDown() {
+ if (server != null) {
+ server.stop(0);
+ }
+ }
+
+ @Test
+ void createsTableAndWritesParameterizedBatchWithAuthentication() throws IOException {
+ CatalogTable table = catalogTable();
+ DeepLakeSinkWriter writer = writer(table, SchemaSaveMode.CREATE_SCHEMA_WHEN_NOT_EXIST, 2);
+
+ writer.write(row(10L, "first document", new byte[] {1, 2, 3}, 0.1F, 0.2F));
+ assertEquals(1, writer.bufferedRows());
+ writer.write(
+ row(
+ 11L,
+ "second document'); DROP TABLE documents; --",
+ new byte[] {4, 5},
+ 0.3F,
+ 0.4F));
+
+ assertEquals(0, writer.bufferedRows());
+ assertEquals(2, requestBodies.size());
+ assertEquals("/workspaces/research/tables/query", requestPaths.get(0));
+ assertEquals("/workspaces/research/tables/query/batch", requestPaths.get(1));
+ assertTrue(requestBodies.get(0).contains("CREATE TABLE IF NOT EXISTS"));
+ assertTrue(requestBodies.get(0).contains("FLOAT4[]"));
+ assertTrue(requestBodies.get(1).contains("params_batch"));
+ assertTrue(requestBodies.get(1).contains("first document"));
+ assertTrue(requestBodies.get(1).contains("[0.1,0.2]"));
+ assertTrue(requestBodies.get(1).contains("AQID"));
+ assertTrue(requestBodies.get(1).contains("DROP TABLE documents"));
+ assertTrue(
+ requestBodies
+ .get(1)
+ .contains("VALUES ($1, $2, decode($3, 'base64'), $4::float4[])"));
+ writer.close();
+ }
+
+ @Test
+ void doesNotRetryFailedBatchWhenWriterCloses() throws IOException {
+ DeepLakeSinkWriter writer = writer(catalogTable(), SchemaSaveMode.IGNORE, 1);
+ responseStatus.set(503);
+
+ DeepLakeConnectorException error =
+ assertThrows(
+ DeepLakeConnectorException.class,
+ () -> writer.write(row(10L, "document", new byte[] {1}, 0.1F, 0.2F)));
+
+ assertTrue(error.getMessage().contains("HTTP 503"));
+ assertEquals(1, writer.bufferedRows());
+ assertEquals(1, requestBodies.size());
+
+ DeepLakeConnectorException terminalError =
+ assertThrows(
+ DeepLakeConnectorException.class,
+ () -> writer.write(row(11L, "later", new byte[] {2}, 0.3F, 0.4F)));
+ assertTrue(terminalError.getMessage().contains("cannot continue"));
+ assertEquals(1, requestBodies.size());
+ responseStatus.set(204);
+ writer.close();
+ assertEquals(1, requestBodies.size());
+ }
+
+ @Test
+ void rejectsNonInsertRowsBeforeSendingThem() throws IOException {
+ DeepLakeSinkWriter writer = writer(catalogTable(), SchemaSaveMode.IGNORE, 10);
+ SeaTunnelRow update = row(10L, "updated document", new byte[] {1}, 0.1F, 0.2F);
+ update.setRowKind(RowKind.UPDATE_AFTER);
+
+ DeepLakeConnectorException error =
+ assertThrows(DeepLakeConnectorException.class, () -> writer.write(update));
+
+ assertTrue(error.getMessage().contains("append-only"));
+ assertTrue(requestBodies.isEmpty());
+ writer.write(row(11L, "valid document", new byte[] {2}, 0.3F, 0.4F));
+ writer.close();
+ assertEquals(1, requestBodies.size());
+ }
+
+ @Test
+ void rejectsUnsupportedTypesForEveryExistingTableMode() {
+ CatalogTable unsupportedTable = unsupportedCatalogTable();
+
+ for (SchemaSaveMode mode :
+ Arrays.asList(SchemaSaveMode.ERROR_WHEN_SCHEMA_NOT_EXIST, SchemaSaveMode.IGNORE)) {
+ DeepLakeConnectorException error =
+ assertThrows(
+ DeepLakeConnectorException.class,
+ () -> writer(unsupportedTable, mode, 10));
+
+ assertTrue(error.getMessage().contains("FLOAT16_VECTOR"));
+ }
+ assertTrue(requestBodies.isEmpty());
+ }
+
+ @Test
+ void validatesExistingTableWhenConfigured() throws IOException {
+ DeepLakeSinkWriter writer =
+ writer(catalogTable(), SchemaSaveMode.ERROR_WHEN_SCHEMA_NOT_EXIST, 10);
+
+ assertEquals(1, requestBodies.size());
+ assertTrue(
+ requestBodies
+ .get(0)
+ .contains("SELECT 1 FROM \\\"research\\\".\\\"documents\\\" LIMIT 0"));
+ writer.close();
+ }
+
+ @Test
+ void flushesPartialBatchWhenPreparingCommit() throws IOException {
+ DeepLakeSinkWriter writer = writer(catalogTable(), SchemaSaveMode.IGNORE, 2);
+ writer.write(row(10L, "document", new byte[] {1}, 0.1F, 0.2F));
+
+ assertTrue(requestBodies.isEmpty());
+ writer.prepareCommit();
+ assertEquals(1, requestBodies.size());
+ assertEquals(0, writer.bufferedRows());
+ writer.close();
+ }
+
+ @Test
+ void flushesPartialBatchWhenWriterCloses() throws IOException {
+ DeepLakeSinkWriter writer = writer(catalogTable(), SchemaSaveMode.IGNORE, 2);
+ writer.write(row(10L, "document", new byte[] {1}, 0.1F, 0.2F));
+
+ assertTrue(requestBodies.isEmpty());
+ writer.close();
+ assertEquals(1, requestBodies.size());
+ }
+
+ @Test
+ void convertsNestedArrayElementsUsingTheirDeclaredType() {
+ SeaTunnelRowType rowType =
+ new SeaTunnelRowType(
+ new String[] {"scores"},
+ new SeaTunnelDataType[] {
+ new ArrayType<>(Float[][].class, ArrayType.FLOAT_ARRAY_TYPE)
+ });
+ SeaTunnelRow row =
+ new SeaTunnelRow(new Object[] {new Float[][] {{1.0F, 2.0F}, {3.0F, 4.0F}}});
+
+ List<Object> converted = DeepLakeRowConverter.convert(row, rowType);
+
+ assertEquals(
+ Collections.singletonList(
+ Arrays.asList(Arrays.asList(1.0F, 2.0F), Arrays.asList(3.0F, 4.0F))),
+ converted);
+ }
+
+ private void handleRequest(HttpExchange exchange) throws IOException {
+ assertEquals("POST", exchange.getRequestMethod());
+ assertEquals("Bearer test-api-key", exchange.getRequestHeaders().getFirst("Authorization"));
+ assertEquals("test-org", exchange.getRequestHeaders().getFirst("X-Activeloop-Org-Id"));
+ requestPaths.add(exchange.getRequestURI().getPath());
+ requestBodies.add(
+ new String(readAllBytes(exchange.getRequestBody()), StandardCharsets.UTF_8));
+ int status = responseStatus.get();
+ byte[] response =
+ status >= 300
+ ? "service unavailable".getBytes(StandardCharsets.UTF_8)
+ : new byte[0];
+ exchange.sendResponseHeaders(status, response.length == 0 ? -1 : response.length);
+ if (response.length > 0) {
+ exchange.getResponseBody().write(response);
+ }
+ exchange.close();
+ }
+
+ private static byte[] readAllBytes(InputStream input) throws IOException {
+ java.io.ByteArrayOutputStream output = new java.io.ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int count;
+ while ((count = input.read(buffer)) != -1) {
+ output.write(buffer, 0, count);
+ }
+ return output.toByteArray();
+ }
+
+ private DeepLakeSinkWriter writer(
+ CatalogTable table, SchemaSaveMode schemaSaveMode, int batchSize) {
+ Map<String, Object> options = new HashMap<>();
+ options.put(DeepLakeSinkOptions.API_URL.key(), apiUrl);
+ options.put(DeepLakeSinkOptions.API_KEY.key(), "test-api-key");
+ options.put(DeepLakeSinkOptions.ORG_ID.key(), "test-org");
+ options.put(DeepLakeSinkOptions.WORKSPACE.key(), "research");
+ options.put(DeepLakeSinkOptions.TABLE.key(), "documents");
+ options.put(DeepLakeSinkOptions.BATCH_SIZE.key(), batchSize);
+ options.put(DeepLakeSinkOptions.SCHEMA_SAVE_MODE.key(), schemaSaveMode.name());
+ return new DeepLakeSinkWriter(
+ table, new DeepLakeSinkConfig(ReadonlyConfig.fromMap(options), table));
+ }
+
+ private static CatalogTable catalogTable() {
+ List<Column> columns =
+ Arrays.asList(
+ PhysicalColumn.builder()
+ .name("document_id")
+ .dataType(BasicType.LONG_TYPE)
+ .nullable(false)
+ .build(),
+ PhysicalColumn.builder()
+ .name("content")
+ .dataType(BasicType.STRING_TYPE)
+ .nullable(true)
+ .build(),
+ PhysicalColumn.builder()
+ .name("payload")
+ .dataType(PrimitiveByteArrayType.INSTANCE)
+ .nullable(true)
+ .build(),
+ PhysicalColumn.builder()
+ .name("embedding")
+ .dataType(VectorType.VECTOR_FLOAT_TYPE)
+ .nullable(true)
+ .build());
+ return CatalogTable.of(
+ TableIdentifier.of("deeplake", "research", "documents"),
+ TableSchema.builder().columns(columns).build(),
+ Collections.emptyMap(),
+ Collections.emptyList(),
+ "Deep Lake documents");
+ }
+
+ private static CatalogTable unsupportedCatalogTable() {
+ return CatalogTable.of(
+ TableIdentifier.of("deeplake", "research", "documents"),
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.builder()
+ .name("embedding")
+ .dataType(VectorType.VECTOR_FLOAT16_TYPE)
+ .nullable(true)
+ .build())
+ .build(),
+ Collections.emptyMap(),
+ Collections.emptyList(),
+ "Unsupported Deep Lake documents");
+ }
+
+ private static SeaTunnelRow row(long id, String content, byte[] payload, Float... embedding) {
+ return new SeaTunnelRow(
+ new Object[] {id, content, payload, VectorUtils.toByteBuffer(embedding)});
+ }
+}
diff --git a/seatunnel-connectors-v2/pom.xml b/seatunnel-connectors-v2/pom.xml
index 208749b90c..3d3de7019e 100644
--- a/seatunnel-connectors-v2/pom.xml
+++ b/seatunnel-connectors-v2/pom.xml
@@ -92,6 +92,7 @@
<module>connector-milvus</module>
<module>connector-activemq</module>
<module>connector-prometheus</module>
+ <module>connector-deeplake</module>
<module>connector-qdrant</module>
<module>connector-sls</module>
<module>connector-typesense</module>
diff --git a/seatunnel-dist/pom.xml b/seatunnel-dist/pom.xml
index 627da6aec9..ae00d170db 100644
--- a/seatunnel-dist/pom.xml
+++ b/seatunnel-dist/pom.xml
@@ -278,6 +278,12 @@
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.seatunnel</groupId>
+ <artifactId>connector-deeplake</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-http-myhours</artifactId>