You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/10/13 06:30:42 UTC

[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2777: [Feature][Connector-v2] Neo4j source connector

hailin0 commented on code in PR #2777:
URL: https://github.com/apache/incubator-seatunnel/pull/2777#discussion_r994208584


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-neo4j-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/neo4j/Neo4jIT.java:
##########
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.e2e.flink.v2.neo4j;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.neo4j.driver.Values.parameters;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.neo4j.driver.AuthTokens;
+import org.neo4j.driver.Driver;
+import org.neo4j.driver.GraphDatabase;
+import org.neo4j.driver.Result;
+import org.neo4j.driver.Session;
+import org.neo4j.driver.SessionConfig;
+import org.neo4j.driver.Value;
+import org.neo4j.driver.types.Node;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.net.URI;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+@Slf4j
+public class Neo4jIT extends FlinkContainer {
+
+    private static final String CONTAINER_IMAGE = "neo4j:latest";
+    private static final String CONTAINER_HOST = "neo4j-host";
+    private static final int CONTAINER_PORT = 7687;
+    private static final String CONTAINER_NEO4J_USERNAME = "neo4j";
+    private static final String CONTAINER_NEO4J_PASSWORD = "1234";
+    private static final URI CONTAINER_URI = URI.create("neo4j://localhost:" + CONTAINER_PORT);
+
+    private GenericContainer<?> container;
+    private Driver neo4jDriver;
+    private Session neo4jSession;
+
+    @BeforeAll
+    public void init() {
+        DockerImageName imageName = DockerImageName.parse(CONTAINER_IMAGE);
+        container = new GenericContainer<>(imageName)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(CONTAINER_HOST)
+            .withExposedPorts(CONTAINER_PORT)
+            .withEnv("NEO4J_AUTH", CONTAINER_NEO4J_USERNAME + "/" + CONTAINER_NEO4J_PASSWORD)
+            .withLogConsumer(new Slf4jLogConsumer(log));

Review Comment:
   ```suggestion
               .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(CONTAINER_IMAGE)));
   ```
   
   https://github.com/apache/incubator-seatunnel/pull/3028
   



##########
seatunnel-e2e/seatunnel-spark-connector-v2-e2e/connector-neo4j-spark-e2e/src/test/java/org/apache/seatunnel/e2e/spark/v2/neo4j/Neo4jIT.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.e2e.spark.v2.neo4j;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.neo4j.driver.Values.parameters;
+
+import org.apache.seatunnel.e2e.spark.SparkContainer;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.neo4j.driver.AuthTokens;
+import org.neo4j.driver.Driver;
+import org.neo4j.driver.GraphDatabase;
+import org.neo4j.driver.Result;
+import org.neo4j.driver.Session;
+import org.neo4j.driver.SessionConfig;
+import org.neo4j.driver.Value;
+import org.neo4j.driver.types.Node;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.lifecycle.Startables;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+import java.net.URI;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+@Slf4j
+public class Neo4jIT extends SparkContainer {
+
+    private static final String CONTAINER_IMAGE = "neo4j:latest";
+    private static final String CONTAINER_HOST = "neo4j-host";
+    private static final int CONTAINER_PORT = 7687;
+    private static final String CONTAINER_NEO4J_USERNAME = "neo4j";
+    private static final String CONTAINER_NEO4J_PASSWORD = "1234";
+    private static final URI CONTAINER_URI = URI.create("neo4j://localhost:" + CONTAINER_PORT);
+
+    private GenericContainer<?> container;
+    private Driver neo4jDriver;
+    private Session neo4jSession;
+
+    @BeforeAll
+    public void init() {
+        DockerImageName imageName = DockerImageName.parse(CONTAINER_IMAGE);
+        container = new GenericContainer<>(imageName)
+            .withExposedPorts(CONTAINER_PORT)
+            .withNetwork(NETWORK)
+            .withNetworkAliases(CONTAINER_HOST)
+            .withEnv("NEO4J_AUTH", CONTAINER_NEO4J_USERNAME + "/" + CONTAINER_NEO4J_PASSWORD)
+            .withLogConsumer(new Slf4jLogConsumer(log));

Review Comment:
   ```suggestion
               .withLogConsumer(new Slf4jLogConsumer(DockerLoggerFactory.getLogger(CONTAINER_IMAGE)));
   ```
   
   https://github.com/apache/incubator-seatunnel/pull/3028



##########
docs/en/connector-v2/source/Neo4j.md:
##########
@@ -0,0 +1,100 @@
+# Neo4j
+
+> Neo4j source connector
+
+## Description
+
+Read data from Neo4j.
+
+`neo4j-java-driver` version 4.4.9
+
+## Key features
+
+- [x] [batch](../../concept/connector-v2-features.md)
+- [ ] [stream](../../concept/connector-v2-features.md)
+- [ ] [exactly-once](../../concept/connector-v2-features.md)
+- [x] [schema projection](../../concept/connector-v2-features.md)
+- [ ] [parallelism](../../concept/connector-v2-features.md)
+- [ ] [support user-defined split](../../concept/connector-v2-features.md)
+
+## 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      | -             |
+| schema.fields              | 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.
+
+### schema.fields [string]
+
+returned fields of `query`
+
+see [schema projection](../../concept/connector-v2-features.md)
+
+### 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
+
+```
+source {
+    Neo4j {
+        uri = "neo4j://localhost:7687"
+        username = "neo4j"
+        password = "1234"
+        database = "neo4j"
+    
+        max_transaction_retry_time = 1
+        max_connection_timeout = 1
+    
+        query = "MATCH (a:Person) RETURN a.name, a.age"
+    
+        schema {
+            fields {
+                a.age=INT
+                a.name=STRING

Review Comment:
   Better not to include  `.` ?
   
   e.g.
   
   xxx_age = INT
   xxx_name = STRING



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org