python - 将数据从 Azure Data Lake 加载到 DSVM 上的 Jupyter notebook

标签 python apache-spark jupyter-notebook azure-data-lake azure-dsvm

我正在尝试将数据从 Azure Data Lake 加载到我的 Data Science VM 中的 Jupyter notebook。请注意,我是数据湖存储的所有者,拥有读取、写入和执行权限。具有 Jupyter 的数据科学 VM 在同一订阅下运行,并且在同一资源组下。我正在尝试以下两种方法,但都面临问题。它们基于 this博客文章。


  • PySpark

以下是我使用 PySpark 加载数据的代码:

hvacText = sc.textFile("adl://name.azuredatalakestore.net/file_to_read.csv")
hvacText.count()

抛出以下异常:

Py4JJavaError: An error occurred while calling o52.text.
: java.io.IOException: No FileSystem for scheme: adl
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2660)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2667)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:94)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2703)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2685)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:373)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:295)
at org.apache.spark.sql.execution.datasources.DataSource$.org$apache$spark$sql$execution$datasources$DataSource$$checkAndGlobPathIfNecessary(DataSource.scala:616)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:350)
at org.apache.spark.sql.execution.datasources.DataSource$$anonfun$14.apply(DataSource.scala:350)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:241)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:241)
at scala.collection.immutable.List.flatMap(List.scala:344)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:349)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
at org.apache.spark.sql.DataFrameReader.text(DataFrameReader.scala:623)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:748)

  • Python 开发工具包:

以下是我使用SDK访问数据的代码:

from azure.datalake.store import core, lib, multithread    
token = lib.auth()
# output: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXX to authenticate.
# here I open the link and enter the code successfully
adl = core.AzureDLFileSystem(token, store_name='store_name')
adl.ls('/')

发生以下异常:

DatalakeRESTException: Data-lake REST exception: LISTSTATUS, .

我对修复 Spark 解决方案更感兴趣,但我们将不胜感激。

最佳答案

您需要做两件事才能在 DSVM 上使用 ADLS 连接器:

  1. 通过编辑/dsvm/tools,将两个 jar,hadoop-azure-datalake-3.0.0-alpha3.jar 和 azure-data-lake-store-sdk-2.1.5.jar 添加到 spark-defaults.conf/spark/current/conf/spark-defaults.conf 并将两个 jar 添加到 spark.jars。默认情况下我们不会加载它们,因此用户可以获得更快的启动时间。
  2. 创建 core-site.xml:同样在 conf 目录中,将 core-site.xml.template 复制到 core-site.xml。仅保留 ADLS 部分并输入您的值。

您还需要修复当前图像中损坏的符号链接(symbolic link):在/dsvm/tools/spark/current/jars 中,有 azure-data-lake-store-sdk-2.0.11.jar 和 hadoop-azure 的符号链接(symbolic link)-datalake-3.0.0-alpha2.jar。您应该删除这些并将符号链接(symbolic link)添加到/opt/adls-jars/hadoop-azure-datalake-3.0.0-alpha3.jar 和/opt/adls-jars/azure-data-lake-store-sdk-2.1.5。 jar 。这是我们的错误。

关于python - 将数据从 Azure Data Lake 加载到 DSVM 上的 Jupyter notebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399751/

相关文章:

apache-spark - Spark on YARN 资源管理器 : Relation between YARN Containers and Spark Executors

Python 金融知识词典

python - 如何在 pysimplegui 中刷新窗口以显示新图像

python - 如何在Python中使用pandas访问导入的csv文件中的元素?

scala - Scala 中 RDD 的直方图?

python - Google Colab 笔记本的演示模式

import - 如何在 Google Colab 中将 jupyter notebook 的功能导入另一个 jupyter notebook

python - 使用count时收到 "IndexError: list index out of range"

python - 通过 sklearn.metrics.make_scorer 将估算器传递给自定义评分函数

java - 使用预参数 Spark 进行 Pycharm 调试