|
| 1 | +# Regression: append offsets and __index__ values above the 32-bit ceiling (a |
| 2 | +# resource with more than ~2.1e9 rows). `index_max` declares the index range so |
| 3 | +# the __index__ column is typed wide enough (int64) up front -- part 0 included |
| 4 | +# -- and every streamed part shares one type, instead of narrowing part 0 to |
| 5 | +# int32 and overflowing later parts on cast. See NEWS 0.99.3. |
| 6 | +# Run: library(BiocDuckDB); library(testthat); source("test-writeParquet-large-index.R") |
| 7 | + |
| 8 | +library(arrow) |
| 9 | + |
| 10 | +.indexArrowType <- function(f) { |
| 11 | + ParquetFileReader$create(f)$GetSchema()$GetFieldByName("__index__")$type$ToString() |
| 12 | +} |
| 13 | + |
| 14 | +test_that("index_max streams a > 2^31 index as a consistent int64 column", { |
| 15 | + dir <- tempfile() |
| 16 | + # Part 0 at offset 0, then a part whose offset crosses the 32-bit ceiling. |
| 17 | + writeParquet(data.frame(v = 1:5), dir, indexcol = "__index__", keycol = NULL, |
| 18 | + dimension = "sample", layout = "data_frame", |
| 19 | + offset = 0, part = 0L, part_digits = 2L, append = FALSE, |
| 20 | + index_max = Inf) |
| 21 | + writeParquet(data.frame(v = 11:15), dir, indexcol = "__index__", keycol = NULL, |
| 22 | + dimension = "sample", layout = "data_frame", |
| 23 | + offset = 3e9, part = 1L, part_digits = 2L, append = TRUE, |
| 24 | + index_max = Inf) |
| 25 | + |
| 26 | + files <- sort(list.files(dir, pattern = "parquet$", recursive = TRUE, |
| 27 | + full.names = TRUE)) |
| 28 | + expect_length(files, 2L) |
| 29 | + # Both parts, and the unified dataset, are int64 (schema-consistent). |
| 30 | + expect_true(all(vapply(files, .indexArrowType, character(1L)) == "int64")) |
| 31 | + ds <- open_dataset(dir) |
| 32 | + expect_identical(ds$schema$GetFieldByName("__index__")$type$ToString(), "int64") |
| 33 | + |
| 34 | + # The index values above 2^31 are stored exactly, with no overflow to NA. |
| 35 | + idx <- sort(as.data.frame(ds)[["__index__"]]) |
| 36 | + expect_false(anyNA(idx)) |
| 37 | + expect_equal(idx[6:10], |
| 38 | + c(3000000001, 3000000002, 3000000003, 3000000004, 3000000005)) |
| 39 | + unlink(dir, recursive = TRUE) |
| 40 | +}) |
| 41 | + |
| 42 | +test_that("without index_max a small index still narrows (no regression)", { |
| 43 | + dir <- tempfile() |
| 44 | + writeParquet(data.frame(v = 1:5), dir, indexcol = "__index__", keycol = NULL, |
| 45 | + dimension = "sample", layout = "data_frame") |
| 46 | + f <- list.files(dir, pattern = "parquet$", recursive = TRUE, |
| 47 | + full.names = TRUE)[1L] |
| 48 | + expect_identical(.indexArrowType(f), "uint8") |
| 49 | + unlink(dir, recursive = TRUE) |
| 50 | +}) |
0 commit comments