Last active
December 30, 2021 21:26
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
from dateutil import parser | |
base_path = "s3://open-data-lake-demo-us-east-1/moma/artists_mor" | |
instances = [ # times in EST | |
"2021-12-30 08:00:00", # reflects original record (r) | |
"2021-12-30 09:00:00", # refects updates 1 and 2 (u) | |
"2021-12-30 09:30:00", # refects updates 3 (u) | |
"2021-12-30 11:00:00", # refects updates 4 (u) | |
"2021-12-30 12:30:00", # refects updates 5 (u) | |
"2021-12-30 14:00:00", # refects delete (d) | |
] | |
for instant in instants: | |
as_of_instant = parser.parse(instant) + timedelta(hours=5) # adjust EST for UTC | |
print(f"Record state as of: {as_of_instant}") | |
artistsSnapshotDF = ( | |
spark.read.format("hudi").option("as.of.instant", as_of_instant).load(base_path) | |
) | |
artistsSnapshotDF.createOrReplaceTempView("hudi_artists_snapshot") | |
spark.sql( | |
""" | |
SELECT _hoodie_commit_time, __op, _hoodie_partition_path, name, nationality, gender, birth_year, death_year | |
FROM hudi_artists_snapshot | |
WHERE artist_id=299; | |
""" | |
).show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment