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/16 04:06:32 UTC

[GitHub] [incubator-seatunnel] zixi0825 opened a new pull request #1051: [Feature][Connectors] add spark cassandra source

zixi0825 opened a new pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051


   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[SeaTunnel #XXXX] [component] Title of the pull request", where *SeaTunnel #XXXX* should be replaced by the actual issue number.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   This pull request adds spark cassandra source. #985
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [x] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


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



[GitHub] [incubator-seatunnel] CalvinKirs commented on pull request #1051: [Feature] [connectors] Add spark cassandra source

Posted by GitBox <gi...@apache.org>.
CalvinKirs commented on pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051#issuecomment-1038565512


   I'll close it due to no feedback for a long time, if you make an update, leave a comment below and I'll reopen it


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



[GitHub] [incubator-seatunnel] wuchunfu commented on a change in pull request #1051: [Feature][Connectors] add spark cassandra source

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051#discussion_r791235943



##########
File path: seatunnel-connectors/seatunnel-connector-spark-cassandra/src/main/scala/org/apache/seatunnel/spark/source/Cassandra.scala
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.check
+import org.apache.seatunnel.common.config.{CheckResult, TypesafeConfigUtils}
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory
+import org.apache.seatunnel.spark.SparkEnvironment
+import org.apache.seatunnel.spark.batch.SparkBatchSource
+import org.apache.spark.sql.{Dataset, Row}
+
+import scala.collection.JavaConversions._
+import scala.util.{Failure, Success, Try}
+
+class Cassandra extends SparkBatchSource {
+
+  override def getData(env: SparkEnvironment): Dataset[Row] = {
+
+    val reader = env.getSparkSession.read.format("org.apache.spark.sql.cassandra")
+      .options(Map(
+        "table" -> config.getString("table"),
+        "keyspace" -> config.getString("keyspace"),
+        "cluster" -> config.getString("cluster"),
+        "pushdown" -> config.getString("pushdown")
+      ))
+
+    Try(TypesafeConfigUtils.extractSubConfigThrowable(config, "options.", false)) match {
+
+      case Success(options) =>
+        val optionMap = options
+          .entrySet()
+          .foldRight(Map[String, String]())((entry, m) => {
+            m + (entry.getKey -> entry.getValue.unwrapped().toString)
+          })
+
+        reader.options(optionMap)
+      case Failure(exception) => // do nothing
+    }
+
+    reader.load()
+  }
+
+  override def checkConfig(): CheckResult = {
+    check(config, "table", "keyspace")
+  }

Review comment:
       We have now changed `check` to `checkAllExists`, please check, thanks




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



[GitHub] [incubator-seatunnel] zixi0825 closed pull request #1051: [Feature][Connectors] add spark cassandra source

Posted by GitBox <gi...@apache.org>.
zixi0825 closed pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051


   


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



[GitHub] [incubator-seatunnel] CalvinKirs closed pull request #1051: [Feature] [connectors] Add spark cassandra source

Posted by GitBox <gi...@apache.org>.
CalvinKirs closed pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051


   


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



[GitHub] [incubator-seatunnel] wuchunfu commented on a change in pull request #1051: [Feature][Connectors] add spark cassandra source

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051#discussion_r791236849



##########
File path: docs/en/spark/configuration/source-plugins/Cassandra.md
##########
@@ -0,0 +1,57 @@
+# Source plugin: Cassandra
+
+### Description
+
+Read data from Cassandra.
+
+### Env
+| name           | type   | required | default value |
+| -------------- | ------ | -------- | ------------- |
+| [spark.cassandra.connection.host](#spark.cassandra.connection.host-string)       | string | yes      | -             |
+
+##### spark.cassandra.connection.host [string]
+
+Cassandra connection host
+
+##### other
+
+Refer to [spark-cassandra-connector-options](https://github.com/datastax/spark-cassandra-connector/blob/b2.4/doc/reference.md) for configurations.
+
+### Options
+
+| name             | type   | required | default value |
+| --------------   | ------ | -------- | ------------- |
+| [table](#table-string)            | string | yes      | -             |
+| [keyspace](#keyspace-string)         | string | yes      | -             |
+| [cluster](#cluster-string)          | string | no       | default       |
+| [pushdown](#pushdown-string)         | string | no       | true         |
+

Review comment:
       If I remember correctly `result_table_name` seems to be required, please check, thanks




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



[GitHub] [incubator-seatunnel] zixi0825 commented on pull request #1051: [Feature] [connectors] Add spark cassandra source

Posted by GitBox <gi...@apache.org>.
zixi0825 commented on pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051#issuecomment-1062544669


   @CalvinKirs please reopen it ,thanks


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



[GitHub] [incubator-seatunnel] wuchunfu commented on a change in pull request #1051: [Feature][Connectors] add spark cassandra source

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on a change in pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051#discussion_r791235943



##########
File path: seatunnel-connectors/seatunnel-connector-spark-cassandra/src/main/scala/org/apache/seatunnel/spark/source/Cassandra.scala
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.check
+import org.apache.seatunnel.common.config.{CheckResult, TypesafeConfigUtils}
+import org.apache.seatunnel.shade.com.typesafe.config.ConfigFactory
+import org.apache.seatunnel.spark.SparkEnvironment
+import org.apache.seatunnel.spark.batch.SparkBatchSource
+import org.apache.spark.sql.{Dataset, Row}
+
+import scala.collection.JavaConversions._
+import scala.util.{Failure, Success, Try}
+
+class Cassandra extends SparkBatchSource {
+
+  override def getData(env: SparkEnvironment): Dataset[Row] = {
+
+    val reader = env.getSparkSession.read.format("org.apache.spark.sql.cassandra")
+      .options(Map(
+        "table" -> config.getString("table"),
+        "keyspace" -> config.getString("keyspace"),
+        "cluster" -> config.getString("cluster"),
+        "pushdown" -> config.getString("pushdown")
+      ))
+
+    Try(TypesafeConfigUtils.extractSubConfigThrowable(config, "options.", false)) match {
+
+      case Success(options) =>
+        val optionMap = options
+          .entrySet()
+          .foldRight(Map[String, String]())((entry, m) => {
+            m + (entry.getKey -> entry.getValue.unwrapped().toString)
+          })
+
+        reader.options(optionMap)
+      case Failure(exception) => // do nothing
+    }
+
+    reader.load()
+  }
+
+  override def checkConfig(): CheckResult = {
+    check(config, "table", "keyspace")
+  }

Review comment:
       We have now changed `check` to `checkAllExists`, please check, thanks

##########
File path: docs/en/spark/configuration/source-plugins/Cassandra.md
##########
@@ -0,0 +1,57 @@
+# Source plugin: Cassandra
+
+### Description
+
+Read data from Cassandra.
+
+### Env
+| name           | type   | required | default value |
+| -------------- | ------ | -------- | ------------- |
+| [spark.cassandra.connection.host](#spark.cassandra.connection.host-string)       | string | yes      | -             |
+
+##### spark.cassandra.connection.host [string]
+
+Cassandra connection host
+
+##### other
+
+Refer to [spark-cassandra-connector-options](https://github.com/datastax/spark-cassandra-connector/blob/b2.4/doc/reference.md) for configurations.
+
+### Options
+
+| name             | type   | required | default value |
+| --------------   | ------ | -------- | ------------- |
+| [table](#table-string)            | string | yes      | -             |
+| [keyspace](#keyspace-string)         | string | yes      | -             |
+| [cluster](#cluster-string)          | string | no       | default       |
+| [pushdown](#pushdown-string)         | string | no       | true         |
+

Review comment:
       If I remember correctly `result_table_name` seems to be required, please check, thanks




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



[GitHub] [incubator-seatunnel] zixi0825 closed pull request #1051: [Feature][Connectors] add spark cassandra source

Posted by GitBox <gi...@apache.org>.
zixi0825 closed pull request #1051:
URL: https://github.com/apache/incubator-seatunnel/pull/1051


   


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