瞌睡中的葡萄虎

博客园 首页 新随笔 联系 订阅 管理

下载源码&编译:

git clone https://github.com/databricks/spark-avro.git
sbt/sbt package

 

Maven GAV:

groupId: com.databricks.spark
artifactId: spark-avro_2.10
version: 0.1

 

$SPARK_HOME/conf/spark-env.sh

export SPARK_CLASSPATH=/home/spark/software/source/spark_package/spark-avro/target/scala-2.10/spark-avro_2.10-0.1.jar:$SPARK_CLASSPATH

 

测试数据下载:

wget https://github.com/databricks/spark-avro/raw/master/src/test/resources/episodes.avro 

 

Scala API:

import org.apache.spark.sql.SQLContext
val sqlContext = new SQLContext(sc)
import com.databricks.spark.avro._
val episodes = sqlContext.avroFile("file:///home/spark/software/data/episodes.avro")
import sqlContext._
episodes.select('title).collect()

 

SQL:

CREATE TEMPORARY TABLE episodes
USING com.databricks.spark.avro
OPTIONS (path "file:///home/spark/software/data/episodes.avro");

select * from episodes;

 

posted on 2014-12-24 10:38  瞌睡中的葡萄虎  阅读(610)  评论(0编辑  收藏  举报