Skip to content

Instantly share code, notes, and snippets.

@lbustelo
Created October 29, 2015 16:23
Show Gist options
  • Save lbustelo/42f074827738ba45c0de to your computer and use it in GitHub Desktop.
Save lbustelo/42f074827738ba45c0de to your computer and use it in GitHub Desktop.
Dataframe Error
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Using Urth Widgets in Scala"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add, import and initialize the widget system:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting download from http://192.168.99.100:8888/nbextensions/urth_widgets/urth-widgets.jar\n",
"Finished download of urth-widgets.jar\n"
]
}
],
"source": [
"// modify to IP and Port of this notebook server\n",
"%addjar http://192.168.99.100:8888/nbextensions/urth_widgets/urth-widgets.jar"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import urth.widgets._\n",
"initWidgets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Import Polymer elements:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"val sqlContext = new org.apache.spark.sql.SQLContext(sc)\n",
"import sqlContext.implicits._\n",
"import org.apache.spark.sql.DataFrame\n",
"\n",
"def dfFunc2(): DataFrame = {\n",
" sqlContext.read.json(\"./people.json\")\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"+----+-------+\n",
"| age| name|\n",
"+----+-------+\n",
"|null|Michael|\n",
"| 30| Andy|\n",
"| 19| Justin|\n",
"+----+-------+\n",
"\n"
]
}
],
"source": [
"dfFunc2().show()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[age: string, name: string]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dffunc"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<template is=\"dom-bind\">\n",
"<urth-core-function ref=\"dfFunc2\" result='{{res}}' limit=\"10\" auto></urth-core-function>\n",
" <label>columns:</label><span>{{res.columns}}</span> <br/>\n",
" <label>index:</label><span>{{res.index}}</span> <br/>\n",
" <label>data:</label><span>{{res.data}}</span>\n",
"</template>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%html\n",
"<template is=\"dom-bind\">\n",
"<urth-core-function ref=\"dfFunc2\" result='{{res}}' limit=\"10\" auto></urth-core-function>\n",
" <label>columns:</label><span>{{res.columns}}</span> <br/>\n",
" <label>index:</label><span>{{res.index}}</span> <br/>\n",
" <label>data:</label><span>{{res.data}}</span>\n",
"</template>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Spark 1.5.1 (Scala 2.10.4)",
"language": "scala",
"name": "scala"
},
"language_info": {
"name": "scala"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
{"name":"Michael"}
{"name":"Andy", "age":"30"}
{"name":"Justin", "age":"19"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment