首页 > 其他 > 详细

spark_load csv to hive via hivecontext

时间:2017-03-15 11:43:44      阅读:310      评论:0      收藏:0      [点我收藏+]

//prepare csv

year,make,model,comment,blank
"2012","Tesla","S","No comment",
"1997","Ford,E350","Go get one now they are going fast",
"2015","Chevy","Volt"

 

//Processing and inserting data in hive without schema

import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.sql.hive.orc._
val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
val df = hiveContext.read.format("com.databricks.spark.csv").option("header", "true").option("inferSchema", "true").load("/tmp/cars.csv")
val selectedData = df.select("year", "model")
selectedData.write.format("orc").option("header", "true").save("/tmp/newcars")

 

//permission issues as user hive 

// org.apache.hadoop.hive.ql.metadata.HiveException: MetaException(message:java.security.AccessControlException: Permission denied: user=hive, access=WRITE, inode="/tmp/newcars":hdfs:hdfs:drwxr-xr-x
//Updated /tmp/newcars_orc_cust17 directory permissions

hiveContext.sql("create external table newcars_orc_ext_cust17(year string,model string) stored as orc location ‘/tmp/newcars‘")
hiveContext.sql("show tables").collect().foreach(println)

 

 

hiveContext.sql("select * from newcars").collect().foreach(println)

spark_load csv to hive via hivecontext

原文:http://www.cnblogs.com/liupuLearning/p/6553223.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!