gpt4 book ai didi

python - 如何将 HIVE 访问集成到派生自 pip 和 conda 的 PySpark(而不是来自 Spark 发行版或包)

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:03 25 4
gpt4 key购买 nike

我通过 condapip pyspark 从头构建并以编程方式使用我的 PySpark 环境(就像我演示的 Here ) ;而不是使用可下载的 Spark 发行版中的 PySpark。正如您在上面 URL 的第一个代码片段中看到的那样,我通过(除其他外)我的 SparkSession 启动脚本中的 k/v conf-pairs 来完成此操作。 (顺便说一句,这种方法使我能够在各种 REPL、IDE 和 JUPYTER 中工作)。

但是,关于配置 Spark 支持访问 HIVE 数据库和元数据存储,手册是这样说的:

Configuration of Hive is done by placing your hive-site.xml, core-site.xml (for security configuration), and hdfs-site.xml (for HDFS configuration) file in conf/.

上面的 conf/ 是指 Spark 分发包中的 conf/ 目录。但是 pyspark 通过 pipconda 当然没有那个目录,那么如何将 HIVE 数据库和 Metastore 支持插入到 Spark 中那种情况?

我怀疑这可能由具有特殊前缀的 SparkConf K/V 对提供,形式为:spark.hadoop.*(参见 here);如果是,我仍然需要确定需要哪些 HADOOP/HIVE/CORE 指令。我想我会试错的。 :)

注意:.enableHiveSupport() 已经包含在内。

我将修改 spark.hadoop.* K/V 对,但如果有人知道这是如何立即完成的,请告诉我。

谢谢。 :)

编辑:提供解决方案后,我更新了first URL above中的内容.它现在集成了下面讨论的 SPARK_CONF_DIRHADOOP_CONF_DIR 环境变量方法。

最佳答案

在这种情况下,我建议 the official configuration guide (强调我的):

If you plan to read and write from HDFS using Spark, there are two Hadoop configuration files that should be included on Spark’s classpath:

  • hdfs-site.xml, which provides default behaviors for the HDFS client.
  • core-site.xml, which sets the default filesystem name.

(...)

To make these files visible to Spark, set HADOOP_CONF_DIR in $SPARK_HOME/conf/spark-env.sh to a location containing the configuration files.

Additionally :

To specify a different configuration directory other than the default “SPARK_HOME/conf”, you can set SPARK_CONF_DIR. Spark will use the configuration files (spark-defaults.conf, spark-env.sh, log4j.properties, etc) from this directory.

因此可以使用您的 Spark 安装可访问的任意目录来放置所需的配置文件,并且 SPARK_CONF_DIR 和/或 HADOOP_CONF_DIR 可以直接在您的脚本中轻松设置, 使用 os.environ .

最后,大多数时候甚至不需要单独的 Hadoop 配置文件,因为 Hadoop 特定属性可以直接在 Spark 文档中设置,使用 spark.hadoop.* 前缀。

关于python - 如何将 HIVE 访问集成到派生自 pip 和 conda 的 PySpark(而不是来自 Spark 发行版或包),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54447775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com