Spark如何连接本地Hive而非远程Hive

3

我使用Spring Framework创建一个api,用于查询Hadoop中的一些表。我使用的命令是:

  println("-----------------------------------------------------------------before )
val spark = SparkSession
  .builder()
  .appName("API")
  .master("local[*])
  .enableHiveSupport()
  .getOrCreate()
  println("--------------------------------------------------------------------Session was created")

我使用Spark 2.11.6和Scala v2.2.0版本。当我使用spark-shell时,我连接到远程集群。
在日志中我没有看到任何错误,但是我发现创建了一个本地的hive仓库:
     [           main] o.a.h.hive.metastore.MetaStoreDirectSql  : Using direct SQL, underlying DB is DERBY
    main] o.a.hadoop.hive.ql.session.SessionState  : Created local directory: C:/Users/..../.../Local/Temp/..._resources
    2018-05-10 16:32:32.556  INFO 16148 --- [           main] o.a.hadoop.hive.ql.session.SessionState  : Created HDFS directory: /tmp/hive/myuser/....

我正在尝试连接到远程Cloudera集群。我将xml文件(hive-site,hdfs-site,core-stire,yarn-site)复制到我的项目的conf目录中,并放置于$SPARK_CONF目录中。我将SPARK_HOME路径添加到PATH变量中,并将HADDOP_HOME变量设置为指向winutils位置。
还有什么其他措施可以采取?
日志非常长,以下是我看到的一些信息,这些信息可能对您意味着什么:
-----------------------------------------------------------------ENV=local[*]
   2018-05-10 16:32:16.930  WARN 16148 --- [           main] org.apache.hadoop.util.NativeCodeLoader  : Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
 [           main] org.apache.spark.util.Utils              : Successfully started service 'SparkUI' on port 4040.
 main] o.s.jetty.server.handler.ContextHandler  : Started o.s.j.s.ServletContextHandler@13ee97af{/stages/pool/json,null,AVAILABLE,@Spark}
[           main] org.apache.spark.ui.SparkUI              : Bound SparkUI to 0.0.0.0, and started at http://192.168.56.1:4040
[           main] o.apache.spark.sql.internal.SharedState  : URL.setURLStreamHandlerFactory failed to set FsUrlStreamHandlerFactory
[           main] DataNucleus.Persistence                  : Property hive.metastore.integral.jdo.pushdown unknown - will be ignored
[           main] DataNucleus.Datastore                    : The class "org.apache.hadoop.hive.metastore.model.MFieldSchema" is tagged as "embedded-only" so does not have its own datastore table.
[           main] DataNucleus.Query                        : Reading in results for query "org.datanucleus.store.rdbms.query.SQLQuery@0" since the connection used is closing
[           main] o.a.h.hive.metastore.MetaStoreDirectSql  : Using direct SQL, underlying DB is DERBY
[           main] o.a.hadoop.hive.metastore.ObjectStore    : Failed to 
      get database global_temp, returning NoSuchObjectException
[           main] o.a.hadoop.hive.ql.session.SessionState  : Created local directory: C:/Users/myuser/AppData/Local/Temp/1fa7a82b-fe17-4795-8973-212010634cd1_resources
[           main] o.a.hadoop.hive.ql.session.SessionState  : Created HDFS directory: /tmp/hive/myuser/1fa7a82b-fe17-4795-8973-212010634cd1
[           main] o.a.hadoop.hive.ql.session.SessionState  : Created local directory: C:/Users/myuser/AppData/Local/Temp/myuser/fileasdasdsa
 [           main] o.a.hadoop.hive.ql.session.SessionState  : Created HDFS directory: /tmp/hive/myuser/asdsadsa/_tmp_space.db
[           main] o.a.s.sql.hive.client.HiveClientImpl     : Warehouse location for Hive client (version 1.2.1) is file:/C:/Users/myuser/SpringScalaAPI/spark-warehouse
 [           main] o.a.s.s.e.s.s.StateStoreCoordinatorRef   : Registered StateStoreCoordinator endpoint
--------------------------------------------------------------------Session was created

说实话,这不是我第一次处理这种错误。上一次我使用的是Play框架。在这种情况下需要执行哪些确切步骤?哪些变量真正需要配置,哪些变量不重要?


这肯定是错误的:.master("local[*]") - vvg
你为什么认为它是错的?我在Play框架中使用了同样的代码,它可以正常工作。 - JeyJ
Spark是一个快速、通用的大数据处理引擎,它支持在Hadoop集群中运行,也可以单独使用。它提供了高级别的API(Java、Scala、Python和R),以及用于分布式SQL查询的SQL查询引擎。Spark还可以用于流处理、机器学习和图形处理等各种场景。在本教程中,我们将首先介绍Spark的基础知识,然后演示如何使用Spark进行数据处理和分析。下面是一个简单的例子,介绍如何使用Spark计算Pi值: - vvg
1个回答

1
使用Spark 2,您可以尝试类似以下的内容:
val ss = SparkSession
.builder()
.appName(" Hive example")
.config("hive.metastore.uris", "thrift://localhost:9083")
.enableHiveSupport()
.getOrCreate()

请注意hive.metastore.uris属性,将localhost更改为指向您的sandbox或集群。
一旦初始化ss,您可以像下面这样读取表格。
val df = ss.read.table("db_name.table_name")

希望这有所帮助。干杯。

是的,我知道,但我想使用我的集群中的 XML 文件,而不是手动配置服务器。还有其他想法吗? - JeyJ
@JeyJ 我也遇到了类似的问题。有解决方案吗? - Avik Aggarwal
@AvikAggarwal,你可以将它们添加到你的Hadoop配置中。从spark.sparkContext.hadoopConfiguration获取Hadoop配置。 - Chitral Verma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接