我通过 conda 和 pip pyspark 从头构建并以编程方式使用我的 PySpark 环境(就像我演示的 Here ) ;而不是使用可下载的 Spark 发行版中的 PySpark。正如您在上面 URL 的第一个代码片段中看到的那样,我通过(除其他外)我的 SparkSession 启动脚本中的 k/v conf-pairs 来完成此操作。 (顺便说一句,这种方法使我能够在各种 REPL、IDE 和 JUPYTER 中工作)。
但是,关于配置 Spark 支持访问 HIVE 数据库和元数据存储,手册是这样说的:
Configuration of
Hiveis done by placing yourhive-site.xml,core-site.xml(for security configuration), andhdfs-site.xml(for HDFS configuration) file inconf/.
上面的 conf/ 是指 Spark 分发包中的 conf/ 目录。但是 pyspark 通过 pip 和 conda 当然没有那个目录,那么如何将 HIVE 数据库和 Metastore 支持插入到 Spark 中那种情况?
我怀疑这可能由具有特殊前缀的 SparkConf K/V 对提供,形式为:spark.hadoop.*(参见 here);如果是,我仍然需要确定需要哪些 HADOOP/HIVE/CORE 指令。我想我会试错的。 :)
注意:.enableHiveSupport() 已经包含在内。
我将修改 spark.hadoop.* K/V 对,但如果有人知道这是如何立即完成的,请告诉我。
谢谢。 :)
编辑:提供解决方案后,我更新了first URL above中的内容.它现在集成了下面讨论的 SPARK_CONF_DIR 和 HADOOP_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_DIRin$SPARK_HOME/conf/spark-env.shto a location containing the configuration files.
To specify a different configuration directory other than the default “
SPARK_HOME/conf”, you can setSPARK_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.* 前缀。
