天蓝色突触:从数据块连接到无服务器 sql 池 - 无法找到数据源:com.databricks.spark.sqldw

时间:2021-07-28 15:45:54

标签: azure-databricks azure-synapse

我正在使用 azure 中的突触。我在无服务器 sql 池中有数据。我想将该数据导入到 databricks 中的数据框。

我收到以下错误:

Py4JJavaError: An error occurred while calling o568.load.
: java.lang.ClassNotFoundException: Failed to find data source: com.databricks.spark.sqldw. Please find packages at http://spark.apache.org/third-party-projects.html
    at org.apache.spark.sql.execution.datasources.DataSource$.lookupDataSource(DataSource.scala:656)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:195)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:168)
    at sun.reflect.GeneratedMethodAccessor102.invoke(Unknown Source)
    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:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: com.databricks.spark.sqldw.DefaultSource
...
...
...

我使用的 pyspark 代码是:

spark.conf.set(
  "fs.azure.account.key.adlsAcct.blob.core.windows.net",
  "GVk3234fds2JX/fahOcjig3gNy198yasdhfkjasdyf87HWmDVlx1wLRmu7asdfaP3g==")



sc._jsc.hadoopConfiguration().set(
  "fs.azure.account.key.adlsAcct.blob.core.windows.net",
  "GVk3234fds2JX/fahOcjig3gNy198yasdhfkjasdyf87HWmDVlx1wLRmu7asdfaP3g==")


  
df = spark.read \
.format("com.databricks.spark.sqldw") \
.option("url","jdbc:sqlserver://synapse-myworkspace-ondemand.sql.azuresynapse.net:1433;database=myDB;user=myUser;password=userPass123;encrypt=false;trustServerCertificate=true;hostNameInCertificate=*.sql.azuresynapse.net;loginTimeout=30;") \
.option("tempdir", "wasbs://projects@adlsAcct.dfs.core.windows.net/Lakehouse/tempDir") \
.option("forwardSparkAzureStorageCredentials","true") \
.option("dbtble","tbl_sampledata") \
.load()

我可以确认:

  • 已配置允许 azure 服务连接的防火墙设置。
  • 用户有权访问 sql serverless 池数据库。
  • 我尝试过集成身份验证,但得到了相同的结果。

在我看来,该错误看起来像 databricks 找不到格式 com.databricks.spark.sqldw,但这可能是一个红鲱鱼。

感谢任何建议和专业知识

1 个答案:

答案 0 :(得分:1)

使用 Azure Synapse Analytics 的优势之一是集成,因为存储、数据库、管道、笔记本等的各种组件往往比设置独立组件更容易协同工作,例如 Databricks notebook,您必须在其中编写类似您的代码,包括 hadoopConfiguration

将数据从专用 SQL 池获取到 Synapse 笔记本的一种简单方法是使用 synapsesql 方法。一个简单的例子:

%%spark
// Get the table with synapsesql method and expose as temp view
val df = spark.read.synapsesql("dedi_pool.dbo.someTable")

df.createOrReplaceTempView("someTable")

不幸的是,此方法目前仅在 Scala 中实现(据我所知),但您可以将数据帧另存为临时视图,将其公开给 SparkSQL 和 Python:

%%sql
SELECT * FROM someTable;

这是在 Python 中检索临时视图的 Python:

%%pyspark
## Get the table with synapsesql method and expose as temp view
df = spark.sql("select * from someTable")

df.show()

这是我的结果:

results

查看此技术的主要文档here

对于无服务器 SQL 池,我最初对它没有内置感到沮丧,但是如果您考虑一下,您将使用重复的服务,即无服务器引擎来查询底层文件和 Apache Spark 池以查询占位符/外部表,这有效地查询了它们的基础文件。因此,您不妨直接使用 spark.read 和任何文件格式(例如 .csv)引用文件。取自 docs 的示例:

%%pyspark
df = spark.read.load('abfss://users@contosolake.dfs.core.windows.net/NYCTripSmall.parquet', format='parquet')
display(df.limit(10))

我是这么想的: parquet serverless and apache spark pools

不过在技术上是可行的,我介绍了技术 here