80
80
# ' \item \code{from_utc_timestamp}, \code{to_utc_timestamp}: time zone to use.
81
81
# ' \item \code{next_day}: day of the week string.
82
82
# ' }
83
+ # ' @param ... additional argument(s).
84
+ # ' \itemize{
85
+ # ' \item \code{months_between}, this contains an optional parameter to specify the
86
+ # ' the result is rounded off to 8 digits.
87
+ # ' }
83
88
# '
84
89
# ' @name column_datetime_diff_functions
85
90
# ' @rdname column_datetime_diff_functions
217
222
# ' additional named properties to control how it is converted and accepts the
218
223
# ' same options as the CSV data source.
219
224
# ' \item \code{arrays_zip}, this contains additional Columns of arrays to be merged.
225
+ # ' \item \code{map_concat}, this contains additional Columns of maps to be unioned.
220
226
# ' }
221
227
# ' @name column_collection_functions
222
228
# ' @rdname column_collection_functions
229
235
# ' head(select(tmp, array_contains(tmp$v1, 21), size(tmp$v1), shuffle(tmp$v1)))
230
236
# ' head(select(tmp, array_max(tmp$v1), array_min(tmp$v1), array_distinct(tmp$v1)))
231
237
# ' head(select(tmp, array_position(tmp$v1, 21), array_repeat(df$mpg, 3), array_sort(tmp$v1)))
232
- # ' head(select(tmp, flatten(tmp$v1), reverse(tmp$v1), array_remove(tmp$v1, 21)))
238
+ # ' head(select(tmp, reverse(tmp$v1), array_remove(tmp$v1, 21)))
233
239
# ' tmp2 <- mutate(tmp, v2 = explode(tmp$v1))
234
240
# ' head(tmp2)
235
241
# ' head(select(tmp, posexplode(tmp$v1)))
@@ -238,15 +244,21 @@ NULL
238
244
# ' head(select(tmp, sort_array(tmp$v1, asc = FALSE)))
239
245
# ' tmp3 <- mutate(df, v3 = create_map(df$model, df$cyl))
240
246
# ' head(select(tmp3, map_entries(tmp3$v3), map_keys(tmp3$v3), map_values(tmp3$v3)))
241
- # ' head(select(tmp3, element_at(tmp3$v3, "Valiant")))
247
+ # ' head(select(tmp3, element_at(tmp3$v3, "Valiant"), map_concat(tmp3$v3, tmp3$v3) ))
242
248
# ' tmp4 <- mutate(df, v4 = create_array(df$mpg, df$cyl), v5 = create_array(df$cyl, df$hp))
243
249
# ' head(select(tmp4, concat(tmp4$v4, tmp4$v5), arrays_overlap(tmp4$v4, tmp4$v5)))
244
250
# ' head(select(tmp4, array_except(tmp4$v4, tmp4$v5), array_intersect(tmp4$v4, tmp4$v5)))
245
251
# ' head(select(tmp4, array_union(tmp4$v4, tmp4$v5)))
246
- # ' head(select(tmp4, arrays_zip(tmp4$v4, tmp4$v5), map_from_arrays(tmp4$v4, tmp4$v5) ))
252
+ # ' head(select(tmp4, arrays_zip(tmp4$v4, tmp4$v5)))
247
253
# ' head(select(tmp, concat(df$mpg, df$cyl, df$hp)))
248
254
# ' tmp5 <- mutate(df, v6 = create_array(df$model, df$model))
249
- # ' head(select(tmp5, array_join(tmp5$v6, "#"), array_join(tmp5$v6, "#", "NULL")))}
255
+ # ' head(select(tmp5, array_join(tmp5$v6, "#"), array_join(tmp5$v6, "#", "NULL")))
256
+ # ' tmp6 <- mutate(df, v7 = create_array(create_array(df$model, df$model)))
257
+ # ' head(select(tmp6, flatten(tmp6$v7)))
258
+ # ' tmp7 <- mutate(df, v8 = create_array(df$model, df$cyl), v9 = create_array(df$model, df$hp))
259
+ # ' head(select(tmp7, map_from_arrays(tmp7$v8, tmp7$v9)))
260
+ # ' tmp8 <- mutate(df, v10 = create_array(struct(df$model, df$cyl)))
261
+ # ' head(select(tmp8, map_from_entries(tmp8$v10)))}
250
262
NULL
251
263
252
264
# ' Window functions for Column operations
@@ -2074,15 +2086,21 @@ setMethod("levenshtein", signature(y = "Column"),
2074
2086
# ' are on the same day of month, or both are the last day of month, time of day will be ignored.
2075
2087
# ' Otherwise, the difference is calculated based on 31 days per month, and rounded to 8 digits.
2076
2088
# '
2089
+ # ' @param roundOff an optional parameter to specify if the result is rounded off to 8 digits
2077
2090
# ' @rdname column_datetime_diff_functions
2078
2091
# ' @aliases months_between months_between,Column-method
2079
2092
# ' @note months_between since 1.5.0
2080
2093
setMethod ("months_between ", signature(y = "Column"),
2081
- function (y , x ) {
2094
+ function (y , x , roundOff = NULL ) {
2082
2095
if (class(x ) == " Column" ) {
2083
2096
x <- x @ jc
2084
2097
}
2085
- jc <- callJStatic(" org.apache.spark.sql.functions" , " months_between" , y @ jc , x )
2098
+ jc <- if (is.null(roundOff )) {
2099
+ callJStatic(" org.apache.spark.sql.functions" , " months_between" , y @ jc , x )
2100
+ } else {
2101
+ callJStatic(" org.apache.spark.sql.functions" , " months_between" , y @ jc , x ,
2102
+ as.logical(roundOff ))
2103
+ }
2086
2104
column(jc )
2087
2105
})
2088
2106
@@ -3448,6 +3466,23 @@ setMethod("flatten",
3448
3466
column(jc )
3449
3467
})
3450
3468
3469
+ # ' @details
3470
+ # ' \code{map_concat}: Returns the union of all the given maps.
3471
+ # '
3472
+ # ' @rdname column_collection_functions
3473
+ # ' @aliases map_concat map_concat,Column-method
3474
+ # ' @note map_concat since 3.0.0
3475
+ setMethod ("map_concat ",
3476
+ signature(x = " Column" ),
3477
+ function (x , ... ) {
3478
+ jcols <- lapply(list (x , ... ), function (arg ) {
3479
+ stopifnot(class(arg ) == " Column" )
3480
+ arg @ jc
3481
+ })
3482
+ jc <- callJStatic(" org.apache.spark.sql.functions" , " map_concat" , jcols )
3483
+ column(jc )
3484
+ })
3485
+
3451
3486
# ' @details
3452
3487
# ' \code{map_entries}: Returns an unordered array of all entries in the given map.
3453
3488
# '
@@ -3476,6 +3511,19 @@ setMethod("map_from_arrays",
3476
3511
column(jc )
3477
3512
})
3478
3513
3514
+ # ' @details
3515
+ # ' \code{map_from_entries}: Returns a map created from the given array of entries.
3516
+ # '
3517
+ # ' @rdname column_collection_functions
3518
+ # ' @aliases map_from_entries map_from_entries,Column-method
3519
+ # ' @note map_from_entries since 3.0.0
3520
+ setMethod ("map_from_entries ",
3521
+ signature(x = " Column" ),
3522
+ function (x ) {
3523
+ jc <- callJStatic(" org.apache.spark.sql.functions" , " map_from_entries" , x @ jc )
3524
+ column(jc )
3525
+ })
3526
+
3479
3527
# ' @details
3480
3528
# ' \code{map_keys}: Returns an unordered array containing the keys of the map.
3481
3529
# '
0 commit comments