@@ -189,6 +189,11 @@ NULL
189189# ' the map or array of maps.
190190# ' \item \code{from_json}: it is the column containing the JSON string.
191191# ' }
192+ # ' @param value A value to compute on.
193+ # ' \itemize{
194+ # ' \item \code{array_contains}: a value to be checked if contained in the column.
195+ # ' \item \code{array_position}: a value to locate in the given array.
196+ # ' }
192197# ' @param ... additional argument(s). In \code{to_json} and \code{from_json}, this contains
193198# ' additional named properties to control how it is converted, accepts the same
194199# ' options as the JSON data source.
@@ -201,14 +206,17 @@ NULL
201206# ' df <- createDataFrame(cbind(model = rownames(mtcars), mtcars))
202207# ' tmp <- mutate(df, v1 = create_array(df$mpg, df$cyl, df$hp))
203208# ' head(select(tmp, array_contains(tmp$v1, 21), size(tmp$v1)))
209+ # ' head(select(tmp, array_max(tmp$v1), array_min(tmp$v1)))
210+ # ' head(select(tmp, array_position(tmp$v1, 21)))
204211# ' tmp2 <- mutate(tmp, v2 = explode(tmp$v1))
205212# ' head(tmp2)
206213# ' head(select(tmp, posexplode(tmp$v1)))
207214# ' head(select(tmp, sort_array(tmp$v1)))
208215# ' head(select(tmp, sort_array(tmp$v1, asc = FALSE)))
209216# ' tmp3 <- mutate(df, v3 = create_map(df$model, df$cyl))
210217# ' head(select(tmp3, map_keys(tmp3$v3)))
211- # ' head(select(tmp3, map_values(tmp3$v3)))}
218+ # ' head(select(tmp3, map_values(tmp3$v3)))
219+ # ' head(select(tmp3, element_at(tmp3$v3, "Valiant")))}
212220NULL
213221
214222# ' Window functions for Column operations
@@ -2975,7 +2983,6 @@ setMethod("row_number",
29752983# ' \code{array_contains}: Returns null if the array is null, true if the array contains
29762984# ' the value, and false otherwise.
29772985# '
2978- # ' @param value a value to be checked if contained in the column
29792986# ' @rdname column_collection_functions
29802987# ' @aliases array_contains array_contains,Column-method
29812988# ' @note array_contains since 1.6.0
@@ -2986,6 +2993,48 @@ setMethod("array_contains",
29862993 column(jc )
29872994 })
29882995
2996+ # ' @details
2997+ # ' \code{array_max}: Returns the maximum value of the array.
2998+ # '
2999+ # ' @rdname column_collection_functions
3000+ # ' @aliases array_max array_max,Column-method
3001+ # ' @note array_max since 2.4.0
3002+ setMethod ("array_max ",
3003+ signature(x = " Column" ),
3004+ function (x ) {
3005+ jc <- callJStatic(" org.apache.spark.sql.functions" , " array_max" , x @ jc )
3006+ column(jc )
3007+ })
3008+
3009+ # ' @details
3010+ # ' \code{array_min}: Returns the minimum value of the array.
3011+ # '
3012+ # ' @rdname column_collection_functions
3013+ # ' @aliases array_min array_min,Column-method
3014+ # ' @note array_min since 2.4.0
3015+ setMethod ("array_min ",
3016+ signature(x = " Column" ),
3017+ function (x ) {
3018+ jc <- callJStatic(" org.apache.spark.sql.functions" , " array_min" , x @ jc )
3019+ column(jc )
3020+ })
3021+
3022+ # ' @details
3023+ # ' \code{array_position}: Locates the position of the first occurrence of the given value
3024+ # ' in the given array. Returns NA if either of the arguments are NA.
3025+ # ' Note: The position is not zero based, but 1 based index. Returns 0 if the given
3026+ # ' value could not be found in the array.
3027+ # '
3028+ # ' @rdname column_collection_functions
3029+ # ' @aliases array_position array_position,Column-method
3030+ # ' @note array_position since 2.4.0
3031+ setMethod ("array_position ",
3032+ signature(x = " Column" , value = " ANY" ),
3033+ function (x , value ) {
3034+ jc <- callJStatic(" org.apache.spark.sql.functions" , " array_position" , x @ jc , value )
3035+ column(jc )
3036+ })
3037+
29893038# ' @details
29903039# ' \code{map_keys}: Returns an unordered array containing the keys of the map.
29913040# '
@@ -3012,6 +3061,22 @@ setMethod("map_values",
30123061 column(jc )
30133062 })
30143063
3064+ # ' @details
3065+ # ' \code{element_at}: Returns element of array at given index in \code{extraction} if
3066+ # ' \code{x} is array. Returns value for the given key in \code{extraction} if \code{x} is map.
3067+ # ' Note: The position is not zero based, but 1 based index.
3068+ # '
3069+ # ' @param extraction index to check for in array or key to check for in map
3070+ # ' @rdname column_collection_functions
3071+ # ' @aliases element_at element_at,Column-method
3072+ # ' @note element_at since 2.4.0
3073+ setMethod ("element_at ",
3074+ signature(x = " Column" , extraction = " ANY" ),
3075+ function (x , extraction ) {
3076+ jc <- callJStatic(" org.apache.spark.sql.functions" , " element_at" , x @ jc , extraction )
3077+ column(jc )
3078+ })
3079+
30153080# ' @details
30163081# ' \code{explode}: Creates a new row for each element in the given array or map column.
30173082# '
0 commit comments