-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
174 additions
and
2 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
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
4 changes: 3 additions & 1 deletion
4
.../main/resources/META-INF/services/io.github.interestinglab.waterdrop.apis.BaseStaticInput
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
io.github.interestinglab.waterdrop.input.Fake2 | ||
io.github.interestinglab.waterdrop.input.Hdfs | ||
io.github.interestinglab.waterdrop.input.File | ||
io.github.interestinglab.waterdrop.input.Hive | ||
io.github.interestinglab.waterdrop.input.Hive | ||
io.github.interestinglab.waterdrop.input.MongoDB | ||
io.github.interestinglab.waterdrop.input.Kudu |
40 changes: 40 additions & 0 deletions
40
waterdrop-core/src/main/scala/io/github/interestinglab/waterdrop/input/Kudu.scala
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,40 @@ | ||
package io.github.interestinglab.waterdrop.input | ||
|
||
|
||
import com.typesafe.config.{Config, ConfigFactory} | ||
import io.github.interestinglab.waterdrop.apis.BaseStaticInput | ||
import org.apache.spark.sql.{Dataset, Row, SparkSession} | ||
import org.apache.kudu.spark.kudu._ | ||
|
||
|
||
class Kudu extends BaseStaticInput { | ||
|
||
var config: Config = ConfigFactory.empty() | ||
|
||
override def setConfig(config: Config): Unit = { | ||
this.config = config | ||
} | ||
|
||
override def getConfig(): Config = { | ||
this.config | ||
} | ||
|
||
override def checkConfig(): (Boolean, String) = { | ||
config.hasPath("kudu_master") && config.hasPath("kudu_table") && config.hasPath("table_name") match { | ||
case true => (true, "") | ||
case false => (false, "please specify [kudu_master] and [kudu_table] and [table_name]") | ||
} | ||
} | ||
|
||
|
||
override def getDataset(spark: SparkSession): Dataset[Row] = { | ||
val mapConf = Map( | ||
"kudu.master" -> config.getString("kudu_master"), | ||
"kudu.table" -> config.getString("kudu_table")) | ||
|
||
val ds = spark.read.format("org.apache.kudu.spark.kudu") | ||
.options(mapConf).kudu | ||
ds.createOrReplaceTempView(config.getString("table_name")) | ||
ds | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
waterdrop-core/src/main/scala/io/github/interestinglab/waterdrop/input/MongoDB.scala
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 @@ | ||
package io.github.interestinglab.waterdrop.input | ||
|
||
import com.mongodb.spark.MongoSpark | ||
import com.mongodb.spark.config.ReadConfig | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import io.github.interestinglab.waterdrop.apis.BaseStaticInput | ||
import org.apache.spark.sql.{Dataset, Row, SparkSession} | ||
|
||
import scala.collection.JavaConversions._ | ||
|
||
class MongoDB extends BaseStaticInput { | ||
|
||
var config: Config = ConfigFactory.empty() | ||
|
||
override def setConfig(config: Config): Unit = { | ||
var defaultConfig = ConfigFactory.parseMap( | ||
Map( | ||
"partitioner" -> "MongoShardedPartitioner" | ||
) | ||
) | ||
this.config = config.withFallback(defaultConfig) | ||
} | ||
|
||
override def getConfig(): Config = { | ||
this.config | ||
} | ||
|
||
override def checkConfig(): (Boolean, String) = { | ||
config.hasPath("mongo_uri") && config.hasPath("database") && config.hasPath("collection") && config.hasPath("table_name") match { | ||
case true => (true, "you can please mongobd input partitioner,default is MongoShardedPartitioner") | ||
case false => (false, "please specify [mongo_uri] and [database] and [collection] and [table_name]") | ||
} | ||
} | ||
|
||
|
||
override def getDataset(spark: SparkSession): Dataset[Row] = { | ||
val configur = ReadConfig(Map( | ||
"uri" -> config.getString("mongo_uri"), | ||
"spark.mongodb.input.partitioner" -> config.getString("partitioner"), | ||
"database" -> config.getString("database"), | ||
"collection" -> config.getString("collection"))) | ||
MongoSpark.load(spark, configur) | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
waterdrop-core/src/main/scala/io/github/interestinglab/waterdrop/output/Kudu.scala
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,37 @@ | ||
package io.github.interestinglab.waterdrop.output | ||
|
||
import com.typesafe.config.{Config, ConfigFactory} | ||
import io.github.interestinglab.waterdrop.apis.{BaseOutput} | ||
import org.apache.kudu.spark.kudu._ | ||
import org.apache.spark.sql.{Dataset, Row} | ||
|
||
|
||
class Kudu extends BaseOutput { | ||
|
||
var config: Config = ConfigFactory.empty() | ||
|
||
override def setConfig(config: Config): Unit = { | ||
this.config = config | ||
} | ||
|
||
override def getConfig(): Config = { | ||
this.config | ||
} | ||
|
||
override def checkConfig(): (Boolean, String) = { | ||
config.hasPath("kudu_master") && config.hasPath("kudu_table") && config.hasPath("table_name") match { | ||
case true => (true, "") | ||
case false => (false, "please specify [kudu_master] and [kudu_table] and [table_name]") | ||
} | ||
} | ||
|
||
|
||
override def process(df: Dataset[Row]): Unit = { | ||
|
||
val kuduContext = new KuduContext(config.getString("kudu_master"),df.sparkSession.sparkContext) | ||
|
||
kuduContext.upsertRows(df,config.getString("kudu_table")) | ||
|
||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
waterdrop-core/src/main/scala/io/github/interestinglab/waterdrop/output/MongoDB.scala
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 @@ | ||
package io.github.interestinglab.waterdrop.output | ||
|
||
import com.mongodb.spark.MongoSpark | ||
import com.mongodb.spark.config.WriteConfig | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import io.github.interestinglab.waterdrop.apis.BaseOutput | ||
import org.apache.spark.sql.{Dataset, Row} | ||
|
||
import scala.collection.JavaConversions._ | ||
|
||
class MongoDB extends BaseOutput { | ||
|
||
var config: Config = ConfigFactory.empty() | ||
|
||
override def setConfig(config: Config): Unit = { | ||
var defaultConfig = ConfigFactory.parseMap( | ||
Map( | ||
"isReplace" -> "false" | ||
) | ||
) | ||
this.config = config.withFallback(defaultConfig) | ||
} | ||
|
||
override def getConfig(): Config = { | ||
this.config | ||
} | ||
|
||
override def checkConfig(): (Boolean, String) = { | ||
config.hasPath("mongo_uri") && config.hasPath("database") && config.hasPath("collection") match { | ||
case true => (true, "") | ||
case false => (false, "please specify [mongo_uri] and [database] and [collection] ") | ||
} | ||
} | ||
|
||
override def process(df: Dataset[Row]): Unit = { | ||
|
||
val writeConf = WriteConfig(Map( | ||
"uri" -> config.getString("mongo_uri"), | ||
"database" -> config.getString("database"), | ||
"collection" -> config.getString("collection"), | ||
"replaceDocument" -> config.getString("isReplace") | ||
)) | ||
MongoSpark.save(df,writeConf) | ||
} | ||
} |