From 129fe3754bc7a80c9ae4d48096d9fbab44db21a2 Mon Sep 17 00:00:00 2001 From: ahmad Date: Thu, 13 Aug 2026 08:08:20 +0300 Subject: [PATCH 1/3] Document preserving leading zeros in partitions Signed-off-by: ahmad --- r/vignettes/dataset.Rmd | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/r/vignettes/dataset.Rmd b/r/vignettes/dataset.Rmd index 36e75963f89a..71af5ed5ede2 100644 --- a/r/vignettes/dataset.Rmd +++ b/r/vignettes/dataset.Rmd @@ -104,6 +104,17 @@ ds <- open_dataset("nyc-taxi", partitioning = c("year", "month")) Either way, when you look at the Dataset, you can see that in addition to the columns present in every file, there are also columns `year` and `month`. These columns are not present in the files themselves: they are inferred from the partitioning structure. +If a partition value contains meaningful leading zeros, specify its type explicitly. Otherwise, type inference may interpret a value such as `001` as the integer `1`. For example, use a string field when opening a Hive-partitioned dataset whose `product_id` values include leading zeros: + +```r +ds <- open_dataset( + "products", + partitioning = hive_partition(product_id = string()) +) +``` + +With this schema, a path such as `product_id=001/part-0.parquet` keeps `product_id` as the string `"001"` instead of converting it to `1`. + ```{r, eval = file.exists("nyc-taxi")} ds ``` From 1ea21e05ca4b1f01f994f31c7b816cbfc4b4fc6f Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Thu, 10 Sep 2026 20:59:43 +0300 Subject: [PATCH 2/3] GH-39660: [R] Document partition value types Signed-off-by: ahmadalguydi --- r/R/dataset.R | 15 +++++++++++++++ r/vignettes/dataset.Rmd | 11 ----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/r/R/dataset.R b/r/R/dataset.R index 4ccf338d267e..112e81e0d81e 100644 --- a/r/R/dataset.R +++ b/r/R/dataset.R @@ -57,6 +57,21 @@ #' you could provide a Schema to specify that "month" should be `int8()` #' instead of the `int32()` it will be parsed as by default. #' +#' If a partition value contains meaningful leading zeros, specify its type +#' explicitly. Otherwise, type inference may interpret a value such as `001` +#' as the integer `1`. For example, use a string field when opening a +#' Hive-partitioned dataset whose `product_id` values include leading zeros: +#' +#' ```r +#' ds <- open_dataset( +#' "products", +#' partitioning = hive_partition(product_id = string()) +#' ) +#' ``` +#' +#' With this schema, a path such as `product_id=001/part-0.parquet` keeps +#' `product_id` as the string `"001"` instead of converting it to `1`. +#' #' If your file paths do not appear to be Hive-style, or if you pass #' `hive_style = FALSE`, the `partitioning` argument will be used to create #' Directory partitioning. A character vector of names is required to create diff --git a/r/vignettes/dataset.Rmd b/r/vignettes/dataset.Rmd index 71af5ed5ede2..36e75963f89a 100644 --- a/r/vignettes/dataset.Rmd +++ b/r/vignettes/dataset.Rmd @@ -104,17 +104,6 @@ ds <- open_dataset("nyc-taxi", partitioning = c("year", "month")) Either way, when you look at the Dataset, you can see that in addition to the columns present in every file, there are also columns `year` and `month`. These columns are not present in the files themselves: they are inferred from the partitioning structure. -If a partition value contains meaningful leading zeros, specify its type explicitly. Otherwise, type inference may interpret a value such as `001` as the integer `1`. For example, use a string field when opening a Hive-partitioned dataset whose `product_id` values include leading zeros: - -```r -ds <- open_dataset( - "products", - partitioning = hive_partition(product_id = string()) -) -``` - -With this schema, a path such as `product_id=001/part-0.parquet` keeps `product_id` as the string `"001"` instead of converting it to `1`. - ```{r, eval = file.exists("nyc-taxi")} ds ``` From 04ba3e975ae12b8311444522a32e051792c0d2c0 Mon Sep 17 00:00:00 2001 From: ahmadalguydi Date: Thu, 10 Sep 2026 21:52:50 +0300 Subject: [PATCH 3/3] GH-39660: refine partitioning example --- r/R/dataset.R | 24 ++++++++++++------------ r/man/open_dataset.Rd | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/r/R/dataset.R b/r/R/dataset.R index 112e81e0d81e..4ebdaee6cfb3 100644 --- a/r/R/dataset.R +++ b/r/R/dataset.R @@ -59,18 +59,8 @@ #' #' If a partition value contains meaningful leading zeros, specify its type #' explicitly. Otherwise, type inference may interpret a value such as `001` -#' as the integer `1`. For example, use a string field when opening a -#' Hive-partitioned dataset whose `product_id` values include leading zeros: -#' -#' ```r -#' ds <- open_dataset( -#' "products", -#' partitioning = hive_partition(product_id = string()) -#' ) -#' ``` -#' -#' With this schema, a path such as `product_id=001/part-0.parquet` keeps -#' `product_id` as the string `"001"` instead of converting it to `1`. +#' as the integer `1`. See the examples below for a runnable Hive-partitioned +#' dataset whose `product_id` values include leading zeros. #' #' If your file paths do not appear to be Hive-style, or if you pass #' `hive_style = FALSE`, the `partitioning` argument will be used to create @@ -186,6 +176,16 @@ #' #' # If you want to specify the data types for your fields, you can pass in a Schema #' open_dataset(tf3, partitioning = schema(Month = int8(), Day = int8())) +#' +#' # If a partition value contains meaningful leading zeros, specify its type +#' # explicitly so values such as "001" remain strings instead of becoming 1. +#' products <- data.frame(x = 1:3, product_id = c("001", "002", "010")) +#' tf4 <- tempfile() +#' write_dataset(products, tf4, partitioning = "product_id") +#' ds <- open_dataset( +#' tf4, +#' partitioning = hive_partition(product_id = string()) +#' ) open_dataset <- function( sources, schema = NULL, diff --git a/r/man/open_dataset.Rd b/r/man/open_dataset.Rd index e2707212d035..73224a22c61a 100644 --- a/r/man/open_dataset.Rd +++ b/r/man/open_dataset.Rd @@ -153,6 +153,11 @@ it will use the types defined by the Schema. In the example file path above, you could provide a Schema to specify that "month" should be \code{int8()} instead of the \code{int32()} it will be parsed as by default. +If a partition value contains meaningful leading zeros, specify its type +explicitly. Otherwise, type inference may interpret a value such as \code{001} +as the integer \code{1}. See the examples below for a runnable Hive-partitioned +dataset whose \code{product_id} values include leading zeros. + If your file paths do not appear to be Hive-style, or if you pass \code{hive_style = FALSE}, the \code{partitioning} argument will be used to create Directory partitioning. A character vector of names is required to create @@ -206,6 +211,16 @@ open_dataset(tf3, partitioning = c("Month", "Day")) # If you want to specify the data types for your fields, you can pass in a Schema open_dataset(tf3, partitioning = schema(Month = int8(), Day = int8())) + +# If a partition value contains meaningful leading zeros, specify its type +# explicitly so values such as "001" remain strings instead of becoming 1. +products <- data.frame(x = 1:3, product_id = c("001", "002", "010")) +tf4 <- tempfile() +write_dataset(products, tf4, partitioning = "product_id") +ds <- open_dataset( + tf4, + partitioning = hive_partition(product_id = string()) +) \dontshow{\}) # examplesIf} } \seealso{