Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在DataRicks上将Azure Synapse Dataframe转换为JSON?_Azure_Pyspark_Databricks_Azure Databricks_Azure Synapse - Fatal编程技术网

如何在DataRicks上将Azure Synapse Dataframe转换为JSON?

如何在DataRicks上将Azure Synapse Dataframe转换为JSON?,azure,pyspark,databricks,azure-databricks,azure-synapse,Azure,Pyspark,Databricks,Azure Databricks,Azure Synapse,我可以将Azure Synapse数据帧转换为JSON吗?因为当我尝试它时,它出错了。我使用脚本作为Pandas数据帧函数df.to_json(),因为我假设Azure Synapse数据帧与Pandas数据帧相同 下面是我的synapse脚本: class UtilAzSynapse(UtilAzSynapse): @staticmethod def write_to_synapse(df, table, write_mode, url, tempDir): l

我可以将Azure Synapse数据帧转换为JSON吗?因为当我尝试它时,它出错了。我使用脚本作为Pandas数据帧函数
df.to_json()
,因为我假设Azure Synapse数据帧与Pandas数据帧相同

下面是我的synapse脚本:

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}")
错误:

AttributeError: 'DataFrame' object has no attribute 'to_json'

为什么我需要将数据帧转换为JSON是因为当我尝试使用
write_to_synapse
函数时,解释了数据帧需要转换为
JSON
格式。

pyspark数据帧与pandas数据帧不同

在pyspark中,您应该能够做到:

df.toJSON()
您可以在此处找到更多信息:

df.toJSON()