Skip to content

Commit

Permalink
update jupyter notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelowenthal committed Feb 3, 2016
1 parent 39c5c24 commit b28777b
Show file tree
Hide file tree
Showing 7 changed files with 626 additions and 806 deletions.
120 changes: 35 additions & 85 deletions jupyter/Collect data as lists.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 31,
"execution_count": null,
"metadata": {
"collapsed": false
},
Expand All @@ -39,22 +39,11 @@
},
{
"cell_type": "code",
"execution_count": 59,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<table><tr><tr></table>"
]
},
"execution_count": 59,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%%Cql truncate music.albums"
]
Expand All @@ -68,16 +57,17 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"case class Track(album_title: String,\n",
"album_year:Int, number:Int,\n",
"album_genre: String,\n",
"performer: String,\n",
"album_year:Int,\n",
"track_number:Int,\n",
"album_genre: Option[String],\n",
"performer: Option[String],\n",
"track_title: String)"
]
},
Expand All @@ -90,33 +80,22 @@
},
{
"cell_type": "code",
"execution_count": 48,
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"val tracks = sc.cassandraTable(\"music\",\"tracks_by_album\").as(Track)"
"val tracks = sc.cassandraTable[Track](\"music\",\"tracks_by_album\")"
]
},
{
"cell_type": "code",
"execution_count": 49,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Track(Duos For Violin and Cello,2000,1,Classical,Nigel Kennedy,Sonata for Violin and Cello - Allegro)"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"tracks.first"
]
Expand All @@ -130,18 +109,19 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"val track_pairs = tracks.filter(t => t.track_title != null).map(t => ((t.album_title, t.album_year), t.track_title))"
"val track_pairs = tracks.filter(t => t.track_title != null).\n",
"map(t => ((t.album_title, t.album_year), t.track_title))"
]
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": null,
"metadata": {
"collapsed": false
},
Expand All @@ -154,12 +134,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use groupByBey, to convert it to (key, collection of track names)"
"## Use groupByKey, to convert it to (key, collection of track names)"
]
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -170,7 +150,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"metadata": {
"collapsed": false
},
Expand All @@ -188,46 +168,37 @@
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"val albums_with_tracks2 = albums_with_tracks.map{ case ((album, year), tracks) => (album, year, tracks) }"
"val albums_with_tracks2 = albums_with_tracks.\n",
"map{ case ((album, year), tracks) => (album, year, tracks) }"
]
},
{
"cell_type": "code",
"execution_count": 54,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"(Bramble Rose,2002,CompactBuffer(Trouble Over Me, Virginia, No One Can Warn You, Neighborhood, Bird Of Freedom, Bramble Rose, I Know Him Too, Sunday, Supposed To Make You Happy, Diamond Shoes, Are You Still In Love With Me?, When I Cross Over))"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"albums_with_tracks2.first"
"albums_with_tracks2.first.toString"
]
},
{
"cell_type": "code",
"execution_count": 61,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"albums_with_tracks2.saveToCassandra(\"music\",\"albums\", SomeColumns(\"album_title\", \"album_year\", \"tracks\"))"
"albums_with_tracks2.saveToCassandra(\"music\",\"albums\",\n",
" SomeColumns(\"album_title\", \"album_year\", \"tracks\"))"
]
},
{
Expand All @@ -239,22 +210,11 @@
},
{
"cell_type": "code",
"execution_count": 62,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<table><tr><th>album_title</th><th>album_year</th><th>album_genre</th><th>performer</th><th>tracks</th><tr><tr><td>Duos For Violin and Cello</td><td>2000</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>[Sonata for Violin and Cello - Allegro, Sonata for Violin and Cello - Tres vif, Sonata for Violin and Cello - Lent, Sonata for Violin and Cello - Vif, avec entrain, Passacaglia, Duo for Violin and Cello Op. 7 - Allegro serioso, non troppo, Duo for Violin and Cello Op. 7 - Adagio-Andante-Tempo I, Duo for Violin and Cello Op. 7 - Maestoso e largamente, ma non troppo lento-Presto, Two-Part Intervention No. 6 in E]</td></tr><tr><td>Golden Boy Elvis</td><td>1981</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>[She's Not You, Return To Sender, Joshua Fit The Battle, Don't, Tutti Frutti, It's Now Or Never, Surrender, Do The Clam, Kiss Me Quick, Such A Night, Blueberry Hill, Don't Be Cruel, Heartbreak Hotel, Fun In Acapulco, Hound Dog, Wooden Heart]</td></tr><tr><td>Home</td><td>1995</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>[I Believe, Let Me Be The One, All Along, Oh Virginia, Nora, Would You Be There, Home, End Of The World, Heaven, Forever For Tonight, Lucky To Be Here]</td></tr><tr><td>Little Sweet Delirium</td><td>1996</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>[Chase, Revolution, 829, Reaction, Hands Like Wings, God Shaped Hole, Fall, Point of You]</td></tr><tr><td>Merry Christmas From Elvis Presley, A</td><td>1982</td><td>&lt;null&gt;</td><td>&lt;null&gt;</td><td>[O Come All Ye Faithful, The First Noel, On A Snowy Christmas Night, Winter Wonderland, The Wonderful World Of Christmas, It Won't Seem Like Christmas, I'll Be Home On Christmas Day, If I Get Home On Christmas Day, Holly Leaves And Christmas Trees, Merry Christmas Baby, Silver Bells]</td></tr></table>"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%%Cql select * from music.albums limit 5;"
]
Expand All @@ -268,33 +228,23 @@
},
{
"cell_type": "code",
"execution_count": 63,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"tracks.saveToCassandra(\"music\",\"albums\",SomeColumns(\"album_title\",\"album_year\",\"album_genre\",\"performer\"))"
"tracks.saveToCassandra(\"music\",\"albums\",\n",
"SomeColumns(\"album_title\",\"album_year\",\"album_genre\",\"performer\"))"
]
},
{
"cell_type": "code",
"execution_count": 64,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<table><tr><th>album_title</th><th>album_year</th><th>album_genre</th><th>performer</th><th>tracks</th><tr><tr><td>Duos For Violin and Cello</td><td>2000</td><td>Classical</td><td>Nigel Kennedy</td><td>[Sonata for Violin and Cello - Allegro, Sonata for Violin and Cello - Tres vif, Sonata for Violin and Cello - Lent, Sonata for Violin and Cello - Vif, avec entrain, Passacaglia, Duo for Violin and Cello Op. 7 - Allegro serioso, non troppo, Duo for Violin and Cello Op. 7 - Adagio-Andante-Tempo I, Duo for Violin and Cello Op. 7 - Maestoso e largamente, ma non troppo lento-Presto, Two-Part Intervention No. 6 in E]</td></tr><tr><td>Golden Boy Elvis</td><td>1981</td><td>Rock</td><td>Elvis Presley</td><td>[She's Not You, Return To Sender, Joshua Fit The Battle, Don't, Tutti Frutti, It's Now Or Never, Surrender, Do The Clam, Kiss Me Quick, Such A Night, Blueberry Hill, Don't Be Cruel, Heartbreak Hotel, Fun In Acapulco, Hound Dog, Wooden Heart]</td></tr><tr><td>Home</td><td>1995</td><td>Rock</td><td>Blessid Union of Souls</td><td>[I Believe, Let Me Be The One, All Along, Oh Virginia, Nora, Would You Be There, Home, End Of The World, Heaven, Forever For Tonight, Lucky To Be Here]</td></tr><tr><td>Little Sweet Delirium</td><td>1996</td><td>Unknown</td><td>Creeker</td><td>[Chase, Revolution, 829, Reaction, Hands Like Wings, God Shaped Hole, Fall, Point of You]</td></tr><tr><td>Merry Christmas From Elvis Presley, A</td><td>1982</td><td>Rock</td><td>Elvis Presley</td><td>[O Come All Ye Faithful, The First Noel, On A Snowy Christmas Night, Winter Wonderland, The Wonderful World Of Christmas, It Won't Seem Like Christmas, I'll Be Home On Christmas Day, If I Get Home On Christmas Day, Holly Leaves And Christmas Trees, Merry Christmas Baby, Silver Bells]</td></tr></table>"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%%Cql select * from music.albums limit 5;"
]
Expand Down
63 changes: 6 additions & 57 deletions jupyter/FlatMap example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,80 +67,29 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"case class Album (album_title: String,\n",
" album_year: Int,\n",
" album_genre: String,\n",
" performer: String,\n",
" tracks: List[String])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"val music_albums = sc.cassandraTable[Album](\"music\",\"albums\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARN 2015-12-11 20:49:53 com.datastax.driver.core.NettyUtil: Found Netty's native epoll transport, but not running on linux-based operating system. Using NIO instead.\n"
]
},
{
"data": {
"text/plain": [
"Album = Album(Duos For Violin and Cello,2000,Classical,Nigel Kennedy,List(Sonata for Violin and Cello - Allegro, Sonata for Violin and Cello - Tres vif, Sonata for Violin and Cello - Lent, Sonata for Violin and Cello - Vif, avec entrain, Passacaglia, Duo for Violin and Cello Op. 7 - Allegro serioso, non troppo, Duo for Violin and Cello Op. 7 - Adagio-Andante-Tempo I, Duo for Violin and Cello Op. 7 - Maestoso e largamente, ma non troppo lento-Presto, Two-Part Intervention No. 6 in E))"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"music_albums.first"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Now dump out all just each track, and the genre."
"val music_albums = sc.cassandraTable[(String,Int,Option[String],Option[String],List[String])](\"music\",\"albums\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"val just_tracks = music_albums.flatMap{ album => album.tracks.map( track => (album.album_genre, track))}"
"val just_tracks = music_albums.flatMap{ case (at,yr,gen,per,tracks) => tracks.map((gen.getOrElse(\"Unknown\"), _))}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 7,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -178,7 +127,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Spark-DSE Cluster",
"display_name": "Spark-DSE Cluster (Scala 2.10.4)",
"language": "scala",
"name": "spark-dse-cluster"
},
Expand Down

0 comments on commit b28777b

Please sign in to comment.