-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature][Connector-v2] Neo4j sink connector #2434
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1bd09c
ConnectorV2 - Neo4j Sink
ff9b6b3
ConnectorV2 Neo4j Sink - minimal feature complete
4da89c2
ConnectorV2 Neo4j Sink - add database config
3541d78
ConnectorV2 Neo4j Sink - add timout config
b110569
ConnectorV2 Neo4j Sink - add API doc
c46730d
ConnectorV2 Neo4j Sink - pass code checker
2740c7a
ConnectorV2 Neo4j Sink - add License header
e2b6c9d
Merge branch 'dev' into connectorv2-neo4j-sink
getChan 4afec22
ConnectorV2 Neo4j Sink - neo4j driver version to root pom
033250c
ConnectorV2 Neo4j Sink - fix plugin name
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Neo4j | ||
|
||
> Neo4j sink connector | ||
|
||
## Description | ||
|
||
Write data to Neo4j. | ||
|
||
`neo4j-java-driver` version 4.4.9 | ||
|
||
## Options | ||
|
||
| name | type | required | default value | | ||
|----------------------------|--------|----------|---------------| | ||
| uri | String | Yes | - | | ||
| username | String | No | - | | ||
| password | String | No | - | | ||
| bearer_token | String | No | - | | ||
| kerberos_ticket | String | No | - | | ||
| database | String | Yes | - | | ||
| query | String | Yes | - | | ||
| queryParamPosition | Object | Yes | - | | ||
| max_transaction_retry_time | Long | No | 30 | | ||
| max_connection_timeout | Long | No | 30 | | ||
|
||
|
||
### uri [string] | ||
The URI of the Neo4j database. Refer to a case: `neo4j://localhost:7687` | ||
|
||
### username [string] | ||
username of the Neo4j | ||
|
||
### password [string] | ||
password of the Neo4j. required if `username` is provided | ||
|
||
### bearer_token [string] | ||
base64 encoded bearer token of the Neo4j. for Auth. | ||
|
||
### kerberos_ticket [string] | ||
base64 encoded kerberos ticket of the Neo4j. for Auth. | ||
|
||
### database [string] | ||
database name. | ||
|
||
### query [string] | ||
Query statement. contain parameter placeholders that are substituted with the corresponding values at runtime | ||
|
||
### queryParamPosition [object] | ||
position mapping information for query parameters. | ||
|
||
key name is parameter placeholder name. | ||
|
||
associated value is position of field in input data row. | ||
|
||
|
||
### max_transaction_retry_time [long] | ||
maximum transaction retry time(seconds). transaction fail if exceeded | ||
|
||
### max_connection_timeout [long] | ||
The maximum amount of time to wait for a TCP connection to be established (seconds) | ||
|
||
|
||
## Example | ||
``` | ||
sink { | ||
Neo4jSink { | ||
uri = "neo4j://localhost:7687" | ||
username = "neo4j" | ||
password = "1234" | ||
database = "neo4j" | ||
|
||
max_transaction_retry_time = 10 | ||
max_connection_timeout = 10 | ||
|
||
query = "CREATE (a:Person {name: $name, age: $age})" | ||
queryParamPosition = { | ||
name = 0 | ||
age = 1 | ||
} | ||
} | ||
} | ||
``` |
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
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
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,45 @@ | ||
<?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> | ||
<artifactId>seatunnel-connectors-v2</artifactId> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>connector-neo4j</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.neo4j.driver</groupId> | ||
<artifactId>neo4j-java-driver</artifactId> | ||
<version>4.4.9</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
76 changes: 76 additions & 0 deletions
76
...j/src/main/java/org/apache/seatunnel/connectors/seatunnel/neo4j/config/DriverBuilder.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,76 @@ | ||
/* | ||
* 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.neo4j.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.neo4j.driver.AuthTokens; | ||
import org.neo4j.driver.Config; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.GraphDatabase; | ||
|
||
import java.io.Serializable; | ||
import java.net.URI; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Getter | ||
@Setter | ||
public class DriverBuilder implements Serializable { | ||
private final URI uri; | ||
private String username; | ||
private String password; | ||
private String bearerToken; | ||
private String kerberosTicket; | ||
private String database; | ||
|
||
private Long maxTransactionRetryTimeSeconds; | ||
private Long maxConnectionTimeoutSeconds; | ||
|
||
public static DriverBuilder create(URI uri) { | ||
return new DriverBuilder(uri); | ||
} | ||
|
||
private DriverBuilder(URI uri) { | ||
this.uri = uri; | ||
} | ||
|
||
public Driver build() { | ||
final Config.ConfigBuilder configBuilder = Config.builder() | ||
.withMaxConnectionPoolSize(1); | ||
if (maxConnectionTimeoutSeconds != null) { | ||
configBuilder | ||
.withConnectionAcquisitionTimeout(maxConnectionTimeoutSeconds * 2, TimeUnit.SECONDS) | ||
.withConnectionTimeout(maxConnectionTimeoutSeconds, TimeUnit.SECONDS); | ||
} | ||
if (maxTransactionRetryTimeSeconds != null) { | ||
configBuilder | ||
.withMaxTransactionRetryTime(maxTransactionRetryTimeSeconds, TimeUnit.SECONDS); | ||
} | ||
Config config = configBuilder | ||
.build(); | ||
|
||
if (username != null) { | ||
return GraphDatabase.driver(uri, AuthTokens.basic(username, password), config); | ||
} else if (bearerToken != null) { | ||
return GraphDatabase.driver(uri, AuthTokens.bearer(bearerToken), config); | ||
} else if (kerberosTicket != null){ | ||
return GraphDatabase.driver(uri, AuthTokens.kerberos(kerberosTicket), config); | ||
} | ||
throw new IllegalArgumentException("Invalid Field"); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...o4j/src/main/java/org/apache/seatunnel/connectors/seatunnel/neo4j/config/Neo4jConfig.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,48 @@ | ||
/* | ||
* 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.neo4j.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@Setter | ||
public class Neo4jConfig implements Serializable { | ||
|
||
public static final String KEY_SINK_PLUGIN_NAME = "Neo4jSink"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better used Neo4j There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it |
||
public static final String KEY_NEO4J_URI = "uri"; | ||
public static final String KEY_USERNAME = "username"; | ||
public static final String KEY_PASSWORD = "password"; | ||
public static final String KEY_BEARER_TOKEN = "bearer_token"; | ||
public static final String KEY_KERBEROS_TICKET = "kerberos_ticket"; // Base64 encoded | ||
|
||
public static final String KEY_DATABASE = "database"; | ||
public static final String KEY_QUERY = "query"; | ||
public static final String KEY_QUERY_PARAM_POSITION = "queryParamPosition"; | ||
public static final String KEY_MAX_TRANSACTION_RETRY_TIME = "max_transaction_retry_time"; | ||
public static final String KEY_MAX_CONNECTION_TIMEOUT = "max_connection_timeout"; | ||
|
||
|
||
private DriverBuilder driverBuilder; | ||
private String query; | ||
private Map<String, Object> queryParamPosition; | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We manage versions uniformly in the root pom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it