nealrichardson commented on a change in pull request #9950:
URL: https://github.com/apache/arrow/pull/9950#discussion_r611805539



##########
File path: r/R/json.R
##########
@@ -20,6 +20,8 @@
 #' Using [JsonTableReader]
 #'
 #' @inheritParams read_delim_arrow
+#' @param schema [Schema] that describes the table.  If provided, it will be
+#' used to satisfy both `col_names` and `col_types`.

Review comment:
       If this were the right docs to include here, you wouldn't need to add 
them--`@inheritParams read_delim_arrow` would pull it in for you. But since 
there are no `col_names` and `col_types` arguments to this function, we should 
specify something different (which will override what inheritParams brings in).
   
   ```suggestion
   #' @param schema [Schema] that describes the column names and data types in 
the table.
   ```

##########
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:
       This was just for debugging right?
   
   ```suggestion
   ```




-- 
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]


Reply via email to