Skip to content
Snippets Groups Projects
  • hyukjinkwon's avatar
    97ba4918
    [SPARK-21602][R] Add map_keys and map_values functions to R · 97ba4918
    hyukjinkwon authored
    ## What changes were proposed in this pull request?
    
    This PR adds `map_values` and `map_keys` to R API.
    
    ```r
    > df <- createDataFrame(cbind(model = rownames(mtcars), mtcars))
    > tmp <- mutate(df, v = create_map(df$model, df$cyl))
    > head(select(tmp, map_keys(tmp$v)))
    ```
    ```
            map_keys(v)
    1         Mazda RX4
    2     Mazda RX4 Wag
    3        Datsun 710
    4    Hornet 4 Drive
    5 Hornet Sportabout
    6           Valiant
    ```
    ```r
    > head(select(tmp, map_values(tmp$v)))
    ```
    ```
      map_values(v)
    1             6
    2             6
    3             4
    4             6
    5             8
    6             6
    ```
    
    ## How was this patch tested?
    
    Manual tests and unit tests in `R/pkg/tests/fulltests/test_sparkSQL.R`
    
    Author: hyukjinkwon <gurwls223@gmail.com>
    
    Closes #18809 from HyukjinKwon/map-keys-values-r.
    97ba4918
    History
    [SPARK-21602][R] Add map_keys and map_values functions to R
    hyukjinkwon authored
    ## What changes were proposed in this pull request?
    
    This PR adds `map_values` and `map_keys` to R API.
    
    ```r
    > df <- createDataFrame(cbind(model = rownames(mtcars), mtcars))
    > tmp <- mutate(df, v = create_map(df$model, df$cyl))
    > head(select(tmp, map_keys(tmp$v)))
    ```
    ```
            map_keys(v)
    1         Mazda RX4
    2     Mazda RX4 Wag
    3        Datsun 710
    4    Hornet 4 Drive
    5 Hornet Sportabout
    6           Valiant
    ```
    ```r
    > head(select(tmp, map_values(tmp$v)))
    ```
    ```
      map_values(v)
    1             6
    2             6
    3             4
    4             6
    5             8
    6             6
    ```
    
    ## How was this patch tested?
    
    Manual tests and unit tests in `R/pkg/tests/fulltests/test_sparkSQL.R`
    
    Author: hyukjinkwon <gurwls223@gmail.com>
    
    Closes #18809 from HyukjinKwon/map-keys-values-r.
NAMESPACE 12.25 KiB