nealrichardson commented on a change in pull request #9950:
URL: https://github.com/apache/arrow/pull/9950#discussion_r611857473
##########
File path: r/tests/testthat/test-json.R
##########
@@ -86,6 +86,89 @@ test_that("read_json_arrow() supports col_select=", {
expect_equal(names(tab2), c("hello", "world"))
})
+test_that("read_json_arrow(schema=) with empty schema", {
+ tf <- tempfile()
+ writeLines('
+ { "hello": 3.5, "world": 2, "third_col": 99}
+ { "hello": 3.25, "world": 5, "third_col": 98}
+ { "hello": 3.125, "world": 8, "third_col": 97 }
+ { "hello": 0.0, "world": 10, "third_col": 96}
+ ', tf)
+
+ tab1 <- read_json_arrow(tf, schema = schema())
+
+ expect_identical(
+ tab1,
+ tibble::tibble(
+ hello = c(3.5, 3.25, 3.125, 0),
+ world = c(2L, 5L, 8L, 10L),
+ third_col = c(99L,98L,97L,96L)
+ )
+ )
+})
+
+test_that("read_json_arrow(schema=) with partial schema", {
+ tf <- tempfile()
+ writeLines('
+ { "hello": 3.5, "world": 2, "third_col": 99}
+ { "hello": 3.25, "world": 5, "third_col": 98}
+ { "hello": 3.125, "world": 8, "third_col": 97 }
+ { "hello": 0.0, "world": 10, "third_col": 96}
+ ', tf)
+
+ tab1 <- read_json_arrow(tf, schema = schema(third_col = float64(), world =
float64()))
+
+ print("input:")
+ print("schema:")
+ print(schema(third_col = float64(), world = float64()))
+ print('
+ { "hello": 3.5, "world": 2, "third_col": 99}
+ { "hello": 3.25, "world": 5, "third_col": 98}
+ { "hello": 3.125, "world": 8, "third_col": 97 }
+ { "hello": 0.0, "world": 10, "third_col": 96}
+ ')
+ print("output:")
+ print(tab1)
+
Review comment:
It wasn't the first thing I would expect but (1) IIUC in JSON the `{}`
is not ordered, so it's not surprising that providing a schema would mean that
the order comes from the schema; and (2) from the perspective of this PR, it
doesn't matter much I don't think because you're just adding R bindings to a
feature in the C++ library--if we think the C++ library is suboptimal we can
open a new JIRA for that, but seems out of scope here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]