[英]Why I am not able to connect with the hive metastore using apache spark?
[英]How I can specify the metastore of Hive in Apache Spark program using java?
我已经编写了用于在Hive上运行SparkSQL的Java代码。 我正在尝试将我的蜂巢元存储库的路径提供给该程序,但是它根本无法正常工作。
看程序:
String warehouseLocation = "file:${system:user.dir}/spark-warehouse";
SparkSession spark = SparkSession
.builder()
.appName("Java Spark Hive Example")
.master("local[*]")
.config("spark.sql.warehouse.dir", warehouseLocation)
.enableHiveSupport()
.getOrCreate();
try
{
spark.sql("select count(*) from health1 ").show();
}
catch (Exception AnalysisException)
{
System.out.print("\nTable is not found\n");
}
我的metastore_db位于以下位置: /home/aims/hadoop/hadoop/hive/var/lib/metastore_db
我希望使用SparkSQL进行的任何操作都应反映在具有HIVE的Hadoop上。 为此,我需要将metastore_db连接到我的Maven程序。
我该怎么做? 有没有办法使用config在程序中提供hive-site.xml
路径?
您可以像下面那样运行Hive Metastore Server。
hive --service metastore &
现在您可以通过设置配置hive.metastore.uris
使用Spark连接到hive.metastore.uris
SparkSession spark = SparkSession
.builder()
.appName("Java Spark Hive Example")
.master("local[*]")
.config("hive.metastore.uris", "thrift://localhost:9083")
.enableHiveSupport()
.getOrCreate();
spark.sql("select count(*) from health1").show();
将您的core-site.xml和hive-site.xml放在resources文件夹中,Spark将自动查找这些文件并初始化Hive的metastore。 还将日志记录级别设置为INFO,以查看有关Hive Metastore的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.