-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/scala/com/hobospark/examples/BasicSharkExample.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,21 @@ | ||
// Basic Shark example in Scala | ||
|
||
package com.hobospark.examples | ||
|
||
import shark._ | ||
import spark.SparkContext._ | ||
|
||
object BasicSharkExample { | ||
def main(args: Array[String]) { | ||
val sc = SharkEnv.initWithSharkContext("BasicSharkExample") | ||
println("Starting shark requests"); | ||
sc.sql("drop table if exists src"); | ||
sc.sql("CREATE TABLE src(key INT, value STRING)") | ||
sc.sql("LOAD DATA LOCAL INPATH '${env:HIVE_HOME}/examples/files/in1.txt' INTO TABLE src") | ||
val rdd = sc.sql2rdd("SELECT src.key, src.value FROM src WHERE src.key < 100") | ||
rdd.cache() | ||
println("Found "+rdd.count()+" num rows") | ||
val normalRDD = rdd.map(x => (x.getInt("src.key"), x.getString("src.value"))) | ||
println("Formatted as "+normalRDD.collect()) | ||
} | ||
} |