NoclassDeffoundError在使用DataProc群集中使用AD验证写入Azure SQL时。但是在本地工作正常
我写了Spark Scala代码。我有一个奇怪的问题,可以使用DataProc群集中的AD身份验证从Azure SQL成功阅读。但是我在写信给Azure SQL时会遇到以下错误。
NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException
而且我只有在DataProc群集中运行时才会遇到此错误。同一代码在我的本地机器中正常工作。
更明确的是,我在DataProc中也阅读时遇到了同样的错误,然后我使用此通过使用Maven Shade插件来重新安置冲突的库来解决。但是现在,我在写作时遇到了同样的错误。不知道怎么了。为什么写入DataProc中的写入失败?请帮助
代码示例:
从Azure SQL读取(工作正常):
spark.read
.format("com.microsoft.sqlserver.jdbc.spark")
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
.option("encrypt", "false")
.option("url", url)
.option("database", database)
.option("user", user)
.option("password", password)
.option("query", query)
.option("authentication", "ActiveDirectoryPassword")
.load()
写入Azure SQL(DataProc中的失败):
df.write
.format("jdbc")
.mode(mode)
.option("url", url)
.option("database", database)
.option("user", user)
.option("password", password)
.option("dbtable", table)
.option("authentication", "ActiveDirectoryPassword")
.save()
Maven Shade插件:
<relocation>
<pattern>com</pattern>
<shadedPattern>repackaged.com.microsoft</shadedPattern>
<includes>
<include>com.microsoft.**</include>
</includes>
</relocation>
其他Azure依赖关系:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spark-mssql-connector_2.12</artifactId>
<version>1.2.0</version>
</dependency>
I have written Spark Scala code. I have a strange issue where I am able to read successfully from Azure SQL using AD authentication in Dataproc cluster. But I am getting the below error while writing to Azure SQL.
NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException
And I am getting this error only while running in Dataproc cluster. The same code works fine in my local machine.
Just to be more clear, I got the same error while reading too in Dataproc and I resolved it using this solution by using Maven shade plugin to relocate the conflicting library. But now again I am getting same error while writing. Not sure what is going wrong. Why is the write failing in Dataproc? Please help
Code sample:
Reading from Azure SQL(Working fine):
spark.read
.format("com.microsoft.sqlserver.jdbc.spark")
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
.option("encrypt", "false")
.option("url", url)
.option("database", database)
.option("user", user)
.option("password", password)
.option("query", query)
.option("authentication", "ActiveDirectoryPassword")
.load()
Writing to Azure SQL(Failing in Dataproc):
df.write
.format("jdbc")
.mode(mode)
.option("url", url)
.option("database", database)
.option("user", user)
.option("password", password)
.option("dbtable", table)
.option("authentication", "ActiveDirectoryPassword")
.save()
Maven Shade plugin:
<relocation>
<pattern>com</pattern>
<shadedPattern>repackaged.com.microsoft</shadedPattern>
<includes>
<include>com.microsoft.**</include>
</includes>
</relocation>
Other Azure dependencies:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>msal4j</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.7</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spark-mssql-connector_2.12</artifactId>
<version>1.2.0</version>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过添加
.option(“驱动程序”,“ com.microsoft.sqlserver.jdbc.sqlserverdriver”)
在写操作中解决了问题,从而解决了问题。找到该问题突出显示了I resolved the issue by adding
.option("driver", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
in write operation and it succeeded. Found the issue highlighted here