Latu.Functions (latu v0.1.0)

Copy Markdown View Source

Spark's function library.

alias Latu.Functions, as: F

df
|> Latu.group_by(:suburb)
|> Latu.agg(avg: F.avg(:price), sold: F.count_distinct(:id))
|> Latu.select([:suburb, :sold, rounded: F.round(:avg, 2)])

Alias this module; it cannot be imported. Spark's names are kept exactly, and quote/1 is one of them — a special form, which Elixir refuses to import over. Nine more (abs, ceil, floor, length, max, min, round, struct, trunc) collide with Kernel's auto-imports. A qualified call is always unambiguous, so under F. none of it costs anything, and F.abs(:x) is PySpark's own F.abs(...) idiom.

That is the opposite of Latu.Column, which is import-first — twelve operators, no collisions. The renames there (divide not div, not_ not not) were forced by import; do not generalise them to this module.

Argument conventions

Arguments go through Latu.Plan.to_expr/1: an atom is a column, anything else is a literal.

A variadic Spark function takes a list here, so it composes with Enum:

F.coalesce([:a, :b, 0])

A function with an optional trailing argument is two clauses rather than a default, because Spark distinguishes "absent" from "present with a default value" — F.round(:x) sends one argument and F.round(:x, 2) sends two.

Coverage

Rows are derived from pyspark/sql/connect/functions/builtin.py by dev/extract_functions.py, never typed by hand; it writes Latu.Functions.Registry, which is checked in. Most functions have one of five uniform shapes and are generated from a row; the rest are hand-written, and the script names every one of them. Several rows generate two arities, which is why ~500 functions make ~670 name/arity pairs.

The higher-order functions are all hand-written: a lambda is an ordinary argument, but their arities and optional lambdas vary too much for a row. Latu.Plan.higher_order/3 is the builder they share.

For a function with no wrapper yet, Latu.Column.fun/3 is the escape hatch:

fun("soundex", [:name])

Summary

Aggregate Functions

Spark's any_value. The trailing argument is optional.

Spark's any_value. With the optional trailing argument.

Spark's approx_count_distinct. The trailing argument is optional.

Spark's approx_count_distinct. With the optional trailing argument.

Spark's approx_percentile. Sends Spark's defaults for the rest: 10000.

Spark's approx_percentile. Every argument is sent.

Spark's array_agg.

Spark's avg.

Spark's bit_and.

Spark's bit_or.

Spark's bit_xor.

Spark's bitmap_and_agg.

Spark's bitmap_construct_agg.

Spark's bitmap_or_agg.

Spark's bool_and.

Spark's bool_or.

Spark's collect_list.

Spark's collect_set.

Spark's corr.

Spark's count.

Spark's count. Over distinct values: count with is_distinct set.

Spark's count. Over distinct values, across several arguments.

Spark's count_if.

Spark's count_min_sketch. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's count_min_sketch. With an explicit seed, so the plan is reproducible.

Spark's covar_pop.

Spark's covar_samp.

Spark's every.

Spark's first. Sends Spark's defaults for the rest: false.

Spark's first. Every argument is sent.

Spark's first_value. The trailing argument is optional.

Spark's first_value. With the optional trailing argument.

Spark's grouping.

Spark's grouping_id. Variadic in Spark; takes a list here.

Spark's histogram_numeric.

Spark's hll_sketch_agg. The trailing argument is optional.

Spark's hll_sketch_agg. With the optional trailing argument.

Spark's hll_union_agg. The trailing argument is optional.

Spark's hll_union_agg. With the optional trailing argument.

Spark's kll_merge_agg_bigint. The trailing argument is optional.

Spark's kll_merge_agg_bigint. With the optional trailing argument.

Spark's kll_merge_agg_double. The trailing argument is optional.

Spark's kll_merge_agg_double. With the optional trailing argument.

Spark's kll_merge_agg_float. The trailing argument is optional.

Spark's kll_merge_agg_float. With the optional trailing argument.

Spark's kll_sketch_agg_bigint. The trailing argument is optional.

Spark's kll_sketch_agg_bigint. With the optional trailing argument.

Spark's kll_sketch_agg_double. The trailing argument is optional.

Spark's kll_sketch_agg_double. With the optional trailing argument.

Spark's kll_sketch_agg_float. The trailing argument is optional.

Spark's kll_sketch_agg_float. With the optional trailing argument.

Spark's kurtosis.

Spark's last. Sends Spark's defaults for the rest: false.

Spark's last. Every argument is sent.

Spark's last_value. The trailing argument is optional.

Spark's last_value. With the optional trailing argument.

Spark's listagg. The trailing argument is optional.

Spark's listagg. With the optional trailing argument.

Spark's listagg. Over distinct values, with an optional delimiter.

Spark's listagg. Over distinct values, with the delimiter given.

Spark's max.

Spark's max_by. The trailing argument is optional.

Spark's max_by. With the optional trailing argument.

The average. Spark's own name for it on the wire is avg, which is what this sends.

Spark's median.

Spark's min.

Spark's min_by. The trailing argument is optional.

Spark's min_by. With the optional trailing argument.

Spark's mode. Sends Spark's defaults for the rest: false.

Spark's mode. Every argument is sent.

Spark's percentile. Sends Spark's defaults for the rest: 1.

Spark's percentile. Every argument is sent.

Spark's percentile_approx. Sends Spark's defaults for the rest: 10000.

Spark's percentile_approx. Every argument is sent.

Spark's product.

Spark's regr_avgx.

Spark's regr_avgy.

Spark's regr_count.

Spark's regr_intercept.

Spark's regr_r2.

Spark's regr_slope.

Spark's regr_sxx.

Spark's regr_sxy.

Spark's regr_syy.

Spark's skewness.

Spark's some.

Spark's std.

Spark's stddev.

Spark's stddev_pop.

Spark's stddev_samp.

Spark's string_agg. The trailing argument is optional.

Spark's string_agg. With the optional trailing argument.

Spark's string_agg. Over distinct values, with an optional delimiter.

Spark's string_agg. Over distinct values, with the delimiter given.

Spark's sum.

Spark's sum. Over distinct values: sum with is_distinct set.

Spark's theta_intersection_agg.

Spark's theta_sketch_agg. The trailing argument is optional.

Spark's theta_sketch_agg. With the optional trailing argument.

Spark's theta_union_agg. The trailing argument is optional.

Spark's theta_union_agg. With the optional trailing argument.

Spark's try_avg.

Spark's try_sum.

Spark's tuple_intersection_agg_double. The trailing argument is optional.

Spark's tuple_intersection_agg_double. With the optional trailing argument.

Spark's tuple_intersection_agg_integer. The trailing argument is optional.

Spark's tuple_intersection_agg_integer. With the optional trailing argument.

Spark's tuple_sketch_agg_double. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_sketch_agg_double. Sends Spark's defaults for the rest: "sum".

Spark's tuple_sketch_agg_double. Every argument is sent.

Spark's tuple_sketch_agg_integer. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_sketch_agg_integer. Sends Spark's defaults for the rest: "sum".

Spark's tuple_sketch_agg_integer. Every argument is sent.

Spark's tuple_union_agg_double. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_agg_double. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_agg_double. Every argument is sent.

Spark's tuple_union_agg_integer. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_agg_integer. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_agg_integer. Every argument is sent.

Spark's var_pop.

Spark's var_samp.

Spark's variance.

Array Functions

Spark's array. Variadic in Spark; takes a list here.

Spark's array_append.

Spark's array_compact.

Spark's array_contains.

Spark's array_distinct.

Spark's array_except.

Spark's array_insert.

Spark's array_intersect.

Spark's array_join. The trailing argument is optional.

Spark's array_join. With the optional trailing argument.

Spark's array_max.

Spark's array_min.

Spark's array_position.

Spark's array_prepend.

Spark's array_remove.

Spark's array_repeat.

Spark's array_size.

Spark's array_union.

Spark's arrays_overlap.

Spark's arrays_zip. Variadic in Spark; takes a list here.

Spark's flatten.

Spark's get.

Spark's sequence. The trailing argument is optional.

Spark's sequence. With the optional trailing argument.

Spark's shuffle. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's shuffle. With an explicit seed, so the plan is reproducible.

Spark's slice.

Spark's sort_array. Sends Spark's defaults for the rest: true.

Spark's sort_array. Every argument is sent.

Bitwise Functions

Spark's bit_count.

Spark's bit_get.

Spark's ~.

Spark's getbit.

Spark's shiftleft.

Spark's shiftright.

Spark's shiftrightunsigned.

Collection Functions

Fold an array, left to right.

aggregate/3 with the finishing lambda, which Spark applies to the result.

Sort an array, optionally by a comparator returning a negative, zero or positive number.

Sort by a comparator of two elements, rather than by Spark's natural order.

Spark's cardinality.

Spark's concat. Variadic in Spark; takes a list here.

Spark's element_at.

Spark's exists. Takes a lambda — fn x -> ... end.

Spark's filter. Takes a lambda — fn x -> ... end.

Spark's forall. Takes a lambda — fn x -> ... end.

Spark's map_filter. Takes a lambda — fn x -> ... end.

Spark's map_zip_with. Takes two columns and a lambda.

aggregate/3,4 under Spark's other name for it. Same plan but for the function name.

reduce/3 with the finishing lambda. Spark's other name for aggregate/4.

Spark's reverse.

Spark's size.

Spark's transform. Takes a lambda — fn x -> ... end.

Spark's transform_keys. Takes a lambda — fn x -> ... end.

Spark's transform_values. Takes a lambda — fn x -> ... end.

Spark's try_element_at.

Spark's zip_with. Takes two columns and a lambda.

Conditional Functions

Spark's coalesce. Variadic in Spark; takes a list here.

Spark's ifnull.

Spark's nanvl.

Spark's nullif.

Spark's nullifzero.

Spark's nvl2.

Spark's nvl.

The else branch, ending a when_/2 chain.

A conditional branch.

Add a branch to an existing chain. Refused once otherwise/2 has closed it.

Spark's zeroifnull.

CSV Functions

Spark's from_csv. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

Spark's from_csv. With parser options, following Latu.read/2's rules.

Spark's schema_of_csv. Options follow Latu.read/2's key and value rules.

Spark's schema_of_csv. With parser options, following Latu.read/2's rules.

Spark's to_csv. Options follow Latu.read/2's key and value rules.

Spark's to_csv. With parser options, following Latu.read/2's rules.

Datasketch Functions

Spark's hll_sketch_estimate.

Spark's hll_union. The trailing argument is optional.

Spark's hll_union. With the optional trailing argument.

Spark's kll_sketch_get_n_bigint.

Spark's kll_sketch_get_n_double.

Spark's kll_sketch_get_n_float.

Spark's kll_sketch_get_quantile_bigint.

Spark's kll_sketch_get_quantile_double.

Spark's kll_sketch_get_quantile_float.

Spark's kll_sketch_get_rank_bigint.

Spark's kll_sketch_get_rank_double.

Spark's kll_sketch_get_rank_float.

Spark's kll_sketch_merge_bigint.

Spark's kll_sketch_merge_double.

Spark's kll_sketch_merge_float.

Spark's kll_sketch_to_string_bigint.

Spark's kll_sketch_to_string_double.

Spark's kll_sketch_to_string_float.

Spark's theta_difference.

Spark's theta_intersection.

Spark's theta_sketch_estimate.

Spark's theta_union. The trailing argument is optional.

Spark's theta_union. With the optional trailing argument.

Spark's tuple_difference_double.

Spark's tuple_difference_integer.

Spark's tuple_difference_theta_double.

Spark's tuple_difference_theta_integer.

Spark's tuple_intersection_double. The trailing argument is optional.

Spark's tuple_intersection_double. With the optional trailing argument.

Spark's tuple_intersection_integer. The trailing argument is optional.

Spark's tuple_intersection_integer. With the optional trailing argument.

Spark's tuple_intersection_theta_double. The trailing argument is optional.

Spark's tuple_intersection_theta_double. With the optional trailing argument.

Spark's tuple_intersection_theta_integer. The trailing argument is optional.

Spark's tuple_intersection_theta_integer. With the optional trailing argument.

Spark's tuple_sketch_estimate_double.

Spark's tuple_sketch_estimate_integer.

Spark's tuple_sketch_summary_double. The trailing argument is optional.

Spark's tuple_sketch_summary_double. With the optional trailing argument.

Spark's tuple_sketch_summary_integer. The trailing argument is optional.

Spark's tuple_sketch_summary_integer. With the optional trailing argument.

Spark's tuple_sketch_theta_double.

Spark's tuple_sketch_theta_integer.

Spark's tuple_union_double. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_double. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_double. Every argument is sent.

Spark's tuple_union_integer. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_integer. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_integer. Every argument is sent.

Spark's tuple_union_theta_double. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_theta_double. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_theta_double. Every argument is sent.

Spark's tuple_union_theta_integer. Sends Spark's defaults for the rest: 12, "sum".

Spark's tuple_union_theta_integer. Sends Spark's defaults for the rest: "sum".

Spark's tuple_union_theta_integer. Every argument is sent.

Date and Timestamp Functions

Spark's add_months.

Move a timestamp between time zones.

With the source timezone given, rather than the session's.

Spark's curdate.

Spark's current_date.

Spark's current_time. The trailing argument is optional.

Spark's current_time. With the optional trailing argument.

Spark's current_timestamp.

Spark's current_timezone.

Spark's date_add.

Spark's date_diff.

Spark's date_format.

Spark's date_from_unix_date.

Spark's date_part.

Spark's date_sub.

Spark's date_trunc.

Spark's dateadd.

Spark's datediff.

Spark's datepart.

Spark's day.

Spark's dayname.

Spark's dayofmonth.

Spark's dayofweek.

Spark's dayofyear.

Spark's extract.

Spark's from_unixtime. Sends Spark's defaults for the rest: "yyyy-MM-dd HH:mm:ss".

Spark's from_unixtime. Every argument is sent.

Spark's from_utc_timestamp.

Spark's hour.

Spark's last_day.

Spark's localtimestamp.

Spark's make_date.

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

Spark's make_dt_interval. Sends Spark's defaults for the rest: Decimal.new("0").

Spark's make_dt_interval. Every argument is sent.

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

Spark's make_interval. Sends Spark's defaults for the rest: Decimal.new("0").

Spark's make_interval. Every argument is sent.

Spark's make_time.

Spark's make_timestamp. One of several arities; they do not overlap.

Spark's make_timestamp. One of several arities; they do not overlap.

Spark's make_timestamp. One of several arities; they do not overlap.

Spark's make_timestamp. One of several arities; they do not overlap.

Spark's make_timestamp_ltz. The trailing argument is optional.

Spark's make_timestamp_ltz. With the optional trailing argument.

Spark's make_timestamp_ntz. One of several arities; they do not overlap.

Spark's make_timestamp_ntz. One of several arities; they do not overlap.

Spark's make_ym_interval. Sends Spark's defaults for the rest: 0, 0.

Spark's make_ym_interval. Sends Spark's defaults for the rest: 0.

Spark's make_ym_interval. Every argument is sent.

Spark's minute.

Spark's month.

Spark's monthname.

Spark's months_between. Sends Spark's defaults for the rest: true.

Spark's months_between. Every argument is sent.

Spark's next_day.

Spark's now.

Spark's quarter.

Spark's second.

Spark's session_window.

Spark's time_bucket. The trailing argument is optional.

Spark's time_bucket. With the optional trailing argument.

Spark's time_diff.

Spark's time_from_micros.

Spark's time_from_millis.

Spark's time_from_seconds.

Spark's time_to_micros.

Spark's time_to_millis.

Spark's time_to_seconds.

Spark's time_trunc.

Spark's timestampadd.

Spark's timestampdiff.

Spark's timestamp_micros.

Spark's timestamp_millis.

Spark's timestamp_seconds.

Spark's to_date. The trailing argument is optional.

Spark's to_date. With the optional trailing argument.

Spark's to_time. The trailing argument is optional.

Spark's to_time. With the optional trailing argument.

Spark's to_timestamp. The trailing argument is optional.

Spark's to_timestamp. With the optional trailing argument.

Spark's to_timestamp_ltz. The trailing argument is optional.

Spark's to_timestamp_ltz. With the optional trailing argument.

Spark's to_timestamp_ntz. The trailing argument is optional.

Spark's to_timestamp_ntz. With the optional trailing argument.

Spark's to_unix_timestamp. The trailing argument is optional.

Spark's to_unix_timestamp. With the optional trailing argument.

Spark's to_utc_timestamp.

Spark's trunc.

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

Spark's try_make_interval. Sends Spark's defaults for the rest: Decimal.new("0").

Spark's try_make_interval. Every argument is sent.

Spark's try_make_timestamp. One of several arities; they do not overlap.

Spark's try_make_timestamp. One of several arities; they do not overlap.

Spark's try_make_timestamp. One of several arities; they do not overlap.

Spark's try_make_timestamp. One of several arities; they do not overlap.

Spark's try_make_timestamp_ltz. The trailing argument is optional.

Spark's try_make_timestamp_ltz. With the optional trailing argument.

Spark's try_make_timestamp_ntz. One of several arities; they do not overlap.

Spark's try_make_timestamp_ntz. One of several arities; they do not overlap.

Spark's try_to_date. The trailing argument is optional.

Spark's try_to_date. With the optional trailing argument.

Spark's try_to_time. The trailing argument is optional.

Spark's try_to_time. With the optional trailing argument.

Spark's try_to_timestamp. The trailing argument is optional.

Spark's try_to_timestamp. With the optional trailing argument.

Spark's unix_date.

Spark's unix_micros.

Spark's unix_millis.

Spark's unix_seconds.

Seconds since the epoch — of now with no arguments, of a timestamp otherwise.

Parse with Spark's default format, yyyy-MM-dd HH:mm:ss, which it always sends.

Parse with the given format.

Spark's weekday.

Spark's weekofyear.

Spark's window. One of several arities; they do not overlap.

Spark's window. One of several arities; they do not overlap.

Spark's window. One of several arities; they do not overlap.

Spark's window_time.

Spark's year.

Generator Functions

Spark's explode.

Spark's explode_outer.

Spark's inline.

Spark's inline_outer.

Spark's posexplode.

Spark's posexplode_outer.

Spark's stack. Variadic in Spark; takes a list here.

Geospatial ST Functions

Spark's st_asbinary. The trailing argument is optional.

Spark's st_asbinary. With the optional trailing argument.

Spark's st_geogfromwkb.

Spark's st_geomfromwkb. The trailing argument is optional.

Spark's st_geomfromwkb. With the optional trailing argument.

Spark's st_setsrid.

Spark's st_srid.

Hash Functions

Spark's crc32.

Spark's hash. Variadic in Spark; takes a list here.

Spark's md5.

Spark's sha1.

Spark's sha2.

Spark's sha.

Spark's xxhash64. Variadic in Spark; takes a list here.

JSON Functions

Spark's from_json. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

Spark's from_json. With parser options, following Latu.read/2's rules.

Spark's get_json_object.

Spark's json_array_length.

Spark's json_object_keys.

Spark's json_tuple. Variadic in Spark; takes a list here.

Spark's schema_of_json. Options follow Latu.read/2's key and value rules.

Spark's schema_of_json. With parser options, following Latu.read/2's rules.

Spark's to_json. Options follow Latu.read/2's key and value rules.

Spark's to_json. With parser options, following Latu.read/2's rules.

Map Functions

Spark's map. Variadic in Spark; takes a list here.

Spark's map_concat. Variadic in Spark; takes a list here.

Spark's map_contains_key.

Spark's map_entries.

Spark's map_from_arrays.

Spark's map_from_entries.

Spark's map_keys.

Spark's map_values.

Spark's str_to_map. Sends Spark's defaults for the rest: ",", ":".

Spark's str_to_map. Sends Spark's defaults for the rest: ":".

Spark's str_to_map. Every argument is sent.

Mathematical Functions

Spark's abs.

Spark's acos.

Spark's acosh.

Spark's asin.

Spark's asinh.

Spark's atan2.

Spark's atan.

Spark's atanh.

Spark's bin.

Spark's bround. The trailing argument is optional.

Spark's bround. With the optional trailing argument.

Spark's cbrt.

Spark's ceil. The trailing argument is optional.

Spark's ceil. With the optional trailing argument.

Spark's ceiling. The trailing argument is optional.

Spark's ceiling. With the optional trailing argument.

Spark's conv.

Spark's cos.

Spark's cosh.

Spark's cot.

Spark's csc.

Spark's degrees.

e()

Spark's e.

Spark's exp.

Spark's expm1.

Spark's factorial.

Spark's floor. The trailing argument is optional.

Spark's floor. With the optional trailing argument.

Spark's greatest. Variadic in Spark; takes a list here.

Spark's hex.

Spark's hypot.

Spark's least. Variadic in Spark; takes a list here.

Spark's ln.

Spark's log1p.

Spark's log2.

Spark's log10.

A logarithm — natural with one argument, to a base with two.

The logarithm of column in base — Spark's log, where log/1 sends ln.

Spark's negative.

Spark's pi.

Spark's pmod.

Spark's positive.

Spark's radians.

Spark's rand. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's rand. With an explicit seed, so the plan is reproducible.

Spark's randn. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's randn. With an explicit seed, so the plan is reproducible.

Spark's rint.

Spark's round. The trailing argument is optional.

Spark's round. With the optional trailing argument.

Spark's sec.

Spark's sign.

Spark's signum.

Spark's sin.

Spark's sinh.

Spark's sqrt.

Spark's tan.

Spark's tanh.

Spark's try_add.

Spark's try_divide.

Spark's try_mod.

Spark's try_multiply.

Spark's try_subtract.

Spark's unhex.

Spark's uniform. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's uniform. With an explicit seed, so the plan is reproducible.

Spark's width_bucket.

Misc Functions

Spark's aes_decrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "".

Spark's aes_decrypt. Sends Spark's defaults for the rest: "DEFAULT", "".

Spark's aes_decrypt. Sends Spark's defaults for the rest: "".

Spark's aes_decrypt. Every argument is sent.

Spark's aes_encrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "", "".

Spark's aes_encrypt. Sends Spark's defaults for the rest: "DEFAULT", "", "".

Spark's aes_encrypt. Sends Spark's defaults for the rest: "", "".

Spark's aes_encrypt. Sends Spark's defaults for the rest: "".

Spark's aes_encrypt. Every argument is sent.

Spark's assert_true. The trailing argument is optional.

Spark's assert_true. With the optional trailing argument.

Spark's bitmap_bit_position.

Spark's bitmap_bucket_number.

Spark's bitmap_count.

Spark's current_catalog.

Spark's current_database.

Spark's current_path.

Spark's current_schema.

Spark's current_user.

Spark's input_file_block_length.

Spark's input_file_block_start.

Spark's input_file_name.

Spark's java_method. Variadic in Spark; takes a list here.

Spark's monotonically_increasing_id.

Spark's raise_error.

Spark's reflect. Variadic in Spark; takes a list here.

Spark's session_user.

Spark's spark_partition_id.

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "".

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "DEFAULT", "".

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "".

Spark's try_aes_decrypt. Every argument is sent.

Spark's try_reflect. Variadic in Spark; takes a list here.

Spark's typeof.

Spark's user.

Spark's uuid. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's uuid. With an explicit seed, so the plan is reproducible.

Spark's version.

Normal Functions

Call a function by name through Spark's catalog.

Predicate Functions

Spark's equal_null.

Spark's regexp.

Spark's regexp_like.

String Functions

Spark's ascii.

Spark's base64.

Spark's bit_length.

Spark's btrim. The trailing argument is optional.

Spark's btrim. With the optional trailing argument.

Spark's char.

Spark's char_length.

Spark's character_length.

Spark's chr.

Spark's collate.

Spark's collation.

Spark's concat_ws. Variadic in Spark; takes a list here.

Spark's decode.

Spark's elt. Variadic in Spark; takes a list here.

Spark's encode.

Spark's find_in_set.

Spark's format_number.

Spark's format_string. Variadic in Spark; takes a list here.

Spark's initcap.

Spark's instr.

Spark's is_valid_utf8.

Spark's lcase.

Spark's left.

Spark's length.

Spark's levenshtein. The trailing argument is optional.

Spark's levenshtein. With the optional trailing argument.

Spark's locate. Sends Spark's defaults for the rest: 1.

Spark's locate. Every argument is sent.

Spark's lower.

Spark's lpad.

Strip characters from the left. Reversed on the wire, as trim/2 is.

Trim the given characters from the left. Spark takes them first; Latu does not.

Spark's make_valid_utf8.

Spark's mask. Sends Spark's defaults for the rest: "X", "x", "n", nil.

Spark's mask. Sends Spark's defaults for the rest: "x", "n", nil.

Spark's mask. Sends Spark's defaults for the rest: "n", nil.

Spark's mask. Sends Spark's defaults for the rest: nil.

Spark's mask. Every argument is sent.

Spark's octet_length.

Spark's overlay. Sends Spark's defaults for the rest: -1.

Spark's overlay. Every argument is sent.

Spark's position. The trailing argument is optional.

Spark's position. With the optional trailing argument.

Spark's printf. Variadic in Spark; takes a list here.

Spark's quote.

Spark's randstr. Draws a random seed, so the plan is not reproducible — pass one to fix it.

Spark's randstr. With an explicit seed, so the plan is reproducible.

Spark's regexp_count.

Spark's regexp_extract.

Spark's regexp_extract_all. The trailing argument is optional.

Spark's regexp_extract_all. With the optional trailing argument.

Spark's regexp_instr. The trailing argument is optional.

Spark's regexp_instr. With the optional trailing argument.

Spark's regexp_replace.

Spark's regexp_substr.

Spark's repeat.

Spark's replace. The trailing argument is optional.

Spark's replace. With the optional trailing argument.

Spark's right.

Spark's rpad.

Strip characters from the right. Reversed on the wire, as trim/2 is.

Trim the given characters from the right. Spark takes them first; Latu does not.

Spark's sentences. Sends Spark's defaults for the rest: "", "".

Spark's sentences. Sends Spark's defaults for the rest: "".

Spark's sentences. Every argument is sent.

Spark's soundex.

Spark's split. Sends Spark's defaults for the rest: -1.

Spark's split. Every argument is sent.

Spark's split_part.

Spark's substr. The trailing argument is optional.

Spark's substr. With the optional trailing argument.

Spark's substring.

Spark's substring_index.

Spark's to_binary. The trailing argument is optional.

Spark's to_binary. With the optional trailing argument.

Spark's to_char.

Spark's to_number.

Spark's to_varchar.

Spark's translate.

Strip characters from both ends.

Trim the given characters from both ends. Spark takes them first; Latu does not.

Spark's try_to_binary. The trailing argument is optional.

Spark's try_to_binary. With the optional trailing argument.

Spark's try_to_number.

Spark's try_validate_utf8.

Spark's ucase.

Spark's unbase64.

Spark's upper.

Spark's validate_utf8.

Struct Functions

Spark's named_struct. Variadic in Spark; takes a list here.

Spark's struct. Variadic in Spark; takes a list here.

UDF, UDTF and UDT

Spark's unwrap_udt.

URL Functions

Spark's parse_url. The trailing argument is optional.

Spark's parse_url. With the optional trailing argument.

Spark's try_parse_url. The trailing argument is optional.

Spark's try_parse_url. With the optional trailing argument.

Spark's try_url_decode.

Spark's url_decode.

Spark's url_encode.

VARIANT Functions

Spark's is_valid_variant.

Spark's is_variant_null.

Spark's parse_json.

Spark's schema_of_variant.

Spark's schema_of_variant_agg.

Spark's to_variant_object.

Spark's try_parse_json.

Spark's try_variant_get.

Spark's variant_get.

Window Functions

Spark's cume_dist.

Spark's dense_rank.

The value some rows behind the current one, within a window.

Look back offset rows. NULL past the start of the partition.

Look back offset rows, with default past the start of the partition.

The value some rows ahead of the current one. lag/1,2,3 in the other direction.

Look ahead offset rows. NULL past the end of the partition.

Look ahead offset rows, with default past the end of the partition.

Spark's nth_value. The trailing argument is optional.

Spark's nth_value. With the optional trailing argument.

Spark's ntile.

Spark's percent_rank.

Spark's rank.

Spark's row_number.

XML Functions

Spark's from_xml. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

Spark's from_xml. With parser options, following Latu.read/2's rules.

Spark's schema_of_xml. Options follow Latu.read/2's key and value rules.

Spark's schema_of_xml. With parser options, following Latu.read/2's rules.

Spark's to_xml. Options follow Latu.read/2's key and value rules.

Spark's to_xml. With parser options, following Latu.read/2's rules.

Spark's xpath.

Spark's xpath_boolean.

Spark's xpath_double.

Spark's xpath_float.

Spark's xpath_int.

Spark's xpath_long.

Spark's xpath_number.

Spark's xpath_short.

Spark's xpath_string.

Aggregate Functions

any_value(arg1)

@spec any_value(term()) :: Latu.Plan.expression()

Spark's any_value. The trailing argument is optional.

any_value(expr[, isIgnoreNull]) - Returns some value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT any_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT any_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT any_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic.

any_value(arg1, optional)

@spec any_value(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's any_value. With the optional trailing argument.

any_value(expr[, isIgnoreNull]) - Returns some value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT any_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT any_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT any_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic.

approx_count_distinct(arg1)

@spec approx_count_distinct(term()) :: Latu.Plan.expression()

Spark's approx_count_distinct. The trailing argument is optional.

approx_count_distinct(expr[, relativeSD]) - Returns the estimated cardinality by HyperLogLog++. relativeSD defines the maximum relative standard deviation allowed.

Examples (Spark SQL)

> SELECT approx_count_distinct(col1) FROM VALUES (1), (1), (2), (2), (3) tab(col1);
3

approx_count_distinct(arg1, optional)

@spec approx_count_distinct(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's approx_count_distinct. With the optional trailing argument.

approx_count_distinct(expr[, relativeSD]) - Returns the estimated cardinality by HyperLogLog++. relativeSD defines the maximum relative standard deviation allowed.

Examples (Spark SQL)

> SELECT approx_count_distinct(col1) FROM VALUES (1), (1), (2), (2), (3) tab(col1);
3

approx_percentile(arg1, arg2)

@spec approx_percentile(term(), term()) :: Latu.Plan.expression()

Spark's approx_percentile. Sends Spark's defaults for the rest: 10000.

approx_percentile(col, percentage [, accuracy]) - Returns the approximate percentile of the numeric or ansi interval column col which is the smallest value in the ordered col values (sorted from least to greatest) such that no more than percentage of col values is less than the value or equal to that value. The value of percentage must be between 0.0 and 1.0. The accuracy parameter (default: 10000) is a positive numeric literal which controls approximation accuracy at the cost of memory. Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error of the approximation. When percentage is an array, each value of the percentage array must be between 0.0 and 1.0. In this case, returns the approximate percentile array of column col at the given percentage array.

Examples (Spark SQL)

> SELECT approx_percentile(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
> SELECT approx_percentile(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
> SELECT approx_percentile(col, 0.5, 100) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '1' MONTH), (INTERVAL '2' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-1
> SELECT approx_percentile(col, array(0.5, 0.7), 100) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '1' SECOND), (INTERVAL '2' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:01.000000000,0 00:00:02.000000000]

approx_percentile(arg1, arg2, arg3)

@spec approx_percentile(term(), term(), term()) :: Latu.Plan.expression()

Spark's approx_percentile. Every argument is sent.

approx_percentile(col, percentage [, accuracy]) - Returns the approximate percentile of the numeric or ansi interval column col which is the smallest value in the ordered col values (sorted from least to greatest) such that no more than percentage of col values is less than the value or equal to that value. The value of percentage must be between 0.0 and 1.0. The accuracy parameter (default: 10000) is a positive numeric literal which controls approximation accuracy at the cost of memory. Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error of the approximation. When percentage is an array, each value of the percentage array must be between 0.0 and 1.0. In this case, returns the approximate percentile array of column col at the given percentage array.

Examples (Spark SQL)

> SELECT approx_percentile(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
> SELECT approx_percentile(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
> SELECT approx_percentile(col, 0.5, 100) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '1' MONTH), (INTERVAL '2' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-1
> SELECT approx_percentile(col, array(0.5, 0.7), 100) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '1' SECOND), (INTERVAL '2' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:01.000000000,0 00:00:02.000000000]

array_agg(arg1)

@spec array_agg(term()) :: Latu.Plan.expression()

Spark's array_agg.

array_agg(expr) - Collects and returns a list of non-unique elements.

Examples (Spark SQL)

> SELECT array_agg(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2,1]

Note: The function is non-deterministic because the order of collected results depends on the order of the rows which may be non-deterministic after a shuffle.

avg(arg1)

@spec avg(term()) :: Latu.Plan.expression()

Spark's avg.

avg(expr) - Returns the mean calculated from values of a group.

Examples (Spark SQL)

> SELECT avg(col) FROM VALUES (1), (2), (3) AS tab(col);
2.0
> SELECT avg(col) FROM VALUES (1), (2), (NULL) AS tab(col);
1.5

bit_and(arg1)

@spec bit_and(term()) :: Latu.Plan.expression()

Spark's bit_and.

bit_and(expr) - Returns the bitwise AND of all non-null input values, or null if none.

Examples (Spark SQL)

> SELECT bit_and(col) FROM VALUES (3), (5) AS tab(col);
1

bit_or(arg1)

@spec bit_or(term()) :: Latu.Plan.expression()

Spark's bit_or.

bit_or(expr) - Returns the bitwise OR of all non-null input values, or null if none.

Examples (Spark SQL)

> SELECT bit_or(col) FROM VALUES (3), (5) AS tab(col);
7

bit_xor(arg1)

@spec bit_xor(term()) :: Latu.Plan.expression()

Spark's bit_xor.

bit_xor(expr) - Returns the bitwise XOR of all non-null input values, or null if none.

Examples (Spark SQL)

> SELECT bit_xor(col) FROM VALUES (3), (5) AS tab(col);
6

bitmap_and_agg(arg1)

@spec bitmap_and_agg(term()) :: Latu.Plan.expression()

Spark's bitmap_and_agg.

bitmap_and_agg(child) - Returns a bitmap that is the bitwise AND of all of the bitmaps from the child expression. The input should be bitmaps created from bitmap_construct_agg().

Examples (Spark SQL)

> SELECT substring(hex(bitmap_and_agg(col)), 0, 6) FROM VALUES (X 'F0'), (X '70'), (X '30') AS tab(col);
300000
> SELECT substring(hex(bitmap_and_agg(col)), 0, 6) FROM VALUES (X 'FF'), (X 'FF'), (X 'FF') AS tab(col);
FF0000

bitmap_construct_agg(arg1)

@spec bitmap_construct_agg(term()) :: Latu.Plan.expression()

Spark's bitmap_construct_agg.

bitmap_construct_agg(child) - Returns a bitmap with the positions of the bits set from all the values from the child expression. The child expression will most likely be bitmap_bit_position().

Examples (Spark SQL)

> SELECT substring(hex(bitmap_construct_agg(bitmap_bit_position(col))), 0, 6) FROM VALUES (1), (2), (3) AS tab(col);
070000
> SELECT substring(hex(bitmap_construct_agg(bitmap_bit_position(col))), 0, 6) FROM VALUES (1), (1), (1) AS tab(col);
010000

bitmap_or_agg(arg1)

@spec bitmap_or_agg(term()) :: Latu.Plan.expression()

Spark's bitmap_or_agg.

bitmap_or_agg(child) - Returns a bitmap that is the bitwise OR of all of the bitmaps from the child expression. The input should be bitmaps created from bitmap_construct_agg().

Examples (Spark SQL)

> SELECT substring(hex(bitmap_or_agg(col)), 0, 6) FROM VALUES (X '10'), (X '20'), (X '40') AS tab(col);
700000
> SELECT substring(hex(bitmap_or_agg(col)), 0, 6) FROM VALUES (X '10'), (X '10'), (X '10') AS tab(col);
100000

bool_and(arg1)

@spec bool_and(term()) :: Latu.Plan.expression()

Spark's bool_and.

bool_and(expr) - Returns true if all values of expr are true.

Examples (Spark SQL)

> SELECT bool_and(col) FROM VALUES (true), (true), (true) AS tab(col);
true
> SELECT bool_and(col) FROM VALUES (NULL), (true), (true) AS tab(col);
true
> SELECT bool_and(col) FROM VALUES (true), (false), (true) AS tab(col);
false

bool_or(arg1)

@spec bool_or(term()) :: Latu.Plan.expression()

Spark's bool_or.

bool_or(expr) - Returns true if at least one value of expr is true.

Examples (Spark SQL)

> SELECT bool_or(col) FROM VALUES (true), (false), (false) AS tab(col);
true
> SELECT bool_or(col) FROM VALUES (NULL), (true), (false) AS tab(col);
true
> SELECT bool_or(col) FROM VALUES (false), (false), (NULL) AS tab(col);
false

collect_list(arg1)

@spec collect_list(term()) :: Latu.Plan.expression()

Spark's collect_list.

collect_list(expr) - Collects and returns a list of non-unique elements.

Examples (Spark SQL)

> SELECT collect_list(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2,1]

Note: The function is non-deterministic because the order of collected results depends on the order of the rows which may be non-deterministic after a shuffle.

collect_set(arg1)

@spec collect_set(term()) :: Latu.Plan.expression()

Spark's collect_set.

collect_set(expr) - Collects and returns a set of unique elements.

Examples (Spark SQL)

> SELECT collect_set(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2]

Note: The function is non-deterministic because the order of collected results depends on the order of the rows which may be non-deterministic after a shuffle.

corr(arg1, arg2)

@spec corr(term(), term()) :: Latu.Plan.expression()

Spark's corr.

corr(expr1, expr2) - Returns Pearson coefficient of correlation between a set of number pairs.

Examples (Spark SQL)

> SELECT corr(c1, c2) FROM VALUES (3, 2), (3, 3), (6, 4) as tab(c1, c2);
0.8660254037844387

count(arg1)

@spec count(term()) :: Latu.Plan.expression()

Spark's count.

count(*) - Returns the total number of retrieved rows, including rows containing null. count(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null. count(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.

Examples (Spark SQL)

> SELECT count(*) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
4
> SELECT count(col) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
3
> SELECT count(DISTINCT col) FROM VALUES (NULL), (5), (5), (10) AS tab(col);
2

count_distinct(first)

@spec count_distinct(term()) :: Latu.Plan.expression()

Spark's count. Over distinct values: count with is_distinct set.

count(*) - Returns the total number of retrieved rows, including rows containing null. count(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null. count(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.

Examples (Spark SQL)

> SELECT count(*) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
4
> SELECT count(col) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
3
> SELECT count(DISTINCT col) FROM VALUES (NULL), (5), (5), (10) AS tab(col);
2

count_distinct(first, more)

@spec count_distinct(term(), [term()]) :: Latu.Plan.expression()

Spark's count. Over distinct values, across several arguments.

count(*) - Returns the total number of retrieved rows, including rows containing null. count(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null. count(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.

Examples (Spark SQL)

> SELECT count(*) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
4
> SELECT count(col) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
3
> SELECT count(DISTINCT col) FROM VALUES (NULL), (5), (5), (10) AS tab(col);
2

count_if(arg1)

@spec count_if(term()) :: Latu.Plan.expression()

Spark's count_if.

count_if(expr) - Returns the number of TRUE values for the expression.

Examples (Spark SQL)

> SELECT count_if(col % 2 = 0) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
2
> SELECT count_if(col IS NULL) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
1

count_min_sketch(arg1, arg2, arg3)

@spec count_min_sketch(term(), term(), term()) :: Latu.Plan.expression()

Spark's count_min_sketch. Draws a random seed, so the plan is not reproducible — pass one to fix it.

count_min_sketch(col, eps, confidence, seed) - Returns a count-min sketch of a column with the given esp, confidence and seed. The result is an array of bytes, which can be deserialized to a CountMinSketch before usage. Count-min sketch is a probabilistic data structure used for cardinality estimation using sub-linear space.

Examples (Spark SQL)

> SELECT hex(count_min_sketch(col, 0.5d, 0.5d, 1)) FROM VALUES (1), (2), (1) AS tab(col);
0000000100000000000000030000000100000004000000005D8D6AB90000000000000000000000000000000200000000000000010000000000000000

count_min_sketch(arg1, arg2, arg3, seed)

@spec count_min_sketch(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's count_min_sketch. With an explicit seed, so the plan is reproducible.

count_min_sketch(col, eps, confidence, seed) - Returns a count-min sketch of a column with the given esp, confidence and seed. The result is an array of bytes, which can be deserialized to a CountMinSketch before usage. Count-min sketch is a probabilistic data structure used for cardinality estimation using sub-linear space.

Examples (Spark SQL)

> SELECT hex(count_min_sketch(col, 0.5d, 0.5d, 1)) FROM VALUES (1), (2), (1) AS tab(col);
0000000100000000000000030000000100000004000000005D8D6AB90000000000000000000000000000000200000000000000010000000000000000

covar_pop(arg1, arg2)

@spec covar_pop(term(), term()) :: Latu.Plan.expression()

Spark's covar_pop.

covar_pop(expr1, expr2) - Returns the population covariance of a set of number pairs.

Examples (Spark SQL)

> SELECT covar_pop(c1, c2) FROM VALUES (1,1), (2,2), (3,3) AS tab(c1, c2);
0.6666666666666666

covar_samp(arg1, arg2)

@spec covar_samp(term(), term()) :: Latu.Plan.expression()

Spark's covar_samp.

covar_samp(expr1, expr2) - Returns the sample covariance of a set of number pairs.

Examples (Spark SQL)

> SELECT covar_samp(c1, c2) FROM VALUES (1,1), (2,2), (3,3) AS tab(c1, c2);
1.0

every(arg1)

@spec every(term()) :: Latu.Plan.expression()

Spark's every.

every(expr) - Returns true if all values of expr are true.

Examples (Spark SQL)

> SELECT every(col) FROM VALUES (true), (true), (true) AS tab(col);
true
> SELECT every(col) FROM VALUES (NULL), (true), (true) AS tab(col);
true
> SELECT every(col) FROM VALUES (true), (false), (true) AS tab(col);
false

first(arg1)

@spec first(term()) :: Latu.Plan.expression()

Spark's first. Sends Spark's defaults for the rest: false.

first(expr[, isIgnoreNull]) - Returns the first value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT first(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

first(arg1, arg2)

@spec first(term(), term()) :: Latu.Plan.expression()

Spark's first. Every argument is sent.

first(expr[, isIgnoreNull]) - Returns the first value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT first(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

first_value(arg1)

@spec first_value(term()) :: Latu.Plan.expression()

Spark's first_value. The trailing argument is optional.

first_value(expr[, isIgnoreNull]) - Returns the first value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT first_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

first_value(arg1, optional)

@spec first_value(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's first_value. With the optional trailing argument.

first_value(expr[, isIgnoreNull]) - Returns the first value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values.

Examples (Spark SQL)

> SELECT first_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

grouping(arg1)

@spec grouping(term()) :: Latu.Plan.expression()

Spark's grouping.

grouping(col) - indicates whether a specified column in a GROUP BY is aggregated or not, returns 1 for aggregated or 0 for not aggregated in the result set.",

Examples (Spark SQL)

> SELECT name, grouping(name), sum(age) FROM VALUES (2, 'Alice'), (5, 'Bob') people(age, name) GROUP BY cube(name);
Alice	0	2
Bob	0	5
NULL	1	7

grouping_id(columns)

@spec grouping_id([term()]) :: Latu.Plan.expression()

Spark's grouping_id. Variadic in Spark; takes a list here.

grouping_id([col1[, col2 ..]]) - returns the level of grouping, equals to (grouping(c1) << (n-1)) + (grouping(c2) << (n-2)) + ... + grouping(cn)

Examples (Spark SQL)

> SELECT name, grouping_id(), sum(age), avg(height) FROM VALUES (2, 'Alice', 165), (5, 'Bob', 180) people(age, name, height) GROUP BY cube(name, height);
Alice	0	2	165.0
Alice	1	2	165.0
NULL	3	7	172.5
Bob	0	5	180.0
Bob	1	5	180.0
NULL	2	2	165.0
NULL	2	5	180.0

Note: Input columns should match with grouping columns exactly, or empty (means all the grouping columns).

histogram_numeric(arg1, arg2)

@spec histogram_numeric(term(), term()) :: Latu.Plan.expression()

Spark's histogram_numeric.

histogram_numeric(expr, nb) - Computes a histogram on numeric 'expr' using nb bins. The return value is an array of (x,y) pairs representing the centers of the histogram's bins. As the value of 'nb' is increased, the histogram approximation gets finer-grained, but may yield artifacts around outliers. In practice, 20-40 histogram bins appear to work well, with more bins being required for skewed or smaller datasets. Note that this function creates a histogram with non-uniform bin widths. It offers no guarantees in terms of the mean-squared-error of the histogram, but in practice is comparable to the histograms produced by the R/S-Plus statistical computing packages. Note: the output type of the 'x' field in the return value is propagated from the input value consumed in the aggregate function.

Examples (Spark SQL)

> SELECT histogram_numeric(col, 5) FROM VALUES (0), (1), (2), (10) AS tab(col);
[{"x":0,"y":1.0},{"x":1,"y":1.0},{"x":2,"y":1.0},{"x":10,"y":1.0}]

hll_sketch_agg(arg1)

@spec hll_sketch_agg(term()) :: Latu.Plan.expression()

Spark's hll_sketch_agg. The trailing argument is optional.

hll_sketch_agg(expr, lgConfigK) - Returns the HllSketch's updatable binary representation. lgConfigK (optional) the log-base-2 of K, with K is the number of buckets or slots for the HllSketch.

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_sketch_agg(col, 12)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3

hll_sketch_agg(arg1, optional)

@spec hll_sketch_agg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's hll_sketch_agg. With the optional trailing argument.

hll_sketch_agg(expr, lgConfigK) - Returns the HllSketch's updatable binary representation. lgConfigK (optional) the log-base-2 of K, with K is the number of buckets or slots for the HllSketch.

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_sketch_agg(col, 12)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3

hll_union_agg(arg1)

@spec hll_union_agg(term()) :: Latu.Plan.expression()

Spark's hll_union_agg. The trailing argument is optional.

hll_union_agg(expr, allowDifferentLgConfigK) - Returns the estimated number of unique values. allowDifferentLgConfigK (optional) Allow sketches with different lgConfigK values to be unioned (defaults to false).

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_union_agg(sketch, true)) FROM (SELECT hll_sketch_agg(col) as sketch FROM VALUES (1) tab(col) UNION ALL SELECT hll_sketch_agg(col, 20) as sketch FROM VALUES (1) tab(col));
1

hll_union_agg(arg1, optional)

@spec hll_union_agg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's hll_union_agg. With the optional trailing argument.

hll_union_agg(expr, allowDifferentLgConfigK) - Returns the estimated number of unique values. allowDifferentLgConfigK (optional) Allow sketches with different lgConfigK values to be unioned (defaults to false).

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_union_agg(sketch, true)) FROM (SELECT hll_sketch_agg(col) as sketch FROM VALUES (1) tab(col) UNION ALL SELECT hll_sketch_agg(col, 20) as sketch FROM VALUES (1) tab(col));
1

kll_merge_agg_bigint(arg1)

@spec kll_merge_agg_bigint(term()) :: Latu.Plan.expression()

Spark's kll_merge_agg_bigint. The trailing argument is optional.

kll_merge_agg_bigint(arg1, optional)

@spec kll_merge_agg_bigint(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_merge_agg_bigint. With the optional trailing argument.

kll_merge_agg_double(arg1)

@spec kll_merge_agg_double(term()) :: Latu.Plan.expression()

Spark's kll_merge_agg_double. The trailing argument is optional.

kll_merge_agg_double(arg1, optional)

@spec kll_merge_agg_double(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_merge_agg_double. With the optional trailing argument.

kll_merge_agg_float(arg1)

@spec kll_merge_agg_float(term()) :: Latu.Plan.expression()

Spark's kll_merge_agg_float. The trailing argument is optional.

kll_merge_agg_float(arg1, optional)

@spec kll_merge_agg_float(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_merge_agg_float. With the optional trailing argument.

kll_sketch_agg_bigint(arg1)

@spec kll_sketch_agg_bigint(term()) :: Latu.Plan.expression()

Spark's kll_sketch_agg_bigint. The trailing argument is optional.

kll_sketch_agg_bigint(arg1, optional)

@spec kll_sketch_agg_bigint(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_sketch_agg_bigint. With the optional trailing argument.

kll_sketch_agg_double(arg1)

@spec kll_sketch_agg_double(term()) :: Latu.Plan.expression()

Spark's kll_sketch_agg_double. The trailing argument is optional.

kll_sketch_agg_double(arg1, optional)

@spec kll_sketch_agg_double(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_sketch_agg_double. With the optional trailing argument.

kll_sketch_agg_float(arg1)

@spec kll_sketch_agg_float(term()) :: Latu.Plan.expression()

Spark's kll_sketch_agg_float. The trailing argument is optional.

kll_sketch_agg_float(arg1, optional)

@spec kll_sketch_agg_float(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's kll_sketch_agg_float. With the optional trailing argument.

kurtosis(arg1)

@spec kurtosis(term()) :: Latu.Plan.expression()

Spark's kurtosis.

kurtosis(expr) - Returns the kurtosis value calculated from values of a group.

Examples (Spark SQL)

> SELECT kurtosis(col) FROM VALUES (-10), (-20), (100), (1000) AS tab(col);
-0.7014368047529627
> SELECT kurtosis(col) FROM VALUES (1), (10), (100), (10), (1) as tab(col);
0.19432323191699075

last(arg1)

@spec last(term()) :: Latu.Plan.expression()

Spark's last. Sends Spark's defaults for the rest: false.

last(expr[, isIgnoreNull]) - Returns the last value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values

Examples (Spark SQL)

> SELECT last(col) FROM VALUES (10), (5), (20) AS tab(col);
20
> SELECT last(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
> SELECT last(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

last(arg1, arg2)

@spec last(term(), term()) :: Latu.Plan.expression()

Spark's last. Every argument is sent.

last(expr[, isIgnoreNull]) - Returns the last value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values

Examples (Spark SQL)

> SELECT last(col) FROM VALUES (10), (5), (20) AS tab(col);
20
> SELECT last(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
> SELECT last(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

last_value(arg1)

@spec last_value(term()) :: Latu.Plan.expression()

Spark's last_value. The trailing argument is optional.

last_value(expr[, isIgnoreNull]) - Returns the last value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values

Examples (Spark SQL)

> SELECT last_value(col) FROM VALUES (10), (5), (20) AS tab(col);
20
> SELECT last_value(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
> SELECT last_value(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

last_value(arg1, optional)

@spec last_value(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's last_value. With the optional trailing argument.

last_value(expr[, isIgnoreNull]) - Returns the last value of expr for a group of rows. If isIgnoreNull is true, returns only non-null values

Examples (Spark SQL)

> SELECT last_value(col) FROM VALUES (10), (5), (20) AS tab(col);
20
> SELECT last_value(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
> SELECT last_value(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5

Note: The function is non-deterministic because its results depends on the order of the rows which may be non-deterministic after a shuffle.

listagg(arg1)

@spec listagg(term()) :: Latu.Plan.expression()

Spark's listagg. The trailing argument is optional.

listagg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT listagg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT listagg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT listagg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT listagg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT listagg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT listagg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT listagg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

listagg(arg1, optional)

@spec listagg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's listagg. With the optional trailing argument.

listagg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT listagg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT listagg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT listagg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT listagg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT listagg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT listagg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT listagg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

listagg_distinct(column)

@spec listagg_distinct(term()) :: Latu.Plan.expression()

Spark's listagg. Over distinct values, with an optional delimiter.

listagg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT listagg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT listagg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT listagg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT listagg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT listagg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT listagg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT listagg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

listagg_distinct(column, delimiter)

@spec listagg_distinct(term(), term()) :: Latu.Plan.expression()

Spark's listagg. Over distinct values, with the delimiter given.

listagg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT listagg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT listagg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT listagg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT listagg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT listagg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT listagg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT listagg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

max(arg1)

@spec max(term()) :: Latu.Plan.expression()

Spark's max.

max(expr) - Returns the maximum value of expr.

Examples (Spark SQL)

> SELECT max(col) FROM VALUES (10), (50), (20) AS tab(col);
50

max_by(arg1, arg2)

@spec max_by(term(), term()) :: Latu.Plan.expression()

Spark's max_by. The trailing argument is optional.

max_by(x, y) - Returns the value of x associated with the maximum value of y. max_by(x, y, k) - Returns an array of the k values of x associated with the maximum values of y, sorted in descending order by y. Returns NULL if there are no non-NULL ordering values.

Examples (Spark SQL)

> SELECT max_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
b
> SELECT max_by(x, y, 2) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
["b","c"]

Note: The function is non-deterministic so the output order can be different for those associated the same values of y. The maximum value of k is 100000.

max_by(arg1, arg2, optional)

@spec max_by(term(), term(), term()) :: Latu.Plan.expression()

Spark's max_by. With the optional trailing argument.

max_by(x, y) - Returns the value of x associated with the maximum value of y. max_by(x, y, k) - Returns an array of the k values of x associated with the maximum values of y, sorted in descending order by y. Returns NULL if there are no non-NULL ordering values.

Examples (Spark SQL)

> SELECT max_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
b
> SELECT max_by(x, y, 2) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
["b","c"]

Note: The function is non-deterministic so the output order can be different for those associated the same values of y. The maximum value of k is 100000.

mean(column)

@spec mean(term()) :: Latu.Plan.expression()

The average. Spark's own name for it on the wire is avg, which is what this sends.

median(arg1)

@spec median(term()) :: Latu.Plan.expression()

Spark's median.

median(col) - Returns the median of numeric or ANSI interval column col.

Examples (Spark SQL)

> SELECT median(col) FROM VALUES (0), (10) AS tab(col);
5.0
> SELECT median(col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-5

min(arg1)

@spec min(term()) :: Latu.Plan.expression()

Spark's min.

min(expr) - Returns the minimum value of expr.

Examples (Spark SQL)

> SELECT min(col) FROM VALUES (10), (-1), (20) AS tab(col);
-1

min_by(arg1, arg2)

@spec min_by(term(), term()) :: Latu.Plan.expression()

Spark's min_by. The trailing argument is optional.

min_by(x, y) - Returns the value of x associated with the minimum value of y. min_by(x, y, k) - Returns an array of the k values of x associated with the minimum values of y, sorted in ascending order by y. Returns NULL if there are no non-NULL ordering values.

Examples (Spark SQL)

> SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
a
> SELECT min_by(x, y, 2) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
["a","c"]

Note: The function is non-deterministic so the output order can be different for those associated the same values of y. The maximum value of k is 100000.

min_by(arg1, arg2, optional)

@spec min_by(term(), term(), term()) :: Latu.Plan.expression()

Spark's min_by. With the optional trailing argument.

min_by(x, y) - Returns the value of x associated with the minimum value of y. min_by(x, y, k) - Returns an array of the k values of x associated with the minimum values of y, sorted in ascending order by y. Returns NULL if there are no non-NULL ordering values.

Examples (Spark SQL)

> SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
a
> SELECT min_by(x, y, 2) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
["a","c"]

Note: The function is non-deterministic so the output order can be different for those associated the same values of y. The maximum value of k is 100000.

mode(arg1)

@spec mode(term()) :: Latu.Plan.expression()

Spark's mode. Sends Spark's defaults for the rest: false.

mode(col[, deterministic]) - Returns the most frequent value for the values within col. NULL values are ignored. If all the values are NULL, or there are 0 rows, returns NULL. When multiple values have the same greatest frequency then either any of values is returned if deterministic is false or is not defined, or the lowest value is returned if deterministic is true. mode() WITHIN GROUP (ORDER BY col) - Returns the most frequent value for the values within col (specified in ORDER BY clause). NULL values are ignored. If all the values are NULL, or there are 0 rows, returns NULL. When multiple values have the same greatest frequency only one value will be returned. The value will be chosen based on sort direction. Return the smallest value if sort direction is asc or the largest value if sort direction is desc from multiple values with the same frequency.

Examples (Spark SQL)

> SELECT mode(col) FROM VALUES (0), (10), (10) AS tab(col);
10
> SELECT mode(col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-10
> SELECT mode(col) FROM VALUES (0), (10), (10), (null), (null), (null) AS tab(col);
10
> SELECT mode(col, false) FROM VALUES (-10), (0), (10) AS tab(col);
0
> SELECT mode(col, true) FROM VALUES (-10), (0), (10) AS tab(col);
-10
> SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10) AS tab(col);
10
> SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
10
> SELECT mode() WITHIN GROUP (ORDER BY col DESC) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
20

mode(arg1, arg2)

@spec mode(term(), term()) :: Latu.Plan.expression()

Spark's mode. Every argument is sent.

mode(col[, deterministic]) - Returns the most frequent value for the values within col. NULL values are ignored. If all the values are NULL, or there are 0 rows, returns NULL. When multiple values have the same greatest frequency then either any of values is returned if deterministic is false or is not defined, or the lowest value is returned if deterministic is true. mode() WITHIN GROUP (ORDER BY col) - Returns the most frequent value for the values within col (specified in ORDER BY clause). NULL values are ignored. If all the values are NULL, or there are 0 rows, returns NULL. When multiple values have the same greatest frequency only one value will be returned. The value will be chosen based on sort direction. Return the smallest value if sort direction is asc or the largest value if sort direction is desc from multiple values with the same frequency.

Examples (Spark SQL)

> SELECT mode(col) FROM VALUES (0), (10), (10) AS tab(col);
10
> SELECT mode(col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-10
> SELECT mode(col) FROM VALUES (0), (10), (10), (null), (null), (null) AS tab(col);
10
> SELECT mode(col, false) FROM VALUES (-10), (0), (10) AS tab(col);
0
> SELECT mode(col, true) FROM VALUES (-10), (0), (10) AS tab(col);
-10
> SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10) AS tab(col);
10
> SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
10
> SELECT mode() WITHIN GROUP (ORDER BY col DESC) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
20

percentile(arg1, arg2)

@spec percentile(term(), term()) :: Latu.Plan.expression()

Spark's percentile. Sends Spark's defaults for the rest: 1.

percentile(col, percentage [, frequency]) - Returns the exact percentile value of numeric or ANSI interval column col at the given percentage. The value of percentage must be between 0.0 and 1.0. The value of frequency should be positive integral percentile(col, array(percentage1 [, percentage2]...) [, frequency]) - Returns the exact percentile value array of numeric column col at the given percentage(s). Each value of the percentage array must be between 0.0 and 1.0. The value of frequency should be positive integral

Examples (Spark SQL)

> SELECT percentile(col, 0.3) FROM VALUES (0), (10) AS tab(col);
3.0
> SELECT percentile(col, array(0.25, 0.75)) FROM VALUES (0), (10) AS tab(col);
[2.5,7.5]
> SELECT percentile(col, 0.5) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-5
> SELECT percentile(col, array(0.2, 0.5)) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:02.000000000,0 00:00:05.000000000]

percentile(arg1, arg2, arg3)

@spec percentile(term(), term(), term()) :: Latu.Plan.expression()

Spark's percentile. Every argument is sent.

percentile(col, percentage [, frequency]) - Returns the exact percentile value of numeric or ANSI interval column col at the given percentage. The value of percentage must be between 0.0 and 1.0. The value of frequency should be positive integral percentile(col, array(percentage1 [, percentage2]...) [, frequency]) - Returns the exact percentile value array of numeric column col at the given percentage(s). Each value of the percentage array must be between 0.0 and 1.0. The value of frequency should be positive integral

Examples (Spark SQL)

> SELECT percentile(col, 0.3) FROM VALUES (0), (10) AS tab(col);
3.0
> SELECT percentile(col, array(0.25, 0.75)) FROM VALUES (0), (10) AS tab(col);
[2.5,7.5]
> SELECT percentile(col, 0.5) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-5
> SELECT percentile(col, array(0.2, 0.5)) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:02.000000000,0 00:00:05.000000000]

percentile_approx(arg1, arg2)

@spec percentile_approx(term(), term()) :: Latu.Plan.expression()

Spark's percentile_approx. Sends Spark's defaults for the rest: 10000.

percentile_approx(col, percentage [, accuracy]) - Returns the approximate percentile of the numeric or ansi interval column col which is the smallest value in the ordered col values (sorted from least to greatest) such that no more than percentage of col values is less than the value or equal to that value. The value of percentage must be between 0.0 and 1.0. The accuracy parameter (default: 10000) is a positive numeric literal which controls approximation accuracy at the cost of memory. Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error of the approximation. When percentage is an array, each value of the percentage array must be between 0.0 and 1.0. In this case, returns the approximate percentile array of column col at the given percentage array.

Examples (Spark SQL)

> SELECT percentile_approx(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
> SELECT percentile_approx(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
> SELECT percentile_approx(col, 0.5, 100) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '1' MONTH), (INTERVAL '2' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-1
> SELECT percentile_approx(col, array(0.5, 0.7), 100) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '1' SECOND), (INTERVAL '2' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:01.000000000,0 00:00:02.000000000]

percentile_approx(arg1, arg2, arg3)

@spec percentile_approx(term(), term(), term()) :: Latu.Plan.expression()

Spark's percentile_approx. Every argument is sent.

percentile_approx(col, percentage [, accuracy]) - Returns the approximate percentile of the numeric or ansi interval column col which is the smallest value in the ordered col values (sorted from least to greatest) such that no more than percentage of col values is less than the value or equal to that value. The value of percentage must be between 0.0 and 1.0. The accuracy parameter (default: 10000) is a positive numeric literal which controls approximation accuracy at the cost of memory. Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error of the approximation. When percentage is an array, each value of the percentage array must be between 0.0 and 1.0. In this case, returns the approximate percentile array of column col at the given percentage array.

Examples (Spark SQL)

> SELECT percentile_approx(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
> SELECT percentile_approx(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
> SELECT percentile_approx(col, 0.5, 100) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '1' MONTH), (INTERVAL '2' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-1
> SELECT percentile_approx(col, array(0.5, 0.7), 100) FROM VALUES (INTERVAL '0' SECOND), (INTERVAL '1' SECOND), (INTERVAL '2' SECOND), (INTERVAL '10' SECOND) AS tab(col);
[0 00:00:01.000000000,0 00:00:02.000000000]

product(arg1)

@spec product(term()) :: Latu.Plan.expression()

Spark's product.

regr_avgx(arg1, arg2)

@spec regr_avgx(term(), term()) :: Latu.Plan.expression()

Spark's regr_avgx.

regr_avgx(y, x) - Returns the average of the independent variable for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
2.75
> SELECT regr_avgx(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_avgx(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
3.0
> SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
3.0

regr_avgy(arg1, arg2)

@spec regr_avgy(term(), term()) :: Latu.Plan.expression()

Spark's regr_avgy.

regr_avgy(y, x) - Returns the average of the dependent variable for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
1.75
> SELECT regr_avgy(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_avgy(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
1.6666666666666667
> SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.5

regr_count(arg1, arg2)

@spec regr_count(term(), term()) :: Latu.Plan.expression()

Spark's regr_count.

regr_count(y, x) - Returns the number of non-null number pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
4
> SELECT regr_count(y, x) FROM VALUES (1, null) AS tab(y, x);
0
> SELECT regr_count(y, x) FROM VALUES (null, 1) AS tab(y, x);
0
> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
3
> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
2

regr_intercept(arg1, arg2)

@spec regr_intercept(term(), term()) :: Latu.Plan.expression()

Spark's regr_intercept.

regr_intercept(y, x) - Returns the intercept of the univariate linear regression line for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_intercept(y, x) FROM VALUES (1, 1), (2, 2), (3, 3), (4, 4) AS tab(y, x);
0.0
> SELECT regr_intercept(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_intercept(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_intercept(y, x) FROM VALUES (1, 1), (2, null), (3, 3), (4, 4) AS tab(y, x);
0.0
> SELECT regr_intercept(y, x) FROM VALUES (1, 1), (2, null), (null, 3), (4, 4) AS tab(y, x);
0.0

regr_r2(arg1, arg2)

@spec regr_r2(term(), term()) :: Latu.Plan.expression()

Spark's regr_r2.

regr_r2(y, x) - Returns the coefficient of determination for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.2727272727272727
> SELECT regr_r2(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_r2(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
0.7500000000000001
> SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.0

regr_slope(arg1, arg2)

@spec regr_slope(term(), term()) :: Latu.Plan.expression()

Spark's regr_slope.

regr_slope(y, x) - Returns the slope of the linear regression line for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_slope(y, x) FROM VALUES (1, 1), (2, 2), (3, 3), (4, 4) AS tab(y, x);
1.0
> SELECT regr_slope(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_slope(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_slope(y, x) FROM VALUES (1, 1), (2, null), (3, 3), (4, 4) AS tab(y, x);
1.0
> SELECT regr_slope(y, x) FROM VALUES (1, 1), (2, null), (null, 3), (4, 4) AS tab(y, x);
1.0

regr_sxx(arg1, arg2)

@spec regr_sxx(term(), term()) :: Latu.Plan.expression()

Spark's regr_sxx.

regr_sxx(y, x) - Returns REGR_COUNT(y, x) * VAR_POP(x) for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
2.75
> SELECT regr_sxx(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_sxx(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
2.0
> SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
2.0

regr_sxy(arg1, arg2)

@spec regr_sxy(term(), term()) :: Latu.Plan.expression()

Spark's regr_sxy.

regr_sxy(y, x) - Returns REGR_COUNT(y, x) * COVAR_POP(y, x) for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.75
> SELECT regr_sxy(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_sxy(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
1.0
> SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.0

regr_syy(arg1, arg2)

@spec regr_syy(term(), term()) :: Latu.Plan.expression()

Spark's regr_syy.

regr_syy(y, x) - Returns REGR_COUNT(y, x) * VAR_POP(y) for non-null pairs in a group, where y is the dependent variable and x is the independent variable.

Examples (Spark SQL)

> SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.75
> SELECT regr_syy(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
> SELECT regr_syy(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
> SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
0.6666666666666666
> SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
0.5

skewness(arg1)

@spec skewness(term()) :: Latu.Plan.expression()

Spark's skewness.

skewness(expr) - Returns the skewness value calculated from values of a group.

Examples (Spark SQL)

> SELECT skewness(col) FROM VALUES (-10), (-20), (100), (1000) AS tab(col);
1.1135657469022011
> SELECT skewness(col) FROM VALUES (-1000), (-100), (10), (20) AS tab(col);
-1.1135657469022011

some(arg1)

@spec some(term()) :: Latu.Plan.expression()

Spark's some.

some(expr) - Returns true if at least one value of expr is true.

Examples (Spark SQL)

> SELECT some(col) FROM VALUES (true), (false), (false) AS tab(col);
true
> SELECT some(col) FROM VALUES (NULL), (true), (false) AS tab(col);
true
> SELECT some(col) FROM VALUES (false), (false), (NULL) AS tab(col);
false

std(arg1)

@spec std(term()) :: Latu.Plan.expression()

Spark's std.

std(expr) - Returns the sample standard deviation calculated from values of a group.

Examples (Spark SQL)

> SELECT std(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0

stddev(arg1)

@spec stddev(term()) :: Latu.Plan.expression()

Spark's stddev.

stddev(expr) - Returns the sample standard deviation calculated from values of a group.

Examples (Spark SQL)

> SELECT stddev(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0

stddev_pop(arg1)

@spec stddev_pop(term()) :: Latu.Plan.expression()

Spark's stddev_pop.

stddev_pop(expr) - Returns the population standard deviation calculated from values of a group.

Examples (Spark SQL)

> SELECT stddev_pop(col) FROM VALUES (1), (2), (3) AS tab(col);
0.816496580927726

stddev_samp(arg1)

@spec stddev_samp(term()) :: Latu.Plan.expression()

Spark's stddev_samp.

stddev_samp(expr) - Returns the sample standard deviation calculated from values of a group.

Examples (Spark SQL)

> SELECT stddev_samp(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0

string_agg(arg1)

@spec string_agg(term()) :: Latu.Plan.expression()

Spark's string_agg. The trailing argument is optional.

string_agg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT string_agg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT string_agg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT string_agg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT string_agg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT string_agg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT string_agg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT string_agg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

string_agg(arg1, optional)

@spec string_agg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's string_agg. With the optional trailing argument.

string_agg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT string_agg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT string_agg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT string_agg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT string_agg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT string_agg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT string_agg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT string_agg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

string_agg_distinct(column)

@spec string_agg_distinct(term()) :: Latu.Plan.expression()

Spark's string_agg. Over distinct values, with an optional delimiter.

string_agg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT string_agg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT string_agg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT string_agg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT string_agg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT string_agg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT string_agg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT string_agg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

string_agg_distinct(column, delimiter)

@spec string_agg_distinct(term(), term()) :: Latu.Plan.expression()

Spark's string_agg. Over distinct values, with the delimiter given.

string_agg(expr[, delimiter])[ WITHIN GROUP (ORDER BY key [ASC | DESC] [,...])] - Returns the concatenation of non-NULL input values, separated by the delimiter ordered by key. If all values are NULL, NULL is returned.

Examples (Spark SQL)

> SELECT string_agg(col) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
abc
> SELECT string_agg(col) WITHIN GROUP (ORDER BY col DESC) FROM VALUES ('a'), ('b'), ('c') AS tab(col);
cba
> SELECT string_agg(col) FROM VALUES ('a'), (NULL), ('b') AS tab(col);
ab
> SELECT string_agg(col) FROM VALUES ('a'), ('a') AS tab(col);
aa
> SELECT string_agg(DISTINCT col) FROM VALUES ('a'), ('a'), ('b') AS tab(col);
ab
> SELECT string_agg(col, ', ') FROM VALUES ('a'), ('b'), ('c') AS tab(col);
a, b, c
> SELECT string_agg(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

Note: * If the order is not specified, the function is non-deterministic because the order of the rows may be non-deterministic after a shuffle.

  • If DISTINCT is specified, then expr and key must be the same expression.

sum(arg1)

@spec sum(term()) :: Latu.Plan.expression()

Spark's sum.

sum(expr) - Returns the sum calculated from values of a group.

Examples (Spark SQL)

> SELECT sum(col) FROM VALUES (5), (10), (15) AS tab(col);
30
> SELECT sum(col) FROM VALUES (NULL), (10), (15) AS tab(col);
25
> SELECT sum(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

sum_distinct(arg1)

@spec sum_distinct(term()) :: Latu.Plan.expression()

Spark's sum. Over distinct values: sum with is_distinct set.

sum(expr) - Returns the sum calculated from values of a group.

Examples (Spark SQL)

> SELECT sum(col) FROM VALUES (5), (10), (15) AS tab(col);
30
> SELECT sum(col) FROM VALUES (NULL), (10), (15) AS tab(col);
25
> SELECT sum(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL

theta_intersection_agg(arg1)

@spec theta_intersection_agg(term()) :: Latu.Plan.expression()

Spark's theta_intersection_agg.

theta_sketch_agg(arg1)

@spec theta_sketch_agg(term()) :: Latu.Plan.expression()

Spark's theta_sketch_agg. The trailing argument is optional.

theta_sketch_agg(arg1, optional)

@spec theta_sketch_agg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's theta_sketch_agg. With the optional trailing argument.

theta_union_agg(arg1)

@spec theta_union_agg(term()) :: Latu.Plan.expression()

Spark's theta_union_agg. The trailing argument is optional.

theta_union_agg(arg1, optional)

@spec theta_union_agg(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's theta_union_agg. With the optional trailing argument.

try_avg(arg1)

@spec try_avg(term()) :: Latu.Plan.expression()

Spark's try_avg.

try_avg(expr) - Returns the mean calculated from values of a group and the result is null on overflow.

Examples (Spark SQL)

> SELECT try_avg(col) FROM VALUES (1), (2), (3) AS tab(col);
2.0
> SELECT try_avg(col) FROM VALUES (1), (2), (NULL) AS tab(col);
1.5
> SELECT try_avg(col) FROM VALUES (interval '2147483647 months'), (interval '1 months') AS tab(col);
NULL

try_sum(arg1)

@spec try_sum(term()) :: Latu.Plan.expression()

Spark's try_sum.

try_sum(expr) - Returns the sum calculated from values of a group and the result is null on overflow.

Examples (Spark SQL)

> SELECT try_sum(col) FROM VALUES (5), (10), (15) AS tab(col);
30
> SELECT try_sum(col) FROM VALUES (NULL), (10), (15) AS tab(col);
25
> SELECT try_sum(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL
> SELECT try_sum(col) FROM VALUES (9223372036854775807L), (1L) AS tab(col);
NULL

tuple_intersection_agg_double(arg1)

@spec tuple_intersection_agg_double(term()) :: Latu.Plan.expression()

Spark's tuple_intersection_agg_double. The trailing argument is optional.

tuple_intersection_agg_double(arg1, optional)

@spec tuple_intersection_agg_double(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's tuple_intersection_agg_double. With the optional trailing argument.

tuple_intersection_agg_integer(arg1)

@spec tuple_intersection_agg_integer(term()) :: Latu.Plan.expression()

Spark's tuple_intersection_agg_integer. The trailing argument is optional.

tuple_intersection_agg_integer(arg1, optional)

@spec tuple_intersection_agg_integer(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's tuple_intersection_agg_integer. With the optional trailing argument.

tuple_sketch_agg_double(arg1, arg2)

@spec tuple_sketch_agg_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_sketch_agg_double. Sends Spark's defaults for the rest: 12, "sum".

tuple_sketch_agg_double(arg1, arg2, arg3)

@spec tuple_sketch_agg_double(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_sketch_agg_double. Sends Spark's defaults for the rest: "sum".

tuple_sketch_agg_double(arg1, arg2, arg3, arg4)

@spec tuple_sketch_agg_double(term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_sketch_agg_double. Every argument is sent.

tuple_sketch_agg_integer(arg1, arg2)

@spec tuple_sketch_agg_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_sketch_agg_integer. Sends Spark's defaults for the rest: 12, "sum".

tuple_sketch_agg_integer(arg1, arg2, arg3)

@spec tuple_sketch_agg_integer(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_sketch_agg_integer. Sends Spark's defaults for the rest: "sum".

tuple_sketch_agg_integer(arg1, arg2, arg3, arg4)

@spec tuple_sketch_agg_integer(term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_sketch_agg_integer. Every argument is sent.

tuple_union_agg_double(arg1)

@spec tuple_union_agg_double(term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_double. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_agg_double(arg1, arg2)

@spec tuple_union_agg_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_double. Sends Spark's defaults for the rest: "sum".

tuple_union_agg_double(arg1, arg2, arg3)

@spec tuple_union_agg_double(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_double. Every argument is sent.

tuple_union_agg_integer(arg1)

@spec tuple_union_agg_integer(term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_integer. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_agg_integer(arg1, arg2)

@spec tuple_union_agg_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_integer. Sends Spark's defaults for the rest: "sum".

tuple_union_agg_integer(arg1, arg2, arg3)

@spec tuple_union_agg_integer(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_agg_integer. Every argument is sent.

var_pop(arg1)

@spec var_pop(term()) :: Latu.Plan.expression()

Spark's var_pop.

var_pop(expr) - Returns the population variance calculated from values of a group.

Examples (Spark SQL)

> SELECT var_pop(col) FROM VALUES (1), (2), (3) AS tab(col);
0.6666666666666666

var_samp(arg1)

@spec var_samp(term()) :: Latu.Plan.expression()

Spark's var_samp.

var_samp(expr) - Returns the sample variance calculated from values of a group.

Examples (Spark SQL)

> SELECT var_samp(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0

variance(arg1)

@spec variance(term()) :: Latu.Plan.expression()

Spark's variance.

variance(expr) - Returns the sample variance calculated from values of a group.

Examples (Spark SQL)

> SELECT variance(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0

Array Functions

array(columns)

@spec array([term()]) :: Latu.Plan.expression()

Spark's array. Variadic in Spark; takes a list here.

array(expr, ...) - Returns an array with the given elements.

Examples (Spark SQL)

> SELECT array(1, 2, 3);
[1,2,3]

array_append(arg1, arg2)

@spec array_append(term(), term()) :: Latu.Plan.expression()

Spark's array_append.

array_append(array, element) - Add the element at the end of the array passed as first argument. Type of element should be similar to type of the elements of the array. Null element is also appended into the array. But if the array passed, is NULL output is NULL

Examples (Spark SQL)

> SELECT array_append(array('b', 'd', 'c', 'a'), 'd');
["b","d","c","a","d"]
> SELECT array_append(array(1, 2, 3, null), null);
[1,2,3,null,null]
> SELECT array_append(CAST(null as Array<Int>), 2);
NULL

array_compact(arg1)

@spec array_compact(term()) :: Latu.Plan.expression()

Spark's array_compact.

array_compact(array) - Removes null values from the array.

Examples (Spark SQL)

> SELECT array_compact(array(1, 2, 3, null));
[1,2,3]
> SELECT array_compact(array("a", "b", "c"));
["a","b","c"]

array_contains(arg1, arg2)

@spec array_contains(term(), term()) :: Latu.Plan.expression()

Spark's array_contains.

array_contains(array, value) - Returns true if the array contains the value.

Examples (Spark SQL)

> SELECT array_contains(array(1, 2, 3), 2);
true

array_distinct(arg1)

@spec array_distinct(term()) :: Latu.Plan.expression()

Spark's array_distinct.

array_distinct(array) - Removes duplicate values from the array.

Examples (Spark SQL)

> SELECT array_distinct(array(1, 2, 3, null, 3));
[1,2,3,null]

array_except(arg1, arg2)

@spec array_except(term(), term()) :: Latu.Plan.expression()

Spark's array_except.

array_except(array1, array2) - Returns an array of the elements in array1 but not in array2, without duplicates.

Examples (Spark SQL)

> SELECT array_except(array(1, 2, 3), array(1, 3, 5));
[2]

array_insert(arg1, arg2, arg3)

@spec array_insert(term(), term(), term()) :: Latu.Plan.expression()

Spark's array_insert.

array_insert(x, pos, val) - Places val into index pos of array x. Array indices start at 1. The maximum negative index is -1 for which the function inserts new element after the current last element. Index above array size appends the array, or prepends the array if index is negative, with 'null' elements.

Examples (Spark SQL)

> SELECT array_insert(array(1, 2, 3, 4), 5, 5);
[1,2,3,4,5]
> SELECT array_insert(array(5, 4, 3, 2), -1, 1);
[5,4,3,2,1]
> SELECT array_insert(array(5, 3, 2, 1), -4, 4);
[5,4,3,2,1]

array_intersect(arg1, arg2)

@spec array_intersect(term(), term()) :: Latu.Plan.expression()

Spark's array_intersect.

array_intersect(array1, array2) - Returns an array of the elements in the intersection of array1 and array2, without duplicates.

Examples (Spark SQL)

> SELECT array_intersect(array(1, 2, 3), array(1, 3, 5));
[1,3]

array_join(arg1, arg2)

@spec array_join(term(), term()) :: Latu.Plan.expression()

Spark's array_join. The trailing argument is optional.

array_join(array, delimiter[, nullReplacement]) - Concatenates the elements of the given array using the delimiter and an optional string to replace nulls. If no value is set for nullReplacement, any null value is filtered.

Examples (Spark SQL)

> SELECT array_join(array('hello', 'world'), ' ');
hello world
> SELECT array_join(array('hello', null ,'world'), ' ');
hello world
> SELECT array_join(array('hello', null ,'world'), ' ', ',');
hello , world

array_join(arg1, arg2, optional)

@spec array_join(term(), term(), term()) :: Latu.Plan.expression()

Spark's array_join. With the optional trailing argument.

array_join(array, delimiter[, nullReplacement]) - Concatenates the elements of the given array using the delimiter and an optional string to replace nulls. If no value is set for nullReplacement, any null value is filtered.

Examples (Spark SQL)

> SELECT array_join(array('hello', 'world'), ' ');
hello world
> SELECT array_join(array('hello', null ,'world'), ' ');
hello world
> SELECT array_join(array('hello', null ,'world'), ' ', ',');
hello , world

array_max(arg1)

@spec array_max(term()) :: Latu.Plan.expression()

Spark's array_max.

array_max(array) - Returns the maximum value in the array. NaN is greater than any non-NaN elements for double/float type. NULL elements are skipped.

Examples (Spark SQL)

> SELECT array_max(array(1, 20, null, 3));
20

array_min(arg1)

@spec array_min(term()) :: Latu.Plan.expression()

Spark's array_min.

array_min(array) - Returns the minimum value in the array. NaN is greater than any non-NaN elements for double/float type. NULL elements are skipped.

Examples (Spark SQL)

> SELECT array_min(array(1, 20, null, 3));
1

array_position(arg1, arg2)

@spec array_position(term(), term()) :: Latu.Plan.expression()

Spark's array_position.

array_position(array, element) - Returns the (1-based) index of the first matching element of the array as long, or 0 if no match is found.

Examples (Spark SQL)

> SELECT array_position(array(312, 773, 708, 708), 708);
3
> SELECT array_position(array(312, 773, 708, 708), 414);
0

array_prepend(arg1, arg2)

@spec array_prepend(term(), term()) :: Latu.Plan.expression()

Spark's array_prepend.

array_prepend(array, element) - Add the element at the beginning of the array passed as first argument. Type of element should be the same as the type of the elements of the array. Null element is also prepended to the array. But if the array passed is NULL output is NULL

Examples (Spark SQL)

> SELECT array_prepend(array('b', 'd', 'c', 'a'), 'd');
["d","b","d","c","a"]
> SELECT array_prepend(array(1, 2, 3, null), null);
[null,1,2,3,null]
> SELECT array_prepend(CAST(null as Array<Int>), 2);
NULL

array_remove(arg1, arg2)

@spec array_remove(term(), term()) :: Latu.Plan.expression()

Spark's array_remove.

array_remove(array, element) - Remove all elements that equal to element from array.

Examples (Spark SQL)

> SELECT array_remove(array(1, 2, 3, null, 3), 3);
[1,2,null]

array_repeat(arg1, arg2)

@spec array_repeat(term(), term()) :: Latu.Plan.expression()

Spark's array_repeat.

array_repeat(element, count) - Returns the array containing element count times.

Examples (Spark SQL)

> SELECT array_repeat('123', 2);
["123","123"]

array_size(arg1)

@spec array_size(term()) :: Latu.Plan.expression()

Spark's array_size.

array_size(expr) - Returns the size of an array. The function returns null for null input.

Examples (Spark SQL)

> SELECT array_size(array('b', 'd', 'c', 'a'));
4

array_union(arg1, arg2)

@spec array_union(term(), term()) :: Latu.Plan.expression()

Spark's array_union.

array_union(array1, array2) - Returns an array of the elements in the union of array1 and array2, without duplicates.

Examples (Spark SQL)

> SELECT array_union(array(1, 2, 3), array(1, 3, 5));
[1,2,3,5]

arrays_overlap(arg1, arg2)

@spec arrays_overlap(term(), term()) :: Latu.Plan.expression()

Spark's arrays_overlap.

arrays_overlap(a1, a2) - Returns true if a1 contains at least a non-null element present also in a2. If the arrays have no common element and they are both non-empty and either of them contains a null element null is returned, false otherwise.

Examples (Spark SQL)

> SELECT arrays_overlap(array(1, 2, 3), array(3, 4, 5));
true

arrays_zip(columns)

@spec arrays_zip([term()]) :: Latu.Plan.expression()

Spark's arrays_zip. Variadic in Spark; takes a list here.

arrays_zip(a1, a2, ...) - Returns a merged array of structs in which the N-th struct contains all N-th values of input arrays.

Examples (Spark SQL)

> SELECT arrays_zip(array(1, 2, 3), array(2, 3, 4));
[{"0":1,"1":2},{"0":2,"1":3},{"0":3,"1":4}]
> SELECT arrays_zip(array(1, 2), array(2, 3), array(3, 4));
[{"0":1,"1":2,"2":3},{"0":2,"1":3,"2":4}]

flatten(arg1)

@spec flatten(term()) :: Latu.Plan.expression()

Spark's flatten.

flatten(arrayOfArrays) - Transforms an array of arrays into a single array.

Examples (Spark SQL)

> SELECT flatten(array(array(1, 2), array(3, 4)));
[1,2,3,4]

get(arg1, arg2)

@spec get(term(), term()) :: Latu.Plan.expression()

Spark's get.

get(array, index) - Returns element of array at given (0-based) index. If the index points outside of the array boundaries, then this function returns NULL.

Examples (Spark SQL)

> SELECT get(array(1, 2, 3), 0);
1
> SELECT get(array(1, 2, 3), 3);
NULL
> SELECT get(array(1, 2, 3), -1);
NULL

sequence(arg1, arg2)

@spec sequence(term(), term()) :: Latu.Plan.expression()

Spark's sequence. The trailing argument is optional.

sequence(start, stop, step) - Generates an array of elements from start to stop (inclusive), incrementing by step. The type of the returned elements is the same as the type of argument expressions. Supported types are: byte, short, integer, long, date, timestamp. The start and stop expressions must resolve to the same type. If start and stop expressions resolve to the 'date' or 'timestamp' type then the step expression must resolve to the 'interval' or 'year-month interval' or 'day-time interval' type, otherwise to the same type as the start and stop expressions.

Examples (Spark SQL)

> SELECT sequence(1, 5);
[1,2,3,4,5]
> SELECT sequence(5, 1);
[5,4,3,2,1]
> SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);
[2018-01-01,2018-02-01,2018-03-01]
> SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval '0-1' year to month);
[2018-01-01,2018-02-01,2018-03-01]

sequence(arg1, arg2, optional)

@spec sequence(term(), term(), term()) :: Latu.Plan.expression()

Spark's sequence. With the optional trailing argument.

sequence(start, stop, step) - Generates an array of elements from start to stop (inclusive), incrementing by step. The type of the returned elements is the same as the type of argument expressions. Supported types are: byte, short, integer, long, date, timestamp. The start and stop expressions must resolve to the same type. If start and stop expressions resolve to the 'date' or 'timestamp' type then the step expression must resolve to the 'interval' or 'year-month interval' or 'day-time interval' type, otherwise to the same type as the start and stop expressions.

Examples (Spark SQL)

> SELECT sequence(1, 5);
[1,2,3,4,5]
> SELECT sequence(5, 1);
[5,4,3,2,1]
> SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);
[2018-01-01,2018-02-01,2018-03-01]
> SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval '0-1' year to month);
[2018-01-01,2018-02-01,2018-03-01]

shuffle(arg1)

@spec shuffle(term()) :: Latu.Plan.expression()

Spark's shuffle. Draws a random seed, so the plan is not reproducible — pass one to fix it.

shuffle(array) - Returns a random permutation of the given array.

Examples (Spark SQL)

> SELECT shuffle(array(1, 20, 3, 5));
[3,1,5,20]
> SELECT shuffle(array(1, 20, null, 3));
[20,null,3,1]

Note: The function is non-deterministic.

shuffle(arg1, seed)

@spec shuffle(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's shuffle. With an explicit seed, so the plan is reproducible.

shuffle(array) - Returns a random permutation of the given array.

Examples (Spark SQL)

> SELECT shuffle(array(1, 20, 3, 5));
[3,1,5,20]
> SELECT shuffle(array(1, 20, null, 3));
[20,null,3,1]

Note: The function is non-deterministic.

slice(arg1, arg2, arg3)

@spec slice(term(), term(), term()) :: Latu.Plan.expression()

Spark's slice.

slice(x, start, length) - Subsets array x starting from index start (array indices start at 1, or starting from the end if start is negative) with the specified length.

Examples (Spark SQL)

> SELECT slice(array(1, 2, 3, 4), 2, 2);
[2,3]
> SELECT slice(array(1, 2, 3, 4), -2, 2);
[3,4]

sort_array(arg1)

@spec sort_array(term()) :: Latu.Plan.expression()

Spark's sort_array. Sends Spark's defaults for the rest: true.

sort_array(array[, ascendingOrder]) - Sorts the input array in ascending or descending order according to the natural ordering of the array elements. NaN is greater than any non-NaN elements for double/float type. Null elements will be placed at the beginning of the returned array in ascending order or at the end of the returned array in descending order.

Examples (Spark SQL)

> SELECT sort_array(array('b', 'd', null, 'c', 'a'), true);
[null,"a","b","c","d"]
> SELECT sort_array(array('b', 'd', null, 'c', 'a'), false);
["d","c","b","a",null]

sort_array(arg1, arg2)

@spec sort_array(term(), term()) :: Latu.Plan.expression()

Spark's sort_array. Every argument is sent.

sort_array(array[, ascendingOrder]) - Sorts the input array in ascending or descending order according to the natural ordering of the array elements. NaN is greater than any non-NaN elements for double/float type. Null elements will be placed at the beginning of the returned array in ascending order or at the end of the returned array in descending order.

Examples (Spark SQL)

> SELECT sort_array(array('b', 'd', null, 'c', 'a'), true);
[null,"a","b","c","d"]
> SELECT sort_array(array('b', 'd', null, 'c', 'a'), false);
["d","c","b","a",null]

Bitwise Functions

bit_count(arg1)

@spec bit_count(term()) :: Latu.Plan.expression()

Spark's bit_count.

bit_count(expr) - Returns the number of bits that are set in the argument expr as an unsigned 64-bit integer, or NULL if the argument is NULL.

Examples (Spark SQL)

> SELECT bit_count(0);
0

bit_get(arg1, arg2)

@spec bit_get(term(), term()) :: Latu.Plan.expression()

Spark's bit_get.

bit_get(expr, pos) - Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative.

Examples (Spark SQL)

> SELECT bit_get(11, 0);
1
> SELECT bit_get(11, 2);
0

bitwise_not(arg1)

@spec bitwise_not(term()) :: Latu.Plan.expression()

Spark's ~.

~ expr - Returns the result of bitwise NOT of expr.

Examples (Spark SQL)

> SELECT ~ 0;
-1

getbit(arg1, arg2)

@spec getbit(term(), term()) :: Latu.Plan.expression()

Spark's getbit.

getbit(expr, pos) - Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative.

Examples (Spark SQL)

> SELECT getbit(11, 0);
1
> SELECT getbit(11, 2);
0

shiftleft(arg1, arg2)

@spec shiftleft(term(), term()) :: Latu.Plan.expression()

Spark's shiftleft.

base shiftleft exp - Bitwise left shift.

Examples (Spark SQL)

> SELECT shiftleft(2, 1);
4
> SELECT 2 << 1;
4

Note: << operator is added in Spark 4.0.0 as an alias for shiftleft.

shiftright(arg1, arg2)

@spec shiftright(term(), term()) :: Latu.Plan.expression()

Spark's shiftright.

base shiftright expr - Bitwise (signed) right shift.

Examples (Spark SQL)

> SELECT shiftright(4, 1);
2
> SELECT 4 >> 1;
2

Note: >> operator is added in Spark 4.0.0 as an alias for shiftright.

shiftrightunsigned(arg1, arg2)

@spec shiftrightunsigned(term(), term()) :: Latu.Plan.expression()

Spark's shiftrightunsigned.

base shiftrightunsigned expr - Bitwise unsigned right shift.

Examples (Spark SQL)

> SELECT shiftrightunsigned(4, 1);
2
> SELECT 4 >>> 1;
2

Note: >>> operator is added in Spark 4.0.0 as an alias for shiftrightunsigned.

Collection Functions

aggregate(column, initial, merge)

@spec aggregate(term(), term(), function()) :: Latu.Plan.expression()

Fold an array, left to right.

F.aggregate(:xs, 0, fn acc, x -> add(acc, x) end)
F.aggregate(:xs, 0, fn acc, x -> add(acc, x) end, fn acc -> divide(acc, F.size(:xs)) end)

merge takes the accumulator and an element; the optional finish transforms the result.

aggregate(column, initial, merge, finish)

@spec aggregate(term(), term(), function(), function()) :: Latu.Plan.expression()

aggregate/3 with the finishing lambda, which Spark applies to the result.

array_sort(column)

@spec array_sort(term()) :: Latu.Plan.expression()

Sort an array, optionally by a comparator returning a negative, zero or positive number.

Without one this is an ordinary call and no lambda reaches the wire, which is why the two clauses build different things.

array_sort(column, comparator)

@spec array_sort(term(), function()) :: Latu.Plan.expression()

Sort by a comparator of two elements, rather than by Spark's natural order.

cardinality(arg1)

@spec cardinality(term()) :: Latu.Plan.expression()

Spark's cardinality.

cardinality(expr) - Returns the size of an array or a map. This function returns -1 for null input only if spark.sql.ansi.enabled is false and spark.sql.legacy.sizeOfNull is true. Otherwise, it returns null for null input. With the default settings, the function returns null for null input.

Examples (Spark SQL)

> SELECT cardinality(array('b', 'd', 'c', 'a'));
4
> SELECT cardinality(map('a', 1, 'b', 2));
2

concat(columns)

@spec concat([term()]) :: Latu.Plan.expression()

Spark's concat. Variadic in Spark; takes a list here.

concat(col1, col2, ..., colN) - Returns the concatenation of col1, col2, ..., colN.

Examples (Spark SQL)

> SELECT concat('Spark', 'SQL');
SparkSQL
> SELECT concat(array(1, 2, 3), array(4, 5), array(6));
[1,2,3,4,5,6]

Note: Concat logic for arrays is available since 2.4.0.

element_at(arg1, arg2)

@spec element_at(term(), term()) :: Latu.Plan.expression()

Spark's element_at.

element_at(array, index) - Returns element of array at given (1-based) index. If Index is 0, Spark will throw an error. If index < 0, accesses elements from the last to the first. The function returns NULL if the index exceeds the length of the array and spark.sql.ansi.enabled is set to false. If spark.sql.ansi.enabled is set to true, it throws ArrayIndexOutOfBoundsException for invalid indices. element_at(map, key) - Returns value for given key. The function returns NULL if the key is not contained in the map.

Examples (Spark SQL)

> SELECT element_at(array(1, 2, 3), 2);
2
> SELECT element_at(map(1, 'a', 2, 'b'), 2);
b

exists(column, fun)

@spec exists(term(), function()) :: Latu.Plan.expression()

Spark's exists. Takes a lambda — fn x -> ... end.

exists(expr, pred) - Tests whether a predicate holds for one or more elements in the array.

Examples (Spark SQL)

> SELECT exists(array(1, 2, 3), x -> x % 2 == 0);
true
> SELECT exists(array(1, 2, 3), x -> x % 2 == 10);
false
> SELECT exists(array(1, null, 3), x -> x % 2 == 0);
NULL
> SELECT exists(array(0, null, 2, 3, null), x -> x IS NULL);
true
> SELECT exists(array(1, 2, 3), x -> x IS NULL);
false

filter(column, fun)

@spec filter(term(), function()) :: Latu.Plan.expression()

Spark's filter. Takes a lambda — fn x -> ... end.

filter(expr, func) - Filters the input array using the given predicate.

Examples (Spark SQL)

> SELECT filter(array(1, 2, 3), x -> x % 2 == 1);
[1,3]
> SELECT filter(array(0, 2, 3), (x, i) -> x > i);
[2,3]
> SELECT filter(array(0, null, 2, 3, null), x -> x IS NOT NULL);
[0,2,3]

Note: The inner function may use the index argument since 3.0.0.

forall(column, fun)

@spec forall(term(), function()) :: Latu.Plan.expression()

Spark's forall. Takes a lambda — fn x -> ... end.

forall(expr, pred) - Tests whether a predicate holds for all elements in the array.

Examples (Spark SQL)

> SELECT forall(array(1, 2, 3), x -> x % 2 == 0);
false
> SELECT forall(array(2, 4, 8), x -> x % 2 == 0);
true
> SELECT forall(array(1, null, 3), x -> x % 2 == 0);
false
> SELECT forall(array(2, null, 8), x -> x % 2 == 0);
NULL

map_filter(column, fun)

@spec map_filter(term(), function()) :: Latu.Plan.expression()

Spark's map_filter. Takes a lambda — fn x -> ... end.

map_filter(expr, func) - Filters entries in a map using the function.

Examples (Spark SQL)

> SELECT map_filter(map(1, 0, 2, 2, 3, -1), (k, v) -> k > v);
{1:0,3:-1}

map_zip_with(left, right, fun)

@spec map_zip_with(term(), term(), function()) :: Latu.Plan.expression()

Spark's map_zip_with. Takes two columns and a lambda.

map_zip_with(map1, map2, function) - Merges two given maps into a single map by applying function to the pair of values with the same key. For keys only presented in one map, NULL will be passed as the value for the missing key. If an input map contains duplicated keys, only the first entry of the duplicated key is passed into the lambda function.

Examples (Spark SQL)

> SELECT map_zip_with(map(1, 'a', 2, 'b'), map(1, 'x', 2, 'y'), (k, v1, v2) -> concat(v1, v2));
{1:"ax",2:"by"}
> SELECT map_zip_with(map('a', 1, 'b', 2), map('b', 3, 'c', 4), (k, v1, v2) -> coalesce(v1, 0) + coalesce(v2, 0));
{"a":1,"b":5,"c":4}

reduce(column, initial, merge)

@spec reduce(term(), term(), function()) :: Latu.Plan.expression()

aggregate/3,4 under Spark's other name for it. Same plan but for the function name.

reduce(column, initial, merge, finish)

@spec reduce(term(), term(), function(), function()) :: Latu.Plan.expression()

reduce/3 with the finishing lambda. Spark's other name for aggregate/4.

reverse(arg1)

@spec reverse(term()) :: Latu.Plan.expression()

Spark's reverse.

reverse(expr) - Returns a reversed string, a binary value with bytes in reverse order, or an array with reverse order of elements.

Examples (Spark SQL)

> SELECT reverse('Spark SQL');
LQS krapS
> SELECT reverse(array(2, 1, 4, 3));
[3,4,1,2]
> SELECT hex(reverse(x'CAFE'));
FECA

Note: Reverse logic for arrays is available since 2.4.0. Reverse logic for binary is available since 4.2.0.

size(arg1)

@spec size(term()) :: Latu.Plan.expression()

Spark's size.

size(expr) - Returns the size of an array or a map. This function returns -1 for null input only if spark.sql.ansi.enabled is false and spark.sql.legacy.sizeOfNull is true. Otherwise, it returns null for null input. With the default settings, the function returns null for null input.

Examples (Spark SQL)

> SELECT size(array('b', 'd', 'c', 'a'));
4
> SELECT size(map('a', 1, 'b', 2));
2

transform(column, fun)

@spec transform(term(), function()) :: Latu.Plan.expression()

Spark's transform. Takes a lambda — fn x -> ... end.

transform(expr, func) - Transforms elements in an array using the function.

Examples (Spark SQL)

> SELECT transform(array(1, 2, 3), x -> x + 1);
[2,3,4]
> SELECT transform(array(1, 2, 3), (x, i) -> x + i);
[1,3,5]

transform_keys(column, fun)

@spec transform_keys(term(), function()) :: Latu.Plan.expression()

Spark's transform_keys. Takes a lambda — fn x -> ... end.

transform_keys(expr, func) - Transforms elements in a map using the function.

Examples (Spark SQL)

> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + 1);
{2:1,3:2,4:3}
> SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
{2:1,4:2,6:3}

transform_values(column, fun)

@spec transform_values(term(), function()) :: Latu.Plan.expression()

Spark's transform_values. Takes a lambda — fn x -> ... end.

transform_values(expr, func) - Transforms values in the map using the function.

Examples (Spark SQL)

> SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> v + 1);
{1:2,2:3,3:4}
> SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -> k + v);
{1:2,2:4,3:6}

try_element_at(arg1, arg2)

@spec try_element_at(term(), term()) :: Latu.Plan.expression()

Spark's try_element_at.

try_element_at(array, index) - Returns element of array at given (1-based) index. If Index is 0, Spark will throw an error. If index < 0, accesses elements from the last to the first. The function always returns NULL if the index exceeds the length of the array. try_element_at(map, key) - Returns value for given key. The function always returns NULL if the key is not contained in the map.

Examples (Spark SQL)

> SELECT try_element_at(array(1, 2, 3), 2);
2
> SELECT try_element_at(map(1, 'a', 2, 'b'), 2);
b

zip_with(left, right, fun)

@spec zip_with(term(), term(), function()) :: Latu.Plan.expression()

Spark's zip_with. Takes two columns and a lambda.

zip_with(left, right, func) - Merges the two given arrays, element-wise, into a single array using function. If one array is shorter, nulls are appended at the end to match the length of the longer array, before applying function.

Examples (Spark SQL)

> SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -> (y, x));
[{"y":"a","x":1},{"y":"b","x":2},{"y":"c","x":3}]
> SELECT zip_with(array(1, 2), array(3, 4), (x, y) -> x + y);
[4,6]
> SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -> concat(x, y));
["ad","be","cf"]

Conditional Functions

coalesce(columns)

@spec coalesce([term()]) :: Latu.Plan.expression()

Spark's coalesce. Variadic in Spark; takes a list here.

coalesce(expr1, expr2, ...) - Returns the first non-null argument if exists. Otherwise, null.

Examples (Spark SQL)

> SELECT coalesce(NULL, 1, NULL);
1

ifnull(arg1, arg2)

@spec ifnull(term(), term()) :: Latu.Plan.expression()

Spark's ifnull.

ifnull(expr1, expr2) - Returns expr2 if expr1 is null, or expr1 otherwise.

Examples (Spark SQL)

> SELECT ifnull(NULL, array('2'));
["2"]

nanvl(arg1, arg2)

@spec nanvl(term(), term()) :: Latu.Plan.expression()

Spark's nanvl.

nanvl(expr1, expr2) - Returns expr1 if it's not NaN, or expr2 otherwise.

Examples (Spark SQL)

> SELECT nanvl(cast('NaN' as double), 123);
123.0

nullif(arg1, arg2)

@spec nullif(term(), term()) :: Latu.Plan.expression()

Spark's nullif.

nullif(expr1, expr2) - Returns null if expr1 equals to expr2, or expr1 otherwise.

Examples (Spark SQL)

> SELECT nullif(2, 2);
NULL

nullifzero(arg1)

@spec nullifzero(term()) :: Latu.Plan.expression()

Spark's nullifzero.

nullifzero(expr) - Returns null if expr is equal to zero, or expr otherwise.

Examples (Spark SQL)

> SELECT nullifzero(0);
NULL
> SELECT nullifzero(2);
2

nvl2(arg1, arg2, arg3)

@spec nvl2(term(), term(), term()) :: Latu.Plan.expression()

Spark's nvl2.

nvl2(expr1, expr2, expr3) - Returns expr2 if expr1 is not null, or expr3 otherwise.

Examples (Spark SQL)

> SELECT nvl2(NULL, 2, 1);
1

nvl(arg1, arg2)

@spec nvl(term(), term()) :: Latu.Plan.expression()

Spark's nvl.

nvl(expr1, expr2) - Returns expr2 if expr1 is null, or expr1 otherwise.

Examples (Spark SQL)

> SELECT nvl(NULL, array('2'));
["2"]

otherwise(chain, value)

@spec otherwise(Latu.CaseWhen.t(), term()) :: Latu.CaseWhen.t()

The else branch, ending a when_/2 chain.

when_(condition, value)

@spec when_(term(), term()) :: Latu.CaseWhen.t()

A conditional branch.

F.when_(greater(:id, 5), "big") |> F.otherwise("small")

F.when_(greater(:id, 100), "huge")
|> F.when_(greater(:id, 5), "big")
|> F.otherwise("small")

Spark spells this when, which is an Elixir operator rather than a special form — and unlike alias it is a syntax error to define, so not even a qualified call is possible. Hence the underscore, as in Latu.Column.not_/1.

Returns a Latu.CaseWhen, not an expression: the wire carries one when call and the chain is client-side, so the half-built state lives in a struct exactly as group_by's does. Latu.Plan.to_expr/1 coerces it wherever an expression is accepted.

With no otherwise/2 the else branch is NULL, as in SQL.

when_(chain, condition, value)

@spec when_(Latu.CaseWhen.t(), term(), term()) :: Latu.CaseWhen.t()

Add a branch to an existing chain. Refused once otherwise/2 has closed it.

zeroifnull(arg1)

@spec zeroifnull(term()) :: Latu.Plan.expression()

Spark's zeroifnull.

zeroifnull(expr) - Returns zero if expr is equal to null, or expr otherwise.

Examples (Spark SQL)

> SELECT zeroifnull(NULL);
0
> SELECT zeroifnull(2);
2

CSV Functions

from_csv(column, schema)

@spec from_csv(term(), term()) :: Latu.Plan.expression()

Spark's from_csv. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

from_csv(csvStr, schema[, options]) - Returns a struct value with the given csvStr and schema.

Examples (Spark SQL)

> SELECT from_csv('1, 0.8', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}

from_csv(column, schema, options)

@spec from_csv(term(), term(), keyword() | map()) :: Latu.Plan.expression()

Spark's from_csv. With parser options, following Latu.read/2's rules.

from_csv(csvStr, schema[, options]) - Returns a struct value with the given csvStr and schema.

Examples (Spark SQL)

> SELECT from_csv('1, 0.8', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}

schema_of_csv(column)

@spec schema_of_csv(term()) :: Latu.Plan.expression()

Spark's schema_of_csv. Options follow Latu.read/2's key and value rules.

schema_of_csv(csv[, options]) - Returns schema in the DDL format of CSV string.

Examples (Spark SQL)

> SELECT schema_of_csv('1,abc');
STRUCT<_c0: INT, _c1: STRING>

schema_of_csv(column, options)

@spec schema_of_csv(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's schema_of_csv. With parser options, following Latu.read/2's rules.

schema_of_csv(csv[, options]) - Returns schema in the DDL format of CSV string.

Examples (Spark SQL)

> SELECT schema_of_csv('1,abc');
STRUCT<_c0: INT, _c1: STRING>

to_csv(column)

@spec to_csv(term()) :: Latu.Plan.expression()

Spark's to_csv. Options follow Latu.read/2's key and value rules.

to_csv(expr[, options]) - Returns a CSV string with a given struct value

Examples (Spark SQL)

> SELECT to_csv(named_struct('a', 1, 'b', 2));
1,2
> SELECT to_csv(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
26/08/2015

to_csv(column, options)

@spec to_csv(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's to_csv. With parser options, following Latu.read/2's rules.

to_csv(expr[, options]) - Returns a CSV string with a given struct value

Examples (Spark SQL)

> SELECT to_csv(named_struct('a', 1, 'b', 2));
1,2
> SELECT to_csv(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
26/08/2015

Datasketch Functions

hll_sketch_estimate(arg1)

@spec hll_sketch_estimate(term()) :: Latu.Plan.expression()

Spark's hll_sketch_estimate.

hll_sketch_estimate(expr) - Returns the estimated number of unique values given the binary representation of a Datasketches HllSketch.

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3

hll_union(arg1, arg2)

@spec hll_union(term(), term()) :: Latu.Plan.expression()

Spark's hll_union. The trailing argument is optional.

hll_union(first, second, allowDifferentLgConfigK) - Merges two binary representations of Datasketches HllSketch objects, using a Datasketches Union object. Set allowDifferentLgConfigK to true to allow unions of sketches with different lgConfigK values (defaults to false).

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_union(hll_sketch_agg(col1), hll_sketch_agg(col2))) FROM VALUES (1, 4), (1, 4), (2, 5), (2, 5), (3, 6) tab(col1, col2);
6

hll_union(arg1, arg2, optional)

@spec hll_union(term(), term(), term()) :: Latu.Plan.expression()

Spark's hll_union. With the optional trailing argument.

hll_union(first, second, allowDifferentLgConfigK) - Merges two binary representations of Datasketches HllSketch objects, using a Datasketches Union object. Set allowDifferentLgConfigK to true to allow unions of sketches with different lgConfigK values (defaults to false).

Examples (Spark SQL)

> SELECT hll_sketch_estimate(hll_union(hll_sketch_agg(col1), hll_sketch_agg(col2))) FROM VALUES (1, 4), (1, 4), (2, 5), (2, 5), (3, 6) tab(col1, col2);
6

kll_sketch_get_n_bigint(arg1)

@spec kll_sketch_get_n_bigint(term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_n_bigint.

kll_sketch_get_n_double(arg1)

@spec kll_sketch_get_n_double(term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_n_double.

kll_sketch_get_n_float(arg1)

@spec kll_sketch_get_n_float(term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_n_float.

kll_sketch_get_quantile_bigint(arg1, arg2)

@spec kll_sketch_get_quantile_bigint(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_quantile_bigint.

kll_sketch_get_quantile_double(arg1, arg2)

@spec kll_sketch_get_quantile_double(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_quantile_double.

kll_sketch_get_quantile_float(arg1, arg2)

@spec kll_sketch_get_quantile_float(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_quantile_float.

kll_sketch_get_rank_bigint(arg1, arg2)

@spec kll_sketch_get_rank_bigint(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_rank_bigint.

kll_sketch_get_rank_double(arg1, arg2)

@spec kll_sketch_get_rank_double(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_rank_double.

kll_sketch_get_rank_float(arg1, arg2)

@spec kll_sketch_get_rank_float(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_get_rank_float.

kll_sketch_merge_bigint(arg1, arg2)

@spec kll_sketch_merge_bigint(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_merge_bigint.

kll_sketch_merge_double(arg1, arg2)

@spec kll_sketch_merge_double(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_merge_double.

kll_sketch_merge_float(arg1, arg2)

@spec kll_sketch_merge_float(term(), term()) :: Latu.Plan.expression()

Spark's kll_sketch_merge_float.

kll_sketch_to_string_bigint(arg1)

@spec kll_sketch_to_string_bigint(term()) :: Latu.Plan.expression()

Spark's kll_sketch_to_string_bigint.

kll_sketch_to_string_double(arg1)

@spec kll_sketch_to_string_double(term()) :: Latu.Plan.expression()

Spark's kll_sketch_to_string_double.

kll_sketch_to_string_float(arg1)

@spec kll_sketch_to_string_float(term()) :: Latu.Plan.expression()

Spark's kll_sketch_to_string_float.

theta_difference(arg1, arg2)

@spec theta_difference(term(), term()) :: Latu.Plan.expression()

Spark's theta_difference.

theta_intersection(arg1, arg2)

@spec theta_intersection(term(), term()) :: Latu.Plan.expression()

Spark's theta_intersection.

theta_sketch_estimate(arg1)

@spec theta_sketch_estimate(term()) :: Latu.Plan.expression()

Spark's theta_sketch_estimate.

theta_union(arg1, arg2)

@spec theta_union(term(), term()) :: Latu.Plan.expression()

Spark's theta_union. The trailing argument is optional.

theta_union(arg1, arg2, optional)

@spec theta_union(term(), term(), term()) :: Latu.Plan.expression()

Spark's theta_union. With the optional trailing argument.

tuple_difference_double(arg1, arg2)

@spec tuple_difference_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_difference_double.

tuple_difference_double(tupleSketch1, tupleSketch2) - Subtracts two binary representations of Datasketches TupleSketch objects with double summary data type using a TupleSketch AnotB object. Returns elements in the first sketch that are not in the second sketch.

Examples (Spark SQL)

> SELECT tuple_sketch_estimate_double(tuple_difference_double(tuple_sketch_agg_double(col1, val1), tuple_sketch_agg_double(col2, val2))) FROM VALUES (5, 5.0D, 4, 4.0D), (1, 1.0D, 4, 4.0D), (2, 2.0D, 5, 5.0D), (3, 3.0D, 1, 1.0D) tab(col1, val1, col2, val2);
2.0

tuple_difference_integer(arg1, arg2)

@spec tuple_difference_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_difference_integer.

tuple_difference_integer(tupleSketch1, tupleSketch2) - Subtracts two binary representations of Datasketches TupleSketch objects with integer summary data type using a TupleSketch AnotB object. Returns elements in the first sketch that are not in the second sketch.

Examples (Spark SQL)

> SELECT tuple_sketch_estimate_integer(tuple_difference_integer(tuple_sketch_agg_integer(col1, val1), tuple_sketch_agg_integer(col2, val2))) FROM VALUES (5, 5, 4, 4), (1, 1, 4, 4), (2, 2, 5, 5), (3, 3, 1, 1) tab(col1, val1, col2, val2);
2.0

tuple_difference_theta_double(arg1, arg2)

@spec tuple_difference_theta_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_difference_theta_double.

tuple_difference_theta_double(tupleSketch, thetaSketch) - Subtracts the binary representation of a Datasketches ThetaSketch from a TupleSketch with double summary data type using a TupleSketch AnotB object. Returns elements in the TupleSketch that are not in the ThetaSketch.

Examples (Spark SQL)

> SELECT tuple_sketch_estimate_double(tuple_difference_theta_double(tuple_sketch_agg_double(col1, val1), theta_sketch_agg(col2))) FROM VALUES (5, 5.0D, 4), (1, 1.0D, 4), (2, 2.0D, 5), (3, 3.0D, 1) tab(col1, val1, col2);
2.0

tuple_difference_theta_integer(arg1, arg2)

@spec tuple_difference_theta_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_difference_theta_integer.

tuple_difference_theta_integer(tupleSketch, thetaSketch) - Subtracts the binary representation of a Datasketches ThetaSketch from a TupleSketch with integer summary data type using a TupleSketch AnotB object. Returns elements in the TupleSketch that are not in the ThetaSketch.

Examples (Spark SQL)

> SELECT tuple_sketch_estimate_integer(tuple_difference_theta_integer(tuple_sketch_agg_integer(col1, val1), theta_sketch_agg(col2))) FROM VALUES (5, 5, 4), (1, 1, 4), (2, 2, 5), (3, 3, 1) tab(col1, val1, col2);
2.0

tuple_intersection_double(arg1, arg2)

@spec tuple_intersection_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_double. The trailing argument is optional.

tuple_intersection_double(arg1, arg2, optional)

@spec tuple_intersection_double(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_double. With the optional trailing argument.

tuple_intersection_integer(arg1, arg2)

@spec tuple_intersection_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_integer. The trailing argument is optional.

tuple_intersection_integer(arg1, arg2, optional)

@spec tuple_intersection_integer(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_integer. With the optional trailing argument.

tuple_intersection_theta_double(arg1, arg2)

@spec tuple_intersection_theta_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_theta_double. The trailing argument is optional.

tuple_intersection_theta_double(arg1, arg2, optional)

@spec tuple_intersection_theta_double(term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_intersection_theta_double. With the optional trailing argument.

tuple_intersection_theta_integer(arg1, arg2)

@spec tuple_intersection_theta_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_intersection_theta_integer. The trailing argument is optional.

tuple_intersection_theta_integer(arg1, arg2, optional)

@spec tuple_intersection_theta_integer(term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_intersection_theta_integer. With the optional trailing argument.

tuple_sketch_estimate_double(arg1)

@spec tuple_sketch_estimate_double(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_estimate_double.

tuple_sketch_estimate_integer(arg1)

@spec tuple_sketch_estimate_integer(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_estimate_integer.

tuple_sketch_summary_double(arg1)

@spec tuple_sketch_summary_double(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_summary_double. The trailing argument is optional.

tuple_sketch_summary_double(arg1, optional)

@spec tuple_sketch_summary_double(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's tuple_sketch_summary_double. With the optional trailing argument.

tuple_sketch_summary_integer(arg1)

@spec tuple_sketch_summary_integer(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_summary_integer. The trailing argument is optional.

tuple_sketch_summary_integer(arg1, optional)

@spec tuple_sketch_summary_integer(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's tuple_sketch_summary_integer. With the optional trailing argument.

tuple_sketch_theta_double(arg1)

@spec tuple_sketch_theta_double(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_theta_double.

tuple_sketch_theta_double(child) - Returns the theta value (sampling rate) from a Datasketches TupleSketch. The theta value represents the effective sampling rate of the sketch, between 0.0 and 1.0. The sketch's summary type must be a double.

Examples (Spark SQL)

> SELECT tuple_sketch_theta_double(tuple_sketch_agg_double(key, summary)) FROM VALUES (1, 1.0D), (2, 2.0D), (3, 3.0D) tab(key, summary);
1.0

tuple_sketch_theta_integer(arg1)

@spec tuple_sketch_theta_integer(term()) :: Latu.Plan.expression()

Spark's tuple_sketch_theta_integer.

tuple_sketch_theta_integer(child) - Returns the theta value (sampling rate) from a Datasketches TupleSketch. The theta value represents the effective sampling rate of the sketch, between 0.0 and 1.0. The sketch's summary type must be an integer.

Examples (Spark SQL)

> SELECT tuple_sketch_theta_integer(tuple_sketch_agg_integer(key, summary)) FROM VALUES (1, 1), (2, 2), (3, 3) tab(key, summary);
1.0

tuple_union_double(arg1, arg2)

@spec tuple_union_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_double. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_double(arg1, arg2, arg3)

@spec tuple_union_double(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_double. Sends Spark's defaults for the rest: "sum".

tuple_union_double(arg1, arg2, arg3, arg4)

@spec tuple_union_double(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_double. Every argument is sent.

tuple_union_integer(arg1, arg2)

@spec tuple_union_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_integer. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_integer(arg1, arg2, arg3)

@spec tuple_union_integer(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_integer. Sends Spark's defaults for the rest: "sum".

tuple_union_integer(arg1, arg2, arg3, arg4)

@spec tuple_union_integer(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_integer. Every argument is sent.

tuple_union_theta_double(arg1, arg2)

@spec tuple_union_theta_double(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_theta_double. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_theta_double(arg1, arg2, arg3)

@spec tuple_union_theta_double(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_theta_double. Sends Spark's defaults for the rest: "sum".

tuple_union_theta_double(arg1, arg2, arg3, arg4)

@spec tuple_union_theta_double(term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_union_theta_double. Every argument is sent.

tuple_union_theta_integer(arg1, arg2)

@spec tuple_union_theta_integer(term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_theta_integer. Sends Spark's defaults for the rest: 12, "sum".

tuple_union_theta_integer(arg1, arg2, arg3)

@spec tuple_union_theta_integer(term(), term(), term()) :: Latu.Plan.expression()

Spark's tuple_union_theta_integer. Sends Spark's defaults for the rest: "sum".

tuple_union_theta_integer(arg1, arg2, arg3, arg4)

@spec tuple_union_theta_integer(term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's tuple_union_theta_integer. Every argument is sent.

Date and Timestamp Functions

add_months(arg1, arg2)

@spec add_months(term(), term()) :: Latu.Plan.expression()

Spark's add_months.

add_months(start_date, num_months) - Returns the date that is num_months after start_date.

Examples (Spark SQL)

> SELECT add_months('2016-08-31', 1);
2016-09-30

convert_timezone(target_tz, source_ts)

@spec convert_timezone(term(), term()) :: Latu.Plan.expression()

Move a timestamp between time zones.

With two arguments the source zone is the session's; the optional one comes first, which is why this cannot be a registry row — a generated wrapper would have sent three arguments always, and nil for the first would encode a NULL rather than an absence.

convert_timezone(source_tz, target_tz, source_ts)

@spec convert_timezone(term(), term(), term()) :: Latu.Plan.expression()

With the source timezone given, rather than the session's.

curdate()

@spec curdate() :: Latu.Plan.expression()

Spark's curdate.

curdate() - Returns the current date at the start of query evaluation. All calls of curdate within the same query return the same value.

Examples (Spark SQL)

> SELECT curdate();
2022-09-06

current_date()

@spec current_date() :: Latu.Plan.expression()

Spark's current_date.

current_date() - Returns the current date at the start of query evaluation. All calls of current_date within the same query return the same value. current_date - Returns the current date at the start of query evaluation.

Examples (Spark SQL)

> SELECT current_date();
2020-04-25
> SELECT current_date;
2020-04-25

Note: The syntax without braces has been supported since 2.0.1.

current_time()

@spec current_time() :: Latu.Plan.expression()

Spark's current_time. The trailing argument is optional.

current_time([precision]) - Returns the current time at the start of query evaluation. All calls of current_time within the same query return the same value. current_time - Returns the current time at the start of query evaluation.

Examples (Spark SQL)

> SELECT current_time();
15:49:11.914120
> SELECT current_time;
15:49:11.914120
> SELECT current_time(0);
15:49:11
> SELECT current_time(3);
15:49:11.914
> SELECT current_time(1+1);
15:49:11.91

current_time(optional)

@spec current_time(term()) :: Latu.Plan.expression()

Spark's current_time. With the optional trailing argument.

current_time([precision]) - Returns the current time at the start of query evaluation. All calls of current_time within the same query return the same value. current_time - Returns the current time at the start of query evaluation.

Examples (Spark SQL)

> SELECT current_time();
15:49:11.914120
> SELECT current_time;
15:49:11.914120
> SELECT current_time(0);
15:49:11
> SELECT current_time(3);
15:49:11.914
> SELECT current_time(1+1);
15:49:11.91

current_timestamp()

@spec current_timestamp() :: Latu.Plan.expression()

Spark's current_timestamp.

current_timestamp() - Returns the current timestamp at the start of query evaluation. All calls of current_timestamp within the same query return the same value. current_timestamp - Returns the current timestamp at the start of query evaluation.

Examples (Spark SQL)

> SELECT current_timestamp();
2020-04-25 15:49:11.914
> SELECT current_timestamp;
2020-04-25 15:49:11.914

Note: The syntax without braces has been supported since 2.0.1.

current_timezone()

@spec current_timezone() :: Latu.Plan.expression()

Spark's current_timezone.

current_timezone() - Returns the current session local timezone.

Examples (Spark SQL)

> SELECT current_timezone();
Asia/Shanghai

date_add(arg1, arg2)

@spec date_add(term(), term()) :: Latu.Plan.expression()

Spark's date_add.

date_add(start_date, num_days) - Returns the date that is num_days after start_date.

Examples (Spark SQL)

> SELECT date_add('2016-07-30', 1);
2016-07-31

date_diff(arg1, arg2)

@spec date_diff(term(), term()) :: Latu.Plan.expression()

Spark's date_diff.

date_diff(endDate, startDate) - Returns the number of days from startDate to endDate.

Examples (Spark SQL)

> SELECT date_diff('2009-07-31', '2009-07-30');
1
> SELECT date_diff('2009-07-30', '2009-07-31');
-1

date_format(arg1, arg2)

@spec date_format(term(), term()) :: Latu.Plan.expression()

Spark's date_format.

date_format(timestamp, fmt) - Converts timestamp to a value of string in the format specified by the date format fmt.

Examples (Spark SQL)

> SELECT date_format('2016-04-08', 'y');
2016

date_from_unix_date(arg1)

@spec date_from_unix_date(term()) :: Latu.Plan.expression()

Spark's date_from_unix_date.

date_from_unix_date(days) - Create date from the number of days since 1970-01-01.

Examples (Spark SQL)

> SELECT date_from_unix_date(1);
1970-01-02

date_part(arg1, arg2)

@spec date_part(term(), term()) :: Latu.Plan.expression()

Spark's date_part.

date_part(field, source) - Extracts a part of the date/timestamp or interval source.

Examples (Spark SQL)

> SELECT date_part('YEAR', TIMESTAMP '2019-08-12 01:00:00.123456');
2019
> SELECT date_part('week', timestamp'2019-08-12 01:00:00.123456');
33
> SELECT date_part('doy', DATE'2019-08-12');
224
> SELECT date_part('SECONDS', timestamp'2019-10-01 00:00:01.000001');
1.000001
> SELECT date_part('days', interval 5 days 3 hours 7 minutes);
5
> SELECT date_part('seconds', interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
> SELECT date_part('MONTH', INTERVAL '2021-11' YEAR TO MONTH);
11
> SELECT date_part('MINUTE', INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55

Note: The date_part function is equivalent to the SQL-standard function EXTRACT(field FROM source)

date_sub(arg1, arg2)

@spec date_sub(term(), term()) :: Latu.Plan.expression()

Spark's date_sub.

date_sub(start_date, num_days) - Returns the date that is num_days before start_date.

Examples (Spark SQL)

> SELECT date_sub('2016-07-30', 1);
2016-07-29

date_trunc(arg1, arg2)

@spec date_trunc(term(), term()) :: Latu.Plan.expression()

Spark's date_trunc.

date_trunc(fmt, ts) - Returns timestamp ts truncated to the unit specified by the format model fmt.

Examples (Spark SQL)

> SELECT date_trunc('YEAR', '2015-03-05T09:32:05.359');
2015-01-01 00:00:00
> SELECT date_trunc('MM', '2015-03-05T09:32:05.359');
2015-03-01 00:00:00
> SELECT date_trunc('DD', '2015-03-05T09:32:05.359');
2015-03-05 00:00:00
> SELECT date_trunc('HOUR', '2015-03-05T09:32:05.359');
2015-03-05 09:00:00
> SELECT date_trunc('MILLISECOND', '2015-03-05T09:32:05.123456');
2015-03-05 09:32:05.123

dateadd(arg1, arg2)

@spec dateadd(term(), term()) :: Latu.Plan.expression()

Spark's dateadd.

dateadd(start_date, num_days) - Returns the date that is num_days after start_date.

Examples (Spark SQL)

> SELECT dateadd('2016-07-30', 1);
2016-07-31

datediff(arg1, arg2)

@spec datediff(term(), term()) :: Latu.Plan.expression()

Spark's datediff.

datediff(endDate, startDate) - Returns the number of days from startDate to endDate.

Examples (Spark SQL)

> SELECT datediff('2009-07-31', '2009-07-30');
1
> SELECT datediff('2009-07-30', '2009-07-31');
-1

datepart(arg1, arg2)

@spec datepart(term(), term()) :: Latu.Plan.expression()

Spark's datepart.

datepart(field, source) - Extracts a part of the date/timestamp or interval source.

Examples (Spark SQL)

> SELECT datepart('YEAR', TIMESTAMP '2019-08-12 01:00:00.123456');
2019
> SELECT datepart('week', timestamp'2019-08-12 01:00:00.123456');
33
> SELECT datepart('doy', DATE'2019-08-12');
224
> SELECT datepart('SECONDS', timestamp'2019-10-01 00:00:01.000001');
1.000001
> SELECT datepart('days', interval 5 days 3 hours 7 minutes);
5
> SELECT datepart('seconds', interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
> SELECT datepart('MONTH', INTERVAL '2021-11' YEAR TO MONTH);
11
> SELECT datepart('MINUTE', INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55

Note: The datepart function is equivalent to the SQL-standard function EXTRACT(field FROM source)

day(arg1)

@spec day(term()) :: Latu.Plan.expression()

Spark's day.

day(date) - Returns the day of month of the date/timestamp.

Examples (Spark SQL)

> SELECT day('2009-07-30');
30

dayname(arg1)

@spec dayname(term()) :: Latu.Plan.expression()

Spark's dayname.

dayname(date) - Returns the three-letter abbreviated day name from the given date.

Examples (Spark SQL)

> SELECT dayname(DATE('2008-02-20'));
Wed

dayofmonth(arg1)

@spec dayofmonth(term()) :: Latu.Plan.expression()

Spark's dayofmonth.

dayofmonth(date) - Returns the day of month of the date/timestamp.

Examples (Spark SQL)

> SELECT dayofmonth('2009-07-30');
30

dayofweek(arg1)

@spec dayofweek(term()) :: Latu.Plan.expression()

Spark's dayofweek.

dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).

Examples (Spark SQL)

> SELECT dayofweek('2009-07-30');
5

dayofyear(arg1)

@spec dayofyear(term()) :: Latu.Plan.expression()

Spark's dayofyear.

dayofyear(date) - Returns the day of year of the date/timestamp.

Examples (Spark SQL)

> SELECT dayofyear('2016-04-09');
100

extract(arg1, arg2)

@spec extract(term(), term()) :: Latu.Plan.expression()

Spark's extract.

extract(field FROM source) - Extracts a part of the date or timestamp or time or interval source.

Examples (Spark SQL)

> SELECT extract(YEAR FROM TIMESTAMP '2019-08-12 01:00:00.123456');
2019
> SELECT extract(week FROM timestamp'2019-08-12 01:00:00.123456');
33
> SELECT extract(doy FROM DATE'2019-08-12');
224
> SELECT extract(SECONDS FROM timestamp'2019-10-01 00:00:01.000001');
1.000001
> SELECT extract(days FROM interval 5 days 3 hours 7 minutes);
5
> SELECT extract(seconds FROM interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
> SELECT extract(MONTH FROM INTERVAL '2021-11' YEAR TO MONTH);
11
> SELECT extract(MINUTE FROM INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55
> SELECT extract(HOUR FROM time '09:08:01.000001');
9
> SELECT extract(MINUTE FROM time '09:08:01.000001');
8
> SELECT extract(SECOND FROM time '09:08:01.000001');
1.000001

Note: The extract function is equivalent to date_part(field, source).

from_unixtime(arg1)

@spec from_unixtime(term()) :: Latu.Plan.expression()

Spark's from_unixtime. Sends Spark's defaults for the rest: "yyyy-MM-dd HH:mm:ss".

from_unixtime(unix_time[, fmt]) - Returns unix_time in the specified fmt.

Examples (Spark SQL)

> SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss');
1969-12-31 16:00:00
> SELECT from_unixtime(0);
1969-12-31 16:00:00

from_unixtime(arg1, arg2)

@spec from_unixtime(term(), term()) :: Latu.Plan.expression()

Spark's from_unixtime. Every argument is sent.

from_unixtime(unix_time[, fmt]) - Returns unix_time in the specified fmt.

Examples (Spark SQL)

> SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss');
1969-12-31 16:00:00
> SELECT from_unixtime(0);
1969-12-31 16:00:00

from_utc_timestamp(arg1, arg2)

@spec from_utc_timestamp(term(), term()) :: Latu.Plan.expression()

Spark's from_utc_timestamp.

from_utc_timestamp(timestamp, timezone) - Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in UTC, and renders that time as a timestamp in the given time zone. For example, 'GMT+1' would yield '2017-07-14 03:40:00.0'.

Examples (Spark SQL)

> SELECT from_utc_timestamp('2016-08-31', 'Asia/Seoul');
2016-08-31 09:00:00

hour(arg1)

@spec hour(term()) :: Latu.Plan.expression()

Spark's hour.

hour(expr) - Returns the hour component of the given expression. If expr is a TIMESTAMP or a string that can be cast to timestamp, it returns the hour of that timestamp. If expr is a TIME type (since 4.1.0), it returns the hour of the time-of-day.

Examples (Spark SQL)

> SELECT hour('2018-02-14 12:58:59');
12
> SELECT hour(TIME'13:59:59.999999');
13

last_day(arg1)

@spec last_day(term()) :: Latu.Plan.expression()

Spark's last_day.

last_day(date) - Returns the last day of the month which the date belongs to.

Examples (Spark SQL)

> SELECT last_day('2009-01-12');
2009-01-31

localtimestamp()

@spec localtimestamp() :: Latu.Plan.expression()

Spark's localtimestamp.

localtimestamp() - Returns the current timestamp without time zone at the start of query evaluation. All calls of localtimestamp within the same query return the same value. localtimestamp - Returns the current local date-time at the session time zone at the start of query evaluation.

Examples (Spark SQL)

> SELECT localtimestamp();
2020-04-25 15:49:11.914

make_date(arg1, arg2, arg3)

@spec make_date(term(), term(), term()) :: Latu.Plan.expression()

Spark's make_date.

make_date(year, month, day) - Create date from year, month and day fields. If the configuration spark.sql.ansi.enabled is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead.

Examples (Spark SQL)

> SELECT make_date(2013, 7, 15);
2013-07-15
> SELECT make_date(2019, 7, NULL);
NULL

make_dt_interval()

@spec make_dt_interval() :: Latu.Plan.expression()

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
> SELECT make_dt_interval(2);
2 00:00:00.000000000
> SELECT make_dt_interval(100, null, 3);
NULL

make_dt_interval(arg1)

@spec make_dt_interval(term()) :: Latu.Plan.expression()

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
> SELECT make_dt_interval(2);
2 00:00:00.000000000
> SELECT make_dt_interval(100, null, 3);
NULL

make_dt_interval(arg1, arg2)

@spec make_dt_interval(term(), term()) :: Latu.Plan.expression()

Spark's make_dt_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
> SELECT make_dt_interval(2);
2 00:00:00.000000000
> SELECT make_dt_interval(100, null, 3);
NULL

make_dt_interval(arg1, arg2, arg3)

@spec make_dt_interval(term(), term(), term()) :: Latu.Plan.expression()

Spark's make_dt_interval. Sends Spark's defaults for the rest: Decimal.new("0").

make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
> SELECT make_dt_interval(2);
2 00:00:00.000000000
> SELECT make_dt_interval(100, null, 3);
NULL

make_dt_interval(arg1, arg2, arg3, arg4)

@spec make_dt_interval(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's make_dt_interval. Every argument is sent.

make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
> SELECT make_dt_interval(2);
2 00:00:00.000000000
> SELECT make_dt_interval(100, null, 3);
NULL

make_interval()

@spec make_interval() :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1)

@spec make_interval(term()) :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2)

@spec make_interval(term(), term()) :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2, arg3)

@spec make_interval(term(), term(), term()) :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2, arg3, arg4)

@spec make_interval(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2, arg3, arg4, arg5)

@spec make_interval(term(), term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2, arg3, arg4, arg5, arg6)

@spec make_interval(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_interval. Sends Spark's defaults for the rest: Decimal.new("0").

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_interval(arg1, arg2, arg3, arg4, arg5, arg6, arg7)

@spec make_interval(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_interval. Every argument is sent.

make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.

Examples (Spark SQL)

> SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT make_interval(100, null, 3);
NULL
> SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds

make_time(arg1, arg2, arg3)

@spec make_time(term(), term(), term()) :: Latu.Plan.expression()

Spark's make_time.

make_time(hour, minute, second) - Create time from hour, minute and second fields. For invalid inputs it will throw an error.

Examples (Spark SQL)

> SELECT make_time(6, 30, 45.887);
06:30:45.887
> SELECT make_time(NULL, 30, 0);
NULL

make_timestamp(arg1, arg2)

@spec make_timestamp(term(), term()) :: Latu.Plan.expression()

Spark's make_timestamp. One of several arities; they do not overlap.

make_timestamp(arg1, arg2, arg3)

@spec make_timestamp(term(), term(), term()) :: Latu.Plan.expression()

Spark's make_timestamp. One of several arities; they do not overlap.

make_timestamp(arg1, arg2, arg3, arg4, arg5, arg6)

@spec make_timestamp(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_timestamp. One of several arities; they do not overlap.

make_timestamp(arg1, arg2, arg3, arg4, arg5, arg6, arg7)

@spec make_timestamp(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_timestamp. One of several arities; they do not overlap.

make_timestamp_ltz(arg1, arg2, arg3, arg4, arg5, arg6)

@spec make_timestamp_ltz(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_timestamp_ltz. The trailing argument is optional.

make_timestamp_ltz(year, month, day, hour, min, sec[, timezone]) - Create the current timestamp with local time zone from year, month, day, hour, min, sec and (optional) timezone fields. If the configuration spark.sql.ansi.enabled is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead. make_timestamp_ltz(date, time[, timezone]) - Create a local date-time from date, time and (optional) timezone fields.

Examples (Spark SQL)

> SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
> SELECT make_timestamp_ltz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
> SELECT make_timestamp_ltz(null, 7, 22, 15, 30, 0);
NULL
> SELECT make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887');
2014-12-28 06:30:45.887
> SELECT make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887', 'CET');
2014-12-27 21:30:45.887

make_timestamp_ltz(arg1, arg2, arg3, arg4, arg5, arg6, optional)

@spec make_timestamp_ltz(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_timestamp_ltz. With the optional trailing argument.

make_timestamp_ltz(year, month, day, hour, min, sec[, timezone]) - Create the current timestamp with local time zone from year, month, day, hour, min, sec and (optional) timezone fields. If the configuration spark.sql.ansi.enabled is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead. make_timestamp_ltz(date, time[, timezone]) - Create a local date-time from date, time and (optional) timezone fields.

Examples (Spark SQL)

> SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
> SELECT make_timestamp_ltz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
> SELECT make_timestamp_ltz(null, 7, 22, 15, 30, 0);
NULL
> SELECT make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887');
2014-12-28 06:30:45.887
> SELECT make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887', 'CET');
2014-12-27 21:30:45.887

make_timestamp_ntz(arg1, arg2)

@spec make_timestamp_ntz(term(), term()) :: Latu.Plan.expression()

Spark's make_timestamp_ntz. One of several arities; they do not overlap.

make_timestamp_ntz(arg1, arg2, arg3, arg4, arg5, arg6)

@spec make_timestamp_ntz(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's make_timestamp_ntz. One of several arities; they do not overlap.

make_ym_interval()

@spec make_ym_interval() :: Latu.Plan.expression()

Spark's make_ym_interval. Sends Spark's defaults for the rest: 0, 0.

make_ym_interval([years[, months]]) - Make year-month interval from years, months.

Examples (Spark SQL)

> SELECT make_ym_interval(1, 2);
1-2
> SELECT make_ym_interval(1, 0);
1-0
> SELECT make_ym_interval(-1, 1);
-0-11
> SELECT make_ym_interval(2);
2-0

make_ym_interval(arg1)

@spec make_ym_interval(term()) :: Latu.Plan.expression()

Spark's make_ym_interval. Sends Spark's defaults for the rest: 0.

make_ym_interval([years[, months]]) - Make year-month interval from years, months.

Examples (Spark SQL)

> SELECT make_ym_interval(1, 2);
1-2
> SELECT make_ym_interval(1, 0);
1-0
> SELECT make_ym_interval(-1, 1);
-0-11
> SELECT make_ym_interval(2);
2-0

make_ym_interval(arg1, arg2)

@spec make_ym_interval(term(), term()) :: Latu.Plan.expression()

Spark's make_ym_interval. Every argument is sent.

make_ym_interval([years[, months]]) - Make year-month interval from years, months.

Examples (Spark SQL)

> SELECT make_ym_interval(1, 2);
1-2
> SELECT make_ym_interval(1, 0);
1-0
> SELECT make_ym_interval(-1, 1);
-0-11
> SELECT make_ym_interval(2);
2-0

minute(arg1)

@spec minute(term()) :: Latu.Plan.expression()

Spark's minute.

minute(expr) - Returns the minute component of the given expression. If expr is a TIMESTAMP or a string that can be cast to timestamp, it returns the minute of that timestamp. If expr is a TIME type (since 4.1.0), it returns the minute of the time-of-day.

Examples (Spark SQL)

> SELECT minute('2009-07-30 12:58:59');
58
> SELECT minute(TIME'23:59:59.999999');
59

month(arg1)

@spec month(term()) :: Latu.Plan.expression()

Spark's month.

month(date) - Returns the month component of the date/timestamp.

Examples (Spark SQL)

> SELECT month('2016-07-30');
7

monthname(arg1)

@spec monthname(term()) :: Latu.Plan.expression()

Spark's monthname.

monthname(date) - Returns the three-letter abbreviated month name from the given date.

Examples (Spark SQL)

> SELECT monthname('2008-02-20');
Feb

months_between(arg1, arg2)

@spec months_between(term(), term()) :: Latu.Plan.expression()

Spark's months_between. Sends Spark's defaults for the rest: true.

months_between(timestamp1, timestamp2[, roundOff]) - If timestamp1 is later than timestamp2, then the result is positive. If timestamp1 and timestamp2 are on the same day of month, or both are the last day of month, time of day will be ignored. Otherwise, the difference is calculated based on 31 days per month, and rounded to 8 digits unless roundOff=false.

Examples (Spark SQL)

> SELECT months_between('1997-02-28 10:30:00', '1996-10-30');
3.94959677
> SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false);
3.9495967741935485

months_between(arg1, arg2, arg3)

@spec months_between(term(), term(), term()) :: Latu.Plan.expression()

Spark's months_between. Every argument is sent.

months_between(timestamp1, timestamp2[, roundOff]) - If timestamp1 is later than timestamp2, then the result is positive. If timestamp1 and timestamp2 are on the same day of month, or both are the last day of month, time of day will be ignored. Otherwise, the difference is calculated based on 31 days per month, and rounded to 8 digits unless roundOff=false.

Examples (Spark SQL)

> SELECT months_between('1997-02-28 10:30:00', '1996-10-30');
3.94959677
> SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false);
3.9495967741935485

next_day(arg1, arg2)

@spec next_day(term(), term()) :: Latu.Plan.expression()

Spark's next_day.

next_day(start_date, day_of_week) - Returns the first date which is later than start_date and named as indicated. The function returns NULL if at least one of the input parameters is NULL. When both of the input parameters are not NULL and day_of_week is an invalid input, the function throws SparkIllegalArgumentException if spark.sql.ansi.enabled is set to true, otherwise NULL.

Examples (Spark SQL)

> SELECT next_day('2015-01-14', 'TU');
2015-01-20

now()

@spec now() :: Latu.Plan.expression()

Spark's now.

now() - Returns the current timestamp at the start of query evaluation.

Examples (Spark SQL)

> SELECT now();
2020-04-25 15:49:11.914

quarter(arg1)

@spec quarter(term()) :: Latu.Plan.expression()

Spark's quarter.

quarter(date) - Returns the quarter of the year for date, in the range 1 to 4.

Examples (Spark SQL)

> SELECT quarter('2016-08-31');
3

second(arg1)

@spec second(term()) :: Latu.Plan.expression()

Spark's second.

second(expr) - Returns the second component of the given expression. If expr is a TIMESTAMP or a string that can be cast to timestamp, it returns the second of that timestamp. If expr is a TIME type (since 4.1.0), it returns the second of the time-of-day.

Examples (Spark SQL)

> SELECT second('2018-02-14 12:58:59');
59
> SELECT second(TIME'13:25:59.999999');
59

session_window(arg1, arg2)

@spec session_window(term(), term()) :: Latu.Plan.expression()

Spark's session_window.

session_window(time_column, gap_duration) - Generates session window given a timestamp specifying column and gap duration. See <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#types-of-time-windows">'Types of time windows'</a> in Structured Streaming guide doc for detailed explanation and examples.

Examples (Spark SQL)

> SELECT a, session_window.start, session_window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:10:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, session_window(b, '5 minutes') ORDER BY a, start;
A1	2021-01-01 00:00:00	2021-01-01 00:09:30	2
A1	2021-01-01 00:10:00	2021-01-01 00:15:00	1
A2	2021-01-01 00:01:00	2021-01-01 00:06:00	1
> SELECT a, session_window.start, session_window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:10:00'), ('A2', '2021-01-01 00:01:00'), ('A2', '2021-01-01 00:04:30') AS tab(a, b) GROUP by a, session_window(b, CASE WHEN a = 'A1' THEN '5 minutes' WHEN a = 'A2' THEN '1 minute' ELSE '10 minutes' END) ORDER BY a, start;
A1	2021-01-01 00:00:00	2021-01-01 00:09:30	2
A1	2021-01-01 00:10:00	2021-01-01 00:15:00	1
A2	2021-01-01 00:01:00	2021-01-01 00:02:00	1
A2	2021-01-01 00:04:30	2021-01-01 00:05:30	1

time_bucket(arg1, arg2)

@spec time_bucket(term(), term()) :: Latu.Plan.expression()

Spark's time_bucket. The trailing argument is optional.

time_bucket(bucketSize, ts[, origin]) - Returns the start of the bucket that ts falls into, where buckets are defined by the given bucketSize interval aligned to optional origin. For TIMESTAMP_NTZ, bucketing is performed in UTC. For TIMESTAMP, year-month interval buckets and calendar-day components of day-time interval buckets align to the session time zone.

Examples (Spark SQL)

> SELECT time_bucket(INTERVAL '15' MINUTE, TIMESTAMP '2024-01-01 11:27:00', TIMESTAMP '1970-01-01 00:00:00');
2024-01-01 11:15:00
> SELECT time_bucket(INTERVAL '1' HOUR, TIMESTAMP '2024-01-01 11:27:00');
2024-01-01 11:00:00
> SELECT time_bucket(INTERVAL '1' MONTH, TIMESTAMP '2024-07-20 14:30:00', TIMESTAMP '2024-06-15 09:00:00');
2024-07-15 09:00:00

time_bucket(arg1, arg2, optional)

@spec time_bucket(term(), term(), term()) :: Latu.Plan.expression()

Spark's time_bucket. With the optional trailing argument.

time_bucket(bucketSize, ts[, origin]) - Returns the start of the bucket that ts falls into, where buckets are defined by the given bucketSize interval aligned to optional origin. For TIMESTAMP_NTZ, bucketing is performed in UTC. For TIMESTAMP, year-month interval buckets and calendar-day components of day-time interval buckets align to the session time zone.

Examples (Spark SQL)

> SELECT time_bucket(INTERVAL '15' MINUTE, TIMESTAMP '2024-01-01 11:27:00', TIMESTAMP '1970-01-01 00:00:00');
2024-01-01 11:15:00
> SELECT time_bucket(INTERVAL '1' HOUR, TIMESTAMP '2024-01-01 11:27:00');
2024-01-01 11:00:00
> SELECT time_bucket(INTERVAL '1' MONTH, TIMESTAMP '2024-07-20 14:30:00', TIMESTAMP '2024-06-15 09:00:00');
2024-07-15 09:00:00

time_diff(arg1, arg2, arg3)

@spec time_diff(term(), term(), term()) :: Latu.Plan.expression()

Spark's time_diff.

time_diff(unit, start, end) - Gets the difference between the times in the specified units.

Examples (Spark SQL)

> SELECT time_diff('HOUR', TIME'20:30:29', TIME'21:30:28');
0
> SELECT time_diff('HOUR', TIME'20:30:29', TIME'21:30:29');
1
> SELECT time_diff('HOUR', TIME'20:30:29', TIME'12:00:00');
-8

time_from_micros(arg1)

@spec time_from_micros(term()) :: Latu.Plan.expression()

Spark's time_from_micros.

time_from_micros(micros) - Creates a TIME value from microseconds since midnight.

Examples (Spark SQL)

> SELECT time_from_micros(0);
00:00:00
> SELECT time_from_micros(52200000000);
14:30:00
> SELECT time_from_micros(52200500000);
14:30:00.5
> SELECT time_from_micros(86399999999);
23:59:59.999999

time_from_millis(arg1)

@spec time_from_millis(term()) :: Latu.Plan.expression()

Spark's time_from_millis.

time_from_millis(millis) - Creates a TIME value from milliseconds since midnight.

Examples (Spark SQL)

> SELECT time_from_millis(0);
00:00:00
> SELECT time_from_millis(52200000);
14:30:00
> SELECT time_from_millis(52200500);
14:30:00.5
> SELECT time_from_millis(86399999);
23:59:59.999

time_from_seconds(arg1)

@spec time_from_seconds(term()) :: Latu.Plan.expression()

Spark's time_from_seconds.

time_from_seconds(seconds) - Creates a TIME value from seconds since midnight.

Examples (Spark SQL)

> SELECT time_from_seconds(0);
00:00:00
> SELECT time_from_seconds(52200);
14:30:00
> SELECT time_from_seconds(52200.5);
14:30:00.5
> SELECT time_from_seconds(86399.999999);
23:59:59.999999

time_to_micros(arg1)

@spec time_to_micros(term()) :: Latu.Plan.expression()

Spark's time_to_micros.

time_to_micros(time) - Returns the number of microseconds since midnight for the given TIME value.

Examples (Spark SQL)

> SELECT time_to_micros(TIME'00:00:00');
0
> SELECT time_to_micros(TIME'14:30:00');
52200000000
> SELECT time_to_micros(TIME'14:30:00.5');
52200500000
> SELECT time_to_micros(TIME'23:59:59.999999');
86399999999

time_to_millis(arg1)

@spec time_to_millis(term()) :: Latu.Plan.expression()

Spark's time_to_millis.

time_to_millis(time) - Returns the number of milliseconds since midnight for the given TIME value.

Examples (Spark SQL)

> SELECT time_to_millis(TIME'00:00:00');
0
> SELECT time_to_millis(TIME'14:30:00');
52200000
> SELECT time_to_millis(TIME'14:30:00.5');
52200500
> SELECT time_to_millis(TIME'23:59:59.999');
86399999

time_to_seconds(arg1)

@spec time_to_seconds(term()) :: Latu.Plan.expression()

Spark's time_to_seconds.

time_to_seconds(time) - Returns the number of seconds since midnight for the given TIME value.

Examples (Spark SQL)

> SELECT time_to_seconds(TIME'00:00:00');
0.000000
> SELECT time_to_seconds(TIME'14:30:00');
52200.000000
> SELECT time_to_seconds(TIME'14:30:00.5');
52200.500000
> SELECT time_to_seconds(TIME'23:59:59.999999');
86399.999999

time_trunc(arg1, arg2)

@spec time_trunc(term(), term()) :: Latu.Plan.expression()

Spark's time_trunc.

time_trunc(unit, time) - Returns time truncated to the unit.

Examples (Spark SQL)

> SELECT time_trunc('HOUR', TIME'09:32:05.359');
09:00:00
> SELECT time_trunc('MILLISECOND', TIME'09:32:05.123456');
09:32:05.123

timestamp_add(arg1, arg2, arg3)

@spec timestamp_add(term(), term(), term()) :: Latu.Plan.expression()

Spark's timestampadd.

timestamp_diff(arg1, arg2, arg3)

@spec timestamp_diff(term(), term(), term()) :: Latu.Plan.expression()

Spark's timestampdiff.

timestamp_micros(arg1)

@spec timestamp_micros(term()) :: Latu.Plan.expression()

Spark's timestamp_micros.

timestamp_micros(microseconds) - Creates timestamp from the number of microseconds since UTC epoch.

Examples (Spark SQL)

> SELECT timestamp_micros(1230219000123123);
2008-12-25 07:30:00.123123

timestamp_millis(arg1)

@spec timestamp_millis(term()) :: Latu.Plan.expression()

Spark's timestamp_millis.

timestamp_millis(milliseconds) - Creates timestamp from the number of milliseconds since UTC epoch.

Examples (Spark SQL)

> SELECT timestamp_millis(1230219000123);
2008-12-25 07:30:00.123

timestamp_seconds(arg1)

@spec timestamp_seconds(term()) :: Latu.Plan.expression()

Spark's timestamp_seconds.

timestamp_seconds(seconds) - Creates timestamp from the number of seconds (can be fractional) since UTC epoch.

Examples (Spark SQL)

> SELECT timestamp_seconds(1230219000);
2008-12-25 07:30:00
> SELECT timestamp_seconds(1230219000.123);
2008-12-25 07:30:00.123

to_date(arg1)

@spec to_date(term()) :: Latu.Plan.expression()

Spark's to_date. The trailing argument is optional.

to_date(date_str[, fmt]) - Parses the date_str expression with the fmt expression to a date. Returns null with invalid input. By default, it follows casting rules to a date if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_date('2009-07-30 04:17:52');
2009-07-30
> SELECT to_date('2016-12-31', 'yyyy-MM-dd');
2016-12-31

to_date(arg1, optional)

@spec to_date(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_date. With the optional trailing argument.

to_date(date_str[, fmt]) - Parses the date_str expression with the fmt expression to a date. Returns null with invalid input. By default, it follows casting rules to a date if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_date('2009-07-30 04:17:52');
2009-07-30
> SELECT to_date('2016-12-31', 'yyyy-MM-dd');
2016-12-31

to_time(arg1)

@spec to_time(term()) :: Latu.Plan.expression()

Spark's to_time. The trailing argument is optional.

to_time(str[, format]) - Parses the str expression with the format expression to a time. If format is malformed or its application does not result in a well formed time, the function raises an error. By default, it follows casting rules to a time if the format is omitted.

Examples (Spark SQL)

> SELECT to_time('00:12:00');
00:12:00
> SELECT to_time('12.10.05', 'HH.mm.ss');
12:10:05

to_time(arg1, optional)

@spec to_time(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_time. With the optional trailing argument.

to_time(str[, format]) - Parses the str expression with the format expression to a time. If format is malformed or its application does not result in a well formed time, the function raises an error. By default, it follows casting rules to a time if the format is omitted.

Examples (Spark SQL)

> SELECT to_time('00:12:00');
00:12:00
> SELECT to_time('12.10.05', 'HH.mm.ss');
12:10:05

to_timestamp(arg1)

@spec to_timestamp(term()) :: Latu.Plan.expression()

Spark's to_timestamp. The trailing argument is optional.

to_timestamp(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted. The result data type is consistent with the value of configuration spark.sql.timestampType.

Examples (Spark SQL)

> SELECT to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_timestamp(arg1, optional)

@spec to_timestamp(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_timestamp. With the optional trailing argument.

to_timestamp(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted. The result data type is consistent with the value of configuration spark.sql.timestampType.

Examples (Spark SQL)

> SELECT to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_timestamp_ltz(arg1)

@spec to_timestamp_ltz(term()) :: Latu.Plan.expression()

Spark's to_timestamp_ltz. The trailing argument is optional.

to_timestamp_ltz(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp with local time zone. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_timestamp_ltz('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp_ltz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_timestamp_ltz(arg1, optional)

@spec to_timestamp_ltz(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_timestamp_ltz. With the optional trailing argument.

to_timestamp_ltz(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp with local time zone. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_timestamp_ltz('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp_ltz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_timestamp_ntz(arg1)

@spec to_timestamp_ntz(term()) :: Latu.Plan.expression()

Spark's to_timestamp_ntz. The trailing argument is optional.

to_timestamp_ntz(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp without time zone. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_timestamp_ntz('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp_ntz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_timestamp_ntz(arg1, optional)

@spec to_timestamp_ntz(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_timestamp_ntz. With the optional trailing argument.

to_timestamp_ntz(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp without time zone. Returns null with invalid input. By default, it follows casting rules to a timestamp if the fmt is omitted.

Examples (Spark SQL)

> SELECT to_timestamp_ntz('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT to_timestamp_ntz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00

to_unix_timestamp(arg1)

@spec to_unix_timestamp(term()) :: Latu.Plan.expression()

Spark's to_unix_timestamp. The trailing argument is optional.

to_unix_timestamp(timeExp[, fmt]) - Returns the UNIX timestamp of the given time.

Examples (Spark SQL)

> SELECT to_unix_timestamp('2016-04-08', 'yyyy-MM-dd');
1460098800

to_unix_timestamp(arg1, optional)

@spec to_unix_timestamp(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_unix_timestamp. With the optional trailing argument.

to_unix_timestamp(timeExp[, fmt]) - Returns the UNIX timestamp of the given time.

Examples (Spark SQL)

> SELECT to_unix_timestamp('2016-04-08', 'yyyy-MM-dd');
1460098800

to_utc_timestamp(arg1, arg2)

@spec to_utc_timestamp(term(), term()) :: Latu.Plan.expression()

Spark's to_utc_timestamp.

to_utc_timestamp(timestamp, timezone) - Given a timestamp like '2017-07-14 02:40:00.0', interprets it as a time in the given time zone, and renders that time as a timestamp in UTC. For example, 'GMT+1' would yield '2017-07-14 01:40:00.0'.

Examples (Spark SQL)

> SELECT to_utc_timestamp('2016-08-31', 'Asia/Seoul');
2016-08-30 15:00:00

trunc(arg1, arg2)

@spec trunc(term(), term()) :: Latu.Plan.expression()

Spark's trunc.

trunc(date, fmt) - Returns date with the time portion of the day truncated to the unit specified by the format model fmt.

Examples (Spark SQL)

> SELECT trunc('2019-08-04', 'week');
2019-07-29
> SELECT trunc('2019-08-04', 'quarter');
2019-07-01
> SELECT trunc('2009-02-12', 'MM');
2009-02-01
> SELECT trunc('2015-10-27', 'YEAR');
2015-01-01

try_make_interval()

@spec try_make_interval() :: Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1)

@spec try_make_interval(term()) :: Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2)

@spec try_make_interval(term(), term()) :: Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2, arg3)

@spec try_make_interval(term(), term(), term()) :: Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2, arg3, arg4)

@spec try_make_interval(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2, arg3, arg4, arg5)

@spec try_make_interval(term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: 0, Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2, arg3, arg4, arg5, arg6)

@spec try_make_interval(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_interval. Sends Spark's defaults for the rest: Decimal.new("0").

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_interval(arg1, arg2, arg3, arg4, arg5, arg6, arg7)

@spec try_make_interval(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_interval. Every argument is sent.

try_make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - This is a special version of make_interval that performs the same operation, but returns NULL when an overflow occurs.

Examples (Spark SQL)

> SELECT try_make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
> SELECT try_make_interval(100, null, 3);
NULL
> SELECT try_make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
> SELECT try_make_interval(2147483647);
NULL

try_make_timestamp(arg1, arg2)

@spec try_make_timestamp(term(), term()) :: Latu.Plan.expression()

Spark's try_make_timestamp. One of several arities; they do not overlap.

try_make_timestamp(arg1, arg2, arg3)

@spec try_make_timestamp(term(), term(), term()) :: Latu.Plan.expression()

Spark's try_make_timestamp. One of several arities; they do not overlap.

try_make_timestamp(arg1, arg2, arg3, arg4, arg5, arg6)

@spec try_make_timestamp(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_timestamp. One of several arities; they do not overlap.

try_make_timestamp(arg1, arg2, arg3, arg4, arg5, arg6, arg7)

@spec try_make_timestamp(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_timestamp. One of several arities; they do not overlap.

try_make_timestamp_ltz(arg1, arg2, arg3, arg4, arg5, arg6)

@spec try_make_timestamp_ltz(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_timestamp_ltz. The trailing argument is optional.

try_make_timestamp_ltz(year, month, day, hour, min, sec[, timezone]) - Try to create the current timestamp with local time zone from year, month, day, hour, min, sec and (optional) timezone fields. The function returns NULL on invalid inputs. try_make_timestamp_ltz(date, time[, timezone]) - Try to create the current timestamp with local time zone from date, time and (optional) timezone fields.

Examples (Spark SQL)

> SELECT try_make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT try_make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
> SELECT try_make_timestamp_ltz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
> SELECT try_make_timestamp_ltz(null, 7, 22, 15, 30, 0);
NULL
> SELECT try_make_timestamp_ltz(2024, 13, 22, 15, 30, 0);
NULL
> SELECT try_make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887');
2014-12-28 06:30:45.887
> SELECT try_make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887', 'CET');
2014-12-27 21:30:45.887

try_make_timestamp_ltz(arg1, arg2, arg3, arg4, arg5, arg6, optional)

@spec try_make_timestamp_ltz(term(), term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_timestamp_ltz. With the optional trailing argument.

try_make_timestamp_ltz(year, month, day, hour, min, sec[, timezone]) - Try to create the current timestamp with local time zone from year, month, day, hour, min, sec and (optional) timezone fields. The function returns NULL on invalid inputs. try_make_timestamp_ltz(date, time[, timezone]) - Try to create the current timestamp with local time zone from date, time and (optional) timezone fields.

Examples (Spark SQL)

> SELECT try_make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
> SELECT try_make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
> SELECT try_make_timestamp_ltz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
> SELECT try_make_timestamp_ltz(null, 7, 22, 15, 30, 0);
NULL
> SELECT try_make_timestamp_ltz(2024, 13, 22, 15, 30, 0);
NULL
> SELECT try_make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887');
2014-12-28 06:30:45.887
> SELECT try_make_timestamp_ltz(DATE'2014-12-28', TIME'6:30:45.887', 'CET');
2014-12-27 21:30:45.887

try_make_timestamp_ntz(arg1, arg2)

@spec try_make_timestamp_ntz(term(), term()) :: Latu.Plan.expression()

Spark's try_make_timestamp_ntz. One of several arities; they do not overlap.

try_make_timestamp_ntz(arg1, arg2, arg3, arg4, arg5, arg6)

@spec try_make_timestamp_ntz(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_make_timestamp_ntz. One of several arities; they do not overlap.

try_to_date(arg1)

@spec try_to_date(term()) :: Latu.Plan.expression()

Spark's try_to_date. The trailing argument is optional.

try_to_date(date_str[, fmt]) - Parses the date_str expression with the fmt expression to a date. The function always returns null on an invalid input with/without ANSI SQL mode enabled. By default, it follows casting rules to a date if the fmt is omitted.

Examples (Spark SQL)

> SELECT try_to_date('2016-12-31');
2016-12-31
> SELECT try_to_date('2016-12-31', 'yyyy-MM-dd');
2016-12-31
> SELECT try_to_date('foo', 'yyyy-MM-dd');
NULL

try_to_date(arg1, optional)

@spec try_to_date(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's try_to_date. With the optional trailing argument.

try_to_date(date_str[, fmt]) - Parses the date_str expression with the fmt expression to a date. The function always returns null on an invalid input with/without ANSI SQL mode enabled. By default, it follows casting rules to a date if the fmt is omitted.

Examples (Spark SQL)

> SELECT try_to_date('2016-12-31');
2016-12-31
> SELECT try_to_date('2016-12-31', 'yyyy-MM-dd');
2016-12-31
> SELECT try_to_date('foo', 'yyyy-MM-dd');
NULL

try_to_time(arg1)

@spec try_to_time(term()) :: Latu.Plan.expression()

Spark's try_to_time. The trailing argument is optional.

try_to_time(str[, format]) - Parses the str expression with the format expression to a time. If format is malformed or its application does not result in a well formed time, the function returns NULL. By default, it follows casting rules to a time if the format is omitted.

Examples (Spark SQL)

> SELECT try_to_time('00:12:00.001');
00:12:00.001
> SELECT try_to_time('12.10.05.999999', 'HH.mm.ss.SSSSSS');
12:10:05.999999
> SELECT try_to_time('foo', 'HH:mm:ss');
NULL

try_to_time(arg1, optional)

@spec try_to_time(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's try_to_time. With the optional trailing argument.

try_to_time(str[, format]) - Parses the str expression with the format expression to a time. If format is malformed or its application does not result in a well formed time, the function returns NULL. By default, it follows casting rules to a time if the format is omitted.

Examples (Spark SQL)

> SELECT try_to_time('00:12:00.001');
00:12:00.001
> SELECT try_to_time('12.10.05.999999', 'HH.mm.ss.SSSSSS');
12:10:05.999999
> SELECT try_to_time('foo', 'HH:mm:ss');
NULL

try_to_timestamp(arg1)

@spec try_to_timestamp(term()) :: Latu.Plan.expression()

Spark's try_to_timestamp. The trailing argument is optional.

try_to_timestamp(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp. The function always returns null on an invalid input with/without ANSI SQL mode enabled. By default, it follows casting rules to a timestamp if the fmt is omitted. The result data type is consistent with the value of configuration spark.sql.timestampType.

Examples (Spark SQL)

> SELECT try_to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT try_to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
> SELECT try_to_timestamp('foo', 'yyyy-MM-dd');
NULL

try_to_timestamp(arg1, optional)

@spec try_to_timestamp(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's try_to_timestamp. With the optional trailing argument.

try_to_timestamp(timestamp_str[, fmt]) - Parses the timestamp_str expression with the fmt expression to a timestamp. The function always returns null on an invalid input with/without ANSI SQL mode enabled. By default, it follows casting rules to a timestamp if the fmt is omitted. The result data type is consistent with the value of configuration spark.sql.timestampType.

Examples (Spark SQL)

> SELECT try_to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
> SELECT try_to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
> SELECT try_to_timestamp('foo', 'yyyy-MM-dd');
NULL

unix_date(arg1)

@spec unix_date(term()) :: Latu.Plan.expression()

Spark's unix_date.

unix_date(date) - Returns the number of days since 1970-01-01.

Examples (Spark SQL)

> SELECT unix_date(DATE("1970-01-02"));
1

unix_micros(arg1)

@spec unix_micros(term()) :: Latu.Plan.expression()

Spark's unix_micros.

unix_micros(timestamp) - Returns the number of microseconds since 1970-01-01 00:00:00 UTC.

Examples (Spark SQL)

> SELECT unix_micros(TIMESTAMP('1970-01-01 00:00:01Z'));
1000000

unix_millis(arg1)

@spec unix_millis(term()) :: Latu.Plan.expression()

Spark's unix_millis.

unix_millis(timestamp) - Returns the number of milliseconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.

Examples (Spark SQL)

> SELECT unix_millis(TIMESTAMP('1970-01-01 00:00:01Z'));
1000

unix_seconds(arg1)

@spec unix_seconds(term()) :: Latu.Plan.expression()

Spark's unix_seconds.

unix_seconds(timestamp) - Returns the number of seconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.

Examples (Spark SQL)

> SELECT unix_seconds(TIMESTAMP('1970-01-01 00:00:01Z'));
1

unix_timestamp()

@spec unix_timestamp() :: Latu.Plan.expression()

Seconds since the epoch — of now with no arguments, of a timestamp otherwise.

The format is always sent once a timestamp is given, defaulting to Spark's own yyyy-MM-dd HH:mm:ss.

unix_timestamp(timestamp)

@spec unix_timestamp(term()) :: Latu.Plan.expression()

Parse with Spark's default format, yyyy-MM-dd HH:mm:ss, which it always sends.

unix_timestamp(timestamp, format)

@spec unix_timestamp(term(), term()) :: Latu.Plan.expression()

Parse with the given format.

weekday(arg1)

@spec weekday(term()) :: Latu.Plan.expression()

Spark's weekday.

weekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).

Examples (Spark SQL)

> SELECT weekday('2009-07-30');
3

weekofyear(arg1)

@spec weekofyear(term()) :: Latu.Plan.expression()

Spark's weekofyear.

weekofyear(date) - Returns the week of the year of the given date. A week is considered to start on a Monday and week 1 is the first week with >3 days.

Examples (Spark SQL)

> SELECT weekofyear('2008-02-20');
8

window(arg1, arg2)

@spec window(term(), term()) :: Latu.Plan.expression()

Spark's window. One of several arities; they do not overlap.

window(time_column, window_duration[, slide_duration[, start_time]]) - Bucketize rows into one or more time windows given a timestamp specifying column. Window starts are inclusive but the window ends are exclusive, e.g. 12:05 will be in the window [12:05,12:10) but not in [12:00,12:05). Windows can support microsecond precision. Windows in the order of months are not supported. See <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#window-operations-on-event-time">'Window Operations on Event Time'</a> in Structured Streaming guide doc for detailed explanation and examples.

Examples (Spark SQL)

> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '5 minutes') ORDER BY a, start;
A1	2021-01-01 00:00:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:05:00	2021-01-01 00:10:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:05:00	1
> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '10 minutes', '5 minutes') ORDER BY a, start;
A1	2020-12-31 23:55:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:00:00	2021-01-01 00:10:00	3
A1	2021-01-01 00:05:00	2021-01-01 00:15:00	1
A2	2020-12-31 23:55:00	2021-01-01 00:05:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:10:00	1

window(arg1, arg2, arg3)

@spec window(term(), term(), term()) :: Latu.Plan.expression()

Spark's window. One of several arities; they do not overlap.

window(time_column, window_duration[, slide_duration[, start_time]]) - Bucketize rows into one or more time windows given a timestamp specifying column. Window starts are inclusive but the window ends are exclusive, e.g. 12:05 will be in the window [12:05,12:10) but not in [12:00,12:05). Windows can support microsecond precision. Windows in the order of months are not supported. See <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#window-operations-on-event-time">'Window Operations on Event Time'</a> in Structured Streaming guide doc for detailed explanation and examples.

Examples (Spark SQL)

> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '5 minutes') ORDER BY a, start;
A1	2021-01-01 00:00:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:05:00	2021-01-01 00:10:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:05:00	1
> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '10 minutes', '5 minutes') ORDER BY a, start;
A1	2020-12-31 23:55:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:00:00	2021-01-01 00:10:00	3
A1	2021-01-01 00:05:00	2021-01-01 00:15:00	1
A2	2020-12-31 23:55:00	2021-01-01 00:05:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:10:00	1

window(arg1, arg2, arg3, arg4)

@spec window(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's window. One of several arities; they do not overlap.

window(time_column, window_duration[, slide_duration[, start_time]]) - Bucketize rows into one or more time windows given a timestamp specifying column. Window starts are inclusive but the window ends are exclusive, e.g. 12:05 will be in the window [12:05,12:10) but not in [12:00,12:05). Windows can support microsecond precision. Windows in the order of months are not supported. See <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#window-operations-on-event-time">'Window Operations on Event Time'</a> in Structured Streaming guide doc for detailed explanation and examples.

Examples (Spark SQL)

> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '5 minutes') ORDER BY a, start;
A1	2021-01-01 00:00:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:05:00	2021-01-01 00:10:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:05:00	1
> SELECT a, window.start, window.end, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '10 minutes', '5 minutes') ORDER BY a, start;
A1	2020-12-31 23:55:00	2021-01-01 00:05:00	2
A1	2021-01-01 00:00:00	2021-01-01 00:10:00	3
A1	2021-01-01 00:05:00	2021-01-01 00:15:00	1
A2	2020-12-31 23:55:00	2021-01-01 00:05:00	1
A2	2021-01-01 00:00:00	2021-01-01 00:10:00	1

window_time(arg1)

@spec window_time(term()) :: Latu.Plan.expression()

Spark's window_time.

window_time(window_column) - Extract the time value from time/session window column which can be used for event time value of window. The extracted time is (window.end - 1) which reflects the fact that the aggregating windows have exclusive upper bound - [start, end) See <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#window-operations-on-event-time">'Window Operations on Event Time'</a> in Structured Streaming guide doc for detailed explanation and examples.

Examples (Spark SQL)

> SELECT a, window.start as start, window.end as end, window_time(window), cnt FROM (SELECT a, window, count(*) as cnt FROM VALUES ('A1', '2021-01-01 00:00:00'), ('A1', '2021-01-01 00:04:30'), ('A1', '2021-01-01 00:06:00'), ('A2', '2021-01-01 00:01:00') AS tab(a, b) GROUP by a, window(b, '5 minutes') ORDER BY a, window.start);
A1	2021-01-01 00:00:00	2021-01-01 00:05:00	2021-01-01 00:04:59.999999	2
A1	2021-01-01 00:05:00	2021-01-01 00:10:00	2021-01-01 00:09:59.999999	1
A2	2021-01-01 00:00:00	2021-01-01 00:05:00	2021-01-01 00:04:59.999999	1

year(arg1)

@spec year(term()) :: Latu.Plan.expression()

Spark's year.

year(date) - Returns the year component of the date/timestamp.

Examples (Spark SQL)

> SELECT year('2016-07-30');
2016

Generator Functions

explode(arg1)

@spec explode(term()) :: Latu.Plan.expression()

Spark's explode.

explode(expr) - Separates the elements of array expr into multiple rows, or the elements of map expr into multiple rows and columns. Unless specified otherwise, uses the default column name col for elements of the array or key and value for the elements of the map.

Examples (Spark SQL)

> SELECT explode(array(10, 20));
10
20
> SELECT explode(collection => array(10, 20));
10
20

explode_outer(arg1)

@spec explode_outer(term()) :: Latu.Plan.expression()

Spark's explode_outer.

explode_outer(expr) - Separates the elements of array expr into multiple rows, or the elements of map expr into multiple rows and columns. Unless specified otherwise, uses the default column name col for elements of the array or key and value for the elements of the map.

Examples (Spark SQL)

> SELECT explode_outer(array(10, 20));
10
20
> SELECT explode_outer(collection => array(10, 20));
10
20

inline(arg1)

@spec inline(term()) :: Latu.Plan.expression()

Spark's inline.

inline(expr) - Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise.

Examples (Spark SQL)

> SELECT inline(array(struct(1, 'a'), struct(2, 'b')));
1	a
2	b
> SELECT inline(input => array(struct(1, 'a'), struct(2, 'b')));
1	a
2	b

inline_outer(arg1)

@spec inline_outer(term()) :: Latu.Plan.expression()

Spark's inline_outer.

inline_outer(expr) - Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise.

Examples (Spark SQL)

> SELECT inline_outer(array(struct(1, 'a'), struct(2, 'b')));
1	a
2	b
> SELECT inline_outer(input => array(struct(1, 'a'), struct(2, 'b')));
1	a
2	b

posexplode(arg1)

@spec posexplode(term()) :: Latu.Plan.expression()

Spark's posexplode.

posexplode(expr) - Separates the elements of array expr into multiple rows with positions, or the elements of map expr into multiple rows and columns with positions. Unless specified otherwise, uses the column name pos for position, col for elements of the array or key and value for elements of the map.

Examples (Spark SQL)

> SELECT posexplode(array(10,20));
0	10
1	20
> SELECT posexplode(collection => array(10,20));
0	10
1	20

posexplode_outer(arg1)

@spec posexplode_outer(term()) :: Latu.Plan.expression()

Spark's posexplode_outer.

posexplode_outer(expr) - Separates the elements of array expr into multiple rows with positions, or the elements of map expr into multiple rows and columns with positions. Unless specified otherwise, uses the column name pos for position, col for elements of the array or key and value for elements of the map.

Examples (Spark SQL)

> SELECT posexplode_outer(array(10,20));
0	10
1	20
> SELECT posexplode_outer(collection => array(10,20));
0	10
1	20

stack(columns)

@spec stack([term()]) :: Latu.Plan.expression()

Spark's stack. Variadic in Spark; takes a list here.

stack(n, expr1, ..., exprk) - Separates expr1, ..., exprk into n rows. Uses column names col0, col1, etc. by default unless specified otherwise.

Examples (Spark SQL)

> SELECT stack(2, 1, 2, 3);
1	2
3	NULL

Geospatial ST Functions

st_asbinary(arg1)

@spec st_asbinary(term()) :: Latu.Plan.expression()

Spark's st_asbinary. The trailing argument is optional.

st_asbinary(geo[, endianness]) - Returns the geospatial value (value of type GEOGRAPHY or GEOMETRY) in WKB format using the specified endianness ('NDR' for little-endian, 'XDR' for big-endian), if provided. Defaults to little-endian encoding.

Examples (Spark SQL)

> SELECT hex(st_asbinary(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040')));
0101000000000000000000F03F0000000000000040
> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040'), 'XDR'));
00000000013FF00000000000004000000000000000

st_asbinary(arg1, optional)

@spec st_asbinary(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's st_asbinary. With the optional trailing argument.

st_asbinary(geo[, endianness]) - Returns the geospatial value (value of type GEOGRAPHY or GEOMETRY) in WKB format using the specified endianness ('NDR' for little-endian, 'XDR' for big-endian), if provided. Defaults to little-endian encoding.

Examples (Spark SQL)

> SELECT hex(st_asbinary(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040')));
0101000000000000000000F03F0000000000000040
> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040'), 'XDR'));
00000000013FF00000000000004000000000000000

st_geogfromwkb(arg1)

@spec st_geogfromwkb(term()) :: Latu.Plan.expression()

Spark's st_geogfromwkb.

st_geogfromwkb(wkb) - Parses the WKB description of a geography and returns the corresponding GEOGRAPHY value.

Examples (Spark SQL)

> SELECT hex(st_asbinary(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040')));
0101000000000000000000F03F0000000000000040

st_geomfromwkb(arg1)

@spec st_geomfromwkb(term()) :: Latu.Plan.expression()

Spark's st_geomfromwkb. The trailing argument is optional.

st_geomfromwkb(wkb[, srid]) - Parses the WKB description of a geometry and returns the corresponding GEOMETRY value.

Examples (Spark SQL)

> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040')));
0101000000000000000000F03F0000000000000040
> SELECT st_srid(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040'));
0
> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040', 4326)));
0101000000000000000000F03F0000000000000040
> SELECT st_srid(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040', 4326));
4326

st_geomfromwkb(arg1, optional)

@spec st_geomfromwkb(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's st_geomfromwkb. With the optional trailing argument.

st_geomfromwkb(wkb[, srid]) - Parses the WKB description of a geometry and returns the corresponding GEOMETRY value.

Examples (Spark SQL)

> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040')));
0101000000000000000000F03F0000000000000040
> SELECT st_srid(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040'));
0
> SELECT hex(st_asbinary(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040', 4326)));
0101000000000000000000F03F0000000000000040
> SELECT st_srid(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040', 4326));
4326

st_setsrid(arg1, arg2)

@spec st_setsrid(term(), term()) :: Latu.Plan.expression()

Spark's st_setsrid.

st_setsrid(geo, srid) - Returns a new GEOGRAPHY or GEOMETRY value whose SRID is the specified SRID value.

Examples (Spark SQL)

> SELECT st_srid(st_setsrid(ST_GeogFromWKB(X'0101000000000000000000F03F0000000000000040'), 4326));
4326
> SELECT st_srid(st_setsrid(ST_GeomFromWKB(X'0101000000000000000000F03F0000000000000040'), 3857));
3857

st_srid(arg1)

@spec st_srid(term()) :: Latu.Plan.expression()

Spark's st_srid.

st_srid(geo) - Returns the SRID of the input GEOGRAPHY or GEOMETRY value.

Examples (Spark SQL)

> SELECT st_srid(st_geogfromwkb(X'0101000000000000000000F03F0000000000000040'));
4326
> SELECT st_srid(st_geomfromwkb(X'0101000000000000000000F03F0000000000000040'));
0
> SELECT st_srid(NULL);
NULL

Hash Functions

crc32(arg1)

@spec crc32(term()) :: Latu.Plan.expression()

Spark's crc32.

crc32(expr) - Returns a cyclic redundancy check value of the expr as a bigint.

Examples (Spark SQL)

> SELECT crc32('Spark');
1557323817

hash(columns)

@spec hash([term()]) :: Latu.Plan.expression()

Spark's hash. Variadic in Spark; takes a list here.

hash(expr1, expr2, ...) - Returns a hash value of the arguments.

Examples (Spark SQL)

> SELECT hash('Spark', array(123), 2);
-1321691492

md5(arg1)

@spec md5(term()) :: Latu.Plan.expression()

Spark's md5.

md5(expr) - Returns an MD5 128-bit checksum as a hex string of expr.

Examples (Spark SQL)

> SELECT md5('Spark');
8cde774d6f7333752ed72cacddb05126

sha1(arg1)

@spec sha1(term()) :: Latu.Plan.expression()

Spark's sha1.

sha1(expr) - Returns a sha1 hash value as a hex string of the expr.

Examples (Spark SQL)

> SELECT sha1('Spark');
85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c

sha2(arg1, arg2)

@spec sha2(term(), term()) :: Latu.Plan.expression()

Spark's sha2.

sha2(expr, bitLength) - Returns a checksum of SHA-2 family as a hex string of expr. SHA-224, SHA-256, SHA-384, and SHA-512 are supported. Bit length of 0 is equivalent to 256.

Examples (Spark SQL)

> SELECT sha2('Spark', 256);
529bc3b07127ecb7e53a4dcf1991d9152c24537d919178022b2c42657f79a26b

sha(arg1)

@spec sha(term()) :: Latu.Plan.expression()

Spark's sha.

sha(expr) - Returns a sha1 hash value as a hex string of the expr.

Examples (Spark SQL)

> SELECT sha('Spark');
85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c

xxhash64(columns)

@spec xxhash64([term()]) :: Latu.Plan.expression()

Spark's xxhash64. Variadic in Spark; takes a list here.

xxhash64(expr1, expr2, ...) - Returns a 64-bit hash value of the arguments. Hash seed is 42.

Examples (Spark SQL)

> SELECT xxhash64('Spark', array(123), 2);
5602566077635097486

JSON Functions

from_json(column, schema)

@spec from_json(term(), term()) :: Latu.Plan.expression()

Spark's from_json. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

from_json(jsonStr, schema[, options]) - Returns a struct value with the given jsonStr and schema.

Examples (Spark SQL)

> SELECT from_json('{"a":1, "b":0.8}', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}
> SELECT from_json('{"teacher": "Alice", "student": [{"name": "Bob", "rank": 1}, {"name": "Charlie", "rank": 2}]}', 'STRUCT<teacher: STRING, student: ARRAY<STRUCT<name: STRING, rank: INT>>>');
{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}

from_json(column, schema, options)

@spec from_json(term(), term(), keyword() | map()) :: Latu.Plan.expression()

Spark's from_json. With parser options, following Latu.read/2's rules.

from_json(jsonStr, schema[, options]) - Returns a struct value with the given jsonStr and schema.

Examples (Spark SQL)

> SELECT from_json('{"a":1, "b":0.8}', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_json('{"time":"26/08/2015"}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}
> SELECT from_json('{"teacher": "Alice", "student": [{"name": "Bob", "rank": 1}, {"name": "Charlie", "rank": 2}]}', 'STRUCT<teacher: STRING, student: ARRAY<STRUCT<name: STRING, rank: INT>>>');
{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}

get_json_object(arg1, arg2)

@spec get_json_object(term(), term()) :: Latu.Plan.expression()

Spark's get_json_object.

get_json_object(json_txt, path) - Extracts a json object from path.

Examples (Spark SQL)

> SELECT get_json_object('{"a":"b"}', '$.a');
b
> SELECT get_json_object('[{"a":"b"},{"a":"c"}]', '$[0].a');
b
> SELECT get_json_object('[{"a":"b"},{"a":"c"}]', '$[*].a');
["b","c"]

json_array_length(arg1)

@spec json_array_length(term()) :: Latu.Plan.expression()

Spark's json_array_length.

json_array_length(jsonArray) - Returns the number of elements in the outermost JSON array.

Examples (Spark SQL)

> SELECT json_array_length('[1,2,3,4]');
4
> SELECT json_array_length('[1,2,3,{"f1":1,"f2":[5,6]},4]');
5
> SELECT json_array_length('[1,2');
NULL

json_object_keys(arg1)

@spec json_object_keys(term()) :: Latu.Plan.expression()

Spark's json_object_keys.

json_object_keys(json_object) - Returns all the keys of the outermost JSON object as an array.

Examples (Spark SQL)

> SELECT json_object_keys('{}');
[]
> SELECT json_object_keys('{"key": "value"}');
["key"]
> SELECT json_object_keys('{"f1":"abc","f2":{"f3":"a", "f4":"b"}}');
["f1","f2"]

json_tuple(first, columns)

@spec json_tuple(term(), [term()]) :: Latu.Plan.expression()

Spark's json_tuple. Variadic in Spark; takes a list here.

json_tuple(jsonStr, p1, p2, ..., pn) - Returns a tuple like the function get_json_object, but it takes multiple names. All the input parameters and output column types are string.

Examples (Spark SQL)

> SELECT json_tuple('{"a":1, "b":2}', 'a', 'b');
1	2

schema_of_json(column)

@spec schema_of_json(term()) :: Latu.Plan.expression()

Spark's schema_of_json. Options follow Latu.read/2's key and value rules.

schema_of_json(json[, options]) - Returns schema in the DDL format of JSON string.

Examples (Spark SQL)

> SELECT schema_of_json('[{"col":0}]');
ARRAY<STRUCT<col: BIGINT>>
> SELECT schema_of_json('[{"col":01}]', map('allowNumericLeadingZeros', 'true'));
ARRAY<STRUCT<col: BIGINT>>

schema_of_json(column, options)

@spec schema_of_json(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's schema_of_json. With parser options, following Latu.read/2's rules.

schema_of_json(json[, options]) - Returns schema in the DDL format of JSON string.

Examples (Spark SQL)

> SELECT schema_of_json('[{"col":0}]');
ARRAY<STRUCT<col: BIGINT>>
> SELECT schema_of_json('[{"col":01}]', map('allowNumericLeadingZeros', 'true'));
ARRAY<STRUCT<col: BIGINT>>

to_json(column)

@spec to_json(term()) :: Latu.Plan.expression()

Spark's to_json. Options follow Latu.read/2's key and value rules.

to_json(expr[, options]) - Returns a JSON string with a given struct value

Examples (Spark SQL)

> SELECT to_json(named_struct('a', 1, 'b', 2));
{"a":1,"b":2}
> SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
{"time":"26/08/2015"}
> SELECT to_json(array(named_struct('a', 1, 'b', 2)));
[{"a":1,"b":2}]
> SELECT to_json(map('a', named_struct('b', 1)));
{"a":{"b":1}}
> SELECT to_json(map(named_struct('a', 1),named_struct('b', 2)));
{"[1]":{"b":2}}
> SELECT to_json(map('a', 1));
{"a":1}
> SELECT to_json(array(map('a', 1)));
[{"a":1}]
> SELECT to_json(named_struct('b', 1, 'a', 2), map('sortKeys', 'true'));
{"a":2,"b":1}

to_json(column, options)

@spec to_json(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's to_json. With parser options, following Latu.read/2's rules.

to_json(expr[, options]) - Returns a JSON string with a given struct value

Examples (Spark SQL)

> SELECT to_json(named_struct('a', 1, 'b', 2));
{"a":1,"b":2}
> SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
{"time":"26/08/2015"}
> SELECT to_json(array(named_struct('a', 1, 'b', 2)));
[{"a":1,"b":2}]
> SELECT to_json(map('a', named_struct('b', 1)));
{"a":{"b":1}}
> SELECT to_json(map(named_struct('a', 1),named_struct('b', 2)));
{"[1]":{"b":2}}
> SELECT to_json(map('a', 1));
{"a":1}
> SELECT to_json(array(map('a', 1)));
[{"a":1}]
> SELECT to_json(named_struct('b', 1, 'a', 2), map('sortKeys', 'true'));
{"a":2,"b":1}

Map Functions

create_map(columns)

@spec create_map([term()]) :: Latu.Plan.expression()

Spark's map. Variadic in Spark; takes a list here.

map(key0, value0, key1, value1, ...) - Creates a map with the given key/value pairs.

Examples (Spark SQL)

> SELECT map(1.0, '2', 3.0, '4');
{1.0:"2",3.0:"4"}

map_concat(columns)

@spec map_concat([term()]) :: Latu.Plan.expression()

Spark's map_concat. Variadic in Spark; takes a list here.

map_concat(map, ...) - Returns the union of all the given maps

Examples (Spark SQL)

> SELECT map_concat(map(1, 'a', 2, 'b'), map(3, 'c'));
{1:"a",2:"b",3:"c"}

map_contains_key(arg1, arg2)

@spec map_contains_key(term(), term()) :: Latu.Plan.expression()

Spark's map_contains_key.

map_contains_key(map, key) - Returns true if the map contains the key.

Examples (Spark SQL)

> SELECT map_contains_key(map(1, 'a', 2, 'b'), 1);
true
> SELECT map_contains_key(map(1, 'a', 2, 'b'), 3);
false

map_entries(arg1)

@spec map_entries(term()) :: Latu.Plan.expression()

Spark's map_entries.

map_entries(map) - Returns an unordered array of all entries in the given map.

Examples (Spark SQL)

> SELECT map_entries(map(1, 'a', 2, 'b'));
[{"key":1,"value":"a"},{"key":2,"value":"b"}]

map_from_arrays(arg1, arg2)

@spec map_from_arrays(term(), term()) :: Latu.Plan.expression()

Spark's map_from_arrays.

map_from_arrays(keys, values) - Creates a map with a pair of the given key/value arrays. All elements in keys should not be null

Examples (Spark SQL)

> SELECT map_from_arrays(array(1.0, 3.0), array('2', '4'));
{1.0:"2",3.0:"4"}

map_from_entries(arg1)

@spec map_from_entries(term()) :: Latu.Plan.expression()

Spark's map_from_entries.

map_from_entries(arrayOfEntries) - Returns a map created from the given array of entries.

Examples (Spark SQL)

> SELECT map_from_entries(array(struct(1, 'a'), struct(2, 'b')));
{1:"a",2:"b"}

map_keys(arg1)

@spec map_keys(term()) :: Latu.Plan.expression()

Spark's map_keys.

map_keys(map) - Returns an unordered array containing the keys of the map.

Examples (Spark SQL)

> SELECT map_keys(map(1, 'a', 2, 'b'));
[1,2]

map_values(arg1)

@spec map_values(term()) :: Latu.Plan.expression()

Spark's map_values.

map_values(map) - Returns an unordered array containing the values of the map.

Examples (Spark SQL)

> SELECT map_values(map(1, 'a', 2, 'b'));
["a","b"]

str_to_map(arg1)

@spec str_to_map(term()) :: Latu.Plan.expression()

Spark's str_to_map. Sends Spark's defaults for the rest: ",", ":".

str_to_map(text[, pairDelim[, keyValueDelim]]) - Creates a map after splitting the text into key/value pairs using delimiters. Default delimiters are ',' for pairDelim and ':' for keyValueDelim. Both pairDelim and keyValueDelim are treated as regular expressions.

Examples (Spark SQL)

> SELECT str_to_map('a:1,b:2,c:3', ',', ':');
{"a":"1","b":"2","c":"3"}
> SELECT str_to_map('a');
{"a":null}

str_to_map(arg1, arg2)

@spec str_to_map(term(), term()) :: Latu.Plan.expression()

Spark's str_to_map. Sends Spark's defaults for the rest: ":".

str_to_map(text[, pairDelim[, keyValueDelim]]) - Creates a map after splitting the text into key/value pairs using delimiters. Default delimiters are ',' for pairDelim and ':' for keyValueDelim. Both pairDelim and keyValueDelim are treated as regular expressions.

Examples (Spark SQL)

> SELECT str_to_map('a:1,b:2,c:3', ',', ':');
{"a":"1","b":"2","c":"3"}
> SELECT str_to_map('a');
{"a":null}

str_to_map(arg1, arg2, arg3)

@spec str_to_map(term(), term(), term()) :: Latu.Plan.expression()

Spark's str_to_map. Every argument is sent.

str_to_map(text[, pairDelim[, keyValueDelim]]) - Creates a map after splitting the text into key/value pairs using delimiters. Default delimiters are ',' for pairDelim and ':' for keyValueDelim. Both pairDelim and keyValueDelim are treated as regular expressions.

Examples (Spark SQL)

> SELECT str_to_map('a:1,b:2,c:3', ',', ':');
{"a":"1","b":"2","c":"3"}
> SELECT str_to_map('a');
{"a":null}

Mathematical Functions

abs(arg1)

@spec abs(term()) :: Latu.Plan.expression()

Spark's abs.

abs(expr) - Returns the absolute value of the numeric or interval value.

Examples (Spark SQL)

> SELECT abs(-1);
1
> SELECT abs(INTERVAL -'1-1' YEAR TO MONTH);
1-1

acos(arg1)

@spec acos(term()) :: Latu.Plan.expression()

Spark's acos.

acos(expr) - Returns the inverse cosine (a.k.a. arc cosine) of expr, as if computed by java.lang.Math.acos.

Examples (Spark SQL)

> SELECT acos(1);
0.0
> SELECT acos(2);
NaN

acosh(arg1)

@spec acosh(term()) :: Latu.Plan.expression()

Spark's acosh.

acosh(expr) - Returns inverse hyperbolic cosine of expr.

Examples (Spark SQL)

> SELECT acosh(1);
0.0
> SELECT acosh(0);
NaN

asin(arg1)

@spec asin(term()) :: Latu.Plan.expression()

Spark's asin.

asin(expr) - Returns the inverse sine (a.k.a. arc sine) the arc sin of expr, as if computed by java.lang.Math.asin.

Examples (Spark SQL)

> SELECT asin(0);
0.0
> SELECT asin(2);
NaN

asinh(arg1)

@spec asinh(term()) :: Latu.Plan.expression()

Spark's asinh.

asinh(expr) - Returns inverse hyperbolic sine of expr.

Examples (Spark SQL)

> SELECT asinh(0);
0.0

atan2(arg1, arg2)

@spec atan2(term(), term()) :: Latu.Plan.expression()

Spark's atan2.

atan2(exprY, exprX) - Returns the angle in radians between the positive x-axis of a plane and the point given by the coordinates (exprX, exprY), as if computed by java.lang.Math.atan2.

Examples (Spark SQL)

> SELECT atan2(0, 0);
0.0

atan(arg1)

@spec atan(term()) :: Latu.Plan.expression()

Spark's atan.

atan(expr) - Returns the inverse tangent (a.k.a. arc tangent) of expr, as if computed by java.lang.Math.atan

Examples (Spark SQL)

> SELECT atan(0);
0.0

atanh(arg1)

@spec atanh(term()) :: Latu.Plan.expression()

Spark's atanh.

atanh(expr) - Returns inverse hyperbolic tangent of expr.

Examples (Spark SQL)

> SELECT atanh(0);
0.0
> SELECT atanh(2);
NaN

bin(arg1)

@spec bin(term()) :: Latu.Plan.expression()

Spark's bin.

bin(expr) - Returns the string representation of the long value expr represented in binary.

Examples (Spark SQL)

> SELECT bin(13);
1101
> SELECT bin(-13);
1111111111111111111111111111111111111111111111111111111111110011
> SELECT bin(13.3);
1101

bround(arg1)

@spec bround(term()) :: Latu.Plan.expression()

Spark's bround. The trailing argument is optional.

bround(expr, d) - Returns expr rounded to d decimal places using HALF_EVEN rounding mode.

Examples (Spark SQL)

> SELECT bround(2.5, 0);
2
> SELECT bround(25, -1);
20

bround(arg1, optional)

@spec bround(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's bround. With the optional trailing argument.

bround(expr, d) - Returns expr rounded to d decimal places using HALF_EVEN rounding mode.

Examples (Spark SQL)

> SELECT bround(2.5, 0);
2
> SELECT bround(25, -1);
20

cbrt(arg1)

@spec cbrt(term()) :: Latu.Plan.expression()

Spark's cbrt.

cbrt(expr) - Returns the cube root of expr.

Examples (Spark SQL)

> SELECT cbrt(27.0);
3.0

ceil(arg1)

@spec ceil(term()) :: Latu.Plan.expression()

Spark's ceil. The trailing argument is optional.

ceil(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT ceil(-0.1);
0
> SELECT ceil(5);
5
> SELECT ceil(3.1411, 3);
3.142
> SELECT ceil(3.1411, -3);
1000

ceil(arg1, optional)

@spec ceil(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's ceil. With the optional trailing argument.

ceil(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT ceil(-0.1);
0
> SELECT ceil(5);
5
> SELECT ceil(3.1411, 3);
3.142
> SELECT ceil(3.1411, -3);
1000

ceiling(arg1)

@spec ceiling(term()) :: Latu.Plan.expression()

Spark's ceiling. The trailing argument is optional.

ceiling(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT ceiling(-0.1);
0
> SELECT ceiling(5);
5
> SELECT ceiling(3.1411, 3);
3.142
> SELECT ceiling(3.1411, -3);
1000

ceiling(arg1, optional)

@spec ceiling(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's ceiling. With the optional trailing argument.

ceiling(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT ceiling(-0.1);
0
> SELECT ceiling(5);
5
> SELECT ceiling(3.1411, 3);
3.142
> SELECT ceiling(3.1411, -3);
1000

conv(arg1, arg2, arg3)

@spec conv(term(), term(), term()) :: Latu.Plan.expression()

Spark's conv.

conv(num, from_base, to_base) - Convert num from from_base to to_base.

Examples (Spark SQL)

> SELECT conv('100', 2, 10);
4
> SELECT conv(-10, 16, -10);
-16

cos(arg1)

@spec cos(term()) :: Latu.Plan.expression()

Spark's cos.

cos(expr) - Returns the cosine of expr, as if computed by java.lang.Math.cos.

Examples (Spark SQL)

> SELECT cos(0);
1.0

cosh(arg1)

@spec cosh(term()) :: Latu.Plan.expression()

Spark's cosh.

cosh(expr) - Returns the hyperbolic cosine of expr, as if computed by java.lang.Math.cosh.

Examples (Spark SQL)

> SELECT cosh(0);
1.0

cot(arg1)

@spec cot(term()) :: Latu.Plan.expression()

Spark's cot.

cot(expr) - Returns the cotangent of expr, as if computed by 1/java.lang.Math.tan.

Examples (Spark SQL)

> SELECT cot(1);
0.6420926159343306

csc(arg1)

@spec csc(term()) :: Latu.Plan.expression()

Spark's csc.

csc(expr) - Returns the cosecant of expr, as if computed by 1/java.lang.Math.sin.

Examples (Spark SQL)

> SELECT csc(1);
1.1883951057781212

degrees(arg1)

@spec degrees(term()) :: Latu.Plan.expression()

Spark's degrees.

degrees(expr) - Converts radians to degrees.

Examples (Spark SQL)

> SELECT degrees(3.141592653589793);
180.0

e()

@spec e() :: Latu.Plan.expression()

Spark's e.

e() - Returns Euler's number, e.

Examples (Spark SQL)

> SELECT e();
2.718281828459045

exp(arg1)

@spec exp(term()) :: Latu.Plan.expression()

Spark's exp.

exp(expr) - Returns e to the power of expr.

Examples (Spark SQL)

> SELECT exp(0);
1.0

expm1(arg1)

@spec expm1(term()) :: Latu.Plan.expression()

Spark's expm1.

expm1(expr) - Returns exp(expr) - 1.

Examples (Spark SQL)

> SELECT expm1(0);
0.0

factorial(arg1)

@spec factorial(term()) :: Latu.Plan.expression()

Spark's factorial.

factorial(expr) - Returns the factorial of expr. expr is [0..20]. Otherwise, null.

Examples (Spark SQL)

> SELECT factorial(5);
120

floor(arg1)

@spec floor(term()) :: Latu.Plan.expression()

Spark's floor. The trailing argument is optional.

floor(expr[, scale]) - Returns the largest number after rounding down that is not greater than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT floor(-0.1);
-1
> SELECT floor(5);
5
> SELECT floor(3.1411, 3);
3.141
> SELECT floor(3.1411, -3);
0

floor(arg1, optional)

@spec floor(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's floor. With the optional trailing argument.

floor(expr[, scale]) - Returns the largest number after rounding down that is not greater than expr. An optional scale parameter can be specified to control the rounding behavior.

Examples (Spark SQL)

> SELECT floor(-0.1);
-1
> SELECT floor(5);
5
> SELECT floor(3.1411, 3);
3.141
> SELECT floor(3.1411, -3);
0

greatest(columns)

@spec greatest([term()]) :: Latu.Plan.expression()

Spark's greatest. Variadic in Spark; takes a list here.

greatest(expr, ...) - Returns the greatest value of all parameters, skipping null values.

Examples (Spark SQL)

> SELECT greatest(10, 9, 2, 4, 3);
10

hex(arg1)

@spec hex(term()) :: Latu.Plan.expression()

Spark's hex.

hex(expr) - Converts expr to hexadecimal.

Examples (Spark SQL)

> SELECT hex(17);
11
> SELECT hex('Spark SQL');
537061726B2053514C

hypot(arg1, arg2)

@spec hypot(term(), term()) :: Latu.Plan.expression()

Spark's hypot.

hypot(expr1, expr2) - Returns sqrt(expr1² + expr2²).

Examples (Spark SQL)

> SELECT hypot(3, 4);
5.0

least(columns)

@spec least([term()]) :: Latu.Plan.expression()

Spark's least. Variadic in Spark; takes a list here.

least(expr, ...) - Returns the least value of all parameters, skipping null values.

Examples (Spark SQL)

> SELECT least(10, 9, 2, 4, 3);
2

ln(arg1)

@spec ln(term()) :: Latu.Plan.expression()

Spark's ln.

ln(expr) - Returns the natural logarithm (base e) of expr.

Examples (Spark SQL)

> SELECT ln(1);
0.0

log1p(arg1)

@spec log1p(term()) :: Latu.Plan.expression()

Spark's log1p.

log1p(expr) - Returns log(1 + expr).

Examples (Spark SQL)

> SELECT log1p(0);
0.0

log2(arg1)

@spec log2(term()) :: Latu.Plan.expression()

Spark's log2.

log2(expr) - Returns the logarithm of expr with base 2.

Examples (Spark SQL)

> SELECT log2(2);
1.0

log10(arg1)

@spec log10(term()) :: Latu.Plan.expression()

Spark's log10.

log10(expr) - Returns the logarithm of expr with base 10.

Examples (Spark SQL)

> SELECT log10(10);
1.0

log(column)

@spec log(term()) :: Latu.Plan.expression()

A logarithm — natural with one argument, to a base with two.

F.log(:x)        # ln(x)
F.log(2, :x)     # log base 2 of x

The wire name changes with the arity: one argument sends ln, two send log. The first argument means different things in the two forms, which is PySpark's design rather than a choice made here; F.ln/1 says the first one unambiguously.

log(base, column)

@spec log(term(), term()) :: Latu.Plan.expression()

The logarithm of column in base — Spark's log, where log/1 sends ln.

negative(arg1)

@spec negative(term()) :: Latu.Plan.expression()

Spark's negative.

negative(expr) - Returns the negated value of expr.

Examples (Spark SQL)

> SELECT negative(1);
-1

pi()

@spec pi() :: Latu.Plan.expression()

Spark's pi.

pi() - Returns pi.

Examples (Spark SQL)

> SELECT pi();
3.141592653589793

pmod(arg1, arg2)

@spec pmod(term(), term()) :: Latu.Plan.expression()

Spark's pmod.

pmod(expr1, expr2) - Returns the positive value of expr1 mod expr2.

Examples (Spark SQL)

> SELECT pmod(10, 3);
1
> SELECT pmod(-10, 3);
2

positive(arg1)

@spec positive(term()) :: Latu.Plan.expression()

Spark's positive.

positive(expr) - Returns the value of expr.

Examples (Spark SQL)

> SELECT positive(1);
1

radians(arg1)

@spec radians(term()) :: Latu.Plan.expression()

Spark's radians.

radians(expr) - Converts degrees to radians.

Examples (Spark SQL)

> SELECT radians(180);
3.141592653589793

rand()

@spec rand() :: Latu.Plan.expression()

Spark's rand. Draws a random seed, so the plan is not reproducible — pass one to fix it.

rand([seed]) - Returns a random value with independent and identically distributed (i.i.d.) uniformly distributed values in [0, 1).

Examples (Spark SQL)

> SELECT rand();
0.9629742951434543
> SELECT rand(0);
0.7604953758285915
> SELECT rand(null);
0.7604953758285915

Note: The function is non-deterministic in general case.

rand(seed)

@spec rand(term()) :: Latu.Plan.expression()

Spark's rand. With an explicit seed, so the plan is reproducible.

rand([seed]) - Returns a random value with independent and identically distributed (i.i.d.) uniformly distributed values in [0, 1).

Examples (Spark SQL)

> SELECT rand();
0.9629742951434543
> SELECT rand(0);
0.7604953758285915
> SELECT rand(null);
0.7604953758285915

Note: The function is non-deterministic in general case.

randn()

@spec randn() :: Latu.Plan.expression()

Spark's randn. Draws a random seed, so the plan is not reproducible — pass one to fix it.

randn([seed]) - Returns a random value with independent and identically distributed (i.i.d.) values drawn from the standard normal distribution.

Examples (Spark SQL)

> SELECT randn();
-0.3254147983080288
> SELECT randn(0);
1.6034991609278433
> SELECT randn(null);
1.6034991609278433

Note: The function is non-deterministic in general case.

randn(seed)

@spec randn(term()) :: Latu.Plan.expression()

Spark's randn. With an explicit seed, so the plan is reproducible.

randn([seed]) - Returns a random value with independent and identically distributed (i.i.d.) values drawn from the standard normal distribution.

Examples (Spark SQL)

> SELECT randn();
-0.3254147983080288
> SELECT randn(0);
1.6034991609278433
> SELECT randn(null);
1.6034991609278433

Note: The function is non-deterministic in general case.

rint(arg1)

@spec rint(term()) :: Latu.Plan.expression()

Spark's rint.

rint(expr) - Returns the double value that is closest in value to the argument and is equal to a mathematical integer.

Examples (Spark SQL)

> SELECT rint(12.3456);
12.0

round(arg1)

@spec round(term()) :: Latu.Plan.expression()

Spark's round. The trailing argument is optional.

round(expr, d) - Returns expr rounded to d decimal places using HALF_UP rounding mode.

Examples (Spark SQL)

> SELECT round(2.5, 0);
3

round(arg1, optional)

@spec round(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's round. With the optional trailing argument.

round(expr, d) - Returns expr rounded to d decimal places using HALF_UP rounding mode.

Examples (Spark SQL)

> SELECT round(2.5, 0);
3

sec(arg1)

@spec sec(term()) :: Latu.Plan.expression()

Spark's sec.

sec(expr) - Returns the secant of expr, as if computed by 1/java.lang.Math.cos.

Examples (Spark SQL)

> SELECT sec(0);
1.0

sign(arg1)

@spec sign(term()) :: Latu.Plan.expression()

Spark's sign.

sign(expr) - Returns -1.0, 0.0 or 1.0 as expr is negative, 0 or positive.

Examples (Spark SQL)

> SELECT sign(40);
1.0
> SELECT sign(INTERVAL -'100' YEAR);
-1.0

signum(arg1)

@spec signum(term()) :: Latu.Plan.expression()

Spark's signum.

signum(expr) - Returns -1.0, 0.0 or 1.0 as expr is negative, 0 or positive.

Examples (Spark SQL)

> SELECT signum(40);
1.0
> SELECT signum(INTERVAL -'100' YEAR);
-1.0

sin(arg1)

@spec sin(term()) :: Latu.Plan.expression()

Spark's sin.

sin(expr) - Returns the sine of expr, as if computed by java.lang.Math.sin.

Examples (Spark SQL)

> SELECT sin(0);
0.0

sinh(arg1)

@spec sinh(term()) :: Latu.Plan.expression()

Spark's sinh.

sinh(expr) - Returns hyperbolic sine of expr, as if computed by java.lang.Math.sinh.

Examples (Spark SQL)

> SELECT sinh(0);
0.0

sqrt(arg1)

@spec sqrt(term()) :: Latu.Plan.expression()

Spark's sqrt.

sqrt(expr) - Returns the square root of expr.

Examples (Spark SQL)

> SELECT sqrt(4);
2.0

tan(arg1)

@spec tan(term()) :: Latu.Plan.expression()

Spark's tan.

tan(expr) - Returns the tangent of expr, as if computed by java.lang.Math.tan.

Examples (Spark SQL)

> SELECT tan(0);
0.0

tanh(arg1)

@spec tanh(term()) :: Latu.Plan.expression()

Spark's tanh.

tanh(expr) - Returns the hyperbolic tangent of expr, as if computed by java.lang.Math.tanh.

Examples (Spark SQL)

> SELECT tanh(0);
0.0

try_add(arg1, arg2)

@spec try_add(term(), term()) :: Latu.Plan.expression()

Spark's try_add.

try_add(expr1, expr2) - Returns the sum of expr1and expr2 and the result is null on overflow. The acceptable input types are the same with the + operator.

Examples (Spark SQL)

> SELECT try_add(1, 2);
3
> SELECT try_add(2147483647, 1);
NULL
> SELECT try_add(date'2021-01-01', 1);
2021-01-02
> SELECT try_add(date'2021-01-01', interval 1 year);
2022-01-01
> SELECT try_add(timestamp'2021-01-01 00:00:00', interval 1 day);
2021-01-02 00:00:00
> SELECT try_add(interval 1 year, interval 2 year);
3-0

try_divide(arg1, arg2)

@spec try_divide(term(), term()) :: Latu.Plan.expression()

Spark's try_divide.

try_divide(dividend, divisor) - Returns dividend/divisor. It always performs floating point division. Its result is always null if expr2 is 0. dividend must be a numeric or an interval. divisor must be a numeric.

Examples (Spark SQL)

> SELECT try_divide(3, 2);
1.5
> SELECT try_divide(2L, 2L);
1.0
> SELECT try_divide(1, 0);
NULL
> SELECT try_divide(interval 2 month, 2);
0-1
> SELECT try_divide(interval 2 month, 0);
NULL

try_mod(arg1, arg2)

@spec try_mod(term(), term()) :: Latu.Plan.expression()

Spark's try_mod.

try_mod(dividend, divisor) - Returns the remainder after expr1/expr2. dividend must be a numeric. divisor must be a numeric.

Examples (Spark SQL)

> SELECT try_mod(3, 2);
1
> SELECT try_mod(2L, 2L);
0
> SELECT try_mod(3.0, 2.0);
1.0
> SELECT try_mod(1, 0);
NULL

try_multiply(arg1, arg2)

@spec try_multiply(term(), term()) :: Latu.Plan.expression()

Spark's try_multiply.

try_multiply(expr1, expr2) - Returns expr1expr2 and the result is null on overflow. The acceptable input types are the same with the `` operator.

Examples (Spark SQL)

> SELECT try_multiply(2, 3);
6
> SELECT try_multiply(-2147483648, 10);
NULL
> SELECT try_multiply(interval 2 year, 3);
6-0

try_subtract(arg1, arg2)

@spec try_subtract(term(), term()) :: Latu.Plan.expression()

Spark's try_subtract.

try_subtract(expr1, expr2) - Returns expr1-expr2 and the result is null on overflow. The acceptable input types are the same with the - operator.

Examples (Spark SQL)

> SELECT try_subtract(2, 1);
1
> SELECT try_subtract(-2147483648, 1);
NULL
> SELECT try_subtract(date'2021-01-02', 1);
2021-01-01
> SELECT try_subtract(date'2021-01-01', interval 1 year);
2020-01-01
> SELECT try_subtract(timestamp'2021-01-02 00:00:00', interval 1 day);
2021-01-01 00:00:00
> SELECT try_subtract(interval 2 year, interval 1 year);
1-0

unhex(arg1)

@spec unhex(term()) :: Latu.Plan.expression()

Spark's unhex.

unhex(expr) - Converts hexadecimal expr to binary.

Examples (Spark SQL)

> SELECT decode(unhex('537061726B2053514C'), 'UTF-8');
Spark SQL

uniform(arg1, arg2)

@spec uniform(term(), term()) :: Latu.Plan.expression()

Spark's uniform. Draws a random seed, so the plan is not reproducible — pass one to fix it.

uniform(min, max[, seed]) - Returns a random value with independent and identically distributed (i.i.d.) values with the specified range of numbers. The random seed is optional. The provided numbers specifying the minimum and maximum values of the range must be constant. If both of these numbers are integers, then the result will also be an integer. Otherwise if one or both of these are floating-point numbers, then the result will also be a floating-point number.

Examples (Spark SQL)

> SELECT uniform(10, 20, 0) > 0 AS result;
true

uniform(arg1, arg2, seed)

@spec uniform(term(), term(), term()) :: Latu.Plan.expression()

Spark's uniform. With an explicit seed, so the plan is reproducible.

uniform(min, max[, seed]) - Returns a random value with independent and identically distributed (i.i.d.) values with the specified range of numbers. The random seed is optional. The provided numbers specifying the minimum and maximum values of the range must be constant. If both of these numbers are integers, then the result will also be an integer. Otherwise if one or both of these are floating-point numbers, then the result will also be a floating-point number.

Examples (Spark SQL)

> SELECT uniform(10, 20, 0) > 0 AS result;
true

width_bucket(arg1, arg2, arg3, arg4)

@spec width_bucket(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's width_bucket.

width_bucket(value, min_value, max_value, num_bucket) - Returns the bucket number to which value would be assigned in an equiwidth histogram with num_bucket buckets, in the range min_value to max_value."

Examples (Spark SQL)

> SELECT width_bucket(5.3, 0.2, 10.6, 5);
3
> SELECT width_bucket(-2.1, 1.3, 3.4, 3);
0
> SELECT width_bucket(8.1, 0.0, 5.7, 4);
5
> SELECT width_bucket(-0.9, 5.2, 0.5, 2);
3
> SELECT width_bucket(INTERVAL '0' YEAR, INTERVAL '0' YEAR, INTERVAL '10' YEAR, 10);
1
> SELECT width_bucket(INTERVAL '1' YEAR, INTERVAL '0' YEAR, INTERVAL '10' YEAR, 10);
2
> SELECT width_bucket(INTERVAL '0' DAY, INTERVAL '0' DAY, INTERVAL '10' DAY, 10);
1
> SELECT width_bucket(INTERVAL '1' DAY, INTERVAL '0' DAY, INTERVAL '10' DAY, 10);
2

Misc Functions

aes_decrypt(arg1, arg2)

@spec aes_decrypt(term(), term()) :: Latu.Plan.expression()

Spark's aes_decrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "".

aes_decrypt(expr, key[, mode[, padding[, aad]]]) - Returns a decrypted value of expr using AES in mode with padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT aes_decrypt(unhex('83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94'), '0000111122223333');
Spark
> SELECT aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT aes_decrypt(unbase64('3lmwu+Mw0H3fi5NDvcu9lg=='), '1234567890abcdef', 'ECB', 'PKCS');
Spark SQL
> SELECT aes_decrypt(unbase64('2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo='), '1234567890abcdef', 'CBC');
Apache Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg='), 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT');
Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4'), 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', 'This is an AAD mixed into the input');
Spark

aes_decrypt(arg1, arg2, arg3)

@spec aes_decrypt(term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_decrypt. Sends Spark's defaults for the rest: "DEFAULT", "".

aes_decrypt(expr, key[, mode[, padding[, aad]]]) - Returns a decrypted value of expr using AES in mode with padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT aes_decrypt(unhex('83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94'), '0000111122223333');
Spark
> SELECT aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT aes_decrypt(unbase64('3lmwu+Mw0H3fi5NDvcu9lg=='), '1234567890abcdef', 'ECB', 'PKCS');
Spark SQL
> SELECT aes_decrypt(unbase64('2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo='), '1234567890abcdef', 'CBC');
Apache Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg='), 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT');
Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4'), 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', 'This is an AAD mixed into the input');
Spark

aes_decrypt(arg1, arg2, arg3, arg4)

@spec aes_decrypt(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_decrypt. Sends Spark's defaults for the rest: "".

aes_decrypt(expr, key[, mode[, padding[, aad]]]) - Returns a decrypted value of expr using AES in mode with padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT aes_decrypt(unhex('83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94'), '0000111122223333');
Spark
> SELECT aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT aes_decrypt(unbase64('3lmwu+Mw0H3fi5NDvcu9lg=='), '1234567890abcdef', 'ECB', 'PKCS');
Spark SQL
> SELECT aes_decrypt(unbase64('2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo='), '1234567890abcdef', 'CBC');
Apache Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg='), 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT');
Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4'), 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', 'This is an AAD mixed into the input');
Spark

aes_decrypt(arg1, arg2, arg3, arg4, arg5)

@spec aes_decrypt(term(), term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_decrypt. Every argument is sent.

aes_decrypt(expr, key[, mode[, padding[, aad]]]) - Returns a decrypted value of expr using AES in mode with padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT aes_decrypt(unhex('83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94'), '0000111122223333');
Spark
> SELECT aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT aes_decrypt(unbase64('3lmwu+Mw0H3fi5NDvcu9lg=='), '1234567890abcdef', 'ECB', 'PKCS');
Spark SQL
> SELECT aes_decrypt(unbase64('2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo='), '1234567890abcdef', 'CBC');
Apache Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg='), 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT');
Spark
> SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4'), 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', 'This is an AAD mixed into the input');
Spark

aes_encrypt(arg1, arg2)

@spec aes_encrypt(term(), term()) :: Latu.Plan.expression()

Spark's aes_encrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "", "".

aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of expr using AES in given mode with the specified padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional initialization vectors (IVs) are only supported for CBC and GCM modes. These must be 16 bytes for CBC and 12 bytes for GCM. If not provided, a random vector will be generated and prepended to the output. Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
> SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
> SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
> SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4

aes_encrypt(arg1, arg2, arg3)

@spec aes_encrypt(term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_encrypt. Sends Spark's defaults for the rest: "DEFAULT", "", "".

aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of expr using AES in given mode with the specified padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional initialization vectors (IVs) are only supported for CBC and GCM modes. These must be 16 bytes for CBC and 12 bytes for GCM. If not provided, a random vector will be generated and prepended to the output. Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
> SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
> SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
> SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4

aes_encrypt(arg1, arg2, arg3, arg4)

@spec aes_encrypt(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_encrypt. Sends Spark's defaults for the rest: "", "".

aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of expr using AES in given mode with the specified padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional initialization vectors (IVs) are only supported for CBC and GCM modes. These must be 16 bytes for CBC and 12 bytes for GCM. If not provided, a random vector will be generated and prepended to the output. Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
> SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
> SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
> SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4

aes_encrypt(arg1, arg2, arg3, arg4, arg5)

@spec aes_encrypt(term(), term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's aes_encrypt. Sends Spark's defaults for the rest: "".

aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of expr using AES in given mode with the specified padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional initialization vectors (IVs) are only supported for CBC and GCM modes. These must be 16 bytes for CBC and 12 bytes for GCM. If not provided, a random vector will be generated and prepended to the output. Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
> SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
> SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
> SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4

aes_encrypt(arg1, arg2, arg3, arg4, arg5, arg6)

@spec aes_encrypt(term(), term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's aes_encrypt. Every argument is sent.

aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of expr using AES in given mode with the specified padding. Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (mode, padding) are ('ECB', 'PKCS'), ('GCM', 'NONE') and ('CBC', 'PKCS'). Optional initialization vectors (IVs) are only supported for CBC and GCM modes. These must be 16 bytes for CBC and 12 bytes for GCM. If not provided, a random vector will be generated and prepended to the output. Optional additional authenticated data (AAD) is only supported for GCM. If provided for encryption, the identical AAD value must be provided for decryption. The default mode is GCM.

Examples (Spark SQL)

> SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
> SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
> SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
> SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
> SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4

assert_true(arg1)

@spec assert_true(term()) :: Latu.Plan.expression()

Spark's assert_true. The trailing argument is optional.

assert_true(expr [, message]) - Throws an exception if expr is not true.

Examples (Spark SQL)

> SELECT assert_true(0 < 1);
NULL

assert_true(arg1, optional)

@spec assert_true(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's assert_true. With the optional trailing argument.

assert_true(expr [, message]) - Throws an exception if expr is not true.

Examples (Spark SQL)

> SELECT assert_true(0 < 1);
NULL

bitmap_bit_position(arg1)

@spec bitmap_bit_position(term()) :: Latu.Plan.expression()

Spark's bitmap_bit_position.

bitmap_bit_position(child) - Returns the bit position for the given input child expression.

Examples (Spark SQL)

> SELECT bitmap_bit_position(1);
0
> SELECT bitmap_bit_position(123);
122

bitmap_bucket_number(arg1)

@spec bitmap_bucket_number(term()) :: Latu.Plan.expression()

Spark's bitmap_bucket_number.

bitmap_bucket_number(child) - Returns the bucket number for the given input child expression.

Examples (Spark SQL)

> SELECT bitmap_bucket_number(123);
1
> SELECT bitmap_bucket_number(0);
0

bitmap_count(arg1)

@spec bitmap_count(term()) :: Latu.Plan.expression()

Spark's bitmap_count.

bitmap_count(child) - Returns the number of set bits in the child bitmap.

Examples (Spark SQL)

> SELECT bitmap_count(X '1010');
2
> SELECT bitmap_count(X 'FFFF');
16
> SELECT bitmap_count(X '0');
0

current_catalog()

@spec current_catalog() :: Latu.Plan.expression()

Spark's current_catalog.

current_catalog() - Returns the current catalog.

Examples (Spark SQL)

> SELECT current_catalog();
spark_catalog

current_database()

@spec current_database() :: Latu.Plan.expression()

Spark's current_database.

current_database() - Returns the current database.

Examples (Spark SQL)

> SELECT current_database();
default

current_path()

@spec current_path() :: Latu.Plan.expression()

Spark's current_path.

current_path() - Returns the current SQL path (qualified schema names).

Examples (Spark SQL)

> SELECT current_path();
system.builtin,system.session,spark_catalog.default

current_schema()

@spec current_schema() :: Latu.Plan.expression()

Spark's current_schema.

current_schema() - Returns the current database.

Examples (Spark SQL)

> SELECT current_schema();
default

current_user()

@spec current_user() :: Latu.Plan.expression()

Spark's current_user.

current_user() - user name of current execution context.

Examples (Spark SQL)

> SELECT current_user();
mockingjay

input_file_block_length()

@spec input_file_block_length() :: Latu.Plan.expression()

Spark's input_file_block_length.

input_file_block_length() - Returns the length of the block being read, or -1 if not available.

Examples (Spark SQL)

> SELECT input_file_block_length();
-1

input_file_block_start()

@spec input_file_block_start() :: Latu.Plan.expression()

Spark's input_file_block_start.

input_file_block_start() - Returns the start offset of the block being read, or -1 if not available.

Examples (Spark SQL)

> SELECT input_file_block_start();
-1

input_file_name()

@spec input_file_name() :: Latu.Plan.expression()

Spark's input_file_name.

input_file_name() - Returns the name of the file being read, or empty string if not available.

Examples (Spark SQL)

> SELECT input_file_name();

java_method(columns)

@spec java_method([term()]) :: Latu.Plan.expression()

Spark's java_method. Variadic in Spark; takes a list here.

java_method(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.

Examples (Spark SQL)

> SELECT java_method('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
> SELECT java_method('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2

monotonically_increasing_id()

@spec monotonically_increasing_id() :: Latu.Plan.expression()

Spark's monotonically_increasing_id.

monotonically_increasing_id() - Returns monotonically increasing 64-bit integers. The generated ID is guaranteed to be monotonically increasing and unique, but not consecutive. The current implementation puts the partition ID in the upper 31 bits, and the lower 33 bits represent the record number within each partition. The assumption is that the data frame has less than 1 billion partitions, and each partition has less than 8 billion records. The function is non-deterministic because its result depends on partition IDs.

Examples (Spark SQL)

> SELECT monotonically_increasing_id();
0

raise_error(arg1)

@spec raise_error(term()) :: Latu.Plan.expression()

Spark's raise_error.

raise_error( expr ) - Throws a USER_RAISED_EXCEPTION with expr as message.

Examples (Spark SQL)

> SELECT raise_error('custom error message');
[USER_RAISED_EXCEPTION] custom error message

reflect(columns)

@spec reflect([term()]) :: Latu.Plan.expression()

Spark's reflect. Variadic in Spark; takes a list here.

reflect(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.

Examples (Spark SQL)

> SELECT reflect('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
> SELECT reflect('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2

session_user()

@spec session_user() :: Latu.Plan.expression()

Spark's session_user.

session_user() - user name of current execution context.

Examples (Spark SQL)

> SELECT session_user();
mockingjay

spark_partition_id()

@spec spark_partition_id() :: Latu.Plan.expression()

Spark's spark_partition_id.

spark_partition_id() - Returns the current partition id.

Examples (Spark SQL)

> SELECT spark_partition_id();
0

try_aes_decrypt(arg1, arg2)

@spec try_aes_decrypt(term(), term()) :: Latu.Plan.expression()

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "GCM", "DEFAULT", "".

try_aes_decrypt(expr, key[, mode[, padding[, aad]]]) - This is a special version of aes_decrypt that performs the same operation, but returns a NULL value instead of raising an error if the decryption cannot be performed.

Examples (Spark SQL)

> SELECT try_aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT try_aes_decrypt(unhex('----------468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
NULL

try_aes_decrypt(arg1, arg2, arg3)

@spec try_aes_decrypt(term(), term(), term()) :: Latu.Plan.expression()

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "DEFAULT", "".

try_aes_decrypt(expr, key[, mode[, padding[, aad]]]) - This is a special version of aes_decrypt that performs the same operation, but returns a NULL value instead of raising an error if the decryption cannot be performed.

Examples (Spark SQL)

> SELECT try_aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT try_aes_decrypt(unhex('----------468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
NULL

try_aes_decrypt(arg1, arg2, arg3, arg4)

@spec try_aes_decrypt(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's try_aes_decrypt. Sends Spark's defaults for the rest: "".

try_aes_decrypt(expr, key[, mode[, padding[, aad]]]) - This is a special version of aes_decrypt that performs the same operation, but returns a NULL value instead of raising an error if the decryption cannot be performed.

Examples (Spark SQL)

> SELECT try_aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT try_aes_decrypt(unhex('----------468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
NULL

try_aes_decrypt(arg1, arg2, arg3, arg4, arg5)

@spec try_aes_decrypt(term(), term(), term(), term(), term()) ::
  Latu.Plan.expression()

Spark's try_aes_decrypt. Every argument is sent.

try_aes_decrypt(expr, key[, mode[, padding[, aad]]]) - This is a special version of aes_decrypt that performs the same operation, but returns a NULL value instead of raising an error if the decryption cannot be performed.

Examples (Spark SQL)

> SELECT try_aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
> SELECT try_aes_decrypt(unhex('----------468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
NULL

try_reflect(columns)

@spec try_reflect([term()]) :: Latu.Plan.expression()

Spark's try_reflect. Variadic in Spark; takes a list here.

try_reflect(class, method[, arg1[, arg2 ..]]) - This is a special version of reflect that performs the same operation, but returns a NULL value instead of raising an error if the invoke method thrown exception.

Examples (Spark SQL)

> SELECT try_reflect('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
> SELECT try_reflect('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2
> SELECT try_reflect('java.net.URLDecoder', 'decode', '%');
NULL

typeof(arg1)

@spec typeof(term()) :: Latu.Plan.expression()

Spark's typeof.

typeof(expr) - Return DDL-formatted type string for the data type of the input.

Examples (Spark SQL)

> SELECT typeof(1);
int
> SELECT typeof(array(1));
array<int>

user()

@spec user() :: Latu.Plan.expression()

Spark's user.

user() - user name of current execution context.

Examples (Spark SQL)

> SELECT user();
mockingjay

uuid()

@spec uuid() :: Latu.Plan.expression()

Spark's uuid. Draws a random seed, so the plan is not reproducible — pass one to fix it.

uuid() - Returns an universally unique identifier (UUID) string. The value is returned as a canonical UUID 36-character string.

Examples (Spark SQL)

> SELECT uuid();
46707d92-02f4-4817-8116-a4c3b23e6266

Note: The function is non-deterministic.

uuid(seed)

@spec uuid(term()) :: Latu.Plan.expression()

Spark's uuid. With an explicit seed, so the plan is reproducible.

uuid() - Returns an universally unique identifier (UUID) string. The value is returned as a canonical UUID 36-character string.

Examples (Spark SQL)

> SELECT uuid();
46707d92-02f4-4817-8116-a4c3b23e6266

Note: The function is non-deterministic.

version()

@spec version() :: Latu.Plan.expression()

Spark's version.

version() - Returns the Spark version. The string contains 2 fields, the first being a release version and the second being a git revision.

Examples (Spark SQL)

> SELECT version();
3.1.0 a6d6ea3efedbad14d99c24143834cd4e2e52fb40

Normal Functions

call_function(name, arguments)

@spec call_function(String.t(), [term()]) :: Latu.Plan.expression()

Call a function by name through Spark's catalog.

F.call_function("my_udf", [:id])

A different wire node from everything else here — CallFunction rather than UnresolvedFunction — which is how Spark reaches a registered or user-defined function. Latu cannot ship a UDF, but it can call one that is already registered.

Predicate Functions

equal_null(arg1, arg2)

@spec equal_null(term(), term()) :: Latu.Plan.expression()

Spark's equal_null.

equal_null(expr1, expr2) - Returns same result as the EQUAL(=) operator for non-null operands, but returns true if both are null, false if one of the them is null.

Examples (Spark SQL)

> SELECT equal_null(3, 3);
true
> SELECT equal_null(1, '11');
false
> SELECT equal_null(true, NULL);
false
> SELECT equal_null(NULL, 'abc');
false
> SELECT equal_null(NULL, NULL);
true

regexp(arg1, arg2)

@spec regexp(term(), term()) :: Latu.Plan.expression()

Spark's regexp.

regexp(str, regexp) - Returns true if str matches regexp, or false otherwise.

Examples (Spark SQL)

> SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals	true
> SELECT regexp('%SystemDrive%\Users\John', '%SystemDrive%\\Users.*');
true
> SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals	false
> SELECT regexp('%SystemDrive%\\Users\\John', '%SystemDrive%\\\\Users.*');
true
> SELECT regexp('%SystemDrive%\\Users\\John', r'%SystemDrive%\\Users.*');
true

Note: Use LIKE to match with simple string pattern.

regexp_like(arg1, arg2)

@spec regexp_like(term(), term()) :: Latu.Plan.expression()

Spark's regexp_like.

regexp_like(str, regexp) - Returns true if str matches regexp, or false otherwise.

Examples (Spark SQL)

> SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals	true
> SELECT regexp_like('%SystemDrive%\Users\John', '%SystemDrive%\\Users.*');
true
> SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals	false
> SELECT regexp_like('%SystemDrive%\\Users\\John', '%SystemDrive%\\\\Users.*');
true
> SELECT regexp_like('%SystemDrive%\\Users\\John', r'%SystemDrive%\\Users.*');
true

Note: Use LIKE to match with simple string pattern.

String Functions

ascii(arg1)

@spec ascii(term()) :: Latu.Plan.expression()

Spark's ascii.

ascii(str) - Returns the numeric value of the first character of str.

Examples (Spark SQL)

> SELECT ascii('222');
50
> SELECT ascii(2);
50

base64(arg1)

@spec base64(term()) :: Latu.Plan.expression()

Spark's base64.

base64(bin) - Converts the argument from a binary bin to a base 64 string.

Examples (Spark SQL)

> SELECT base64('Spark SQL');
U3BhcmsgU1FM
> SELECT base64(x'537061726b2053514c');
U3BhcmsgU1FM

bit_length(arg1)

@spec bit_length(term()) :: Latu.Plan.expression()

Spark's bit_length.

bit_length(expr) - Returns the bit length of string data or number of bits of binary data.

Examples (Spark SQL)

> SELECT bit_length('Spark SQL');
72
> SELECT bit_length(x'537061726b2053514c');
72

btrim(arg1)

@spec btrim(term()) :: Latu.Plan.expression()

Spark's btrim. The trailing argument is optional.

btrim(str) - Removes the leading and trailing space characters from str. btrim(str, trimStr) - Remove the leading and trailing trimStr characters from str.

Examples (Spark SQL)

> SELECT btrim('    SparkSQL   ');
SparkSQL
> SELECT btrim(encode('    SparkSQL   ', 'utf-8'));
SparkSQL
> SELECT btrim('SSparkSQLS', 'SL');
parkSQ
> SELECT btrim(encode('SSparkSQLS', 'utf-8'), encode('SL', 'utf-8'));
parkSQ

btrim(arg1, optional)

@spec btrim(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's btrim. With the optional trailing argument.

btrim(str) - Removes the leading and trailing space characters from str. btrim(str, trimStr) - Remove the leading and trailing trimStr characters from str.

Examples (Spark SQL)

> SELECT btrim('    SparkSQL   ');
SparkSQL
> SELECT btrim(encode('    SparkSQL   ', 'utf-8'));
SparkSQL
> SELECT btrim('SSparkSQLS', 'SL');
parkSQ
> SELECT btrim(encode('SSparkSQLS', 'utf-8'), encode('SL', 'utf-8'));
parkSQ

char(arg1)

@spec char(term()) :: Latu.Plan.expression()

Spark's char.

char(expr) - Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)

Examples (Spark SQL)

> SELECT char(65);
A

char_length(arg1)

@spec char_length(term()) :: Latu.Plan.expression()

Spark's char_length.

char_length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.

Examples (Spark SQL)

> SELECT char_length('Spark SQL ');
10
> SELECT char_length(x'537061726b2053514c');
9
> SELECT CHAR_LENGTH('Spark SQL ');
10
> SELECT CHARACTER_LENGTH('Spark SQL ');
10

character_length(arg1)

@spec character_length(term()) :: Latu.Plan.expression()

Spark's character_length.

character_length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.

Examples (Spark SQL)

> SELECT character_length('Spark SQL ');
10
> SELECT character_length(x'537061726b2053514c');
9
> SELECT CHAR_LENGTH('Spark SQL ');
10
> SELECT CHARACTER_LENGTH('Spark SQL ');
10

chr(arg1)

@spec chr(term()) :: Latu.Plan.expression()

Spark's chr.

chr(expr) - Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)

Examples (Spark SQL)

> SELECT chr(65);
A

collate(arg1, arg2)

@spec collate(term(), term()) :: Latu.Plan.expression()

Spark's collate.

collate(expr, collationName) - Marks a given expression with the specified collation.

Examples (Spark SQL)

> SELECT COLLATION('Spark SQL' collate UTF8_LCASE);
SYSTEM.BUILTIN.UTF8_LCASE

collation(arg1)

@spec collation(term()) :: Latu.Plan.expression()

Spark's collation.

collation(expr) - Returns the collation name of a given expression.

Examples (Spark SQL)

> SELECT collation('Spark SQL');
SYSTEM.BUILTIN.UTF8_BINARY

concat_ws(first, columns)

@spec concat_ws(term(), [term()]) :: Latu.Plan.expression()

Spark's concat_ws. Variadic in Spark; takes a list here.

concat_ws(sep[, str | array(str)]+) - Returns the concatenation of the strings separated by sep, skipping null values.

Examples (Spark SQL)

> SELECT concat_ws(' ', 'Spark', 'SQL');
Spark SQL
> SELECT concat_ws('s');
> SELECT concat_ws('/', 'foo', null, 'bar');
foo/bar
> SELECT concat_ws(null, 'Spark', 'SQL');
NULL

decode(arg1, arg2)

@spec decode(term(), term()) :: Latu.Plan.expression()

Spark's decode.

decode(bin, charset) - Decodes the first argument using the second argument character set. If either argument is null, the result will also be null. decode(expr, search, result [, search, result ] ... [, default]) - Compares expr to each search value in order. If expr is equal to a search value, decode returns the corresponding result. If no match is found, then it returns default. If default is omitted, it returns null.

Examples (Spark SQL)

> SELECT decode(encode('abc', 'utf-8'), 'utf-8');
abc
> SELECT decode(2, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic');
San Francisco
> SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic');
Non domestic
> SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle');
NULL
> SELECT decode(null, 6, 'Spark', NULL, 'SQL', 4, 'rocks');
SQL

Note: decode(expr, search, result [, search, result ] ... [, default]) is supported since 3.2.0

elt(columns)

@spec elt([term()]) :: Latu.Plan.expression()

Spark's elt. Variadic in Spark; takes a list here.

elt(n, input1, input2, ...) - Returns the n-th input, e.g., returns input2 when n is 2. The function returns NULL if the index exceeds the length of the array and spark.sql.ansi.enabled is set to false. If spark.sql.ansi.enabled is set to true, it throws ArrayIndexOutOfBoundsException for invalid indices.

Examples (Spark SQL)

> SELECT elt(1, 'scala', 'java');
scala
> SELECT elt(2, 'a', 1);
1

encode(arg1, arg2)

@spec encode(term(), term()) :: Latu.Plan.expression()

Spark's encode.

encode(str, charset) - Encodes the first argument using the second argument character set. If either argument is null, the result will also be null.

Examples (Spark SQL)

> SELECT encode('abc', 'utf-8');
abc

find_in_set(arg1, arg2)

@spec find_in_set(term(), term()) :: Latu.Plan.expression()

Spark's find_in_set.

find_in_set(str, str_array) - Returns the index (1-based) of the given string (str) in the comma-delimited list (str_array). Returns 0, if the string was not found or if the given string (str) contains a comma.

Examples (Spark SQL)

> SELECT find_in_set('ab','abc,b,ab,c,def');
3

format_number(arg1, arg2)

@spec format_number(term(), term()) :: Latu.Plan.expression()

Spark's format_number.

format_number(expr1, expr2) - Formats the number expr1 like '#,###,###.##', rounded to expr2 decimal places. If expr2 is 0, the result has no decimal point or fractional part. expr2 also accept a user specified format. This is supposed to function like MySQL's FORMAT.

Examples (Spark SQL)

> SELECT format_number(12332.123456, 4);
12,332.1235
> SELECT format_number(12332.123456, '##################.###');
12332.123

format_string(first, columns)

@spec format_string(term(), [term()]) :: Latu.Plan.expression()

Spark's format_string. Variadic in Spark; takes a list here.

format_string(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.

Examples (Spark SQL)

> SELECT format_string("Hello World %d %s", 100, "days");
Hello World 100 days

initcap(arg1)

@spec initcap(term()) :: Latu.Plan.expression()

Spark's initcap.

initcap(str) - Returns str with the first letter of each word in uppercase. All other letters are in lowercase. Words are delimited by white space.

Examples (Spark SQL)

> SELECT initcap('sPark sql');
Spark Sql

instr(arg1, arg2)

@spec instr(term(), term()) :: Latu.Plan.expression()

Spark's instr.

instr(str, substr) - Returns the (1-based) index of the first occurrence of substr in str.

Examples (Spark SQL)

> SELECT instr('SparkSQL', 'SQL');
6

is_valid_utf8(arg1)

@spec is_valid_utf8(term()) :: Latu.Plan.expression()

Spark's is_valid_utf8.

is_valid_utf8(str) - Returns true if str is a valid UTF-8 string, otherwise returns false.

Examples (Spark SQL)

> SELECT is_valid_utf8('Spark');
true
> SELECT is_valid_utf8(x'61');
true
> SELECT is_valid_utf8(x'80');
false
> SELECT is_valid_utf8(x'61C262');
false

lcase(arg1)

@spec lcase(term()) :: Latu.Plan.expression()

Spark's lcase.

lcase(str) - Returns str with all characters changed to lowercase.

Examples (Spark SQL)

> SELECT lcase('SparkSql');
sparksql

left(arg1, arg2)

@spec left(term(), term()) :: Latu.Plan.expression()

Spark's left.

left(str, len) - Returns the leftmost len(len can be string type) characters from the string str,if len is less or equal than 0 the result is an empty string.

Examples (Spark SQL)

> SELECT left('Spark SQL', 3);
Spa
> SELECT left(encode('Spark SQL', 'utf-8'), 3);
Spa

length(arg1)

@spec length(term()) :: Latu.Plan.expression()

Spark's length.

length(expr) - Returns the character length of string data or number of bytes of binary data. The length of string data includes the trailing spaces. The length of binary data includes binary zeros.

Examples (Spark SQL)

> SELECT length('Spark SQL ');
10
> SELECT length(x'537061726b2053514c');
9
> SELECT CHAR_LENGTH('Spark SQL ');
10
> SELECT CHARACTER_LENGTH('Spark SQL ');
10

levenshtein(arg1, arg2)

@spec levenshtein(term(), term()) :: Latu.Plan.expression()

Spark's levenshtein. The trailing argument is optional.

levenshtein(str1, str2[, threshold]) - Returns the Levenshtein distance between the two given strings. If threshold is set and distance more than it, return -1.

Examples (Spark SQL)

> SELECT levenshtein('kitten', 'sitting');
3
> SELECT levenshtein('kitten', 'sitting', 2);
-1

levenshtein(arg1, arg2, optional)

@spec levenshtein(term(), term(), term()) :: Latu.Plan.expression()

Spark's levenshtein. With the optional trailing argument.

levenshtein(str1, str2[, threshold]) - Returns the Levenshtein distance between the two given strings. If threshold is set and distance more than it, return -1.

Examples (Spark SQL)

> SELECT levenshtein('kitten', 'sitting');
3
> SELECT levenshtein('kitten', 'sitting', 2);
-1

locate(arg1, arg2)

@spec locate(term(), term()) :: Latu.Plan.expression()

Spark's locate. Sends Spark's defaults for the rest: 1.

locate(substr, str[, pos]) - Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.

Examples (Spark SQL)

> SELECT locate('bar', 'foobarbar');
4
> SELECT locate('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' IN 'foobarbar');
4

locate(arg1, arg2, arg3)

@spec locate(term(), term(), term()) :: Latu.Plan.expression()

Spark's locate. Every argument is sent.

locate(substr, str[, pos]) - Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.

Examples (Spark SQL)

> SELECT locate('bar', 'foobarbar');
4
> SELECT locate('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' IN 'foobarbar');
4

lower(arg1)

@spec lower(term()) :: Latu.Plan.expression()

Spark's lower.

lower(str) - Returns str with all characters changed to lowercase.

Examples (Spark SQL)

> SELECT lower('SparkSql');
sparksql

lpad(arg1, arg2, arg3)

@spec lpad(term(), term(), term()) :: Latu.Plan.expression()

Spark's lpad.

lpad(str, len[, pad]) - Returns str, left-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters or bytes. If pad is not specified, str will be padded to the left with space characters if it is a character string, and with zeros if it is a byte sequence.

Examples (Spark SQL)

> SELECT lpad('hi', 5, '??');
???hi
> SELECT lpad('hi', 1, '??');
h
> SELECT lpad('hi', 5);
hi
> SELECT hex(lpad(unhex('aabb'), 5));
000000AABB
> SELECT hex(lpad(unhex('aabb'), 5, unhex('1122')));
112211AABB

ltrim(column)

@spec ltrim(term()) :: Latu.Plan.expression()

Strip characters from the left. Reversed on the wire, as trim/2 is.

ltrim(column, characters)

@spec ltrim(term(), term()) :: Latu.Plan.expression()

Trim the given characters from the left. Spark takes them first; Latu does not.

make_valid_utf8(arg1)

@spec make_valid_utf8(term()) :: Latu.Plan.expression()

Spark's make_valid_utf8.

make_valid_utf8(str) - Returns the original string if str is a valid UTF-8 string, otherwise returns a new string whose invalid UTF8 byte sequences are replaced using the UNICODE replacement character U+FFFD.

Examples (Spark SQL)

> SELECT make_valid_utf8('Spark');
Spark
> SELECT make_valid_utf8(x'61');
a
> SELECT make_valid_utf8(x'80');
�
> SELECT make_valid_utf8(x'61C262');
a�b

mask(arg1)

@spec mask(term()) :: Latu.Plan.expression()

Spark's mask. Sends Spark's defaults for the rest: "X", "x", "n", nil.

mask(input[, upperChar, lowerChar, digitChar, otherChar]) - masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.

Examples (Spark SQL)

> SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
> SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
> SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
> SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
> SELECT mask(NULL);
NULL
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#

mask(arg1, arg2)

@spec mask(term(), term()) :: Latu.Plan.expression()

Spark's mask. Sends Spark's defaults for the rest: "x", "n", nil.

mask(input[, upperChar, lowerChar, digitChar, otherChar]) - masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.

Examples (Spark SQL)

> SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
> SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
> SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
> SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
> SELECT mask(NULL);
NULL
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#

mask(arg1, arg2, arg3)

@spec mask(term(), term(), term()) :: Latu.Plan.expression()

Spark's mask. Sends Spark's defaults for the rest: "n", nil.

mask(input[, upperChar, lowerChar, digitChar, otherChar]) - masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.

Examples (Spark SQL)

> SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
> SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
> SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
> SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
> SELECT mask(NULL);
NULL
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#

mask(arg1, arg2, arg3, arg4)

@spec mask(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's mask. Sends Spark's defaults for the rest: nil.

mask(input[, upperChar, lowerChar, digitChar, otherChar]) - masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.

Examples (Spark SQL)

> SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
> SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
> SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
> SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
> SELECT mask(NULL);
NULL
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#

mask(arg1, arg2, arg3, arg4, arg5)

@spec mask(term(), term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's mask. Every argument is sent.

mask(input[, upperChar, lowerChar, digitChar, otherChar]) - masks the given string value. The function replaces characters with 'X' or 'x', and numbers with 'n'. This can be useful for creating copies of tables with sensitive information removed.

Examples (Spark SQL)

> SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
> SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
> SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
> SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
> SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
> SELECT mask(NULL);
NULL
> SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#

octet_length(arg1)

@spec octet_length(term()) :: Latu.Plan.expression()

Spark's octet_length.

octet_length(expr) - Returns the byte length of string data or number of bytes of binary data.

Examples (Spark SQL)

> SELECT octet_length('Spark SQL');
9
> SELECT octet_length(x'537061726b2053514c');
9

overlay(arg1, arg2, arg3)

@spec overlay(term(), term(), term()) :: Latu.Plan.expression()

Spark's overlay. Sends Spark's defaults for the rest: -1.

overlay(input, replace, pos[, len]) - Replace input with replace that starts at pos and is of length len.

Examples (Spark SQL)

> SELECT overlay('Spark SQL' PLACING '_' FROM 6);
Spark_SQL
> SELECT overlay('Spark SQL' PLACING 'CORE' FROM 7);
Spark CORE
> SELECT overlay('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0);
Spark ANSI SQL
> SELECT overlay('Spark SQL' PLACING 'tructured' FROM 2 FOR 4);
Structured SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('_', 'utf-8') FROM 6);
Spark_SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('CORE', 'utf-8') FROM 7);
Spark CORE
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('ANSI ', 'utf-8') FROM 7 FOR 0);
Spark ANSI SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('tructured', 'utf-8') FROM 2 FOR 4);
Structured SQL

overlay(arg1, arg2, arg3, arg4)

@spec overlay(term(), term(), term(), term()) :: Latu.Plan.expression()

Spark's overlay. Every argument is sent.

overlay(input, replace, pos[, len]) - Replace input with replace that starts at pos and is of length len.

Examples (Spark SQL)

> SELECT overlay('Spark SQL' PLACING '_' FROM 6);
Spark_SQL
> SELECT overlay('Spark SQL' PLACING 'CORE' FROM 7);
Spark CORE
> SELECT overlay('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0);
Spark ANSI SQL
> SELECT overlay('Spark SQL' PLACING 'tructured' FROM 2 FOR 4);
Structured SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('_', 'utf-8') FROM 6);
Spark_SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('CORE', 'utf-8') FROM 7);
Spark CORE
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('ANSI ', 'utf-8') FROM 7 FOR 0);
Spark ANSI SQL
> SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('tructured', 'utf-8') FROM 2 FOR 4);
Structured SQL

position(arg1, arg2)

@spec position(term(), term()) :: Latu.Plan.expression()

Spark's position. The trailing argument is optional.

position(substr, str[, pos]) - Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.

Examples (Spark SQL)

> SELECT position('bar', 'foobarbar');
4
> SELECT position('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' IN 'foobarbar');
4

position(arg1, arg2, optional)

@spec position(term(), term(), term()) :: Latu.Plan.expression()

Spark's position. With the optional trailing argument.

position(substr, str[, pos]) - Returns the position of the first occurrence of substr in str after position pos. The given pos and return value are 1-based.

Examples (Spark SQL)

> SELECT position('bar', 'foobarbar');
4
> SELECT position('bar', 'foobarbar', 5);
7
> SELECT POSITION('bar' IN 'foobarbar');
4

printf(first, columns)

@spec printf(term(), [term()]) :: Latu.Plan.expression()

Spark's printf. Variadic in Spark; takes a list here.

printf(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.

Examples (Spark SQL)

> SELECT printf("Hello World %d %s", 100, "days");
Hello World 100 days

quote(arg1)

@spec quote(term()) :: Latu.Plan.expression()

Spark's quote.

quote(str) - Returns str enclosed by single quotes and each instance of single quote in it is preceded by a backslash.

Examples (Spark SQL)

> SELECT quote('Don\'t');
'Don\'t'

randstr(arg1)

@spec randstr(term()) :: Latu.Plan.expression()

Spark's randstr. Draws a random seed, so the plan is not reproducible — pass one to fix it.

randstr(length[, seed]) - Returns a string of the specified length whose characters are chosen uniformly at random from the following pool of characters: 0-9, a-z, A-Z. The random seed is optional. The string length must be a constant two-byte or four-byte integer (SMALLINT or INT, respectively).

Examples (Spark SQL)

> SELECT randstr(3, 0) AS result;
ceV

randstr(arg1, seed)

@spec randstr(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's randstr. With an explicit seed, so the plan is reproducible.

randstr(length[, seed]) - Returns a string of the specified length whose characters are chosen uniformly at random from the following pool of characters: 0-9, a-z, A-Z. The random seed is optional. The string length must be a constant two-byte or four-byte integer (SMALLINT or INT, respectively).

Examples (Spark SQL)

> SELECT randstr(3, 0) AS result;
ceV

regexp_count(arg1, arg2)

@spec regexp_count(term(), term()) :: Latu.Plan.expression()

Spark's regexp_count.

regexp_count(str, regexp) - Returns a count of the number of times that the regular expression pattern regexp is matched in the string str.

Examples (Spark SQL)

> SELECT regexp_count('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
2
> SELECT regexp_count('abcdefghijklmnopqrstuvwxyz', '[a-z]{3}');
8

regexp_extract(arg1, arg2, arg3)

@spec regexp_extract(term(), term(), term()) :: Latu.Plan.expression()

Spark's regexp_extract.

regexp_extract(str, regexp[, idx]) - Extract the first string in the str that match the regexp expression and corresponding to the regex group index.

Examples (Spark SQL)

> SELECT regexp_extract('100-200', '(\\d+)-(\\d+)', 1);
100
> SELECT regexp_extract('100-200', r'(\d+)-(\d+)', 1);
100

regexp_extract_all(arg1, arg2)

@spec regexp_extract_all(term(), term()) :: Latu.Plan.expression()

Spark's regexp_extract_all. The trailing argument is optional.

regexp_extract_all(str, regexp[, idx]) - Extract all strings in the str that match the regexp expression and corresponding to the regex group index.

Examples (Spark SQL)

> SELECT regexp_extract_all('100-200, 300-400', '(\\d+)-(\\d+)', 1);
["100","300"]
> SELECT regexp_extract_all('100-200, 300-400', r'(\d+)-(\d+)', 1);
["100","300"]

regexp_extract_all(arg1, arg2, optional)

@spec regexp_extract_all(term(), term(), term()) :: Latu.Plan.expression()

Spark's regexp_extract_all. With the optional trailing argument.

regexp_extract_all(str, regexp[, idx]) - Extract all strings in the str that match the regexp expression and corresponding to the regex group index.

Examples (Spark SQL)

> SELECT regexp_extract_all('100-200, 300-400', '(\\d+)-(\\d+)', 1);
["100","300"]
> SELECT regexp_extract_all('100-200, 300-400', r'(\d+)-(\d+)', 1);
["100","300"]

regexp_instr(arg1, arg2)

@spec regexp_instr(term(), term()) :: Latu.Plan.expression()

Spark's regexp_instr. The trailing argument is optional.

regexp_instr(str, regexp) - Searches a string for a regular expression and returns an integer that indicates the beginning position of the matched substring. Positions are 1-based, not 0-based. If no match is found, returns 0.

Examples (Spark SQL)

> SELECT regexp_instr(r"\abc", r"^\\abc$");
1
> SELECT regexp_instr('user@spark.apache.org', '@[^.]*');
5

regexp_instr(arg1, arg2, optional)

@spec regexp_instr(term(), term(), term()) :: Latu.Plan.expression()

Spark's regexp_instr. With the optional trailing argument.

regexp_instr(str, regexp) - Searches a string for a regular expression and returns an integer that indicates the beginning position of the matched substring. Positions are 1-based, not 0-based. If no match is found, returns 0.

Examples (Spark SQL)

> SELECT regexp_instr(r"\abc", r"^\\abc$");
1
> SELECT regexp_instr('user@spark.apache.org', '@[^.]*');
5

regexp_replace(arg1, arg2, arg3)

@spec regexp_replace(term(), term(), term()) :: Latu.Plan.expression()

Spark's regexp_replace.

regexp_replace(str, regexp, rep[, position]) - Replaces all substrings of str that match regexp with rep.

Examples (Spark SQL)

> SELECT regexp_replace('100-200', '(\\d+)', 'num');
num-num
> SELECT regexp_replace('100-200', r'(\d+)', 'num');
num-num

regexp_substr(arg1, arg2)

@spec regexp_substr(term(), term()) :: Latu.Plan.expression()

Spark's regexp_substr.

regexp_substr(str, regexp) - Returns the substring that matches the regular expression regexp within the string str. If the regular expression is not found, the result is null.

Examples (Spark SQL)

> SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
Steven
> SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Jeck');
NULL

repeat(arg1, arg2)

@spec repeat(term(), term()) :: Latu.Plan.expression()

Spark's repeat.

repeat(str, n) - Returns the string which repeats the given string value n times.

Examples (Spark SQL)

> SELECT repeat('123', 2);
123123

replace(arg1, arg2)

@spec replace(term(), term()) :: Latu.Plan.expression()

Spark's replace. The trailing argument is optional.

replace(str, search[, replace]) - Replaces all occurrences of search with replace.

Examples (Spark SQL)

> SELECT replace('ABCabc', 'abc', 'DEF');
ABCDEF

replace(arg1, arg2, optional)

@spec replace(term(), term(), term()) :: Latu.Plan.expression()

Spark's replace. With the optional trailing argument.

replace(str, search[, replace]) - Replaces all occurrences of search with replace.

Examples (Spark SQL)

> SELECT replace('ABCabc', 'abc', 'DEF');
ABCDEF

right(arg1, arg2)

@spec right(term(), term()) :: Latu.Plan.expression()

Spark's right.

right(str, len) - Returns the rightmost len(len can be string type) characters from the string str,if len is less or equal than 0 the result is an empty string.

Examples (Spark SQL)

> SELECT right('Spark SQL', 3);
SQL

rpad(arg1, arg2, arg3)

@spec rpad(term(), term(), term()) :: Latu.Plan.expression()

Spark's rpad.

rpad(str, len[, pad]) - Returns str, right-padded with pad to a length of len. If str is longer than len, the return value is shortened to len characters. If pad is not specified, str will be padded to the right with space characters if it is a character string, and with zeros if it is a binary string.

Examples (Spark SQL)

> SELECT rpad('hi', 5, '??');
hi???
> SELECT rpad('hi', 1, '??');
h
> SELECT rpad('hi', 5);
hi
> SELECT hex(rpad(unhex('aabb'), 5));
AABB000000
> SELECT hex(rpad(unhex('aabb'), 5, unhex('1122')));
AABB112211

rtrim(column)

@spec rtrim(term()) :: Latu.Plan.expression()

Strip characters from the right. Reversed on the wire, as trim/2 is.

rtrim(column, characters)

@spec rtrim(term(), term()) :: Latu.Plan.expression()

Trim the given characters from the right. Spark takes them first; Latu does not.

sentences(arg1)

@spec sentences(term()) :: Latu.Plan.expression()

Spark's sentences. Sends Spark's defaults for the rest: "", "".

sentences(str[, lang[, country]]) - Splits str into an array of array of words.

Examples (Spark SQL)

> SELECT sentences('Hi there! Good morning.');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en', 'US');
[["Hi","there"],["Good","morning"]]

sentences(arg1, arg2)

@spec sentences(term(), term()) :: Latu.Plan.expression()

Spark's sentences. Sends Spark's defaults for the rest: "".

sentences(str[, lang[, country]]) - Splits str into an array of array of words.

Examples (Spark SQL)

> SELECT sentences('Hi there! Good morning.');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en', 'US');
[["Hi","there"],["Good","morning"]]

sentences(arg1, arg2, arg3)

@spec sentences(term(), term(), term()) :: Latu.Plan.expression()

Spark's sentences. Every argument is sent.

sentences(str[, lang[, country]]) - Splits str into an array of array of words.

Examples (Spark SQL)

> SELECT sentences('Hi there! Good morning.');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en');
[["Hi","there"],["Good","morning"]]
> SELECT sentences('Hi there! Good morning.', 'en', 'US');
[["Hi","there"],["Good","morning"]]

soundex(arg1)

@spec soundex(term()) :: Latu.Plan.expression()

Spark's soundex.

soundex(str) - Returns Soundex code of the string.

Examples (Spark SQL)

> SELECT soundex('Miller');
M460

split(arg1, arg2)

@spec split(term(), term()) :: Latu.Plan.expression()

Spark's split. Sends Spark's defaults for the rest: -1.

split(str, regex, limit) - Splits str around occurrences that match regex and returns an array with a length of at most limit

Examples (Spark SQL)

> SELECT split('oneAtwoBthreeC', '[ABC]');
["one","two","three",""]
> SELECT split('oneAtwoBthreeC', '[ABC]', -1);
["one","two","three",""]
> SELECT split('oneAtwoBthreeC', '[ABC]', 2);
["one","twoBthreeC"]

split(arg1, arg2, arg3)

@spec split(term(), term(), term()) :: Latu.Plan.expression()

Spark's split. Every argument is sent.

split(str, regex, limit) - Splits str around occurrences that match regex and returns an array with a length of at most limit

Examples (Spark SQL)

> SELECT split('oneAtwoBthreeC', '[ABC]');
["one","two","three",""]
> SELECT split('oneAtwoBthreeC', '[ABC]', -1);
["one","two","three",""]
> SELECT split('oneAtwoBthreeC', '[ABC]', 2);
["one","twoBthreeC"]

split_part(arg1, arg2, arg3)

@spec split_part(term(), term(), term()) :: Latu.Plan.expression()

Spark's split_part.

split_part(str, delimiter, partNum) - Splits str by delimiter and return requested part of the split (1-based). If any input is null, returns null. if partNum is out of range of split parts, returns empty string. If partNum is 0, throws an error. If partNum is negative, the parts are counted backward from the end of the string. If the delimiter is an empty string, the str is not split.

Examples (Spark SQL)

> SELECT split_part('11.12.13', '.', 3);
13

substr(arg1, arg2)

@spec substr(term(), term()) :: Latu.Plan.expression()

Spark's substr. The trailing argument is optional.

substr(str, pos[, len]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len. substr(str FROM pos[ FOR len]]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.

Examples (Spark SQL)

> SELECT substr('Spark SQL', 5);
k SQL
> SELECT substr('Spark SQL', -3);
SQL
> SELECT substr('Spark SQL', 5, 1);
k
> SELECT substr('Spark SQL' FROM 5);
k SQL
> SELECT substr('Spark SQL' FROM -3);
SQL
> SELECT substr('Spark SQL' FROM 5 FOR 1);
k
> SELECT substr(encode('Spark SQL', 'utf-8'), 5);
k SQL

substr(arg1, arg2, optional)

@spec substr(term(), term(), term()) :: Latu.Plan.expression()

Spark's substr. With the optional trailing argument.

substr(str, pos[, len]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len. substr(str FROM pos[ FOR len]]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.

Examples (Spark SQL)

> SELECT substr('Spark SQL', 5);
k SQL
> SELECT substr('Spark SQL', -3);
SQL
> SELECT substr('Spark SQL', 5, 1);
k
> SELECT substr('Spark SQL' FROM 5);
k SQL
> SELECT substr('Spark SQL' FROM -3);
SQL
> SELECT substr('Spark SQL' FROM 5 FOR 1);
k
> SELECT substr(encode('Spark SQL', 'utf-8'), 5);
k SQL

substring(arg1, arg2, arg3)

@spec substring(term(), term(), term()) :: Latu.Plan.expression()

Spark's substring.

substring(str, pos[, len]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len. substring(str FROM pos[ FOR len]]) - Returns the substring of str that starts at pos and is of length len, or the slice of byte array that starts at pos and is of length len.

Examples (Spark SQL)

> SELECT substring('Spark SQL', 5);
k SQL
> SELECT substring('Spark SQL', -3);
SQL
> SELECT substring('Spark SQL', 5, 1);
k
> SELECT substring('Spark SQL' FROM 5);
k SQL
> SELECT substring('Spark SQL' FROM -3);
SQL
> SELECT substring('Spark SQL' FROM 5 FOR 1);
k
> SELECT substring(encode('Spark SQL', 'utf-8'), 5);
k SQL

substring_index(arg1, arg2, arg3)

@spec substring_index(term(), term(), term()) :: Latu.Plan.expression()

Spark's substring_index.

substring_index(str, delim, count) - Returns the substring from str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. The function substring_index performs a case-sensitive match when searching for delim.

Examples (Spark SQL)

> SELECT substring_index('www.apache.org', '.', 2);
www.apache

to_binary(arg1)

@spec to_binary(term()) :: Latu.Plan.expression()

Spark's to_binary. The trailing argument is optional.

to_binary(str[, fmt]) - Converts the input str to a binary value based on the supplied fmt. fmt can be a case-insensitive string literal of "hex", "utf-8", "utf8", or "base64". By default, the binary format for conversion is "hex" if fmt is omitted. The function returns NULL if at least one of the input parameters is NULL.

Examples (Spark SQL)

> SELECT to_binary('abc', 'utf-8');
abc

to_binary(arg1, optional)

@spec to_binary(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's to_binary. With the optional trailing argument.

to_binary(str[, fmt]) - Converts the input str to a binary value based on the supplied fmt. fmt can be a case-insensitive string literal of "hex", "utf-8", "utf8", or "base64". By default, the binary format for conversion is "hex" if fmt is omitted. The function returns NULL if at least one of the input parameters is NULL.

Examples (Spark SQL)

> SELECT to_binary('abc', 'utf-8');
abc

to_char(arg1, arg2)

@spec to_char(term(), term()) :: Latu.Plan.expression()

Spark's to_char.

to_char(expr, format) - Convert expr to a string based on the format. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input value, generating a result string of the same length as the corresponding sequence in the format string. The result string is left-padded with zeros if the 0/9 sequence comprises more digits than the matching part of the decimal value, starts with 0, and is before the decimal point. Otherwise, it is padded with spaces. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. '$': Specifies the location of the $ currency sign. This character may only be specified once. 'S' or 'MI': Specifies the position of a '-' or '+' sign (optional, only allowed once at the beginning or end of the format string). Note that 'S' prints '+' for positive values but 'MI' prints a space. 'PR': Only allowed at the end of the format string; specifies that the result string will be wrapped by angle brackets if the input value is negative. ('<1>'). If expr is a datetime, format shall be a valid datetime pattern, see <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>. If expr is a binary, it is converted to a string in one of the formats: 'base64': a base 64 string. 'hex': a string in the hexadecimal format. 'utf-8': the input binary is decoded to UTF-8 string.

Examples (Spark SQL)

> SELECT to_char(454, '999');
454
> SELECT to_char(454.00, '000D00');
454.00
> SELECT to_char(12454, '99G999');
12,454
> SELECT to_char(78.12, '$99.99');
$78.12
> SELECT to_char(-12454.8, '99G999D9S');
12,454.8-
> SELECT to_char(date'2016-04-08', 'y');
2016
> SELECT to_char(x'537061726b2053514c', 'base64');
U3BhcmsgU1FM
> SELECT to_char(x'537061726b2053514c', 'hex');
537061726B2053514C
> SELECT to_char(encode('abc', 'utf-8'), 'utf-8');
abc

to_number(arg1, arg2)

@spec to_number(term(), term()) :: Latu.Plan.expression()

Spark's to_number.

to_number(expr, fmt) - Convert string 'expr' to a number based on the string format 'fmt'. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input string. If the 0/9 sequence starts with 0 and is before the decimal point, it can only match a digit sequence of the same size. Otherwise, if the sequence starts with 9 or is after the decimal point, it can match a digit sequence that has the same or smaller size. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. 'expr' must match the grouping separator relevant for the size of the number. '$': Specifies the location of the $ currency sign. This character may only be specified once. 'S' or 'MI': Specifies the position of a '-' or '+' sign (optional, only allowed once at the beginning or end of the format string). Note that 'S' allows '-' but 'MI' does not. 'PR': Only allowed at the end of the format string; specifies that 'expr' indicates a negative number with wrapping angled brackets. ('<1>').

Examples (Spark SQL)

> SELECT to_number('454', '999');
454
> SELECT to_number('454.00', '000.00');
454.00
> SELECT to_number('12,454', '99,999');
12454
> SELECT to_number('$78.12', '$99.99');
78.12
> SELECT to_number('12,454.8-', '99,999.9S');
-12454.8

to_varchar(arg1, arg2)

@spec to_varchar(term(), term()) :: Latu.Plan.expression()

Spark's to_varchar.

to_varchar(expr, format) - Convert expr to a string based on the format. Throws an exception if the conversion fails. The format can consist of the following characters, case insensitive: '0' or '9': Specifies an expected digit between 0 and 9. A sequence of 0 or 9 in the format string matches a sequence of digits in the input value, generating a result string of the same length as the corresponding sequence in the format string. The result string is left-padded with zeros if the 0/9 sequence comprises more digits than the matching part of the decimal value, starts with 0, and is before the decimal point. Otherwise, it is padded with spaces. '.' or 'D': Specifies the position of the decimal point (optional, only allowed once). ',' or 'G': Specifies the position of the grouping (thousands) separator (,). There must be a 0 or 9 to the left and right of each grouping separator. '$': Specifies the location of the $ currency sign. This character may only be specified once. 'S' or 'MI': Specifies the position of a '-' or '+' sign (optional, only allowed once at the beginning or end of the format string). Note that 'S' prints '+' for positive values but 'MI' prints a space. 'PR': Only allowed at the end of the format string; specifies that the result string will be wrapped by angle brackets if the input value is negative. ('<1>'). If expr is a datetime, format shall be a valid datetime pattern, see <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>. If expr is a binary, it is converted to a string in one of the formats: 'base64': a base 64 string. 'hex': a string in the hexadecimal format. 'utf-8': the input binary is decoded to UTF-8 string.

Examples (Spark SQL)

> SELECT to_varchar(454, '999');
454
> SELECT to_varchar(454.00, '000D00');
454.00
> SELECT to_varchar(12454, '99G999');
12,454
> SELECT to_varchar(78.12, '$99.99');
$78.12
> SELECT to_varchar(-12454.8, '99G999D9S');
12,454.8-
> SELECT to_varchar(date'2016-04-08', 'y');
2016
> SELECT to_varchar(x'537061726b2053514c', 'base64');
U3BhcmsgU1FM
> SELECT to_varchar(x'537061726b2053514c', 'hex');
537061726B2053514C
> SELECT to_varchar(encode('abc', 'utf-8'), 'utf-8');
abc

translate(arg1, arg2, arg3)

@spec translate(term(), term(), term()) :: Latu.Plan.expression()

Spark's translate.

translate(input, from, to) - Translates the input string by replacing the characters present in the from string with the corresponding characters in the to string.

Examples (Spark SQL)

> SELECT translate('AaBbCc', 'abc', '123');
A1B2C3

trim(column)

@spec trim(term()) :: Latu.Plan.expression()

Strip characters from both ends.

The wire order is reversed: trim(col, chars) sends trim(chars, col), which is Spark's own argument order and PySpark's. Latu keeps the column first, as every other function does.

trim(column, characters)

@spec trim(term(), term()) :: Latu.Plan.expression()

Trim the given characters from both ends. Spark takes them first; Latu does not.

try_to_binary(arg1)

@spec try_to_binary(term()) :: Latu.Plan.expression()

Spark's try_to_binary. The trailing argument is optional.

try_to_binary(str[, fmt]) - This is a special version of to_binary that performs the same operation, but returns a NULL value instead of raising an error if the conversion cannot be performed.

Examples (Spark SQL)

> SELECT try_to_binary('abc', 'utf-8');
abc
> select try_to_binary('a!', 'base64');
NULL
> select try_to_binary('abc', 'invalidFormat');
NULL

try_to_binary(arg1, optional)

@spec try_to_binary(
  term(),
  term()
) :: Latu.Plan.expression()

Spark's try_to_binary. With the optional trailing argument.

try_to_binary(str[, fmt]) - This is a special version of to_binary that performs the same operation, but returns a NULL value instead of raising an error if the conversion cannot be performed.

Examples (Spark SQL)

> SELECT try_to_binary('abc', 'utf-8');
abc
> select try_to_binary('a!', 'base64');
NULL
> select try_to_binary('abc', 'invalidFormat');
NULL

try_to_number(arg1, arg2)

@spec try_to_number(term(), term()) :: Latu.Plan.expression()

Spark's try_to_number.

try_to_number(expr, fmt) - Convert string 'expr' to a number based on the string format fmt. Returns NULL if the string 'expr' does not match the expected format. The format follows the same semantics as the to_number function.

Examples (Spark SQL)

> SELECT try_to_number('454', '999');
454
> SELECT try_to_number('454.00', '000.00');
454.00
> SELECT try_to_number('12,454', '99,999');
12454
> SELECT try_to_number('$78.12', '$99.99');
78.12
> SELECT try_to_number('12,454.8-', '99,999.9S');
-12454.8

try_validate_utf8(arg1)

@spec try_validate_utf8(term()) :: Latu.Plan.expression()

Spark's try_validate_utf8.

try_validate_utf8(str) - Returns the original string if str is a valid UTF-8 string, otherwise returns NULL.

Examples (Spark SQL)

> SELECT try_validate_utf8('Spark');
Spark
> SELECT try_validate_utf8(x'61');
a
> SELECT try_validate_utf8(x'80');
NULL
> SELECT try_validate_utf8(x'61C262');
NULL

ucase(arg1)

@spec ucase(term()) :: Latu.Plan.expression()

Spark's ucase.

ucase(str) - Returns str with all characters changed to uppercase.

Examples (Spark SQL)

> SELECT ucase('SparkSql');
SPARKSQL

unbase64(arg1)

@spec unbase64(term()) :: Latu.Plan.expression()

Spark's unbase64.

unbase64(str) - Converts the argument from a base 64 string str to a binary.

Examples (Spark SQL)

> SELECT unbase64('U3BhcmsgU1FM');
Spark SQL

upper(arg1)

@spec upper(term()) :: Latu.Plan.expression()

Spark's upper.

upper(str) - Returns str with all characters changed to uppercase.

Examples (Spark SQL)

> SELECT upper('SparkSql');
SPARKSQL

validate_utf8(arg1)

@spec validate_utf8(term()) :: Latu.Plan.expression()

Spark's validate_utf8.

validate_utf8(str) - Returns the original string if str is a valid UTF-8 string, otherwise throws an exception.

Examples (Spark SQL)

> SELECT validate_utf8('Spark');
Spark
> SELECT validate_utf8(x'61');
a

Struct Functions

named_struct(columns)

@spec named_struct([term()]) :: Latu.Plan.expression()

Spark's named_struct. Variadic in Spark; takes a list here.

named_struct(name1, val1, name2, val2, ...) - Creates a struct with the given field names and values.

Examples (Spark SQL)

> SELECT named_struct("a", 1, "b", 2, "c", 3);
{"a":1,"b":2,"c":3}

struct(columns)

@spec struct([term()]) :: Latu.Plan.expression()

Spark's struct. Variadic in Spark; takes a list here.

struct(col1, col2, col3, ...) - Creates a struct with the given field values.

Examples (Spark SQL)

> SELECT struct(1, 2, 3);
{"col1":1,"col2":2,"col3":3}

UDF, UDTF and UDT

unwrap_udt(arg1)

@spec unwrap_udt(term()) :: Latu.Plan.expression()

Spark's unwrap_udt.

URL Functions

parse_url(arg1, arg2)

@spec parse_url(term(), term()) :: Latu.Plan.expression()

Spark's parse_url. The trailing argument is optional.

parse_url(url, partToExtract[, key]) - Extracts a part from a URL.

Examples (Spark SQL)

> SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST');
spark.apache.org
> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY');
query=1
> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
1

parse_url(arg1, arg2, optional)

@spec parse_url(term(), term(), term()) :: Latu.Plan.expression()

Spark's parse_url. With the optional trailing argument.

parse_url(url, partToExtract[, key]) - Extracts a part from a URL.

Examples (Spark SQL)

> SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST');
spark.apache.org
> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY');
query=1
> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
1

try_parse_url(arg1, arg2)

@spec try_parse_url(term(), term()) :: Latu.Plan.expression()

Spark's try_parse_url. The trailing argument is optional.

try_parse_url(url, partToExtract[, key]) - This is a special version of parse_url that performs the same operation, but returns a NULL value instead of raising an error if the parsing cannot be performed.

Examples (Spark SQL)

> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'HOST');
spark.apache.org
> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'QUERY');
query=1
> SELECT try_parse_url('inva lid://spark.apache.org/path?query=1', 'QUERY');
NULL
> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
1

try_parse_url(arg1, arg2, optional)

@spec try_parse_url(term(), term(), term()) :: Latu.Plan.expression()

Spark's try_parse_url. With the optional trailing argument.

try_parse_url(url, partToExtract[, key]) - This is a special version of parse_url that performs the same operation, but returns a NULL value instead of raising an error if the parsing cannot be performed.

Examples (Spark SQL)

> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'HOST');
spark.apache.org
> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'QUERY');
query=1
> SELECT try_parse_url('inva lid://spark.apache.org/path?query=1', 'QUERY');
NULL
> SELECT try_parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
1

try_url_decode(arg1)

@spec try_url_decode(term()) :: Latu.Plan.expression()

Spark's try_url_decode.

try_url_decode(str) - This is a special version of url_decode that performs the same operation, but returns a NULL value instead of raising an error if the decoding cannot be performed.

Examples (Spark SQL)

> SELECT try_url_decode('https%3A%2F%2Fspark.apache.org');
https://spark.apache.org

url_decode(arg1)

@spec url_decode(term()) :: Latu.Plan.expression()

Spark's url_decode.

url_decode(str) - Decodes a str in 'application/x-www-form-urlencoded' format using a specific encoding scheme.

Examples (Spark SQL)

> SELECT url_decode('https%3A%2F%2Fspark.apache.org');
https://spark.apache.org

url_encode(arg1)

@spec url_encode(term()) :: Latu.Plan.expression()

Spark's url_encode.

url_encode(str) - Translates a string into 'application/x-www-form-urlencoded' format using a specific encoding scheme.

Examples (Spark SQL)

> SELECT url_encode('https://spark.apache.org');
https%3A%2F%2Fspark.apache.org

VARIANT Functions

is_valid_variant(arg1)

@spec is_valid_variant(term()) :: Latu.Plan.expression()

Spark's is_valid_variant.

is_valid_variant(v) - Returns true if the variant is valid, false if it is malformed, NULL if v is NULL.

Examples (Spark SQL)

> SELECT is_valid_variant(parse_json('null'));
true
> SELECT is_valid_variant(parse_json('[{"b":true,"a":0}]'));
true

is_variant_null(arg1)

@spec is_variant_null(term()) :: Latu.Plan.expression()

Spark's is_variant_null.

is_variant_null(expr) - Check if a variant value is a variant null. Returns true if and only if the input is a variant null and false otherwise (including in the case of SQL NULL).

Examples (Spark SQL)

> SELECT is_variant_null(parse_json('null'));
true
> SELECT is_variant_null(parse_json('"null"'));
false
> SELECT is_variant_null(parse_json('13'));
false
> SELECT is_variant_null(parse_json(null));
false
> SELECT is_variant_null(variant_get(parse_json('{"a":null, "b":"spark"}'), "$.c"));
false
> SELECT is_variant_null(variant_get(parse_json('{"a":null, "b":"spark"}'), "$.a"));
true

parse_json(arg1)

@spec parse_json(term()) :: Latu.Plan.expression()

Spark's parse_json.

parse_json(jsonStr) - Parse a JSON string as a Variant value. Throw an exception when the string is not valid JSON value.

Examples (Spark SQL)

> SELECT parse_json('{"a":1,"b":0.8}');
{"a":1,"b":0.8}

schema_of_variant(arg1)

@spec schema_of_variant(term()) :: Latu.Plan.expression()

Spark's schema_of_variant.

schema_of_variant(v) - Returns schema in the SQL format of a variant.

Examples (Spark SQL)

> SELECT schema_of_variant(parse_json('null'));
VOID
> SELECT schema_of_variant(parse_json('[{"b":true,"a":0}]'));
ARRAY<OBJECT<a: BIGINT, b: BOOLEAN>>

schema_of_variant_agg(arg1)

@spec schema_of_variant_agg(term()) :: Latu.Plan.expression()

Spark's schema_of_variant_agg.

schema_of_variant_agg(v) - Returns the merged schema in the SQL format of a variant column.

Examples (Spark SQL)

> SELECT schema_of_variant_agg(parse_json(j)) FROM VALUES ('1'), ('2'), ('3') AS tab(j);
BIGINT
> SELECT schema_of_variant_agg(parse_json(j)) FROM VALUES ('{"a": 1}'), ('{"b": true}'), ('{"c": 1.23}') AS tab(j);
OBJECT<a: BIGINT, b: BOOLEAN, c: DECIMAL(3,2)>

to_variant_object(arg1)

@spec to_variant_object(term()) :: Latu.Plan.expression()

Spark's to_variant_object.

to_variant_object(expr) - Convert a nested input (array/map/struct) into a variant where maps and structs are converted to variant objects which are unordered unlike SQL structs. Input maps can only have string keys.

Examples (Spark SQL)

> SELECT to_variant_object(named_struct('a', 1, 'b', 2));
{"a":1,"b":2}
> SELECT to_variant_object(array(1, 2, 3));
[1,2,3]
> SELECT to_variant_object(array(named_struct('a', 1)));
[{"a":1}]
> SELECT to_variant_object(array(map("a", 2)));
[{"a":2}]

try_parse_json(arg1)

@spec try_parse_json(term()) :: Latu.Plan.expression()

Spark's try_parse_json.

try_parse_json(jsonStr) - Parse a JSON string as a Variant value. Return NULL when the string is not valid JSON value.

Examples (Spark SQL)

> SELECT try_parse_json('{"a":1,"b":0.8}');
{"a":1,"b":0.8}
> SELECT try_parse_json('{"a":1,');
NULL

try_variant_get(arg1, arg2, arg3)

@spec try_variant_get(term(), term(), term()) :: Latu.Plan.expression()

Spark's try_variant_get.

try_variant_get(v, path[, type]) - Extracts a sub-variant from v according to path, and then cast the sub-variant to type. When type is omitted, it is default to variant. Returns null if the path does not exist or the cast fails.

Examples (Spark SQL)

> SELECT try_variant_get(parse_json('{"a": 1}'), '$.a', 'int');
1
> SELECT try_variant_get(parse_json('{"a": 1}'), '$.b', 'int');
NULL
> SELECT try_variant_get(parse_json('[1, "2"]'), '$[1]', 'string');
2
> SELECT try_variant_get(parse_json('[1, "2"]'), '$[2]', 'string');
NULL
> SELECT try_variant_get(parse_json('[1, "hello"]'), '$[1]');
"hello"
> SELECT try_variant_get(parse_json('[1, "hello"]'), '$[1]', 'int');
NULL

variant_get(arg1, arg2, arg3)

@spec variant_get(term(), term(), term()) :: Latu.Plan.expression()

Spark's variant_get.

variant_get(v, path[, type]) - Extracts a sub-variant from v according to path, and then cast the sub-variant to type. When type is omitted, it is default to variant. Returns null if the path does not exist. Throws an exception if the cast fails.

Examples (Spark SQL)

> SELECT variant_get(parse_json('{"a": 1}'), '$.a', 'int');
1
> SELECT variant_get(parse_json('{"a": 1}'), '$.b', 'int');
NULL
> SELECT variant_get(parse_json('[1, "2"]'), '$[1]', 'string');
2
> SELECT variant_get(parse_json('[1, "2"]'), '$[2]', 'string');
NULL
> SELECT variant_get(parse_json('[1, "hello"]'), '$[1]');
"hello"

Window Functions

cume_dist()

@spec cume_dist() :: Latu.Plan.expression()

Spark's cume_dist.

cume_dist() - Computes the position of a value relative to all values in the partition.

Examples (Spark SQL)

> SELECT a, b, cume_dist() OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	0.6666666666666666
A1	1	0.6666666666666666
A1	2	1.0
A2	3	1.0

dense_rank()

@spec dense_rank() :: Latu.Plan.expression()

Spark's dense_rank.

dense_rank() - Computes the rank of a value in a group of values. The result is one plus the previously assigned rank value. Unlike the function rank, dense_rank will not produce gaps in the ranking sequence.

Examples (Spark SQL)

> SELECT a, b, dense_rank(b) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	1
A1	2	2
A2	3	1

lag(column)

@spec lag(term()) :: Latu.Plan.expression()

The value some rows behind the current one, within a window.

F.lag(:price) |> over(window)

The offset is always sent and defaults to 1; the fallback value is sent only when given. Two different answers to "the caller left it out", in one signature.

lag(column, offset)

@spec lag(term(), term()) :: Latu.Plan.expression()

Look back offset rows. NULL past the start of the partition.

lag(column, offset, default)

@spec lag(term(), term(), term()) :: Latu.Plan.expression()

Look back offset rows, with default past the start of the partition.

lead(column)

@spec lead(term()) :: Latu.Plan.expression()

The value some rows ahead of the current one. lag/1,2,3 in the other direction.

lead(column, offset)

@spec lead(term(), term()) :: Latu.Plan.expression()

Look ahead offset rows. NULL past the end of the partition.

lead(column, offset, default)

@spec lead(term(), term(), term()) :: Latu.Plan.expression()

Look ahead offset rows, with default past the end of the partition.

nth_value(arg1, arg2)

@spec nth_value(term(), term()) :: Latu.Plan.expression()

Spark's nth_value. The trailing argument is optional.

nth_value(input[, offset]) - Returns the value of input at the row that is the offsetth row from beginning of the window frame. Offset starts at 1. If ignoreNulls=true, we will skip nulls when finding the offsetth row. Otherwise, every row counts for the offset. If there is no such an offsetth row (e.g., when the offset is 10, size of the window frame is less than 10), null is returned.

Examples (Spark SQL)

> SELECT a, b, nth_value(b, 2) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	1
A1	2	1
A2	3	NULL

nth_value(arg1, arg2, optional)

@spec nth_value(term(), term(), term()) :: Latu.Plan.expression()

Spark's nth_value. With the optional trailing argument.

nth_value(input[, offset]) - Returns the value of input at the row that is the offsetth row from beginning of the window frame. Offset starts at 1. If ignoreNulls=true, we will skip nulls when finding the offsetth row. Otherwise, every row counts for the offset. If there is no such an offsetth row (e.g., when the offset is 10, size of the window frame is less than 10), null is returned.

Examples (Spark SQL)

> SELECT a, b, nth_value(b, 2) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	1
A1	2	1
A2	3	NULL

ntile(arg1)

@spec ntile(term()) :: Latu.Plan.expression()

Spark's ntile.

ntile(n) - Divides the rows for each window partition into n buckets ranging from 1 to at most n.

Examples (Spark SQL)

> SELECT a, b, ntile(2) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	1
A1	2	2
A2	3	1

percent_rank()

@spec percent_rank() :: Latu.Plan.expression()

Spark's percent_rank.

percent_rank() - Computes the percentage ranking of a value in a group of values.

Examples (Spark SQL)

> SELECT a, b, percent_rank(b) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	0.0
A1	1	0.0
A1	2	1.0
A2	3	0.0

rank()

@spec rank() :: Latu.Plan.expression()

Spark's rank.

rank() - Computes the rank of a value in a group of values. The result is one plus the number of rows preceding or equal to the current row in the ordering of the partition. The values will produce gaps in the sequence.

Examples (Spark SQL)

> SELECT a, b, rank(b) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	1
A1	2	3
A2	3	1

row_number()

@spec row_number() :: Latu.Plan.expression()

Spark's row_number.

row_number() - Assigns a unique, sequential number to each row, starting with one, according to the ordering of rows within the window partition.

Examples (Spark SQL)

> SELECT a, b, row_number() OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1	1	1
A1	1	2
A1	2	3
A2	3	1

XML Functions

from_xml(column, schema)

@spec from_xml(term(), term()) :: Latu.Plan.expression()

Spark's from_xml. The schema is a string (DDL, or Spark's JSON schema form) or a built expression; options follow Latu.read/2's key and value rules.

from_xml(xmlStr, schema[, options]) - Returns a struct value with the given xmlStr and schema.

Examples (Spark SQL)

> SELECT from_xml('<p><a>1</a><b>0.8</b></p>', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_xml('<p><time>26/08/2015</time></p>', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}
> SELECT from_xml('<p><teacher>Alice</teacher><student><name>Bob</name><rank>1</rank></student><student><name>Charlie</name><rank>2</rank></student></p>', 'STRUCT<teacher: STRING, student: ARRAY<STRUCT<name: STRING, rank: INT>>>');
{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}

from_xml(column, schema, options)

@spec from_xml(term(), term(), keyword() | map()) :: Latu.Plan.expression()

Spark's from_xml. With parser options, following Latu.read/2's rules.

from_xml(xmlStr, schema[, options]) - Returns a struct value with the given xmlStr and schema.

Examples (Spark SQL)

> SELECT from_xml('<p><a>1</a><b>0.8</b></p>', 'a INT, b DOUBLE');
{"a":1,"b":0.8}
> SELECT from_xml('<p><time>26/08/2015</time></p>', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{"time":2015-08-26 00:00:00}
> SELECT from_xml('<p><teacher>Alice</teacher><student><name>Bob</name><rank>1</rank></student><student><name>Charlie</name><rank>2</rank></student></p>', 'STRUCT<teacher: STRING, student: ARRAY<STRUCT<name: STRING, rank: INT>>>');
{"teacher":"Alice","student":[{"name":"Bob","rank":1},{"name":"Charlie","rank":2}]}

schema_of_xml(column)

@spec schema_of_xml(term()) :: Latu.Plan.expression()

Spark's schema_of_xml. Options follow Latu.read/2's key and value rules.

schema_of_xml(xml[, options]) - Returns schema in the DDL format of XML string.

Examples (Spark SQL)

> SELECT schema_of_xml('<p><a>1</a></p>');
STRUCT<a: BIGINT>
> SELECT schema_of_xml('<p><a attr="2">1</a><a>3</a></p>', map('excludeAttribute', 'true'));
STRUCT<a: ARRAY<BIGINT>>

schema_of_xml(column, options)

@spec schema_of_xml(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's schema_of_xml. With parser options, following Latu.read/2's rules.

schema_of_xml(xml[, options]) - Returns schema in the DDL format of XML string.

Examples (Spark SQL)

> SELECT schema_of_xml('<p><a>1</a></p>');
STRUCT<a: BIGINT>
> SELECT schema_of_xml('<p><a attr="2">1</a><a>3</a></p>', map('excludeAttribute', 'true'));
STRUCT<a: ARRAY<BIGINT>>

to_xml(column)

@spec to_xml(term()) :: Latu.Plan.expression()

Spark's to_xml. Options follow Latu.read/2's key and value rules.

to_xml(expr[, options]) - Returns a XML string with a given struct value

Examples (Spark SQL)

> SELECT to_xml(named_struct('a', 1, 'b', 2));
<ROW>
<a>1</a>
<b>2</b>
</ROW>
> SELECT to_xml(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
<ROW>
<time>26/08/2015</time>
</ROW>

to_xml(column, options)

@spec to_xml(term(), keyword() | map()) :: Latu.Plan.expression()

Spark's to_xml. With parser options, following Latu.read/2's rules.

to_xml(expr[, options]) - Returns a XML string with a given struct value

Examples (Spark SQL)

> SELECT to_xml(named_struct('a', 1, 'b', 2));
<ROW>
<a>1</a>
<b>2</b>
</ROW>
> SELECT to_xml(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
<ROW>
<time>26/08/2015</time>
</ROW>

xpath(arg1, arg2)

@spec xpath(term(), term()) :: Latu.Plan.expression()

Spark's xpath.

xpath(xml, xpath) - Returns a string array of values within the nodes of xml that match the XPath expression.

Examples (Spark SQL)

> SELECT xpath('<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>','a/b/text()');
["b1","b2","b3"]
> SELECT xpath('<a><b>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>','a/b');
[null,null,null]

xpath_boolean(arg1, arg2)

@spec xpath_boolean(term(), term()) :: Latu.Plan.expression()

Spark's xpath_boolean.

xpath_boolean(xml, xpath) - Returns true if the XPath expression evaluates to true, or if a matching node is found.

Examples (Spark SQL)

> SELECT xpath_boolean('<a><b>1</b></a>','a/b');
true

xpath_double(arg1, arg2)

@spec xpath_double(term(), term()) :: Latu.Plan.expression()

Spark's xpath_double.

xpath_double(xml, xpath) - Returns a double value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_double('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3.0

xpath_float(arg1, arg2)

@spec xpath_float(term(), term()) :: Latu.Plan.expression()

Spark's xpath_float.

xpath_float(xml, xpath) - Returns a float value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_float('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3.0

xpath_int(arg1, arg2)

@spec xpath_int(term(), term()) :: Latu.Plan.expression()

Spark's xpath_int.

xpath_int(xml, xpath) - Returns an integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_int('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3

xpath_long(arg1, arg2)

@spec xpath_long(term(), term()) :: Latu.Plan.expression()

Spark's xpath_long.

xpath_long(xml, xpath) - Returns a long integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_long('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3

xpath_number(arg1, arg2)

@spec xpath_number(term(), term()) :: Latu.Plan.expression()

Spark's xpath_number.

xpath_number(xml, xpath) - Returns a double value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_number('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3.0

xpath_short(arg1, arg2)

@spec xpath_short(term(), term()) :: Latu.Plan.expression()

Spark's xpath_short.

xpath_short(xml, xpath) - Returns a short integer value, or the value zero if no match is found, or a match is found but the value is non-numeric.

Examples (Spark SQL)

> SELECT xpath_short('<a><b>1</b><b>2</b></a>', 'sum(a/b)');
3

xpath_string(arg1, arg2)

@spec xpath_string(term(), term()) :: Latu.Plan.expression()

Spark's xpath_string.

xpath_string(xml, xpath) - Returns the text contents of the first xml node that matches the XPath expression.

Examples (Spark SQL)

> SELECT xpath_string('<a><b>b</b><c>cc</c></a>','a/c');
cc