//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 

//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)

相关文章:

  • 2021-06-30
  • 2022-01-10
  • 2021-08-23
  • 2021-08-19
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-08-06
  • 2021-09-07
  • 2022-02-09
  • 2022-12-23
  • 2021-09-25
  • 2021-08-19
相关资源
相似解决方案