我正在尝试使用用于 Azure SQL 数据库库 ( GitHub ) 的 Spark 连接器从 Spark 获取数据并将其批量插入 Azure 数据库。我正在尝试使用“ActiveDirectoryPassword”作为身份验证方法,但 adal4j 总是抛出一个 AuthenticationException 异常,指出抛出了 javax.mail.internet.ParseException。
我正在构建一个包含所有库的胖 jar,并使用 spark-submit 运行它。
Azure 组织有一个自定义域。
对于我尝试过的用户配置选项:
- myUser@myDomain.com
- 我的用户
- myUser@myDomain.com@myDB.database.windows.net
- myUser@myDomain.com@database.windows.net
- myUser@organization.onmicrosoft.com
当我将该字段留空时,它会引发用户名为空的错误。
我可以使用该用户通过 Azure Active Directory 登录到 Azure Data Studio。
这是我用来加载数据的片段:
val config = Config(Map(
"url" -> "myDB.database.windows.net",
"databaseName" -> "DatabaseName",
"user" -> "myUser@myDomain.com",
"password" -> "****",
"authentication" -> "ActiveDirectoryPassword",
"encrypt" -> "true",
"trustServerCertificate" -> "false",
"hostNameInCertificate" -> "myDB.database.windows.net",
"dbTable" -> "test.testing",
"bulkCopyBatchSize" -> "2500",
"bulkCopyTableLock" -> "true",
"bulkCopyTimeout" -> "600"
))
val session = SparkSession.builder.appName("App").enableHiveSupport.getOrCreate
val sqlContext = session.sqlContext
val df = sqlContext.sql(s"SELECT * FROM myTable")
df.bulkCopyToSqlDB(config)
这里抛出的异常:
com.microsoft.sqlserver.jdbc.SQLServerException: Failed to authenticate the user myUser@myDomain.com in Active Directory (Authentication=ActiveDirectoryPassword).
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:62)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getFedAuthToken(SQLServerConnection.java:4264)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.onFedAuthInfo(SQLServerConnection.java:4237)
......Truncated for readability......
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.util.concurrent.ExecutionException: com.microsoft.aad.adal4j.AuthenticationException: javax/mail/internet/ParseException
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:60)
... 48 more
Caused by: com.microsoft.aad.adal4j.AuthenticationException: javax/mail/internet/ParseException
at com.microsoft.sqlserver.jdbc.SQLServerADAL4JUtils.getSqlFedAuthToken(SQLServerADAL4JUtils.java:53)
... 48 more
提前致谢