S3上没有数据,爬到data catalog时有数据

No data on S3 but there is data when the data is crawled to data catalog

我在调用 S3 parquet 文件然后覆盖路径时遇到错误消息,但如果我使用追加则工作正常。下面的代码只是整个脚本的一部分

df = spark.read.format("jdbc")
.option("driver", jdbc_driver_name)
.option("url", db_url)
.option("dbtable", table_name)
.option("user", db_username)
.option("password", db_password)
.option("fetchSize", 100000).load()

load_test = spark.read.parquet("s3://s3-raw/test_table")

new_test = df.withColumn("load_timestamp", unix_timestamp(lit(timestamp),'yyyy-MM-dd HH:mm:ss').cast("timestamp"))
new_test.write.partitionBy("load_timestamp").format("parquet").mode("overwrite").save("s3://s3-raw/test_table")

我尝试编辑代码(见下文),它现在可以调用 S3 镶木地板文件,然后覆盖路径,但是当我检查 S3 路径 (s3://s3-raw/test_table) 时,分区 table 即 load_timestamp 在那里可用,但里面没有数据。当我将它抓取到数据目录并在 AWS Athena 上查询时,预期的输出在那里可用。

load_test = spark.read.parquet("s3://s3-raw/" + 'test_table')

new_test = df.withColumn("load_timestamp", unix_timestamp(lit(timestamp),'yyyy-MM-dd HH:mm:ss').cast("timestamp"))
new_test.write.partitionBy("load_timestamp").format("parquet").mode("overwrite").save("s3://s3-raw/" + 'test_table')

出现这种行为的原因是 S3 一致性模型。 S3 为存储桶中创建的新对象提供写入后读取一致性。至于对象 删除和修改 它是 最终 一致的,即可能需要一段时间才能反映 S3 中对象的更新或删除。正如你在这里写的那样,这将是一个修改,因此,最终的一致性。

您可以在 AWS 文档中阅读更多相关信息:S3 一致性模型。可以在此处找到一个很好的 post 来实际理解它以及如何处理它:https://medium.com/@dhruvsharma_50981/s3-eventual-data-consistency-model-issues-and-tackling-them-47093365a595