SparkSQL External Datasource简易使用之CSV

下载源码&编译:

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

 

Maven GAV:

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

 

$SPARK_HOME/conf/spark-env.sh

export SPARK_CLASSPATH=/home/spark/software/source/spark_package/spark-csv/target/scala-2.10/spark-csv-assembly-0.1.jar:$SPARK_CLASSPATH

 

测试数据下载:

wget https://github.com/databricks/spark-csv/raw/master/src/test/resources/cars.csv 

 

Scala API:

import org.apache.spark.sql.SQLContext
val sqlContext = new SQLContext(sc)
import com.databricks.spark.csv._
val cars = sqlContext.csvFile("file:///home/spark/software/data/cars.csv")
cars.collect

 

SQL:

CREATE TEMPORARY TABLE cars
USING com.databricks.spark.csv
OPTIONS (path "file:///home/spark/software/data/cars.csv", header "true");

select * from cars;

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。