[英]How to access hive data using spark
I have table stored as text file eg employee in hive and I want to access it using spark. 我将表格存储为文本文件,例如,雇员在蜂巢中,我想使用spark访问它。
First i have set sql context object using 首先我已经使用设置了SQL上下文对象
val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)
Then i have created table 然后我创建了表格
scala>sqlContext.sql("CREATE TABLE IF NOT EXISTS employee( id INT, name STRING, age INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY '\\n'")
Further i was trying to load the contents of text file by using 此外,我试图通过使用加载文本文件的内容
scala> sqlContext.sql("LOAD DATA LOCAL INPATH 'employee.txt' INTO TABLE employee")
I am getting error as 我收到错误消息
SET hive.support.sql11.reserved.keywords=false
FAILED: SemanticException Line 1:23 Invalid path ''employee.txt'': No files
matching path file:/home/username/employee.txt
If i have to place the textfile in current directory where the spark-shell is running how to do that ? 如果我必须将文本文件放在运行spark-shell的当前目录中,该怎么办?
Do you run hive on hadoop? 您在hadoop上运行蜂巢吗? try to use absolute path... if this doesn't work, try to load your file to hdfs and then give absolute path to your file (hdfs location) .
尝试使用绝对路径...如果不起作用,请尝试将文件加载到hdfs,然后提供文件的绝对路径(hdfs位置)。
Try doing the below steps 尝试执行以下步骤
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.