【问题标题】:Spark connect to local Hive and not to remoteSpark 连接到本地 Hive 而不是远程
【发布时间】:2018-10-20 20:40:45
【问题描述】:

我正在使用 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 时,我连接到远程集群。

在日志中我没有收到任何错误,但我看到创建了一个本地配置单元存储库:

     [           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

说实话,这不是我第一次处理这种类型的错误。上次我使用播放框架。在这种情况下需要执行哪些具体步骤?哪些变量真正应该配置,哪些变量不重要?

【问题讨论】:

  • 这肯定是错误的.master("local[*])
  • 为什么你认为它错了?我在 play framework 中使用了相同的代码,它工作了..
  • spark.apache.org/docs/latest 这是第一段,带有入门示例。

标签: scala apache-spark hadoop hive


【解决方案1】:

使用 Spark 2,您可以尝试这样的事情,

val ss = SparkSession
.builder()
.appName(" Hive example")
.config("hive.metastore.uris", "thrift://localhost:9083")
.enableHiveSupport()
.getOrCreate()

注意 hive.metastore.uris 属性,将 localhost 更改为指向您的沙箱或集群。

一个ss被初始化,你可以读取如下表格,

val df = ss.read.table("db_name.table_name")

希望这会有所帮助。干杯。

【讨论】:

  • 是的,我知道,但我想使用集群中的 xml 文件,而不是手动配置服务器。还有其他想法吗?
  • @JeyJ 我面临着类似的问题。有什么解决办法吗?
  • @AvikAggarwal 您可以将它们添加到您的 hadoop 配置文件中。从 spark.sparkContext.hadoopConfiguration 获取 hadoop conf
猜你喜欢
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
  • 2016-01-13
  • 2020-04-07
  • 1970-01-01
  • 2019-06-09
  • 2017-02-09
  • 1970-01-01
相关资源
最近更新 更多