Skip to content

Instantly share code, notes, and snippets.

@gbraccialli
Created February 3, 2017 08:58
Show Gist options
  • Select an option

  • Save gbraccialli/62a54badf70a311b57ecb30cf80e8f41 to your computer and use it in GitHub Desktop.

Select an option

Save gbraccialli/62a54badf70a311b57ecb30cf80e8f41 to your computer and use it in GitHub Desktop.
val jdbcDF = spark.read.format("jdbc").options(
Map(
"driver" -> "org.postgresql.Driver",
"url" -> "jdbc:postgresql://localhost/?user=postgres&password=postgres",
"dbtable" -> "nifi_test"
)
).load()
jdbcDF.show
case class Test (field1: String, field2: String)
val test = List(Test("B", "xx"), Test("B", "2"), Test("B", "35"), Test("A", "6"), Test("A", "3"))
val rdd = sc.parallelize(test)
val df = rdd.toDF
df.write.format("jdbc").options(
Map(
"driver" -> "org.postgresql.Driver",
"url" -> "jdbc:postgresql://localhost/?user=postgres&password=postgres",
"dbtable" -> "nifi_test"
)
).mode("append").save("nifi_test")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment