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/01/14 11:29:50 UTC

[GitHub] [incubator-seatunnel] RickyHuo commented on a change in pull request #1028: [SeaTunnel #967][seatunnel-connector] Add neo4j spark source

RickyHuo commented on a change in pull request #1028:
URL: https://github.com/apache/incubator-seatunnel/pull/1028#discussion_r784770165



##########
File path: seatunnel-connectors/seatunnel-connector-spark-neo4j/src/main/scala/org/apache/seatunnel/spark/source/Neo4j.scala
##########
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.seatunnel.spark.source
+
+import org.apache.seatunnel.common.config.{CheckConfigUtil, CheckResult}
+import org.apache.seatunnel.spark.SparkEnvironment
+import org.apache.seatunnel.spark.batch.SparkBatchSource
+import org.apache.spark.sql.{DataFrameReader, Dataset, Row}
+
+import scala.collection.JavaConverters._
+import scala.collection.mutable
+
+class Neo4j extends SparkBatchSource {
+
+  val neo4jConf: mutable.Map[String, String] = mutable.Map()
+  val readFormatter: String = "org.neo4j.spark.DataSource"
+
+
+  override def getData(env: SparkEnvironment): Dataset[Row] = {
+    val read: DataFrameReader = env.getSparkSession.read
+    read.format(readFormatter)
+    neo4jConf.foreach(it => {
+      read.option(it._1, it._2)
+    })
+    read.load()
+
+  }
+
+  override def checkConfig(): CheckResult = {
+
+    val checkALL: CheckResult = CheckConfigUtil.checkOne(config, "query", "labels", "relationship")
+    val checkOne: CheckResult = CheckConfigUtil.check(config, "result_table_name", "url")
+    CheckConfigUtil.mergeCheckMessage(checkALL, checkOne);
+
+  }
+
+  override def prepare(prepareEnv: SparkEnvironment): Unit = {
+    config.entrySet().asScala.foreach(entry => {
+      neo4jConf.put(entry.getKey.replaceAll(raw"_", raw"."), config.getString(entry.getKey))

Review comment:
       we can use '.' directly, such as `schema.flatten.limit`




-- 
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