简体   繁体   English

使用 Databricks 上的 Apache Spark 将文件写入 delta lake 会产生与读取 Data Frame 不同的结果

[英]Writing out file to delta lake produces different results from Data Frame read using Apache Spark on Databricks

I have the following code on my databricks notebook我的数据块笔记本上有以下代码

fulldf = spark.read.format("csv").option("header", True).option("inferSchema",True).load("/databricks-datasets/flights/")

fulldf.write.format("delta").mode("overwrite").save('/mnt/lake/BASE/flights/Full/')

df = fulldf.limit(10)
df.write.format("delta").mode("overwrite").save('/mnt/lake/BASE/flights/Small/')

when I do a display on df I get the results I expect to see:当我在 df 上显示时,我得到了我期望看到的结果:

display(df)

在此处输入图像描述

As you can see there are ten rows with correct information如您所见,有十行包含正确的信息

However, when I read the actual parquet saved to '/mnt/lake/BASE/flights/Small/' using the following:但是,当我使用以下命令读取保存到“/mnt/lake/BASE/flights/Small/”的实际镶木地板时:

test = spark.read.parquet('/mnt/lake/BASE/flights/Small/part-00000-d9d24a80-28d6-43f5-950f-3c53a7d1336a-c000.snappy.parquet')

display(test)

I get a completely different result (although it should be the exact same result)我得到一个完全不同的结果(尽管它应该是完全相同的结果)

在此处输入图像描述

This is so strange.这太奇怪了。

I believe the problem is with limiting the results to 10 rows, but I don't see why I should get a completely different result我认为问题在于将结果限制为 10 行,但我不明白为什么我会得到完全不同的结果

I am surprised you even got output. On Databricks I got nothing but an error with your read approach.我很惊讶你竟然得到了 output。在 Databricks 上,除了你的读取方法出错之外,我什么也没得到。

As it is a delta file / sub directory and you must use the delta format therefore.由于它是一个delta文件/子目录,因此您必须使用delta格式。 Sure, it uses parquet underneath, but you need to use the delta api .当然,它在下面使用parquet ,但您需要使用delta api

Eg例如

df.write.format("delta").mode("overwrite").save("/AAAGed") 

and

df = spark.read.format("delta").load("/AAAGed")

and apply partitioning - if present, with a filter.并应用分区 - 如果存在,则使用过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 delta lake 手动删除数据文件 - Manually Deleted data file from delta lake 使用 Databricks(和 Apache Spark)从 AWS Redshift 读取 - Read from AWS Redshift using Databricks (and Apache Spark) 如何在不使用 Spark 的情况下从 Synapse 笔记本中的 Azure 数据湖读取 XML 文件 - How To Read XML File from Azure Data Lake In Synapse Notebook without Using Spark 将 delta lake 写入 AWS S3(没有 Databricks) - Writing delta lake to AWS S3 (Without Databricks) 同时将数据从 Sql 服务器复制到 Databricks delta lake(sql notebook 活动)空白值填充为 Null 值 - while copying data from Sql server to Databricks delta lake(sql notebook activity) Blank values populating as Null values 在集群 Spark Config 中为 Azure Databricks 设置数据湖连接 - Setting data lake connection in cluster Spark Config for Azure Databricks 如何使用 Databricks 的 Apache Spark 从 SQL 表中获取 stream 数据 - How to stream data from SQL Table with Apache Spark with Databricks 使用 spark sql 写入增量表 - Writing to delta table using spark sql 从存储帐户(Azure Data lake)读取 pdf 文件,无需使用 python 下载 - Read pdf file from storage account (Azure Data lake) without downloading it using python 使用符号链接格式清单对 Delta Lake 表进行 Spark SQL 查询 - Spark SQL queries against Delta Lake Tables using Symlink Format Manifest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM