diff options
author | Ethan Jewett <esjewett@gmail.com> | 2013-05-04 12:31:30 -0500 |
---|---|---|
committer | Ethan Jewett <esjewett@gmail.com> | 2013-05-04 12:31:30 -0500 |
commit | 02e8cfa61792f296555c7ed16613a91d895181a1 (patch) | |
tree | 67de868dc97d92866adfc33589e6696f8ae6cfb1 /examples/src | |
parent | 3bf2c868c311f6afd286d7a25adda9fe94561eb0 (diff) | |
download | spark-02e8cfa61792f296555c7ed16613a91d895181a1.tar.gz spark-02e8cfa61792f296555c7ed16613a91d895181a1.tar.bz2 spark-02e8cfa61792f296555c7ed16613a91d895181a1.zip |
HBase example
Diffstat (limited to 'examples/src')
-rw-r--r-- | examples/src/main/scala/spark/examples/HBaseTest.scala | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/src/main/scala/spark/examples/HBaseTest.scala b/examples/src/main/scala/spark/examples/HBaseTest.scala new file mode 100644 index 0000000000..90ff64b483 --- /dev/null +++ b/examples/src/main/scala/spark/examples/HBaseTest.scala @@ -0,0 +1,34 @@ +package spark.examples + +import spark._ +import spark.rdd.NewHadoopRDD +import org.apache.hadoop.hbase.{HBaseConfiguration, HTableDescriptor, HColumnDescriptor} +import org.apache.hadoop.hbase.client.HBaseAdmin +import org.apache.hadoop.hbase.mapreduce.TableInputFormat + +object HBaseTest { + def main(args: Array[String]) { + val sc = new SparkContext(args(0), "HBaseTest", + System.getenv("SPARK_HOME"), Seq(System.getenv("SPARK_EXAMPLES_JAR"))) + + val conf = HBaseConfiguration.create() + conf.set(TableInputFormat.INPUT_TABLE, args(1)) + + // Initialize hBase tables if necessary + val admin = new HBaseAdmin(conf) + if(!admin.isTableAvailable(args(1))) { + val colDesc = new HColumnDescriptor(args(2)) + val tableDesc = new HTableDescriptor(args(1)) + tableDesc.addFamily(colDesc) + admin.createTable(tableDesc) + } + + val hBaseRDD = new NewHadoopRDD(sc, classOf[TableInputFormat], + classOf[org.apache.hadoop.hbase.io.ImmutableBytesWritable], + classOf[org.apache.hadoop.hbase.client.Result], conf) + + hBaseRDD.count() + + System.exit(0) + } +} |