java.lang.NoSuchMethodError:org.apache.hadoop.security.ProviderUtils.excludeIncompatibleCredentialProviders从Azure Blob存储读取

时间:2020-08-26 12:56:52

标签: azure apache-spark pyspark azure-storage-account

我正在尝试读取存储在Azure存储帐户中的CSV文件。为此,我在虚拟机上安装了火花,并尝试从pyspark读取数据框中的CSV文件。

我在某处阅读了如何执行此操作,然后按照步骤操作,并在/ jar目录中复制了最新的hadoop-azure和azure-storage JAR文件。然后,我想到了这个错误:-

NoClassDefFoundError:org / apache / hadoop / fs / StreamCapabilities

我搜索了此错误,发现我需要引用hadoop-azure-2.8.5.jar而不是最新的hadoop-azure JAR。因此,我用最新的hadoop-azure jar替换了此JAR,然后再次执行了pyspark代码。

执行代码后,我遇到另一个错误:-

:java.lang.NoSuchMethodError: org.apache.hadoop.security.ProviderUtils.excludeIncompatibleCredentialProviders(Lorg / apache / hadoop / conf / Configuration; Ljava / lang / Class;)Lorg / apache / hadoop / conf / Configuration;

此外,下面是我的pyspark代码:-

from pyspark import SparkContext
from pyspark.sql import SparkSession
from pyspark.sql import Window
from pyspark.sql.types import *
from pyspark.sql.functions import *

spark = SparkSession.builder.getOrCreate()
storage_account_name = "<storage_account_name>"
storage_account_access_key = "<storage_account_access_key>"
spark.conf.set("fs.azure.account.key." + storage_account_name + ".blob.core.windows.net",storage_account_access_key)

spark._jsc.hadoopConfiguration().set("fs.wasbs.impl","org.apache.hadoop.fs.azure.NativeAzureFileSystem")
spark._jsc.hadoopConfiguration().set("fs.azure", "org.apache.hadoop.fs.azure.NativeAzureFileSystem")
spark._jsc.hadoopConfiguration().set("fs.azure.account.key.my_account.blob.core.windows.net", "storage_account_access_key")


df = spark.read.format("csv").option("inferSchema", "true").load("wasbs://<container_name>@<storage_account_name>.blob.core.windows.net/<path_to_csv>/sample_file.csv")
df.show()

1 个答案:

答案 0 :(得分:0)

我搜索了此内容,并尝试了多种hadoop-azure JAR版本。对我有用的是 hadoop-azure-2.7.0.jar

使用此JAR版本,我能够从Blob存储中读取CSV文件。