【问题标题】:Apache Spark : how to read from hdfs fileApache Spark:如何从 hdfs 文件中读取
【发布时间】:2018-06-17 14:35:03
【问题描述】:

我已经在本地安装了 spark 2.3.0 并使用了 pyspark。我可以毫无问题地处理本地文件。

但如果我必须从 hdfs 读取数据,我就做不到。

我对 spark 如何访问 hadoop 文件感到困惑。在安装 spark 时,我被要求复制 winutil。不明白winutil的作用是什么。

我们应该先启动 hadoop 服务,然后再使用 spark 吗? 如果我使用外部安装的 hadoop 并尝试在 spark 中使用它,则会出现 java.lang.UnsatisfiedLinkError 错误。任何指向正确文档的指针都会有很大帮助。

谢谢, 基兰

【问题讨论】:

  • 如果您使用 pip 安装 PySpark,它不附带任何 Hadoop 库。当然,Hadoop 服务器需要运行(远程,而不是本地)才能访问 HDFS 文件
  • 通过stackoverflow.com/questions/34697744/…你应该明白为什么windows需要winutils
  • 感谢您的帮助..我试过这个并且工作了..再次感谢

标签: apache-spark pyspark hdfs


【解决方案1】:

如果你使用 spark-submit 在集群模式下运行应用程序,那么它可以带一个标志 --files 用于从驱动节点到工人。我相信您能够在本地模式下运行的原因是因为您的驱动程序和工作人员在同一台机器上,但是在集群模式下,驱动程序和工作人员可能在不同的机器上。在这种情况下,Spark 需要知道将哪些文件发送到工作节点。按照 Holden Karau 的 Learning Spark 一书中的描述,可以使用以下标志;安迪·康温斯基;帕特里克·温德尔;马泰·扎哈里亚

--master
Indicates the cluster manager to connect to. The options for this flag are described in Table 7-1.

--deploy-mode
Whether to launch the driver program locally (“client”) or on one of the worker machines inside the cluster (“cluster”). In client mode spark-submit will run your driver on the same machine where spark-submit >s itself being invoked. In cluster mode, the driver will be shipped to execute on a worker node in the cluster. The default is client mode.

--class
The “main” class of your application if you’re running a Java or Scala program.

--name
A human-readable name for your application. This will be displayed in Spark’s web UI.

--jars
A list of JAR files to upload and place on the classpath of your application. If your application depends on a small number of third-party JARs, you can add them here.

--files
A list of files to be placed in the working directory of your application. This can be used for data files that you want to distribute to each node.

--py-files
A list of files to be added to the PYTHONPATH of your application. This can contain .py, .egg, or .zip files.

--executor-memory
The amount of memory to use for executors, in bytes. Suffixes can be used to specify larger quantities such as “512m” (512 megabytes) or “15g” (15 gigabytes).

--driver-memory
The amount of memory to use for the driver process, in bytes. Suffixes can be used to specify larger quantities such as “512m” (512 megabytes) or “15g” (15 gigabytes).

更新 我假设 Kiran 有 Hadoop 设置(正如他在外部提到的)并且无法以编程方式从 HDFS 读取程序。如果不是这样,请忽略答案。

【讨论】:

  • 这并不能真正回答有关 HDFS 文件的问题
猜你喜欢
  • 2017-06-14
  • 2019-08-22
  • 1970-01-01
  • 2021-06-18
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
  • 2017-08-07
  • 1970-01-01
相关资源
最近更新 更多