Skip to content

Commit

Permalink
Add scala example
Browse files Browse the repository at this point in the history
  • Loading branch information
holdenk committed Jun 9, 2013
1 parent 791ee7d commit e2cf9c3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/scala/com/hobospark/examples/BasicSharkExample.scala
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())
}
}

0 comments on commit e2cf9c3

Please sign in to comment.