我在 Azure Databricks 中有一个 PySpark 数据框。我想写入 Azure Synapse。但我遇到了以下错误。
com.microsoft.sqlserver.jdbc.SQLServerException: The statement failed. Column 'ETL_TableName' has a data type that cannot participate in a columnstore index.
我检查了 Synapse 的连接。一切正常,我能够读取数据。但是在写作时,我遇到了问题。任何人都可以帮助如何处理这个错误。
将数据写入 Synapse 的代码:
dataFrame.repartition(1).write.format("jdbc")\
.option("url", azureurl)\
.option("tempDir", tempDir) \
.option("forwardSparkAzureStorageCredentials", "true") \
.option("dbTable", dbTable)\
.option("append", "true")\
.save()
最佳答案
有几件事需要改变。
格式应为.format("jdbc")
=> .format("com.databricks.spark.sqldw")
。
将此选项“tableOptions”子句添加到您的写入语句中。它取代了 CREATE TABLE (AS) 语句的 with() 子句:
.option ("tableOptions","heap,distribution=MY_DISTRIBUTION")
代码应如下所示:
dataFrame.repartition(1).write.format("com.databricks.spark.sqldw")\
.option("tableOptions","heap,distribution=HASH(rownum)")
.option("url", azureurl)\
.option("tempDir", tempDir) \
.option("forwardSparkAzureStorageCredentials", "true") \
.option("dbTable", dbTable)\
.option("append", "true")\
.save()
引用:
Azure Databricks - Azure Synapse Analytics
根据以下指导选择 MY_DISTRIBUTION 的值:
Guidance for designing distributed tables in Synapse SQL pool
关于azure - 将 PySpark Dataframe 写入 Azure Synapse 时遇到的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62701128/