Skip to content

Commit

Permalink
Test case for writing min/max for DATEs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Sep 16, 2024
1 parent 5dae2d8 commit 12016fa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/testthat/_snaps/write-parquet-statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@
68 5 2 08, 00, .... 08, 00, ....
81 6 2 08, 00, .... 08, 00, ....

# min/max for DATEs

Code
as.data.frame(read_parquet_schema(tmp)[, -1])
Output
name r_type type type_length repetition_type converted_type logical_type
1 schema <NA> <NA> NA <NA> <NA>
2 day Date INT32 NA REQUIRED DATE DATE
3 count integer INT32 NA REQUIRED INT_32 INT, 32,....
num_children scale precision field_id
1 2 NA NA NA
2 NA NA NA NA
3 NA NA NA NA
Code
as.Date(map_int(minv, readBin, what = "integer", n = 1))
Output
[1] "2024-09-06" "2024-09-08" "2024-09-10" "2024-09-12" "2024-09-14"
Code
as.Date(map_int(maxv, readBin, what = "integer", n = 1))
Output
[1] "2024-09-07" "2024-09-09" "2024-09-11" "2024-09-13" "2024-09-15"

23 changes: 23 additions & 0 deletions tests/testthat/test-write-parquet-statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ test_that("min/max for integers", {
mtd[mtd$column == 2, c("row_group", "column", "min_value", "max_value")]
)
})

test_that("min/max for DATEs", {
tmp <- tempfile(fileext = ".parquet")
on.exit(unlink(tmp), add = TRUE)

df <- data.frame(
day = rep(as.Date("2024-09-16") - 10:1, each = 10),
count = 1:100
)
write_parquet(
df, tmp,
options = parquet_options(num_rows_per_row_group = 20)
)
expect_equal(as.data.frame(df), as.data.frame(read_parquet(tmp)))
mtd <- as.data.frame(read_parquet_metadata(tmp)[["column_chunks"]])
minv <- mtd[mtd$column == 0, "min_value"]
maxv <- mtd[mtd$column == 0, "max_value"]
expect_snapshot({
as.data.frame(read_parquet_schema(tmp)[,-1])
as.Date(map_int(minv, readBin, what = "integer", n = 1))
as.Date(map_int(maxv, readBin, what = "integer", n = 1))
})
})

0 comments on commit 12016fa

Please sign in to comment.