Last active
June 28, 2017 05:20
-
-
Save vabarbosa/62a58f68960d767a0281b2513b6ab43a to your computer and use it in GitHub Desktop.
PixieDust codegen
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
[ | |
{ | |
"id": "spark.cloudant", | |
"iconUri": "//ibm-watson-data-lab.github.io/pixiedust_learning/codegen/icons/cloudant_tile.png", | |
"title": "Spark Cloudant connector", | |
"subtopics": [ | |
{ | |
"id": "cloudant.load", | |
"iconUri": "//ibm-watson-data-lab.github.io/pixiedust_learning/codegen/icons/cloudant_tile.png", | |
"title": "Load a dataframe from Cloudant", | |
"snippetUrl": "https://gist.githubusercontent.com/vabarbosa/62a58f68960d767a0281b2513b6ab43a/raw/5345bf7aaf00254b0c6080ce627348b13ebf4d86/df-load-cloudant.json" | |
}, | |
{ | |
"id": "cloudant.save", | |
"iconUri": "//ibm-watson-data-lab.github.io/pixiedust_learning/codegen/icons/cloudant_tile.png", | |
"title": "Save a dataframe to Cloudant", | |
"snippetUrl": "https://gist.githubusercontent.com/vabarbosa/62a58f68960d767a0281b2513b6ab43a/raw/5345bf7aaf00254b0c6080ce627348b13ebf4d86/df-save-cloudant.json" | |
} | |
] | |
} | |
] |
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
{ | |
"metadata": { | |
"pixiedust": { | |
"codegen_variables": [ | |
{ "id":"host", "label":"Cloudant Host", "type":"text" }, | |
{ "id":"username", "label":"Username", "type":"text" }, | |
{ "id":"password", "label":"Password", "type":"text" }, | |
{ "id":"dbname", "label":"Database Name", "type":"text" } | |
] | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": {}, | |
"source": [ | |
"CLOUDANTHOST=\"{host}\"\n", | |
"CLOUDANTUSERNAME=\"{username}\"\n", | |
"CLOUDANTPASSWORD=\"{password}\"\n", | |
"CLOUDANTDBNAME=\"{dbname}\"\n", | |
"cloudantdata = SQLContext(sc).read.format(\"com.cloudant.spark\")\\\n", | |
".option(\"cloudant.host\", CLOUDANTHOST)\\\n", | |
".option(\"cloudant.username\", CLOUDANTUSERNAME)\\\n", | |
".option(\"cloudant.password\", CLOUDANTPASSWORD)\\\n", | |
".load(CLOUDANTDBNAME)\n", | |
"cloudantdata.cache()\n", | |
"print(\"Successfully cached dataframe\")\n", | |
"cloudantdata.printSchema()\n" | |
] | |
} | |
] | |
} |
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
{ | |
"metadata": { | |
"pixiedust": { | |
"codegen_variables": [ | |
{ "id":"host", "label":"Cloudant Host", "type":"text" }, | |
{ "id":"username", "label":"Username", "type":"text" }, | |
{ "id":"password", "label":"Password", "type":"text" }, | |
{ "id":"dbname", "label":"Database Name", "type":"text" }, | |
{ "id":"dframe", "label":"DataFrame Variable", "type":"text" } | |
] | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"source": [ | |
"{dframe}.write.format(\"com.cloudant.spark\")\\\n", | |
".option(\"cloudant.host\", \"{host}\")\\\n", | |
".option(\"cloudant.username\", \"{username}\")\\\n", | |
".option(\"cloudant.password\", \"{password}\")\\\n", | |
".save(\"{dbname}\")\n" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment