[ 
https://issues.apache.org/jira/browse/ARROW-18102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17621425#comment-17621425
 ] 

Weston Pace commented on ARROW-18102:
-------------------------------------

Supposedly both behaviors are useful (returning null is SQL standards 
compliant.  See 
https://database.guide/sqlite-sum-vs-total-whats-the-difference/).  I think we 
could add an option to the sum function.  See also: 
https://github.com/substrait-io/substrait/issues/259 so I expect we will 
eventually need both behaviors.

> [R] dplyr::count and dplyr::tally implementation return NA instead of 0
> -----------------------------------------------------------------------
>
>                 Key: ARROW-18102
>                 URL: https://issues.apache.org/jira/browse/ARROW-18102
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: R
>         Environment: Arrow R package 9.0.0 on Mac OS 12.6 with R 4.2.0
>            Reporter: Adam Black
>            Priority: Major
>
> I'm using dplyr with FileSystemDataset objects. The expected behavior is 
> similar (or the same as) dataframe behavior. When the FileSystemDataset has 
> zero rows dplyr::count and dplyr::tally return NA instead of 0. I would 
> expect the result to be 0.
>  
> {code:r}
> library(arrow)
> #> 
> #> Attaching package: 'arrow'
> #> The following object is masked from 'package:utils':
> #> 
> #>     timestamp
> library(dplyr)
> #> 
> #> Attaching package: 'dplyr'
> #> The following objects are masked from 'package:stats':
> #> 
> #>     filter, lag
> #> The following objects are masked from 'package:base':
> #> 
> #>     intersect, setdiff, setequal, union
> path <- tempfile(fileext = ".feather")
> zero_row_dataset <- cars %>% filter(dist < 0)
> # expected behavior
> zero_row_dataset %>% 
>   count()
> #>   n
> #> 1 0
> zero_row_dataset %>% 
>   tally()
> #>   n
> #> 1 0
> nrow(zero_row_dataset)
> #> [1] 0
> # now test behavior with a FileSystemDataset
> write_feather(zero_row_dataset, path)
> ds <- open_dataset(path, format = "feather")
> ds
> #> FileSystemDataset with 1 Feather file
> #> speed: double
> #> dist: double
> #> 
> #> See $metadata for additional Schema metadata
> # actual behavior
> ds %>% 
>   count() %>% 
>   collect() # incorrect result
> #> # A tibble: 1 × 1
> #>       n
> #>   <int>
> #> 1    NA
> ds %>% 
>   tally() %>% 
>   collect() # incorrect result
> #> # A tibble: 1 × 1
> #>       n
> #>   <int>
> #> 1    NA
> nrow(ds) # works as expected
> #> [1] 0
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to