189189# ' the map or array of maps.
190190# ' \item \code{from_json}: it is the column containing the JSON string.
191191# ' }
192+ # ' @param y Column to compute on.
192193# ' @param value A value to compute on.
193194# ' \itemize{
194195# ' \item \code{array_contains}: a value to be checked if contained in the column.
@@ -207,18 +208,20 @@ NULL
207208# ' tmp <- mutate(df, v1 = create_array(df$mpg, df$cyl, df$hp))
208209# ' head(select(tmp, array_contains(tmp$v1, 21), size(tmp$v1)))
209210# ' head(select(tmp, array_max(tmp$v1), array_min(tmp$v1)))
210- # ' head(select(tmp, array_position(tmp$v1, 21), array_sort(tmp$v1)))
211- # ' head(select(tmp, flatten(tmp$v1)))
211+ # ' head(select(tmp, array_position(tmp$v1, 21), array_repeat(df$mpg, 3), array_sort(tmp$v1)))
212+ # ' head(select(tmp, flatten(tmp$v1), reverse(tmp$v1) ))
212213# ' tmp2 <- mutate(tmp, v2 = explode(tmp$v1))
213214# ' head(tmp2)
214215# ' head(select(tmp, posexplode(tmp$v1)))
215216# ' head(select(tmp, slice(tmp$v1, 2L, 2L)))
216217# ' head(select(tmp, sort_array(tmp$v1)))
217218# ' head(select(tmp, sort_array(tmp$v1, asc = FALSE)))
218219# ' tmp3 <- mutate(df, v3 = create_map(df$model, df$cyl))
219- # ' head(select(tmp3, map_keys(tmp3$v3)))
220- # ' head(select(tmp3, map_values(tmp3$v3)))
221- # ' head(select(tmp3, element_at(tmp3$v3, "Valiant")))}
220+ # ' head(select(tmp3, map_entries(tmp3$v3), map_keys(tmp3$v3), map_values(tmp3$v3)))
221+ # ' head(select(tmp3, element_at(tmp3$v3, "Valiant")))
222+ # ' tmp4 <- mutate(df, v4 = create_array(df$mpg, df$cyl), v5 = create_array(df$cyl, df$hp))
223+ # ' head(select(tmp4, concat(tmp4$v4, tmp4$v5), arrays_overlap(tmp4$v4, tmp4$v5)))
224+ # ' head(select(tmp, concat(df$mpg, df$cyl, df$hp)))}
222225NULL
223226
224227# ' Window functions for Column operations
@@ -1260,9 +1263,9 @@ setMethod("quarter",
12601263 })
12611264
12621265# ' @details
1263- # ' \code{reverse}: Reverses the string column and returns it as a new string column .
1266+ # ' \code{reverse}: Returns a reversed string or an array with reverse order of elements .
12641267# '
1265- # ' @rdname column_string_functions
1268+ # ' @rdname column_collection_functions
12661269# ' @aliases reverse reverse,Column-method
12671270# ' @note reverse since 1.5.0
12681271setMethod ("reverse ",
@@ -2055,20 +2058,10 @@ setMethod("countDistinct",
20552058
20562059# ' @details
20572060# ' \code{concat}: Concatenates multiple input columns together into a single column.
2058- # ' If all inputs are binary, concat returns an output as binary. Otherwise, it returns as string .
2061+ # ' The function works with strings, binary and compatible array columns .
20592062# '
2060- # ' @rdname column_string_functions
2063+ # ' @rdname column_collection_functions
20612064# ' @aliases concat concat,Column-method
2062- # ' @examples
2063- # '
2064- # ' \dontrun{
2065- # ' # concatenate strings
2066- # ' tmp <- mutate(df, s1 = concat(df$Class, df$Sex),
2067- # ' s2 = concat(df$Class, df$Sex, df$Age),
2068- # ' s3 = concat(df$Class, df$Sex, df$Age, df$Class),
2069- # ' s4 = concat_ws("_", df$Class, df$Sex),
2070- # ' s5 = concat_ws("+", df$Class, df$Sex, df$Age, df$Survived))
2071- # ' head(tmp)}
20722065# ' @note concat since 1.5.0
20732066setMethod ("concat ",
20742067 signature(x = " Column" ),
@@ -2409,6 +2402,13 @@ setMethod("shiftRightUnsigned", signature(y = "Column", x = "numeric"),
24092402# ' @param sep separator to use.
24102403# ' @rdname column_string_functions
24112404# ' @aliases concat_ws concat_ws,character,Column-method
2405+ # ' @examples
2406+ # '
2407+ # ' \dontrun{
2408+ # ' # concatenate strings
2409+ # ' tmp <- mutate(df, s1 = concat_ws("_", df$Class, df$Sex),
2410+ # ' s2 = concat_ws("+", df$Class, df$Sex, df$Age, df$Survived))
2411+ # ' head(tmp)}
24122412# ' @note concat_ws since 1.5.0
24132413setMethod ("concat_ws ", signature(sep = "character", x = "Column"),
24142414 function (sep , x , ... ) {
@@ -3048,6 +3048,26 @@ setMethod("array_position",
30483048 column(jc )
30493049 })
30503050
3051+ # ' @details
3052+ # ' \code{array_repeat}: Creates an array containing \code{x} repeated the number of times
3053+ # ' given by \code{count}.
3054+ # '
3055+ # ' @param count a Column or constant determining the number of repetitions.
3056+ # ' @rdname column_collection_functions
3057+ # ' @aliases array_repeat array_repeat,Column,numericOrColumn-method
3058+ # ' @note array_repeat since 2.4.0
3059+ setMethod ("array_repeat ",
3060+ signature(x = " Column" , count = " numericOrColumn" ),
3061+ function (x , count ) {
3062+ if (class(count ) == " Column" ) {
3063+ count <- count @ jc
3064+ } else {
3065+ count <- as.integer(count )
3066+ }
3067+ jc <- callJStatic(" org.apache.spark.sql.functions" , " array_repeat" , x @ jc , count )
3068+ column(jc )
3069+ })
3070+
30513071# ' @details
30523072# ' \code{array_sort}: Sorts the input array in ascending order. The elements of the input array
30533073# ' must be orderable. NA elements will be placed at the end of the returned array.
@@ -3063,7 +3083,23 @@ setMethod("array_sort",
30633083 })
30643084
30653085# ' @details
3066- # ' \code{flatten}: Transforms an array of arrays into a single array.
3086+ # ' \code{arrays_overlap}: Returns true if the input arrays have at least one non-null element in
3087+ # ' common. If not and both arrays are non-empty and any of them contains a null, it returns null.
3088+ # ' It returns false otherwise.
3089+ # '
3090+ # ' @rdname column_collection_functions
3091+ # ' @aliases arrays_overlap arrays_overlap,Column-method
3092+ # ' @note arrays_overlap since 2.4.0
3093+ setMethod ("arrays_overlap ",
3094+ signature(x = " Column" , y = " Column" ),
3095+ function (x , y ) {
3096+ jc <- callJStatic(" org.apache.spark.sql.functions" , " arrays_overlap" , x @ jc , y @ jc )
3097+ column(jc )
3098+ })
3099+
3100+ # ' @details
3101+ # ' \code{flatten}: Creates a single array from an array of arrays.
3102+ # ' If a structure of nested arrays is deeper than two levels, only one level of nesting is removed.
30673103# '
30683104# ' @rdname column_collection_functions
30693105# ' @aliases flatten flatten,Column-method
@@ -3075,6 +3111,19 @@ setMethod("flatten",
30753111 column(jc )
30763112 })
30773113
3114+ # ' @details
3115+ # ' \code{map_entries}: Returns an unordered array of all entries in the given map.
3116+ # '
3117+ # ' @rdname column_collection_functions
3118+ # ' @aliases map_entries map_entries,Column-method
3119+ # ' @note map_entries since 2.4.0
3120+ setMethod ("map_entries ",
3121+ signature(x = " Column" ),
3122+ function (x ) {
3123+ jc <- callJStatic(" org.apache.spark.sql.functions" , " map_entries" , x @ jc )
3124+ column(jc )
3125+ })
3126+
30783127# ' @details
30793128# ' \code{map_keys}: Returns an unordered array containing the keys of the map.
30803129# '
0 commit comments