【发布时间】:2021-08-18 12:24:04
【问题描述】:
我可以将我的 Azure Synapse Dataframe 转换为 JSON 吗?因为当我尝试它时,它出错了。我使用脚本作为 Pandas DataFrame 函数df.to_json(),因为我假设 Azure Synapse Dataframe 与 Pandas DataFrame 相同。
这是我的突触脚本:
class UtilAzSynapse(UtilAzSynapse):
@staticmethod
def write_to_synapse(df, table, write_mode, url, tempDir):
log_msg = {
"table": table,
"url": url,
"tempDir": tempDir
}
UtilInfo.pnt("UtilAzSynapse.write_to_synapse log:\n" +
json.dumps(log_msg, indent=4))
(df.write
.format("com.databricks.spark.sqldw") # Commented at 20200121 Sql dw connetion exception (email keyword: Databricks cannot access the DW)
# .format("jdbc") # Added at 20200121
.option("tableOptions", "CLUSTERED COLUMNSTORE INDEX, DISTRIBUTION = ROUND_ROBIN") # Added at 20200121
.option("url", url)
.option("dbtable", table)
.option("forward_spark_azure_storage_credentials","True")
.option("tempdir", tempDir)
.mode(write_mode)
.save()
)
这就是我选择我的桌子的时候
temp_write_dir = azBlob.get_blob_path(
container = '03-analyse',
folder_path = f"{params['working_dir']}/sqlDwWriteTempDirs"
)
print(f"temp_write_dir = {temp_write_dir}")
df_dim_store = azSynapse._read_from_synapse(fact_sales_sql, tempDir=temp_read_dir)
df_dim_store = df_dim_store.to_json()
错误:
AttributeError: 'DataFrame' object has no attribute 'to_json'
为什么我需要将我的 DataFrame 转换为 JSON 是因为当我尝试使用我的 write_to_synapse 函数时,它被解释为 DataFrame 需要转换为 JSON 格式。
【问题讨论】:
标签: azure pyspark databricks azure-databricks azure-synapse