System.setProperty("hive.metastore.uris", "thrift://METASTORE:9083");
final SparkConf conf = new SparkConf();
SparkContext sc = new SparkContext(conf);
HiveContext hiveContext = new HiveContext(sc);
要么
final SparkConf conf = new SparkConf();
SparkContext sc = new SparkContext(conf);
HiveContext hiveContext = new HiveContext(sc);
hiveContext.setConf("hive.metastore.uris", "thrift://METASTORE:9083");
val spark = SparkSession.builder.master(“local”) . appName(“testing”) . enableHiveSupport() . getOrCreate()
Sample code:
package sparkSQL
/**
* Created by venuk on 7/12/16.
*/
import org.apache.spark.sql.SparkSession
object hivetable {
def main(args: Array[String]): Unit = {
val spark = SparkSession.builder.master("local[*]").appName("hivetable").enableHiveSupport().getOrCreate()
spark.sql("create table hivetab (name string, age int, location string) row format delimited fields terminated by ',' stored as textfile")
spark.sql("load data local inpath '/home/hadoop/Desktop/asl' into table hivetab").show()
val x = spark.sql("select * from hivetab")
x.write.saveAsTable("hivetab")
}
}
4 回答
对于Spark 1.x,您可以设置:
要么
Update If your Hive is Kerberized :
在创建HiveContext之前尝试设置它们:
在火花2.0 . 它看起来应该是这样的:
我也面临同样的问题,但已经解决了 . 只需按照Spark 2.0版本中的步骤操作即可
Step1: 将Hive conf文件夹中的hive-site.xml文件复制到spark conf .
Step 2: 编辑spark-env.sh文件并配置你的mysql驱动程序 . (如果您使用Mysql作为hive Metastore . )
或者将MySQL驱动程序添加到Maven / SBT(如果使用那些)
Step3: 创建spark会话时添加enableHiveSupport()
Sample code:
Output:
下面的代码对我有用 . 我们可以忽略
hive.metastore.uris
的配置为本地Metastore,spark将在本地的备用仓库目录中创建配置单元对象 .