forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pinecone source connector for seatunnel
- Loading branch information
Showing
15 changed files
with
1,124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
seatunnel-common/src/main/java/org/apache/seatunnel/common/constants/CommonOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.apache.seatunnel.common.constants; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum CommonOptions { | ||
JSON("Json"), | ||
METADATA("Metadata"); | ||
|
||
private final String name; | ||
|
||
CommonOptions(String name) { | ||
this.name = name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?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-pinecone</artifactId> | ||
<name>SeaTunnel : Connectors V2 : Pinecone</name> | ||
|
||
<properties> | ||
<!-- Specify the gRPC version --> | ||
<grpc.version>1.59.1</grpc.version> | ||
<protobuf.version>3.25.1</protobuf.version> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>${protobuf.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.grpc</groupId> | ||
<artifactId>grpc-netty</artifactId> | ||
<version>${grpc.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.grpc</groupId> | ||
<artifactId>grpc-netty-shaded</artifactId> | ||
<version>${grpc.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.grpc</groupId> | ||
<artifactId>grpc-protobuf</artifactId> | ||
<version>${grpc.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.grpc</groupId> | ||
<artifactId>grpc-stub</artifactId> | ||
<version>${grpc.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.pinecone</groupId> | ||
<artifactId>pinecone-client</artifactId> | ||
<version>2.1.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.10.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.protobuf</groupId> | ||
<artifactId>protobuf-java</artifactId> | ||
<version>3.25.1</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
</project> |
43 changes: 43 additions & 0 deletions
43
...e/src/main/java/org/apache/seatunnel/connectors/pinecone/config/PineconeSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.pinecone.config; | ||
|
||
import org.apache.seatunnel.api.configuration.Option; | ||
import org.apache.seatunnel.api.configuration.Options; | ||
|
||
public class PineconeSourceConfig { | ||
public static final String CONNECTOR_IDENTITY = "Pinecone"; | ||
|
||
public static final Option<String> API_KEY = | ||
Options.key("api_key") | ||
.stringType() | ||
.noDefaultValue() | ||
.withDescription("Pinecone token for authentication"); | ||
|
||
public static final Option<String> INDEX = | ||
Options.key("index") | ||
.stringType() | ||
.noDefaultValue() | ||
.withDescription("Pinecone index name"); | ||
|
||
public static final Option<Integer> BATCH_SIZE = | ||
Options.key("batch_size") | ||
.intType() | ||
.defaultValue(100) | ||
.withDescription("writer batch size"); | ||
} |
35 changes: 35 additions & 0 deletions
35
.../java/org/apache/seatunnel/connectors/pinecone/exception/PineconeConnectionErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.pinecone.exception; | ||
|
||
import lombok.Getter; | ||
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode; | ||
|
||
@Getter | ||
public enum PineconeConnectionErrorCode implements SeaTunnelErrorCode { | ||
SOURCE_TABLE_SCHEMA_IS_NULL("PINECONE-01", "Source table schema is null"), | ||
READ_DATA_FAIL("PINECONE-02", "Read data fail"); | ||
|
||
private final String code; | ||
private final String description; | ||
|
||
PineconeConnectionErrorCode(String code, String description) { | ||
this.code = code; | ||
this.description = description; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...n/java/org/apache/seatunnel/connectors/pinecone/exception/PineconeConnectorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* 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.pinecone.exception; | ||
|
||
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode; | ||
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException; | ||
|
||
public class PineconeConnectorException extends SeaTunnelRuntimeException { | ||
public PineconeConnectorException(SeaTunnelErrorCode seaTunnelErrorCode) { | ||
super(seaTunnelErrorCode, seaTunnelErrorCode.getErrorMessage()); | ||
} | ||
|
||
public PineconeConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, Throwable cause) { | ||
super(seaTunnelErrorCode, seaTunnelErrorCode.getErrorMessage(), cause); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...inecone/src/main/java/org/apache/seatunnel/connectors/pinecone/source/PineconeSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.pinecone.source; | ||
|
||
import org.apache.seatunnel.api.configuration.ReadonlyConfig; | ||
import org.apache.seatunnel.api.source.Boundedness; | ||
import org.apache.seatunnel.api.source.SeaTunnelSource; | ||
import org.apache.seatunnel.api.source.SourceReader; | ||
import org.apache.seatunnel.api.source.SourceSplitEnumerator; | ||
import org.apache.seatunnel.api.source.SupportColumnProjection; | ||
import org.apache.seatunnel.api.source.SupportParallelism; | ||
import org.apache.seatunnel.api.table.catalog.CatalogTable; | ||
import org.apache.seatunnel.api.table.catalog.TablePath; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelRow; | ||
import org.apache.seatunnel.connectors.pinecone.config.PineconeSourceConfig; | ||
import org.apache.seatunnel.connectors.pinecone.utils.PineconeUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class PineconeSource implements SeaTunnelSource<SeaTunnelRow, PineconeSourceSplit, PineconeSourceState>, | ||
SupportParallelism, | ||
SupportColumnProjection { | ||
private final ReadonlyConfig config; | ||
private final Map<TablePath, CatalogTable> sourceTables; | ||
|
||
public PineconeSource(ReadonlyConfig config) { | ||
this.config = config; | ||
PineconeUtils pineconeUtils = new PineconeUtils(config); | ||
this.sourceTables = pineconeUtils.getSourceTables(); | ||
} | ||
|
||
/** | ||
* Get the boundedness of this source. | ||
* | ||
* @return the boundedness of this source. | ||
*/ | ||
@Override | ||
public Boundedness getBoundedness() { | ||
return Boundedness.BOUNDED; | ||
} | ||
|
||
/** | ||
* Create source reader, used to produce data. | ||
* | ||
* @param readerContext reader context. | ||
* @return source reader. | ||
* @throws Exception when create reader failed. | ||
*/ | ||
@Override | ||
public SourceReader<SeaTunnelRow, PineconeSourceSplit> createReader(SourceReader.Context readerContext) throws Exception { | ||
return new PineconeSourceReader(readerContext, config, sourceTables); | ||
} | ||
|
||
@Override | ||
public List<CatalogTable> getProducedCatalogTables() { | ||
return new ArrayList<>(sourceTables.values()); | ||
} | ||
|
||
/** | ||
* Create source split enumerator, used to generate splits. This method will be called only once | ||
* when start a source. | ||
* | ||
* @param enumeratorContext enumerator context. | ||
* @return source split enumerator. | ||
* @throws Exception when create enumerator failed. | ||
*/ | ||
@Override | ||
public SourceSplitEnumerator<PineconeSourceSplit, PineconeSourceState> createEnumerator(SourceSplitEnumerator.Context<PineconeSourceSplit> enumeratorContext) throws Exception { | ||
return new PineconeSourceSplitEnumertor(enumeratorContext, config, sourceTables, null); | ||
} | ||
|
||
/** | ||
* Create source split enumerator, used to generate splits. This method will be called when | ||
* restore from checkpoint. | ||
* | ||
* @param enumeratorContext enumerator context. | ||
* @param checkpointState checkpoint state. | ||
* @return source split enumerator. | ||
* @throws Exception when create enumerator failed. | ||
*/ | ||
@Override | ||
public SourceSplitEnumerator<PineconeSourceSplit, PineconeSourceState> restoreEnumerator(SourceSplitEnumerator.Context<PineconeSourceSplit> enumeratorContext, PineconeSourceState checkpointState) throws Exception { | ||
return new PineconeSourceSplitEnumertor(enumeratorContext, config, sourceTables, checkpointState); | ||
} | ||
|
||
/** | ||
* Returns a unique identifier among same factory interfaces. | ||
* | ||
* <p>For consistency, an identifier should be declared as one lower case word (e.g. {@code | ||
* kafka}). If multiple factories exist for different versions, a version should be appended | ||
* using "-" (e.g. {@code elasticsearch-7}). | ||
*/ | ||
@Override | ||
public String getPluginName() { | ||
return PineconeSourceConfig.CONNECTOR_IDENTITY; | ||
} | ||
} |
Oops, something went wrong.