【问题标题】:Write dataframe to SQL dedicated database using Synapse Analytics使用 Synapse Analytics 将数据帧写入 SQL 专用数据库
【发布时间】:2021-12-11 16:30:48
【问题描述】:

我想从我的 Azure Data Lake Storage Gen2 加载数据帧并将其写入 SQL 我在 Synapse 中创建的专用数据库。

这就是我所做的:

df = spark.read.format("delta").load(BronzePath)
df.write.format("com.databricks.spark.sqldw").option("url", jdbcUrl).save()

我有以下错误:

java.lang.ClassNotFoundException: Failed to find data source: com.databricks.spark.sqldw.

在做:

df.write.mode("overwrite").saveAsTable("MyTable")

在 Spark 默认数据库中创建表(蓝色十字)。那不是我需要的。我想将我的表放在专用数据库中(蓝色箭头):

【问题讨论】:

    标签: pyspark apache-spark-sql azure-synapse


    【解决方案1】:

    发布更多代码,包括 jdbc url,如果它不同于 this guide。我没有看到在 conf 中设置存储密钥的代码,而且您似乎也在使用不同的方式进行保存。

    
    # Otherwise, set up the Blob storage account access key in the notebook session conf.
    spark.conf.set(
      "fs.azure.account.key.<your-storage-account-name>.blob.core.windows.net",
      "<your-storage-account-access-key>")
    
    # Get some data from an Azure Synapse table.
    df = spark.read \
      .format("com.databricks.spark.sqldw") \
      .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
      .option("tempDir", "wasbs://<your-container-name>@<your-storage-account-name>.blob.core.windows.net/<your-directory-name>") \
      .option("forwardSparkAzureStorageCredentials", "true") \
      .option("dbTable", "<your-table-name>") \
      .load()
    
    # Load data from an Azure Synapse query.
    df = spark.read \
      .format("com.databricks.spark.sqldw") \
      .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
      .option("tempDir", "wasbs://<your-container-name>@<your-storage-account-name>.blob.core.windows.net/<your-directory-name>") \
      .option("forwardSparkAzureStorageCredentials", "true") \
      .option("query", "select x, count(*) as cnt from table group by x") \
      .load()
    
    # Apply some transformations to the data, then use the
    # Data Source API to write the data back to another table in Azure Synapse.
    
    df.write \
      .format("com.databricks.spark.sqldw") \
      .option("url", "jdbc:sqlserver://<the-rest-of-the-connection-string>") \
      .option("forwardSparkAzureStorageCredentials", "true") \
      .option("dbTable", "<your-table-name>") \
      .option("tempDir", "wasbs://<your-container-name>@<your-storage-account-name>.blob.core.windows.net/<your-directory-name>") \
      .save()
    
    

    另请阅读


    在 Spark 默认数据库中创建表(蓝色十字)。那不是我需要的。我想将我的表放在专用数据库中(蓝色箭头):

    here 所述“Spark 将为您创建一个默认的本地 Hive 元存储(使用 Derby)。”

    所以当你不给它路径/jdbcurl (df.write.mode("overwrite").saveAsTable("MyTable")) 时,它会保存到本地 Hive。

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2021-10-11
      • 2021-11-10
      • 2020-07-25
      • 2021-12-07
      • 2016-02-22
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      相关资源
      最近更新 更多