Skip to content

Commit

Permalink
use seconds for file properties in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Ulmasov <[email protected]>
  • Loading branch information
r3stl355 committed Dec 31, 2023
1 parent a8d46ee commit ff6ac93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions crates/deltalake-core/tests/time_travel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ async fn time_travel_by_ds() {
// Need to set both the commit timestamp in each log file and, as a secondary, the modifed time of the file in case the timestamp is not defined
let log_dir_path = Path::new(log_dir);
for (fname, ds) in log_mtime_pair {
let ts = ds_to_ts(ds);
let (file_ts, commit_ts) = ds_to_ts(ds);
let file = log_dir_path.join(fname);
let contents = std::fs::read_to_string(&file).unwrap();
let my_reg = regex::Regex::new(r#"("timestamp"):\s*\d+([\s,}])"#).unwrap();
let new_contents = my_reg
.replace(&contents, format!("$1:{}$2", ts))
.replace(&contents, format!("$1:{}$2", commit_ts))
.to_string();
std::fs::write(&file, new_contents).unwrap();
utime::set_file_times(file, ts, ts).unwrap();
utime::set_file_times(file, file_ts, file_ts).unwrap();
}

let mut table = deltalake_core::open_table_with_ds(
Expand All @@ -33,7 +33,6 @@ async fn time_travel_by_ds() {
)
.await
.unwrap();

assert_eq!(table.version(), 0);

table = deltalake_core::open_table_with_ds(
Expand Down Expand Up @@ -93,7 +92,8 @@ async fn time_travel_by_ds() {
assert_eq!(table.version(), 4);
}

fn ds_to_ts(ds: &str) -> i64 {
fn ds_to_ts(ds: &str) -> (i64, i64) {
let fixed_dt = DateTime::<FixedOffset>::parse_from_rfc3339(ds).unwrap();
DateTime::<Utc>::from(fixed_dt).timestamp_millis()
let td_datetime = DateTime::<Utc>::from(fixed_dt);
(td_datetime.timestamp(), td_datetime.timestamp_millis())
}
5 changes: 4 additions & 1 deletion python/tests/test_table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def test_load_as_version_datetime(date_value: str, expected_version):
new_contents = re.sub(regex, rf"\1:{dt_epoch}\2", contents)
with open(file_path, "w") as out:
out.write(new_contents)
os.utime(file_path, (dt_epoch, dt_epoch))

# File timestamps are in seconds
file_ts = dt_epoch / 1000
os.utime(file_path, (file_ts, file_ts))

table_path = "../crates/deltalake-core/tests/data/simple_table"
dt = DeltaTable(table_path)
Expand Down

0 comments on commit ff6ac93

Please sign in to comment.