blob: 287dddb099e1819cfe1959c4e4746a0c0d336858 [file] [log] [blame]
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="description" content="None" />
<link rel="shortcut icon" href="img/favicon.ico" />
<title>Spark SQL, Built-in Functions</title>
<link rel="stylesheet" href="css/theme.css" />
<link rel="stylesheet" href="css/theme_extra.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github.min.css" />
<script>
// Current page data
var mkdocs_page_name = "Functions";
var mkdocs_page_input_path = "index.md";
var mkdocs_page_url = null;
</script>
<!--[if lt IE 9]>
<script src="js/html5shiv.min.js"></script>
<![endif]-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="." class="icon icon-home"> Spark SQL, Built-in Functions
</a><div role="search">
<form id ="rtd-search-form" class="wy-form" action="./search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal current" href="#">Functions</a>
<ul class="current">
<li class="toctree-l2"><a class="reference internal" href="#_1">!</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_2">!=</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_3">%</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_4">&amp;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_5">*</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_6">+</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#-">-</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_7">/</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_8">&lt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_9">&lt;&lt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_10">&lt;=</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_11">&lt;=&gt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_12">&lt;&gt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_13">=</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_14">==</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_15">&gt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_16">&gt;=</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_17">&gt;&gt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_18">&gt;&gt;&gt;</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_19">^</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#abs">abs</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#acos">acos</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#acosh">acosh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#add_months">add_months</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#aes_decrypt">aes_decrypt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#aes_encrypt">aes_encrypt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#aggregate">aggregate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#and">and</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#any">any</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#any_value">any_value</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#approx_count_distinct">approx_count_distinct</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#approx_percentile">approx_percentile</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array">array</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_agg">array_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_append">array_append</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_compact">array_compact</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_contains">array_contains</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_distinct">array_distinct</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_except">array_except</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_insert">array_insert</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_intersect">array_intersect</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_join">array_join</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_max">array_max</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_min">array_min</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_position">array_position</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_prepend">array_prepend</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_remove">array_remove</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_repeat">array_repeat</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_size">array_size</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_sort">array_sort</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#array_union">array_union</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#arrays_overlap">arrays_overlap</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#arrays_zip">arrays_zip</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ascii">ascii</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#asin">asin</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#asinh">asinh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#assert_true">assert_true</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#atan">atan</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#atan2">atan2</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#atanh">atanh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#avg">avg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#base64">base64</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#between">between</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#between_1">between</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bigint">bigint</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bin">bin</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#binary">binary</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_and">bit_and</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_count">bit_count</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_get">bit_get</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_length">bit_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_or">bit_or</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bit_xor">bit_xor</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bitmap_bit_position">bitmap_bit_position</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bitmap_bucket_number">bitmap_bucket_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bitmap_construct_agg">bitmap_construct_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bitmap_count">bitmap_count</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bitmap_or_agg">bitmap_or_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bool_and">bool_and</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bool_or">bool_or</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#boolean">boolean</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#bround">bround</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#btrim">btrim</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cardinality">cardinality</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#case">case</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cast">cast</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cbrt">cbrt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ceil">ceil</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ceiling">ceiling</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#char">char</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#char_length">char_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#character_length">character_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#chr">chr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#coalesce">coalesce</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#collate">collate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#collation">collation</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#collect_list">collect_list</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#collect_set">collect_set</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#concat">concat</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#concat_ws">concat_ws</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#contains">contains</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#conv">conv</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#convert_timezone">convert_timezone</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#corr">corr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cos">cos</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cosh">cosh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cot">cot</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#count">count</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#count_if">count_if</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#count_min_sketch">count_min_sketch</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#covar_pop">covar_pop</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#covar_samp">covar_samp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#crc32">crc32</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#csc">csc</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#cume_dist">cume_dist</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#curdate">curdate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_catalog">current_catalog</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_database">current_database</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_date">current_date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_schema">current_schema</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_timestamp">current_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_timezone">current_timezone</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#current_user">current_user</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date">date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_add">date_add</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_diff">date_diff</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_format">date_format</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_from_unix_date">date_from_unix_date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_part">date_part</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_sub">date_sub</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#date_trunc">date_trunc</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dateadd">dateadd</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#datediff">datediff</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#datepart">datepart</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#day">day</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dayname">dayname</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dayofmonth">dayofmonth</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dayofweek">dayofweek</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dayofyear">dayofyear</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#decimal">decimal</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#decode">decode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#degrees">degrees</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#dense_rank">dense_rank</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#div">div</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#double">double</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#e">e</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#element_at">element_at</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#elt">elt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#encode">encode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#endswith">endswith</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#equal_null">equal_null</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#every">every</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#exists">exists</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#exp">exp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#explode">explode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#explode_outer">explode_outer</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#expm1">expm1</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#extract">extract</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#factorial">factorial</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#filter">filter</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#find_in_set">find_in_set</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#first">first</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#first_value">first_value</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#flatten">flatten</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#float">float</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#floor">floor</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#forall">forall</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#format_number">format_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#format_string">format_string</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#from_csv">from_csv</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#from_json">from_json</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#from_unixtime">from_unixtime</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#from_utc_timestamp">from_utc_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#from_xml">from_xml</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#get">get</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#get_json_object">get_json_object</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#getbit">getbit</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#greatest">greatest</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#grouping">grouping</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#grouping_id">grouping_id</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hash">hash</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hex">hex</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#histogram_numeric">histogram_numeric</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hll_sketch_agg">hll_sketch_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hll_sketch_estimate">hll_sketch_estimate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hll_union">hll_union</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hll_union_agg">hll_union_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hour">hour</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hypot">hypot</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#if">if</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ifnull">ifnull</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ilike">ilike</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#in">in</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#initcap">initcap</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#inline">inline</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#inline_outer">inline_outer</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#input_file_block_length">input_file_block_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#input_file_block_start">input_file_block_start</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#input_file_name">input_file_name</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#instr">instr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#int">int</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#is_variant_null">is_variant_null</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#isnan">isnan</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#isnotnull">isnotnull</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#isnull">isnull</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#java_method">java_method</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#json_array_length">json_array_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#json_object_keys">json_object_keys</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#json_tuple">json_tuple</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#kurtosis">kurtosis</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#lag">lag</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#last">last</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#last_day">last_day</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#last_value">last_value</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#lcase">lcase</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#lead">lead</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#least">least</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#left">left</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#len">len</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#length">length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#levenshtein">levenshtein</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#like">like</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ln">ln</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#localtimestamp">localtimestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#locate">locate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#log">log</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#log10">log10</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#log1p">log1p</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#log2">log2</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#lower">lower</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#lpad">lpad</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ltrim">ltrim</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#luhn_check">luhn_check</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_date">make_date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_dt_interval">make_dt_interval</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_interval">make_interval</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_timestamp">make_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_timestamp_ltz">make_timestamp_ltz</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_timestamp_ntz">make_timestamp_ntz</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#make_ym_interval">make_ym_interval</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map">map</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_concat">map_concat</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_contains_key">map_contains_key</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_entries">map_entries</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_filter">map_filter</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_from_arrays">map_from_arrays</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_from_entries">map_from_entries</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_keys">map_keys</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_values">map_values</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#map_zip_with">map_zip_with</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#mask">mask</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#max">max</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#max_by">max_by</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#md5">md5</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#mean">mean</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#median">median</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#min">min</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#min_by">min_by</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#minute">minute</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#mod">mod</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#mode">mode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#monotonically_increasing_id">monotonically_increasing_id</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#month">month</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#monthname">monthname</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#months_between">months_between</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#named_struct">named_struct</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#nanvl">nanvl</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#negative">negative</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#next_day">next_day</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#not">not</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#now">now</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#nth_value">nth_value</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ntile">ntile</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#nullif">nullif</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#nvl">nvl</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#nvl2">nvl2</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#octet_length">octet_length</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#or">or</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#overlay">overlay</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#parse_json">parse_json</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#parse_url">parse_url</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#percent_rank">percent_rank</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#percentile">percentile</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#percentile_approx">percentile_approx</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#percentile_cont">percentile_cont</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#percentile_disc">percentile_disc</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#pi">pi</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#pmod">pmod</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#posexplode">posexplode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#posexplode_outer">posexplode_outer</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#position">position</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#positive">positive</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#pow">pow</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#power">power</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#printf">printf</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#quarter">quarter</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#radians">radians</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#raise_error">raise_error</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rand">rand</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#randn">randn</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#random">random</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rank">rank</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#reduce">reduce</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#reflect">reflect</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp">regexp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_count">regexp_count</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_extract">regexp_extract</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_extract_all">regexp_extract_all</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_instr">regexp_instr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_like">regexp_like</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_replace">regexp_replace</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regexp_substr">regexp_substr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_avgx">regr_avgx</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_avgy">regr_avgy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_count">regr_count</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_intercept">regr_intercept</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_r2">regr_r2</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_slope">regr_slope</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_sxx">regr_sxx</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_sxy">regr_sxy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#regr_syy">regr_syy</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#repeat">repeat</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#replace">replace</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#reverse">reverse</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#right">right</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rint">rint</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rlike">rlike</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#round">round</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#row_number">row_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rpad">rpad</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#rtrim">rtrim</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#schema_of_csv">schema_of_csv</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#schema_of_json">schema_of_json</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#schema_of_variant">schema_of_variant</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#schema_of_variant_agg">schema_of_variant_agg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#schema_of_xml">schema_of_xml</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sec">sec</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#second">second</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sentences">sentences</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sequence">sequence</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#session_user">session_user</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#session_window">session_window</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sha">sha</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sha1">sha1</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sha2">sha2</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#shiftleft">shiftleft</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#shiftright">shiftright</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#shiftrightunsigned">shiftrightunsigned</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#shuffle">shuffle</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sign">sign</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#signum">signum</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sin">sin</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sinh">sinh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#size">size</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#skewness">skewness</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#slice">slice</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#smallint">smallint</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#some">some</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sort_array">sort_array</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#soundex">soundex</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#space">space</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#spark_partition_id">spark_partition_id</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#split">split</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#split_part">split_part</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sqrt">sqrt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#stack">stack</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#startswith">startswith</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#std">std</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#stddev">stddev</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#stddev_pop">stddev_pop</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#stddev_samp">stddev_samp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#str_to_map">str_to_map</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#string">string</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#struct">struct</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#substr">substr</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#substring">substring</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#substring_index">substring_index</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#sum">sum</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#tan">tan</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#tanh">tanh</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#timestamp">timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#timestamp_micros">timestamp_micros</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#timestamp_millis">timestamp_millis</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#timestamp_seconds">timestamp_seconds</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#tinyint">tinyint</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_binary">to_binary</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_char">to_char</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_csv">to_csv</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_date">to_date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_json">to_json</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_number">to_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_timestamp">to_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_timestamp_ltz">to_timestamp_ltz</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_timestamp_ntz">to_timestamp_ntz</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_unix_timestamp">to_unix_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_utc_timestamp">to_utc_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_varchar">to_varchar</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#to_xml">to_xml</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#transform">transform</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#transform_keys">transform_keys</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#transform_values">transform_values</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#translate">translate</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#trim">trim</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#trunc">trunc</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_add">try_add</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_aes_decrypt">try_aes_decrypt</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_avg">try_avg</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_divide">try_divide</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_element_at">try_element_at</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_multiply">try_multiply</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_parse_json">try_parse_json</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_reflect">try_reflect</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_remainder">try_remainder</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_subtract">try_subtract</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_sum">try_sum</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_to_binary">try_to_binary</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_to_number">try_to_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_to_timestamp">try_to_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#try_variant_get">try_variant_get</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#typeof">typeof</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#ucase">ucase</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unbase64">unbase64</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unhex">unhex</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unix_date">unix_date</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unix_micros">unix_micros</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unix_millis">unix_millis</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unix_seconds">unix_seconds</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#unix_timestamp">unix_timestamp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#upper">upper</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#url_decode">url_decode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#url_encode">url_encode</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#user">user</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#uuid">uuid</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#var_pop">var_pop</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#var_samp">var_samp</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#variance">variance</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#variant_get">variant_get</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#version">version</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#weekday">weekday</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#weekofyear">weekofyear</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#when">when</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#width_bucket">width_bucket</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#window">window</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#window_time">window_time</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath">xpath</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_boolean">xpath_boolean</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_double">xpath_double</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_float">xpath_float</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_int">xpath_int</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_long">xpath_long</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_number">xpath_number</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_short">xpath_short</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xpath_string">xpath_string</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#xxhash64">xxhash64</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#year">year</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#zip_with">zip_with</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_20">|</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_21">||</a>
</li>
<li class="toctree-l2"><a class="reference internal" href="#_22">~</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="Mobile navigation menu">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href=".">Spark SQL, Built-in Functions</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content"><div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="." class="icon icon-home" aria-label="Docs"></a></li>
<li class="breadcrumb-item active">Functions</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div class="section" itemprop="articleBody">
<h1 id="built-in-functions"><a class="toclink" href="#built-in-functions">Built-in Functions</a></h1>
<h3 id="_1"><a class="toclink" href="#_1">!</a></h3>
<p>! expr - Logical not.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ! true;
false
&gt; SELECT ! false;
true
&gt; SELECT ! NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_2"><a class="toclink" href="#_2">!=</a></h3>
<p>expr1 != expr2 - Returns true if <code>expr1</code> is not equal to <code>expr2</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to
a common type, and must be a type that can be used in equality comparison.
Map type is not supported. For complex types such array/struct,
the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 1 != 2;
true
&gt; SELECT 1 != '2';
true
&gt; SELECT true != NULL;
NULL
&gt; SELECT NULL != NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_3"><a class="toclink" href="#_3">%</a></h3>
<p>expr1 % expr2 - Returns the remainder after <code>expr1</code>/<code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 % 1.8;
0.2
&gt; SELECT MOD(2, 1.8);
0.2
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_4"><a class="toclink" href="#_4">&amp;</a></h3>
<p>expr1 &amp; expr2 - Returns the result of bitwise AND of <code>expr1</code> and <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 3 &amp; 5;
1
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="_5"><a class="toclink" href="#_5">*</a></h3>
<p>expr1 * expr2 - Returns <code>expr1</code>*<code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 * 3;
6
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_6"><a class="toclink" href="#_6">+</a></h3>
<p>expr1 + expr2 - Returns <code>expr1</code>+<code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 1 + 2;
3
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="-"><a class="toclink" href="#-">-</a></h3>
<p>expr1 - expr2 - Returns <code>expr1</code>-<code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 - 1;
1
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_7"><a class="toclink" href="#_7">/</a></h3>
<p>expr1 / expr2 - Returns <code>expr1</code>/<code>expr2</code>. It always performs floating point division.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 3 / 2;
1.5
&gt; SELECT 2L / 2L;
1.0
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_8"><a class="toclink" href="#_8">&lt;</a></h3>
<p>expr1 &lt; expr2 - Returns true if <code>expr1</code> is less than <code>expr2</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be ordered. For example, map type is not orderable, so it
is not supported. For complex types such array/struct, the data types of fields must
be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 1 &lt; 2;
true
&gt; SELECT 1.1 &lt; '1';
false
&gt; SELECT to_date('2009-07-30 04:17:52') &lt; to_date('2009-07-30 04:17:52');
false
&gt; SELECT to_date('2009-07-30 04:17:52') &lt; to_date('2009-08-01 04:17:52');
true
&gt; SELECT 1 &lt; NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_9"><a class="toclink" href="#_9">&lt;&lt;</a></h3>
<p>base &lt;&lt; exp - Bitwise left shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftleft(2, 1);
4
&gt; SELECT 2 &lt;&lt; 1;
4
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&lt;&lt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftleft</code>.</p>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="_10"><a class="toclink" href="#_10">&lt;=</a></h3>
<p>expr1 &lt;= expr2 - Returns true if <code>expr1</code> is less than or equal to <code>expr2</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be ordered. For example, map type is not orderable, so it
is not supported. For complex types such array/struct, the data types of fields must
be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 &lt;= 2;
true
&gt; SELECT 1.0 &lt;= '1';
true
&gt; SELECT to_date('2009-07-30 04:17:52') &lt;= to_date('2009-07-30 04:17:52');
true
&gt; SELECT to_date('2009-07-30 04:17:52') &lt;= to_date('2009-08-01 04:17:52');
true
&gt; SELECT 1 &lt;= NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_11"><a class="toclink" href="#_11">&lt;=&gt;</a></h3>
<p>expr1 &lt;=&gt; 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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be used in equality comparison. Map type is not supported.
For complex types such array/struct, the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 &lt;=&gt; 2;
true
&gt; SELECT 1 &lt;=&gt; '1';
true
&gt; SELECT true &lt;=&gt; NULL;
false
&gt; SELECT NULL &lt;=&gt; NULL;
true
</code></pre>
<p><strong>Since:</strong> 1.1.0</p>
<p><br/></p>
<h3 id="_12"><a class="toclink" href="#_12">&lt;&gt;</a></h3>
<p>expr1 != expr2 - Returns true if <code>expr1</code> is not equal to <code>expr2</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to
a common type, and must be a type that can be used in equality comparison.
Map type is not supported. For complex types such array/struct,
the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 1 != 2;
true
&gt; SELECT 1 != '2';
true
&gt; SELECT true != NULL;
NULL
&gt; SELECT NULL != NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_13"><a class="toclink" href="#_13">=</a></h3>
<p>expr1 = expr2 - Returns true if <code>expr1</code> equals <code>expr2</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be used in equality comparison. Map type is not supported.
For complex types such array/struct, the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 = 2;
true
&gt; SELECT 1 = '1';
true
&gt; SELECT true = NULL;
NULL
&gt; SELECT NULL = NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_14"><a class="toclink" href="#_14">==</a></h3>
<p>expr1 == expr2 - Returns true if <code>expr1</code> equals <code>expr2</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be used in equality comparison. Map type is not supported.
For complex types such array/struct, the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 == 2;
true
&gt; SELECT 1 == '1';
true
&gt; SELECT true == NULL;
NULL
&gt; SELECT NULL == NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_15"><a class="toclink" href="#_15">&gt;</a></h3>
<p>expr1 &gt; expr2 - Returns true if <code>expr1</code> is greater than <code>expr2</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be ordered. For example, map type is not orderable, so it
is not supported. For complex types such array/struct, the data types of fields must
be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 &gt; 1;
true
&gt; SELECT 2 &gt; 1.1;
true
&gt; SELECT to_date('2009-07-30 04:17:52') &gt; to_date('2009-07-30 04:17:52');
false
&gt; SELECT to_date('2009-07-30 04:17:52') &gt; to_date('2009-08-01 04:17:52');
false
&gt; SELECT 1 &gt; NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_16"><a class="toclink" href="#_16">&gt;=</a></h3>
<p>expr1 &gt;= expr2 - Returns true if <code>expr1</code> is greater than or equal to <code>expr2</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be ordered. For example, map type is not orderable, so it
is not supported. For complex types such array/struct, the data types of fields must
be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 &gt;= 1;
true
&gt; SELECT 2.0 &gt;= '2.1';
false
&gt; SELECT to_date('2009-07-30 04:17:52') &gt;= to_date('2009-07-30 04:17:52');
true
&gt; SELECT to_date('2009-07-30 04:17:52') &gt;= to_date('2009-08-01 04:17:52');
false
&gt; SELECT 1 &gt;= NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="_17"><a class="toclink" href="#_17">&gt;&gt;</a></h3>
<p>base &gt;&gt; expr - Bitwise (signed) right shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftright(4, 1);
2
&gt; SELECT 4 &gt;&gt; 1;
2
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&gt;&gt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftright</code>.</p>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="_18"><a class="toclink" href="#_18">&gt;&gt;&gt;</a></h3>
<p>base &gt;&gt;&gt; expr - Bitwise unsigned right shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftrightunsigned(4, 1);
2
&gt; SELECT 4 &gt;&gt;&gt; 1;
2
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&gt;&gt;&gt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftrightunsigned</code>.</p>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="_19"><a class="toclink" href="#_19">^</a></h3>
<p>expr1 ^ expr2 - Returns the result of bitwise exclusive OR of <code>expr1</code> and <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 3 ^ 5;
6
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="abs"><a class="toclink" href="#abs">abs</a></h3>
<p>abs(expr) - Returns the absolute value of the numeric or interval value.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT abs(-1);
1
&gt; SELECT abs(INTERVAL -'1-1' YEAR TO MONTH);
1-1
</code></pre>
<p><strong>Since:</strong> 1.2.0</p>
<p><br/></p>
<h3 id="acos"><a class="toclink" href="#acos">acos</a></h3>
<p>acos(expr) - Returns the inverse cosine (a.k.a. arc cosine) of <code>expr</code>, as if computed by
<code>java.lang.Math.acos</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT acos(1);
0.0
&gt; SELECT acos(2);
NaN
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="acosh"><a class="toclink" href="#acosh">acosh</a></h3>
<p>acosh(expr) - Returns inverse hyperbolic cosine of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT acosh(1);
0.0
&gt; SELECT acosh(0);
NaN
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="add_months"><a class="toclink" href="#add_months">add_months</a></h3>
<p>add_months(start_date, num_months) - Returns the date that is <code>num_months</code> after <code>start_date</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT add_months('2016-08-31', 1);
2016-09-30
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="aes_decrypt"><a class="toclink" href="#aes_decrypt">aes_decrypt</a></h3>
<p>aes_decrypt(expr, key[, mode[, padding[, aad]]]) - Returns a decrypted value of <code>expr</code> using AES in <code>mode</code> with <code>padding</code>.
Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (<code>mode</code>, <code>padding</code>) 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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - The binary value to decrypt.</li>
<li>key - The passphrase to use to decrypt the data.</li>
<li>mode - Specifies which block cipher mode should be used to decrypt messages.
Valid modes: ECB, GCM, CBC.</li>
<li>padding - Specifies how to pad messages whose length is not a multiple of the block size.
Valid values: PKCS, NONE, DEFAULT. The DEFAULT padding means PKCS for ECB, NONE for GCM and PKCS for CBC.</li>
<li>aad - Optional additional authenticated data. Only supported for GCM mode. This can be any free-form input and
must be provided for both encryption and decryption.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT aes_decrypt(unhex('83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94'), '0000111122223333');
Spark
&gt; SELECT aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
&gt; SELECT aes_decrypt(unbase64('3lmwu+Mw0H3fi5NDvcu9lg=='), '1234567890abcdef', 'ECB', 'PKCS');
Spark SQL
&gt; SELECT aes_decrypt(unbase64('2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo='), '1234567890abcdef', 'CBC');
Apache Spark
&gt; SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg='), 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT');
Spark
&gt; SELECT aes_decrypt(unbase64('AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4'), 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', 'This is an AAD mixed into the input');
Spark
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="aes_encrypt"><a class="toclink" href="#aes_encrypt">aes_encrypt</a></h3>
<p>aes_encrypt(expr, key[, mode[, padding[, iv[, aad]]]]) - Returns an encrypted value of <code>expr</code> using AES in given <code>mode</code> with the specified <code>padding</code>.
Key lengths of 16, 24 and 32 bits are supported. Supported combinations of (<code>mode</code>, <code>padding</code>) 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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - The binary value to encrypt.</li>
<li>key - The passphrase to use to encrypt the data.</li>
<li>mode - Specifies which block cipher mode should be used to encrypt messages.
Valid modes: ECB, GCM, CBC.</li>
<li>padding - Specifies how to pad messages whose length is not a multiple of the block size.
Valid values: PKCS, NONE, DEFAULT. The DEFAULT padding means PKCS for ECB, NONE for GCM and PKCS for CBC.</li>
<li>iv - Optional initialization vector. Only supported for CBC and GCM modes.
Valid values: None or ''. 16-byte array for CBC mode. 12-byte array for GCM mode.</li>
<li>aad - Optional additional authenticated data. Only supported for GCM mode. This can be any free-form input and
must be provided for both encryption and decryption.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hex(aes_encrypt('Spark', '0000111122223333'));
83F16B2AA704794132802D248E6BFD4E380078182D1544813898AC97E709B28A94
&gt; SELECT hex(aes_encrypt('Spark SQL', '0000111122223333', 'GCM'));
6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210
&gt; SELECT base64(aes_encrypt('Spark SQL', '1234567890abcdef', 'ECB', 'PKCS'));
3lmwu+Mw0H3fi5NDvcu9lg==
&gt; SELECT base64(aes_encrypt('Apache Spark', '1234567890abcdef', 'CBC', 'DEFAULT'));
2NYmDCjgXTbbxGA3/SnJEfFC/JQ7olk2VQWReIAAFKo=
&gt; SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'CBC', 'DEFAULT', unhex('00000000000000000000000000000000')));
AAAAAAAAAAAAAAAAAAAAAPSd4mWyMZ5mhvjiAPQJnfg=
&gt; SELECT base64(aes_encrypt('Spark', 'abcdefghijklmnop12345678ABCDEFGH', 'GCM', 'DEFAULT', unhex('000000000000000000000000'), 'This is an AAD mixed into the input'));
AAAAAAAAAAAAAAAAQiYi+sTLm7KD9UcZ2nlRdYDe/PX4
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="aggregate"><a class="toclink" href="#aggregate">aggregate</a></h3>
<p>aggregate(expr, start, merge, finish) - Applies a binary operator to an initial state and all
elements in the array, and reduces this to a single state. The final state is converted
into the final result by applying a finish function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT aggregate(array(1, 2, 3), 0, (acc, x) -&gt; acc + x);
6
&gt; SELECT aggregate(array(1, 2, 3), 0, (acc, x) -&gt; acc + x, acc -&gt; acc * 10);
60
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="and"><a class="toclink" href="#and">and</a></h3>
<p>expr1 and expr2 - Logical AND.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT true and true;
true
&gt; SELECT true and false;
false
&gt; SELECT true and NULL;
NULL
&gt; SELECT false and NULL;
false
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="any"><a class="toclink" href="#any">any</a></h3>
<p>any(expr) - Returns true if at least one value of <code>expr</code> is true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT any(col) FROM VALUES (true), (false), (false) AS tab(col);
true
&gt; SELECT any(col) FROM VALUES (NULL), (true), (false) AS tab(col);
true
&gt; SELECT any(col) FROM VALUES (false), (false), (NULL) AS tab(col);
false
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="any_value"><a class="toclink" href="#any_value">any_value</a></h3>
<p>any_value(expr[, isIgnoreNull]) - Returns some value of <code>expr</code> for a group of rows.
If <code>isIgnoreNull</code> is true, returns only non-null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT any_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
&gt; SELECT any_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
&gt; SELECT any_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic.</p>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="approx_count_distinct"><a class="toclink" href="#approx_count_distinct">approx_count_distinct</a></h3>
<p>approx_count_distinct(expr[, relativeSD]) - Returns the estimated cardinality by HyperLogLog++.
<code>relativeSD</code> defines the maximum relative standard deviation allowed.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT approx_count_distinct(col1) FROM VALUES (1), (1), (2), (2), (3) tab(col1);
3
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="approx_percentile"><a class="toclink" href="#approx_percentile">approx_percentile</a></h3>
<p>approx_percentile(col, percentage [, accuracy]) - Returns the approximate <code>percentile</code> of the numeric or
ansi interval column <code>col</code> which is the smallest value in the ordered <code>col</code> values (sorted
from least to greatest) such that no more than <code>percentage</code> of <code>col</code> values is less than
the value or equal to that value. The value of percentage must be between 0.0 and 1.0.
The <code>accuracy</code> parameter (default: 10000) is a positive numeric literal which controls
approximation accuracy at the cost of memory. Higher value of <code>accuracy</code> yields better
accuracy, <code>1.0/accuracy</code> is the relative error of the approximation.
When <code>percentage</code> 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 <code>col</code> at the given
percentage array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT approx_percentile(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
&gt; SELECT approx_percentile(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
&gt; 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
&gt; 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]
</code></pre>
<p><strong>Since:</strong> 2.1.0</p>
<p><br/></p>
<h3 id="array"><a class="toclink" href="#array">array</a></h3>
<p>array(expr, ...) - Returns an array with the given elements.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array(1, 2, 3);
[1,2,3]
</code></pre>
<p><strong>Since:</strong> 1.1.0</p>
<p><br/></p>
<h3 id="array_agg"><a class="toclink" href="#array_agg">array_agg</a></h3>
<p>array_agg(expr) - Collects and returns a list of non-unique elements.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_agg(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2,1]
</code></pre>
<p><strong>Note:</strong></p>
<p>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.</p>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="array_append"><a class="toclink" href="#array_append">array_append</a></h3>
<p>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</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_append(array('b', 'd', 'c', 'a'), 'd');
[&quot;b&quot;,&quot;d&quot;,&quot;c&quot;,&quot;a&quot;,&quot;d&quot;]
&gt; SELECT array_append(array(1, 2, 3, null), null);
[1,2,3,null,null]
&gt; SELECT array_append(CAST(null as Array&lt;Int&gt;), 2);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="array_compact"><a class="toclink" href="#array_compact">array_compact</a></h3>
<p>array_compact(array) - Removes null values from the array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_compact(array(1, 2, 3, null));
[1,2,3]
&gt; SELECT array_compact(array(&quot;a&quot;, &quot;b&quot;, &quot;c&quot;));
[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;]
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="array_contains"><a class="toclink" href="#array_contains">array_contains</a></h3>
<p>array_contains(array, value) - Returns true if the array contains the value.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_contains(array(1, 2, 3), 2);
true
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="array_distinct"><a class="toclink" href="#array_distinct">array_distinct</a></h3>
<p>array_distinct(array) - Removes duplicate values from the array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_distinct(array(1, 2, 3, null, 3));
[1,2,3,null]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_except"><a class="toclink" href="#array_except">array_except</a></h3>
<p>array_except(array1, array2) - Returns an array of the elements in array1 but not in array2,
without duplicates.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_except(array(1, 2, 3), array(1, 3, 5));
[2]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_insert"><a class="toclink" href="#array_insert">array_insert</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_insert(array(1, 2, 3, 4), 5, 5);
[1,2,3,4,5]
&gt; SELECT array_insert(array(5, 4, 3, 2), -1, 1);
[5,4,3,2,1]
&gt; SELECT array_insert(array(5, 3, 2, 1), -4, 4);
[5,4,3,2,1]
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="array_intersect"><a class="toclink" href="#array_intersect">array_intersect</a></h3>
<p>array_intersect(array1, array2) - Returns an array of the elements in the intersection of array1 and
array2, without duplicates.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_intersect(array(1, 2, 3), array(1, 3, 5));
[1,3]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_join"><a class="toclink" href="#array_join">array_join</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_join(array('hello', 'world'), ' ');
hello world
&gt; SELECT array_join(array('hello', null ,'world'), ' ');
hello world
&gt; SELECT array_join(array('hello', null ,'world'), ' ', ',');
hello , world
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_max"><a class="toclink" href="#array_max">array_max</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_max(array(1, 20, null, 3));
20
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_min"><a class="toclink" href="#array_min">array_min</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_min(array(1, 20, null, 3));
1
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_position"><a class="toclink" href="#array_position">array_position</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_position(array(312, 773, 708, 708), 708);
3
&gt; SELECT array_position(array(312, 773, 708, 708), 414);
0
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_prepend"><a class="toclink" href="#array_prepend">array_prepend</a></h3>
<p>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</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_prepend(array('b', 'd', 'c', 'a'), 'd');
[&quot;d&quot;,&quot;b&quot;,&quot;d&quot;,&quot;c&quot;,&quot;a&quot;]
&gt; SELECT array_prepend(array(1, 2, 3, null), null);
[null,1,2,3,null]
&gt; SELECT array_prepend(CAST(null as Array&lt;Int&gt;), 2);
NULL
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="array_remove"><a class="toclink" href="#array_remove">array_remove</a></h3>
<p>array_remove(array, element) - Remove all elements that equal to element from array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_remove(array(1, 2, 3, null, 3), 3);
[1,2,null]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_repeat"><a class="toclink" href="#array_repeat">array_repeat</a></h3>
<p>array_repeat(element, count) - Returns the array containing element count times.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_repeat('123', 2);
[&quot;123&quot;,&quot;123&quot;]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_size"><a class="toclink" href="#array_size">array_size</a></h3>
<p>array_size(expr) - Returns the size of an array. The function returns null for null input.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_size(array('b', 'd', 'c', 'a'));
4
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="array_sort"><a class="toclink" href="#array_sort">array_sort</a></h3>
<p>array_sort(expr, func) - Sorts the input array. If func is omitted, sort
in ascending order. The elements of the input array must be orderable.
NaN is greater than any non-NaN elements for double/float type.
Null elements will be placed at the end of the returned array.
Since 3.0.0 this function also sorts and returns the array based on the
given comparator function. The comparator will take two arguments representing
two elements of the array.
It returns a negative integer, 0, or a positive integer as the first element is less than,
equal to, or greater than the second element. If the comparator function returns null,
the function will fail and raise an error.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_sort(array(5, 6, 1), (left, right) -&gt; case when left &lt; right then -1 when left &gt; right then 1 else 0 end);
[1,5,6]
&gt; SELECT array_sort(array('bc', 'ab', 'dc'), (left, right) -&gt; case when left is null and right is null then 0 when left is null then -1 when right is null then 1 when left &lt; right then 1 when left &gt; right then -1 else 0 end);
[&quot;dc&quot;,&quot;bc&quot;,&quot;ab&quot;]
&gt; SELECT array_sort(array('b', 'd', null, 'c', 'a'));
[&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,null]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="array_union"><a class="toclink" href="#array_union">array_union</a></h3>
<p>array_union(array1, array2) - Returns an array of the elements in the union of array1 and array2,
without duplicates.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT array_union(array(1, 2, 3), array(1, 3, 5));
[1,2,3,5]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="arrays_overlap"><a class="toclink" href="#arrays_overlap">arrays_overlap</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT arrays_overlap(array(1, 2, 3), array(3, 4, 5));
true
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="arrays_zip"><a class="toclink" href="#arrays_zip">arrays_zip</a></h3>
<p>arrays_zip(a1, a2, ...) - Returns a merged array of structs in which the N-th struct contains all
N-th values of input arrays.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT arrays_zip(array(1, 2, 3), array(2, 3, 4));
[{&quot;0&quot;:1,&quot;1&quot;:2},{&quot;0&quot;:2,&quot;1&quot;:3},{&quot;0&quot;:3,&quot;1&quot;:4}]
&gt; SELECT arrays_zip(array(1, 2), array(2, 3), array(3, 4));
[{&quot;0&quot;:1,&quot;1&quot;:2,&quot;2&quot;:3},{&quot;0&quot;:2,&quot;1&quot;:3,&quot;2&quot;:4}]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="ascii"><a class="toclink" href="#ascii">ascii</a></h3>
<p>ascii(str) - Returns the numeric value of the first character of <code>str</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ascii('222');
50
&gt; SELECT ascii(2);
50
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="asin"><a class="toclink" href="#asin">asin</a></h3>
<p>asin(expr) - Returns the inverse sine (a.k.a. arc sine) the arc sin of <code>expr</code>,
as if computed by <code>java.lang.Math.asin</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT asin(0);
0.0
&gt; SELECT asin(2);
NaN
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="asinh"><a class="toclink" href="#asinh">asinh</a></h3>
<p>asinh(expr) - Returns inverse hyperbolic sine of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT asinh(0);
0.0
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="assert_true"><a class="toclink" href="#assert_true">assert_true</a></h3>
<p>assert_true(expr [, message]) - Throws an exception if <code>expr</code> is not true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT assert_true(0 &lt; 1);
NULL
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="atan"><a class="toclink" href="#atan">atan</a></h3>
<p>atan(expr) - Returns the inverse tangent (a.k.a. arc tangent) of <code>expr</code>, as if computed by
<code>java.lang.Math.atan</code></p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT atan(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="atan2"><a class="toclink" href="#atan2">atan2</a></h3>
<p>atan2(exprY, exprX) - Returns the angle in radians between the positive x-axis of a plane
and the point given by the coordinates (<code>exprX</code>, <code>exprY</code>), as if computed by
<code>java.lang.Math.atan2</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>exprY - coordinate on y-axis</li>
<li>exprX - coordinate on x-axis</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT atan2(0, 0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="atanh"><a class="toclink" href="#atanh">atanh</a></h3>
<p>atanh(expr) - Returns inverse hyperbolic tangent of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT atanh(0);
0.0
&gt; SELECT atanh(2);
NaN
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="avg"><a class="toclink" href="#avg">avg</a></h3>
<p>avg(expr) - Returns the mean calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT avg(col) FROM VALUES (1), (2), (3) AS tab(col);
2.0
&gt; SELECT avg(col) FROM VALUES (1), (2), (NULL) AS tab(col);
1.5
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="base64"><a class="toclink" href="#base64">base64</a></h3>
<p>base64(bin) - Converts the argument from a binary <code>bin</code> to a base 64 string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT base64('Spark SQL');
U3BhcmsgU1FM
&gt; SELECT base64(x'537061726b2053514c');
U3BhcmsgU1FM
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="between"><a class="toclink" href="#between">between</a></h3>
<p>expr1 [NOT] BETWEEN expr2 AND expr3 - evaluate if <code>expr1</code> is [not] in between <code>expr2</code> and <code>expr3</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT col1 FROM VALUES 1, 3, 5, 7 WHERE col1 BETWEEN 2 AND 5;
3
5
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="between_1"><a class="toclink" href="#between_1">between</a></h3>
<p>Usage: input [NOT] BETWEEN lower AND upper - evaluate if <code>input</code> is [not] in between <code>lower</code> and <code>upper</code></p>
<p><strong>Arguments:</strong></p>
<ul>
<li>input - An expression that is being compared with lower and upper bound.</li>
<li>lower - Lower bound of the between check.</li>
<li>upper - Upper bound of the between check.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 0.5 between 0.1 AND 1.0;
true
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="bigint"><a class="toclink" href="#bigint">bigint</a></h3>
<p>bigint(expr) - Casts the value <code>expr</code> to the target data type <code>bigint</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="bin"><a class="toclink" href="#bin">bin</a></h3>
<p>bin(expr) - Returns the string representation of the long value <code>expr</code> represented in binary.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bin(13);
1101
&gt; SELECT bin(-13);
1111111111111111111111111111111111111111111111111111111111110011
&gt; SELECT bin(13.3);
1101
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="binary"><a class="toclink" href="#binary">binary</a></h3>
<p>binary(expr) - Casts the value <code>expr</code> to the target data type <code>binary</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="bit_and"><a class="toclink" href="#bit_and">bit_and</a></h3>
<p>bit_and(expr) - Returns the bitwise AND of all non-null input values, or null if none.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_and(col) FROM VALUES (3), (5) AS tab(col);
1
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="bit_count"><a class="toclink" href="#bit_count">bit_count</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_count(0);
0
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="bit_get"><a class="toclink" href="#bit_get">bit_get</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_get(11, 0);
1
&gt; SELECT bit_get(11, 2);
0
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="bit_length"><a class="toclink" href="#bit_length">bit_length</a></h3>
<p>bit_length(expr) - Returns the bit length of string data or number of bits of binary data.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_length('Spark SQL');
72
&gt; SELECT bit_length(x'537061726b2053514c');
72
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="bit_or"><a class="toclink" href="#bit_or">bit_or</a></h3>
<p>bit_or(expr) - Returns the bitwise OR of all non-null input values, or null if none.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_or(col) FROM VALUES (3), (5) AS tab(col);
7
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="bit_xor"><a class="toclink" href="#bit_xor">bit_xor</a></h3>
<p>bit_xor(expr) - Returns the bitwise XOR of all non-null input values, or null if none.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bit_xor(col) FROM VALUES (3), (5) AS tab(col);
6
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="bitmap_bit_position"><a class="toclink" href="#bitmap_bit_position">bitmap_bit_position</a></h3>
<p>bitmap_bit_position(child) - Returns the bit position for the given input child expression.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bitmap_bit_position(1);
0
&gt; SELECT bitmap_bit_position(123);
122
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="bitmap_bucket_number"><a class="toclink" href="#bitmap_bucket_number">bitmap_bucket_number</a></h3>
<p>bitmap_bucket_number(child) - Returns the bucket number for the given input child expression.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bitmap_bucket_number(123);
1
&gt; SELECT bitmap_bucket_number(0);
0
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="bitmap_construct_agg"><a class="toclink" href="#bitmap_construct_agg">bitmap_construct_agg</a></h3>
<p>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().</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT substring(hex(bitmap_construct_agg(bitmap_bit_position(col))), 0, 6) FROM VALUES (1), (2), (3) AS tab(col);
070000
&gt; SELECT substring(hex(bitmap_construct_agg(bitmap_bit_position(col))), 0, 6) FROM VALUES (1), (1), (1) AS tab(col);
010000
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="bitmap_count"><a class="toclink" href="#bitmap_count">bitmap_count</a></h3>
<p>bitmap_count(child) - Returns the number of set bits in the child bitmap.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bitmap_count(X '1010');
2
&gt; SELECT bitmap_count(X 'FFFF');
16
&gt; SELECT bitmap_count(X '0');
0
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="bitmap_or_agg"><a class="toclink" href="#bitmap_or_agg">bitmap_or_agg</a></h3>
<p>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().</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT substring(hex(bitmap_or_agg(col)), 0, 6) FROM VALUES (X '10'), (X '20'), (X '40') AS tab(col);
700000
&gt; SELECT substring(hex(bitmap_or_agg(col)), 0, 6) FROM VALUES (X '10'), (X '10'), (X '10') AS tab(col);
100000
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="bool_and"><a class="toclink" href="#bool_and">bool_and</a></h3>
<p>bool_and(expr) - Returns true if all values of <code>expr</code> are true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bool_and(col) FROM VALUES (true), (true), (true) AS tab(col);
true
&gt; SELECT bool_and(col) FROM VALUES (NULL), (true), (true) AS tab(col);
true
&gt; SELECT bool_and(col) FROM VALUES (true), (false), (true) AS tab(col);
false
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="bool_or"><a class="toclink" href="#bool_or">bool_or</a></h3>
<p>bool_or(expr) - Returns true if at least one value of <code>expr</code> is true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bool_or(col) FROM VALUES (true), (false), (false) AS tab(col);
true
&gt; SELECT bool_or(col) FROM VALUES (NULL), (true), (false) AS tab(col);
true
&gt; SELECT bool_or(col) FROM VALUES (false), (false), (NULL) AS tab(col);
false
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="boolean"><a class="toclink" href="#boolean">boolean</a></h3>
<p>boolean(expr) - Casts the value <code>expr</code> to the target data type <code>boolean</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="bround"><a class="toclink" href="#bround">bround</a></h3>
<p>bround(expr, d) - Returns <code>expr</code> rounded to <code>d</code> decimal places using HALF_EVEN rounding mode.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT bround(2.5, 0);
2
&gt; SELECT bround(25, -1);
20
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="btrim"><a class="toclink" href="#btrim">btrim</a></h3>
<p>btrim(str) - Removes the leading and trailing space characters from <code>str</code>.</p>
<p>btrim(str, trimStr) - Remove the leading and trailing <code>trimStr</code> characters from <code>str</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>trimStr - the trim string characters to trim, the default value is a single space</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT btrim(' SparkSQL ');
SparkSQL
&gt; SELECT btrim(encode(' SparkSQL ', 'utf-8'));
SparkSQL
&gt; SELECT btrim('SSparkSQLS', 'SL');
parkSQ
&gt; SELECT btrim(encode('SSparkSQLS', 'utf-8'), encode('SL', 'utf-8'));
parkSQ
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="cardinality"><a class="toclink" href="#cardinality">cardinality</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cardinality(array('b', 'd', 'c', 'a'));
4
&gt; SELECT cardinality(map('a', 1, 'b', 2));
2
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="case"><a class="toclink" href="#case">case</a></h3>
<p>CASE expr1 WHEN expr2 THEN expr3 [WHEN expr4 THEN expr5]* [ELSE expr6] END - When <code>expr1</code> = <code>expr2</code>, returns <code>expr3</code>; when <code>expr1</code> = <code>expr4</code>, return <code>expr5</code>; else return <code>expr6</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1 - the expression which is one operand of comparison.</li>
<li>expr2, expr4 - the expressions each of which is the other operand of comparison.</li>
<li>expr3, expr5, expr6 - the branch value expressions and else value expression should all be same type or coercible to a common type.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT CASE col1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE '?' END FROM VALUES 1, 2, 3;
one
two
?
&gt; SELECT CASE col1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END FROM VALUES 1, 2, 3;
one
two
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="cast"><a class="toclink" href="#cast">cast</a></h3>
<p>cast(expr AS type) - Casts the value <code>expr</code> to the target data type <code>type</code>. <code>expr</code> :: <code>type</code> alternative casting syntax is also supported.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cast('10' as int);
10
&gt; SELECT '10' :: int;
10
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="cbrt"><a class="toclink" href="#cbrt">cbrt</a></h3>
<p>cbrt(expr) - Returns the cube root of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cbrt(27.0);
3.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="ceil"><a class="toclink" href="#ceil">ceil</a></h3>
<p>ceil(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than <code>expr</code>. An optional <code>scale</code> parameter can be specified to control the rounding behavior.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ceil(-0.1);
0
&gt; SELECT ceil(5);
5
&gt; SELECT ceil(3.1411, 3);
3.142
&gt; SELECT ceil(3.1411, -3);
1000
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="ceiling"><a class="toclink" href="#ceiling">ceiling</a></h3>
<p>ceiling(expr[, scale]) - Returns the smallest number after rounding up that is not smaller than <code>expr</code>. An optional <code>scale</code> parameter can be specified to control the rounding behavior.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ceiling(-0.1);
0
&gt; SELECT ceiling(5);
5
&gt; SELECT ceiling(3.1411, 3);
3.142
&gt; SELECT ceiling(3.1411, -3);
1000
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="char"><a class="toclink" href="#char">char</a></h3>
<p>char(expr) - Returns the ASCII character having the binary equivalent to <code>expr</code>. If n is larger than 256 the result is equivalent to chr(n % 256)</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT char(65);
A
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="char_length"><a class="toclink" href="#char_length">char_length</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT char_length('Spark SQL ');
10
&gt; SELECT char_length(x'537061726b2053514c');
9
&gt; SELECT CHAR_LENGTH('Spark SQL ');
10
&gt; SELECT CHARACTER_LENGTH('Spark SQL ');
10
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="character_length"><a class="toclink" href="#character_length">character_length</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT character_length('Spark SQL ');
10
&gt; SELECT character_length(x'537061726b2053514c');
9
&gt; SELECT CHAR_LENGTH('Spark SQL ');
10
&gt; SELECT CHARACTER_LENGTH('Spark SQL ');
10
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="chr"><a class="toclink" href="#chr">chr</a></h3>
<p>chr(expr) - Returns the ASCII character having the binary equivalent to <code>expr</code>. If n is larger than 256 the result is equivalent to chr(n % 256)</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT chr(65);
A
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="coalesce"><a class="toclink" href="#coalesce">coalesce</a></h3>
<p>coalesce(expr1, expr2, ...) - Returns the first non-null argument if exists. Otherwise, null.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT coalesce(NULL, 1, NULL);
1
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="collate"><a class="toclink" href="#collate">collate</a></h3>
<p>collate(expr, collationName) - Marks a given expression with the specified collation.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - String expression to perform collation on.</li>
<li>collationName - Foldable string expression that specifies the collation name.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SET spark.sql.collation.enabled=true;
spark.sql.collation.enabled true
&gt; SELECT COLLATION('Spark SQL' collate UTF8_BINARY_LCASE);
UTF8_BINARY_LCASE
&gt; SET spark.sql.collation.enabled=false;
spark.sql.collation.enabled false
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="collation"><a class="toclink" href="#collation">collation</a></h3>
<p>collation(expr) - Returns the collation name of a given expression.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - String expression to perform collation on.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SET spark.sql.collation.enabled=true;
spark.sql.collation.enabled true
&gt; SELECT collation('Spark SQL');
UTF8_BINARY
&gt; SET spark.sql.collation.enabled=false;
spark.sql.collation.enabled false
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="collect_list"><a class="toclink" href="#collect_list">collect_list</a></h3>
<p>collect_list(expr) - Collects and returns a list of non-unique elements.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT collect_list(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2,1]
</code></pre>
<p><strong>Note:</strong></p>
<p>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.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="collect_set"><a class="toclink" href="#collect_set">collect_set</a></h3>
<p>collect_set(expr) - Collects and returns a set of unique elements.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT collect_set(col) FROM VALUES (1), (2), (1) AS tab(col);
[1,2]
</code></pre>
<p><strong>Note:</strong></p>
<p>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.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="concat"><a class="toclink" href="#concat">concat</a></h3>
<p>concat(col1, col2, ..., colN) - Returns the concatenation of col1, col2, ..., colN.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT concat('Spark', 'SQL');
SparkSQL
&gt; SELECT concat(array(1, 2, 3), array(4, 5), array(6));
[1,2,3,4,5,6]
</code></pre>
<p><strong>Note:</strong></p>
<p>Concat logic for arrays is available since 2.4.0.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="concat_ws"><a class="toclink" href="#concat_ws">concat_ws</a></h3>
<p>concat_ws(sep[, str | array(str)]+) - Returns the concatenation of the strings separated by <code>sep</code>, skipping null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT concat_ws(' ', 'Spark', 'SQL');
Spark SQL
&gt; SELECT concat_ws('s');
&gt; SELECT concat_ws('/', 'foo', null, 'bar');
foo/bar
&gt; SELECT concat_ws(null, 'Spark', 'SQL');
NULL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="contains"><a class="toclink" href="#contains">contains</a></h3>
<p>contains(left, right) - Returns a boolean. The value is True if right is found inside left.
Returns NULL if either input expression is NULL. Otherwise, returns False.
Both left or right must be of STRING or BINARY type.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT contains('Spark SQL', 'Spark');
true
&gt; SELECT contains('Spark SQL', 'SPARK');
false
&gt; SELECT contains('Spark SQL', null);
NULL
&gt; SELECT contains(x'537061726b2053514c', x'537061726b');
true
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="conv"><a class="toclink" href="#conv">conv</a></h3>
<p>conv(num, from_base, to_base) - Convert <code>num</code> from <code>from_base</code> to <code>to_base</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT conv('100', 2, 10);
4
&gt; SELECT conv(-10, 16, -10);
-16
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="convert_timezone"><a class="toclink" href="#convert_timezone">convert_timezone</a></h3>
<p>convert_timezone([sourceTz, ]targetTz, sourceTs) - Converts the timestamp without time zone <code>sourceTs</code> from the <code>sourceTz</code> time zone to <code>targetTz</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>sourceTz - the time zone for the input timestamp.
If it is missed, the current session time zone is used as the source time zone.</li>
<li>targetTz - the time zone to which the input timestamp should be converted</li>
<li>sourceTs - a timestamp without time zone</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT convert_timezone('Europe/Brussels', 'America/Los_Angeles', timestamp_ntz'2021-12-06 00:00:00');
2021-12-05 15:00:00
&gt; SELECT convert_timezone('Europe/Brussels', timestamp_ntz'2021-12-05 15:00:00');
2021-12-06 00:00:00
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="corr"><a class="toclink" href="#corr">corr</a></h3>
<p>corr(expr1, expr2) - Returns Pearson coefficient of correlation between a set of number pairs.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT corr(c1, c2) FROM VALUES (3, 2), (3, 3), (6, 4) as tab(c1, c2);
0.8660254037844387
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="cos"><a class="toclink" href="#cos">cos</a></h3>
<p>cos(expr) - Returns the cosine of <code>expr</code>, as if computed by
<code>java.lang.Math.cos</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cos(0);
1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="cosh"><a class="toclink" href="#cosh">cosh</a></h3>
<p>cosh(expr) - Returns the hyperbolic cosine of <code>expr</code>, as if computed by
<code>java.lang.Math.cosh</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - hyperbolic angle</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cosh(0);
1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="cot"><a class="toclink" href="#cot">cot</a></h3>
<p>cot(expr) - Returns the cotangent of <code>expr</code>, as if computed by <code>1/java.lang.Math.tan</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT cot(1);
0.6420926159343306
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="count"><a class="toclink" href="#count">count</a></h3>
<p>count(*) - Returns the total number of retrieved rows, including rows containing null.</p>
<p>count(expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are all non-null.</p>
<p>count(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT count(*) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
4
&gt; SELECT count(col) FROM VALUES (NULL), (5), (5), (20) AS tab(col);
3
&gt; SELECT count(DISTINCT col) FROM VALUES (NULL), (5), (5), (10) AS tab(col);
2
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="count_if"><a class="toclink" href="#count_if">count_if</a></h3>
<p>count_if(expr) - Returns the number of <code>TRUE</code> values for the expression.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT count_if(col % 2 = 0) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
2
&gt; SELECT count_if(col IS NULL) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
1
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="count_min_sketch"><a class="toclink" href="#count_min_sketch">count_min_sketch</a></h3>
<p>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
<code>CountMinSketch</code> before usage. Count-min sketch is a probabilistic data structure used for
cardinality estimation using sub-linear space.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hex(count_min_sketch(col, 0.5d, 0.5d, 1)) FROM VALUES (1), (2), (1) AS tab(col);
0000000100000000000000030000000100000004000000005D8D6AB90000000000000000000000000000000200000000000000010000000000000000
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="covar_pop"><a class="toclink" href="#covar_pop">covar_pop</a></h3>
<p>covar_pop(expr1, expr2) - Returns the population covariance of a set of number pairs.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT covar_pop(c1, c2) FROM VALUES (1,1), (2,2), (3,3) AS tab(c1, c2);
0.6666666666666666
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="covar_samp"><a class="toclink" href="#covar_samp">covar_samp</a></h3>
<p>covar_samp(expr1, expr2) - Returns the sample covariance of a set of number pairs.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT covar_samp(c1, c2) FROM VALUES (1,1), (2,2), (3,3) AS tab(c1, c2);
1.0
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="crc32"><a class="toclink" href="#crc32">crc32</a></h3>
<p>crc32(expr) - Returns a cyclic redundancy check value of the <code>expr</code> as a bigint.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT crc32('Spark');
1557323817
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="csc"><a class="toclink" href="#csc">csc</a></h3>
<p>csc(expr) - Returns the cosecant of <code>expr</code>, as if computed by <code>1/java.lang.Math.sin</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT csc(1);
1.1883951057781212
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="cume_dist"><a class="toclink" href="#cume_dist">cume_dist</a></h3>
<p>cume_dist() - Computes the position of a value relative to all values in the partition.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="curdate"><a class="toclink" href="#curdate">curdate</a></h3>
<p>curdate() - Returns the current date at the start of query evaluation. All calls of curdate within the same query return the same value.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT curdate();
2022-09-06
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="current_catalog"><a class="toclink" href="#current_catalog">current_catalog</a></h3>
<p>current_catalog() - Returns the current catalog.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_catalog();
spark_catalog
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="current_database"><a class="toclink" href="#current_database">current_database</a></h3>
<p>current_database() - Returns the current database.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_database();
default
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="current_date"><a class="toclink" href="#current_date">current_date</a></h3>
<p>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.</p>
<p>current_date - Returns the current date at the start of query evaluation.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_date();
2020-04-25
&gt; SELECT current_date;
2020-04-25
</code></pre>
<p><strong>Note:</strong></p>
<p>The syntax without braces has been supported since 2.0.1.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="current_schema"><a class="toclink" href="#current_schema">current_schema</a></h3>
<p>current_schema() - Returns the current database.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_schema();
default
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="current_timestamp"><a class="toclink" href="#current_timestamp">current_timestamp</a></h3>
<p>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.</p>
<p>current_timestamp - Returns the current timestamp at the start of query evaluation.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_timestamp();
2020-04-25 15:49:11.914
&gt; SELECT current_timestamp;
2020-04-25 15:49:11.914
</code></pre>
<p><strong>Note:</strong></p>
<p>The syntax without braces has been supported since 2.0.1.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="current_timezone"><a class="toclink" href="#current_timezone">current_timezone</a></h3>
<p>current_timezone() - Returns the current session local timezone.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_timezone();
Asia/Shanghai
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="current_user"><a class="toclink" href="#current_user">current_user</a></h3>
<p>current_user() - user name of current execution context.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT current_user();
mockingjay
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="date"><a class="toclink" href="#date">date</a></h3>
<p>date(expr) - Casts the value <code>expr</code> to the target data type <code>date</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="date_add"><a class="toclink" href="#date_add">date_add</a></h3>
<p>date_add(start_date, num_days) - Returns the date that is <code>num_days</code> after <code>start_date</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_add('2016-07-30', 1);
2016-07-31
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="date_diff"><a class="toclink" href="#date_diff">date_diff</a></h3>
<p>date_diff(endDate, startDate) - Returns the number of days from <code>startDate</code> to <code>endDate</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_diff('2009-07-31', '2009-07-30');
1
&gt; SELECT date_diff('2009-07-30', '2009-07-31');
-1
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="date_format"><a class="toclink" href="#date_format">date_format</a></h3>
<p>date_format(timestamp, fmt) - Converts <code>timestamp</code> to a value of string in the format specified by the date format <code>fmt</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timestamp - A date/timestamp or string to be converted to the given format.</li>
<li>fmt - Date/time format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid date
and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_format('2016-04-08', 'y');
2016
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="date_from_unix_date"><a class="toclink" href="#date_from_unix_date">date_from_unix_date</a></h3>
<p>date_from_unix_date(days) - Create date from the number of days since 1970-01-01.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_from_unix_date(1);
1970-01-02
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="date_part"><a class="toclink" href="#date_part">date_part</a></h3>
<p>date_part(field, source) - Extracts a part of the date/timestamp or interval source.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>field - selects which part of the source should be extracted, and supported string values are as same as the fields of the equivalent function <code>EXTRACT</code>.</li>
<li>source - a date/timestamp or interval column from where <code>field</code> should be extracted</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_part('YEAR', TIMESTAMP '2019-08-12 01:00:00.123456');
2019
&gt; SELECT date_part('week', timestamp'2019-08-12 01:00:00.123456');
33
&gt; SELECT date_part('doy', DATE'2019-08-12');
224
&gt; SELECT date_part('SECONDS', timestamp'2019-10-01 00:00:01.000001');
1.000001
&gt; SELECT date_part('days', interval 5 days 3 hours 7 minutes);
5
&gt; SELECT date_part('seconds', interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
&gt; SELECT date_part('MONTH', INTERVAL '2021-11' YEAR TO MONTH);
11
&gt; SELECT date_part('MINUTE', INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55
</code></pre>
<p><strong>Note:</strong></p>
<p>The date_part function is equivalent to the SQL-standard function <code>EXTRACT(field FROM source)</code></p>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="date_sub"><a class="toclink" href="#date_sub">date_sub</a></h3>
<p>date_sub(start_date, num_days) - Returns the date that is <code>num_days</code> before <code>start_date</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_sub('2016-07-30', 1);
2016-07-29
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="date_trunc"><a class="toclink" href="#date_trunc">date_trunc</a></h3>
<p>date_trunc(fmt, ts) - Returns timestamp <code>ts</code> truncated to the unit specified by the format model <code>fmt</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>fmt - the format representing the unit to be truncated to<ul>
<li>"YEAR", "YYYY", "YY" - truncate to the first date of the year that the <code>ts</code> falls in, the time part will be zero out</li>
<li>"QUARTER" - truncate to the first date of the quarter that the <code>ts</code> falls in, the time part will be zero out</li>
<li>"MONTH", "MM", "MON" - truncate to the first date of the month that the <code>ts</code> falls in, the time part will be zero out</li>
<li>"WEEK" - truncate to the Monday of the week that the <code>ts</code> falls in, the time part will be zero out</li>
<li>"DAY", "DD" - zero out the time part</li>
<li>"HOUR" - zero out the minute and second with fraction part</li>
<li>"MINUTE"- zero out the second with fraction part</li>
<li>"SECOND" - zero out the second fraction part</li>
<li>"MILLISECOND" - zero out the microseconds</li>
<li>"MICROSECOND" - everything remains</li>
</ul>
</li>
<li>ts - datetime value or valid timestamp string</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT date_trunc('YEAR', '2015-03-05T09:32:05.359');
2015-01-01 00:00:00
&gt; SELECT date_trunc('MM', '2015-03-05T09:32:05.359');
2015-03-01 00:00:00
&gt; SELECT date_trunc('DD', '2015-03-05T09:32:05.359');
2015-03-05 00:00:00
&gt; SELECT date_trunc('HOUR', '2015-03-05T09:32:05.359');
2015-03-05 09:00:00
&gt; SELECT date_trunc('MILLISECOND', '2015-03-05T09:32:05.123456');
2015-03-05 09:32:05.123
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="dateadd"><a class="toclink" href="#dateadd">dateadd</a></h3>
<p>dateadd(start_date, num_days) - Returns the date that is <code>num_days</code> after <code>start_date</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT dateadd('2016-07-30', 1);
2016-07-31
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="datediff"><a class="toclink" href="#datediff">datediff</a></h3>
<p>datediff(endDate, startDate) - Returns the number of days from <code>startDate</code> to <code>endDate</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT datediff('2009-07-31', '2009-07-30');
1
&gt; SELECT datediff('2009-07-30', '2009-07-31');
-1
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="datepart"><a class="toclink" href="#datepart">datepart</a></h3>
<p>datepart(field, source) - Extracts a part of the date/timestamp or interval source.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>field - selects which part of the source should be extracted, and supported string values are as same as the fields of the equivalent function <code>EXTRACT</code>.</li>
<li>source - a date/timestamp or interval column from where <code>field</code> should be extracted</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT datepart('YEAR', TIMESTAMP '2019-08-12 01:00:00.123456');
2019
&gt; SELECT datepart('week', timestamp'2019-08-12 01:00:00.123456');
33
&gt; SELECT datepart('doy', DATE'2019-08-12');
224
&gt; SELECT datepart('SECONDS', timestamp'2019-10-01 00:00:01.000001');
1.000001
&gt; SELECT datepart('days', interval 5 days 3 hours 7 minutes);
5
&gt; SELECT datepart('seconds', interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
&gt; SELECT datepart('MONTH', INTERVAL '2021-11' YEAR TO MONTH);
11
&gt; SELECT datepart('MINUTE', INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55
</code></pre>
<p><strong>Note:</strong></p>
<p>The datepart function is equivalent to the SQL-standard function <code>EXTRACT(field FROM source)</code></p>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="day"><a class="toclink" href="#day">day</a></h3>
<p>day(date) - Returns the day of month of the date/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT day('2009-07-30');
30
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="dayname"><a class="toclink" href="#dayname">dayname</a></h3>
<p>dayname(date) - Returns the three-letter abbreviated day name from the given date.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT dayname(DATE('2008-02-20'));
Wed
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="dayofmonth"><a class="toclink" href="#dayofmonth">dayofmonth</a></h3>
<p>dayofmonth(date) - Returns the day of month of the date/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT dayofmonth('2009-07-30');
30
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="dayofweek"><a class="toclink" href="#dayofweek">dayofweek</a></h3>
<p>dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT dayofweek('2009-07-30');
5
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="dayofyear"><a class="toclink" href="#dayofyear">dayofyear</a></h3>
<p>dayofyear(date) - Returns the day of year of the date/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT dayofyear('2016-04-09');
100
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="decimal"><a class="toclink" href="#decimal">decimal</a></h3>
<p>decimal(expr) - Casts the value <code>expr</code> to the target data type <code>decimal</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="decode"><a class="toclink" href="#decode">decode</a></h3>
<p>decode(bin, charset) - Decodes the first argument using the second argument character set.</p>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>bin - a binary expression to decode</li>
<li>charset - one of the charsets 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16', 'UTF-32' to decode <code>bin</code> into a STRING. It is case insensitive.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT decode(encode('abc', 'utf-8'), 'utf-8');
abc
&gt; SELECT decode(2, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic');
San Francisco
&gt; SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle', 'Non domestic');
Non domestic
&gt; SELECT decode(6, 1, 'Southlake', 2, 'San Francisco', 3, 'New Jersey', 4, 'Seattle');
NULL
&gt; SELECT decode(null, 6, 'Spark', NULL, 'SQL', 4, 'rocks');
SQL
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="degrees"><a class="toclink" href="#degrees">degrees</a></h3>
<p>degrees(expr) - Converts radians to degrees.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT degrees(3.141592653589793);
180.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="dense_rank"><a class="toclink" href="#dense_rank">dense_rank</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>children - this is to base the rank on; a change in the value of one the children will
trigger a change in rank. This is an internal parameter and will be assigned by the
Analyser.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="div"><a class="toclink" href="#div">div</a></h3>
<p>expr1 div expr2 - Divide <code>expr1</code> by <code>expr2</code>. It returns NULL if an operand is NULL or <code>expr2</code> is 0. The result is casted to long.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 3 div 2;
1
&gt; SELECT INTERVAL '1-1' YEAR TO MONTH div INTERVAL '-1' MONTH;
-13
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="double"><a class="toclink" href="#double">double</a></h3>
<p>double(expr) - Casts the value <code>expr</code> to the target data type <code>double</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="e"><a class="toclink" href="#e">e</a></h3>
<p>e() - Returns Euler's number, e.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT e();
2.718281828459045
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="element_at"><a class="toclink" href="#element_at">element_at</a></h3>
<p>element_at(array, index) - Returns element of array at given (1-based) index. If Index is 0,
Spark will throw an error. If index &lt; 0, accesses elements from the last to the first.
The function returns NULL if the index exceeds the length of the array and
<code>spark.sql.ansi.enabled</code> is set to false.
If <code>spark.sql.ansi.enabled</code> is set to true, it throws ArrayIndexOutOfBoundsException
for invalid indices.</p>
<p>element_at(map, key) - Returns value for given key. The function returns NULL if the key is not
contained in the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT element_at(array(1, 2, 3), 2);
2
&gt; SELECT element_at(map(1, 'a', 2, 'b'), 2);
b
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="elt"><a class="toclink" href="#elt">elt</a></h3>
<p>elt(n, input1, input2, ...) - Returns the <code>n</code>-th input, e.g., returns <code>input2</code> when <code>n</code> is 2.
The function returns NULL if the index exceeds the length of the array
and <code>spark.sql.ansi.enabled</code> is set to false. If <code>spark.sql.ansi.enabled</code> is set to true,
it throws ArrayIndexOutOfBoundsException for invalid indices.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT elt(1, 'scala', 'java');
scala
&gt; SELECT elt(2, 'a', 1);
1
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="encode"><a class="toclink" href="#encode">encode</a></h3>
<p>encode(str, charset) - Encodes the first argument using the second argument character set. If either argument is null, the result will also be null.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>charset - one of the charsets 'US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16BE', 'UTF-16LE', 'UTF-16', 'UTF-32' to encode <code>str</code> into a BINARY. It is case insensitive.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT encode('abc', 'utf-8');
abc
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="endswith"><a class="toclink" href="#endswith">endswith</a></h3>
<p>endswith(left, right) - Returns a boolean. The value is True if left ends with right.
Returns NULL if either input expression is NULL. Otherwise, returns False.
Both left or right must be of STRING or BINARY type.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT endswith('Spark SQL', 'SQL');
true
&gt; SELECT endswith('Spark SQL', 'Spark');
false
&gt; SELECT endswith('Spark SQL', null);
NULL
&gt; SELECT endswith(x'537061726b2053514c', x'537061726b');
false
&gt; SELECT endswith(x'537061726b2053514c', x'53514c');
true
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="equal_null"><a class="toclink" href="#equal_null">equal_null</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2 - the two expressions must be same type or can be casted to a common type,
and must be a type that can be used in equality comparison. Map type is not supported.
For complex types such array/struct, the data types of fields must be orderable.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT equal_null(3, 3);
true
&gt; SELECT equal_null(1, '11');
false
&gt; SELECT equal_null(true, NULL);
false
&gt; SELECT equal_null(NULL, 'abc');
false
&gt; SELECT equal_null(NULL, NULL);
true
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="every"><a class="toclink" href="#every">every</a></h3>
<p>every(expr) - Returns true if all values of <code>expr</code> are true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT every(col) FROM VALUES (true), (true), (true) AS tab(col);
true
&gt; SELECT every(col) FROM VALUES (NULL), (true), (true) AS tab(col);
true
&gt; SELECT every(col) FROM VALUES (true), (false), (true) AS tab(col);
false
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="exists"><a class="toclink" href="#exists">exists</a></h3>
<p>exists(expr, pred) - Tests whether a predicate holds for one or more elements in the array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT exists(array(1, 2, 3), x -&gt; x % 2 == 0);
true
&gt; SELECT exists(array(1, 2, 3), x -&gt; x % 2 == 10);
false
&gt; SELECT exists(array(1, null, 3), x -&gt; x % 2 == 0);
NULL
&gt; SELECT exists(array(0, null, 2, 3, null), x -&gt; x IS NULL);
true
&gt; SELECT exists(array(1, 2, 3), x -&gt; x IS NULL);
false
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="exp"><a class="toclink" href="#exp">exp</a></h3>
<p>exp(expr) - Returns e to the power of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT exp(0);
1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="explode"><a class="toclink" href="#explode">explode</a></h3>
<p>explode(expr) - Separates the elements of array <code>expr</code> into multiple rows, or the elements of map <code>expr</code> into multiple rows and columns. Unless specified otherwise, uses the default column name <code>col</code> for elements of the array or <code>key</code> and <code>value</code> for the elements of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT explode(array(10, 20));
10
20
&gt; SELECT explode(collection =&gt; array(10, 20));
10
20
&gt; SELECT * FROM explode(collection =&gt; array(10, 20));
10
20
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="explode_outer"><a class="toclink" href="#explode_outer">explode_outer</a></h3>
<p>explode_outer(expr) - Separates the elements of array <code>expr</code> into multiple rows, or the elements of map <code>expr</code> into multiple rows and columns. Unless specified otherwise, uses the default column name <code>col</code> for elements of the array or <code>key</code> and <code>value</code> for the elements of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT explode_outer(array(10, 20));
10
20
&gt; SELECT explode_outer(collection =&gt; array(10, 20));
10
20
&gt; SELECT * FROM explode_outer(collection =&gt; array(10, 20));
10
20
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="expm1"><a class="toclink" href="#expm1">expm1</a></h3>
<p>expm1(expr) - Returns exp(<code>expr</code>) - 1.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT expm1(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="extract"><a class="toclink" href="#extract">extract</a></h3>
<p>extract(field FROM source) - Extracts a part of the date/timestamp or interval source.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>field - selects which part of the source should be extracted<ul>
<li>Supported string values of <code>field</code> for dates and timestamps are(case insensitive):<ul>
<li>"YEAR", ("Y", "YEARS", "YR", "YRS") - the year field</li>
<li>"YEAROFWEEK" - the ISO 8601 week-numbering year that the datetime falls in. For example, 2005-01-02 is part of the 53rd week of year 2004, so the result is 2004</li>
<li>"QUARTER", ("QTR") - the quarter (1 - 4) of the year that the datetime falls in</li>
<li>"MONTH", ("MON", "MONS", "MONTHS") - the month field (1 - 12)</li>
<li>"WEEK", ("W", "WEEKS") - the number of the ISO 8601 week-of-week-based-year. A week is considered to start on a Monday and week 1 is the first week with &gt;3 days. In the ISO week-numbering system, it is possible for early-January dates to be part of the 52nd or 53rd week of the previous year, and for late-December dates to be part of the first week of the next year. For example, 2005-01-02 is part of the 53rd week of year 2004, while 2012-12-31 is part of the first week of 2013</li>
<li>"DAY", ("D", "DAYS") - the day of the month field (1 - 31)</li>
<li>"DAYOFWEEK",("DOW") - the day of the week for datetime as Sunday(1) to Saturday(7)</li>
<li>"DAYOFWEEK_ISO",("DOW_ISO") - ISO 8601 based day of the week for datetime as Monday(1) to Sunday(7)</li>
<li>"DOY" - the day of the year (1 - 365/366)</li>
<li>"HOUR", ("H", "HOURS", "HR", "HRS") - The hour field (0 - 23)</li>
<li>"MINUTE", ("M", "MIN", "MINS", "MINUTES") - the minutes field (0 - 59)</li>
<li>"SECOND", ("S", "SEC", "SECONDS", "SECS") - the seconds field, including fractional parts</li>
</ul>
</li>
<li>Supported string values of <code>field</code> for interval(which consists of <code>months</code>, <code>days</code>, <code>microseconds</code>) are(case insensitive):<ul>
<li>"YEAR", ("Y", "YEARS", "YR", "YRS") - the total <code>months</code> / 12</li>
<li>"MONTH", ("MON", "MONS", "MONTHS") - the total <code>months</code> % 12</li>
<li>"DAY", ("D", "DAYS") - the <code>days</code> part of interval</li>
<li>"HOUR", ("H", "HOURS", "HR", "HRS") - how many hours the <code>microseconds</code> contains</li>
<li>"MINUTE", ("M", "MIN", "MINS", "MINUTES") - how many minutes left after taking hours from <code>microseconds</code></li>
<li>"SECOND", ("S", "SEC", "SECONDS", "SECS") - how many second with fractions left after taking hours and minutes from <code>microseconds</code></li>
</ul>
</li>
</ul>
</li>
<li>source - a date/timestamp or interval column from where <code>field</code> should be extracted</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT extract(YEAR FROM TIMESTAMP '2019-08-12 01:00:00.123456');
2019
&gt; SELECT extract(week FROM timestamp'2019-08-12 01:00:00.123456');
33
&gt; SELECT extract(doy FROM DATE'2019-08-12');
224
&gt; SELECT extract(SECONDS FROM timestamp'2019-10-01 00:00:01.000001');
1.000001
&gt; SELECT extract(days FROM interval 5 days 3 hours 7 minutes);
5
&gt; SELECT extract(seconds FROM interval 5 hours 30 seconds 1 milliseconds 1 microseconds);
30.001001
&gt; SELECT extract(MONTH FROM INTERVAL '2021-11' YEAR TO MONTH);
11
&gt; SELECT extract(MINUTE FROM INTERVAL '123 23:55:59.002001' DAY TO SECOND);
55
</code></pre>
<p><strong>Note:</strong></p>
<p>The extract function is equivalent to <code>date_part(field, source)</code>.</p>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="factorial"><a class="toclink" href="#factorial">factorial</a></h3>
<p>factorial(expr) - Returns the factorial of <code>expr</code>. <code>expr</code> is [0..20]. Otherwise, null.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT factorial(5);
120
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="filter"><a class="toclink" href="#filter">filter</a></h3>
<p>filter(expr, func) - Filters the input array using the given predicate.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT filter(array(1, 2, 3), x -&gt; x % 2 == 1);
[1,3]
&gt; SELECT filter(array(0, 2, 3), (x, i) -&gt; x &gt; i);
[2,3]
&gt; SELECT filter(array(0, null, 2, 3, null), x -&gt; x IS NOT NULL);
[0,2,3]
</code></pre>
<p><strong>Note:</strong></p>
<p>The inner function may use the index argument since 3.0.0.</p>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="find_in_set"><a class="toclink" href="#find_in_set">find_in_set</a></h3>
<p>find_in_set(str, str_array) - Returns the index (1-based) of the given string (<code>str</code>) in the comma-delimited list (<code>str_array</code>).
Returns 0, if the string was not found or if the given string (<code>str</code>) contains a comma.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT find_in_set('ab','abc,b,ab,c,def');
3
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="first"><a class="toclink" href="#first">first</a></h3>
<p>first(expr[, isIgnoreNull]) - Returns the first value of <code>expr</code> for a group of rows.
If <code>isIgnoreNull</code> is true, returns only non-null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT first(col) FROM VALUES (10), (5), (20) AS tab(col);
10
&gt; SELECT first(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
&gt; SELECT first(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic because its results depends on the order of the rows
which may be non-deterministic after a shuffle.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="first_value"><a class="toclink" href="#first_value">first_value</a></h3>
<p>first_value(expr[, isIgnoreNull]) - Returns the first value of <code>expr</code> for a group of rows.
If <code>isIgnoreNull</code> is true, returns only non-null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT first_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
&gt; SELECT first_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
&gt; SELECT first_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic because its results depends on the order of the rows
which may be non-deterministic after a shuffle.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="flatten"><a class="toclink" href="#flatten">flatten</a></h3>
<p>flatten(arrayOfArrays) - Transforms an array of arrays into a single array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT flatten(array(array(1, 2), array(3, 4)));
[1,2,3,4]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="float"><a class="toclink" href="#float">float</a></h3>
<p>float(expr) - Casts the value <code>expr</code> to the target data type <code>float</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="floor"><a class="toclink" href="#floor">floor</a></h3>
<p>floor(expr[, scale]) - Returns the largest number after rounding down that is not greater than <code>expr</code>. An optional <code>scale</code> parameter can be specified to control the rounding behavior.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT floor(-0.1);
-1
&gt; SELECT floor(5);
5
&gt; SELECT floor(3.1411, 3);
3.141
&gt; SELECT floor(3.1411, -3);
0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="forall"><a class="toclink" href="#forall">forall</a></h3>
<p>forall(expr, pred) - Tests whether a predicate holds for all elements in the array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT forall(array(1, 2, 3), x -&gt; x % 2 == 0);
false
&gt; SELECT forall(array(2, 4, 8), x -&gt; x % 2 == 0);
true
&gt; SELECT forall(array(1, null, 3), x -&gt; x % 2 == 0);
false
&gt; SELECT forall(array(2, null, 8), x -&gt; x % 2 == 0);
NULL
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="format_number"><a class="toclink" href="#format_number">format_number</a></h3>
<p>format_number(expr1, expr2) - Formats the number <code>expr1</code> like '#,###,###.##', rounded to <code>expr2</code>
decimal places. If <code>expr2</code> is 0, the result has no decimal point or fractional part.
<code>expr2</code> also accept a user specified format.
This is supposed to function like MySQL's FORMAT.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT format_number(12332.123456, 4);
12,332.1235
&gt; SELECT format_number(12332.123456, '##################.###');
12332.123
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="format_string"><a class="toclink" href="#format_string">format_string</a></h3>
<p>format_string(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT format_string(&quot;Hello World %d %s&quot;, 100, &quot;days&quot;);
Hello World 100 days
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="from_csv"><a class="toclink" href="#from_csv">from_csv</a></h3>
<p>from_csv(csvStr, schema[, options]) - Returns a struct value with the given <code>csvStr</code> and <code>schema</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT from_csv('1, 0.8', 'a INT, b DOUBLE');
{&quot;a&quot;:1,&quot;b&quot;:0.8}
&gt; SELECT from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{&quot;time&quot;:2015-08-26 00:00:00}
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="from_json"><a class="toclink" href="#from_json">from_json</a></h3>
<p>from_json(jsonStr, schema[, options]) - Returns a struct value with the given <code>jsonStr</code> and <code>schema</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT from_json('{&quot;a&quot;:1, &quot;b&quot;:0.8}', 'a INT, b DOUBLE');
{&quot;a&quot;:1,&quot;b&quot;:0.8}
&gt; SELECT from_json('{&quot;time&quot;:&quot;26/08/2015&quot;}', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{&quot;time&quot;:2015-08-26 00:00:00}
&gt; SELECT from_json('{&quot;teacher&quot;: &quot;Alice&quot;, &quot;student&quot;: [{&quot;name&quot;: &quot;Bob&quot;, &quot;rank&quot;: 1}, {&quot;name&quot;: &quot;Charlie&quot;, &quot;rank&quot;: 2}]}', 'STRUCT&lt;teacher: STRING, student: ARRAY&lt;STRUCT&lt;name: STRING, rank: INT&gt;&gt;&gt;');
{&quot;teacher&quot;:&quot;Alice&quot;,&quot;student&quot;:[{&quot;name&quot;:&quot;Bob&quot;,&quot;rank&quot;:1},{&quot;name&quot;:&quot;Charlie&quot;,&quot;rank&quot;:2}]}
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="from_unixtime"><a class="toclink" href="#from_unixtime">from_unixtime</a></h3>
<p>from_unixtime(unix_time[, fmt]) - Returns <code>unix_time</code> in the specified <code>fmt</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>unix_time - UNIX Timestamp to be converted to the provided format.</li>
<li>fmt - Date/time format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>
for valid date and time format patterns. The 'yyyy-MM-dd HH:mm:ss' pattern is used if omitted.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT from_unixtime(0, 'yyyy-MM-dd HH:mm:ss');
1969-12-31 16:00:00
&gt; SELECT from_unixtime(0);
1969-12-31 16:00:00
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="from_utc_timestamp"><a class="toclink" href="#from_utc_timestamp">from_utc_timestamp</a></h3>
<p>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'.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT from_utc_timestamp('2016-08-31', 'Asia/Seoul');
2016-08-31 09:00:00
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="from_xml"><a class="toclink" href="#from_xml">from_xml</a></h3>
<p>from_xml(xmlStr, schema[, options]) - Returns a struct value with the given <code>xmlStr</code> and <code>schema</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT from_xml('&lt;p&gt;&lt;a&gt;1&lt;/a&gt;&lt;b&gt;0.8&lt;/b&gt;&lt;/p&gt;', 'a INT, b DOUBLE');
{&quot;a&quot;:1,&quot;b&quot;:0.8}
&gt; SELECT from_xml('&lt;p&gt;&lt;time&gt;26/08/2015&lt;/time&gt;&lt;/p&gt;', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
{&quot;time&quot;:2015-08-26 00:00:00}
&gt; SELECT from_xml('&lt;p&gt;&lt;teacher&gt;Alice&lt;/teacher&gt;&lt;student&gt;&lt;name&gt;Bob&lt;/name&gt;&lt;rank&gt;1&lt;/rank&gt;&lt;/student&gt;&lt;student&gt;&lt;name&gt;Charlie&lt;/name&gt;&lt;rank&gt;2&lt;/rank&gt;&lt;/student&gt;&lt;/p&gt;', 'STRUCT&lt;teacher: STRING, student: ARRAY&lt;STRUCT&lt;name: STRING, rank: INT&gt;&gt;&gt;');
{&quot;teacher&quot;:&quot;Alice&quot;,&quot;student&quot;:[{&quot;name&quot;:&quot;Bob&quot;,&quot;rank&quot;:1},{&quot;name&quot;:&quot;Charlie&quot;,&quot;rank&quot;:2}]}
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="get"><a class="toclink" href="#get">get</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT get(array(1, 2, 3), 0);
1
&gt; SELECT get(array(1, 2, 3), 3);
NULL
&gt; SELECT get(array(1, 2, 3), -1);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="get_json_object"><a class="toclink" href="#get_json_object">get_json_object</a></h3>
<p>get_json_object(json_txt, path) - Extracts a json object from <code>path</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT get_json_object('{&quot;a&quot;:&quot;b&quot;}', '$.a');
b
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="getbit"><a class="toclink" href="#getbit">getbit</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT getbit(11, 0);
1
&gt; SELECT getbit(11, 2);
0
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="greatest"><a class="toclink" href="#greatest">greatest</a></h3>
<p>greatest(expr, ...) - Returns the greatest value of all parameters, skipping null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT greatest(10, 9, 2, 4, 3);
10
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="grouping"><a class="toclink" href="#grouping">grouping</a></h3>
<p>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.",</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="grouping_id"><a class="toclink" href="#grouping_id">grouping_id</a></h3>
<p>grouping_id([col1[, col2 ..]]) - returns the level of grouping, equals to
<code>(grouping(c1) &lt;&lt; (n-1)) + (grouping(c2) &lt;&lt; (n-2)) + ... + grouping(cn)</code></p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Note:</strong></p>
<p>Input columns should match with grouping columns exactly, or empty (means all the grouping
columns).</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="hash"><a class="toclink" href="#hash">hash</a></h3>
<p>hash(expr1, expr2, ...) - Returns a hash value of the arguments.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hash('Spark', array(123), 2);
-1321691492
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="hex"><a class="toclink" href="#hex">hex</a></h3>
<p>hex(expr) - Converts <code>expr</code> to hexadecimal.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hex(17);
11
&gt; SELECT hex('Spark SQL');
537061726B2053514C
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="histogram_numeric"><a class="toclink" href="#histogram_numeric">histogram_numeric</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT histogram_numeric(col, 5) FROM VALUES (0), (1), (2), (10) AS tab(col);
[{&quot;x&quot;:0,&quot;y&quot;:1.0},{&quot;x&quot;:1,&quot;y&quot;:1.0},{&quot;x&quot;:2,&quot;y&quot;:1.0},{&quot;x&quot;:10,&quot;y&quot;:1.0}]
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="hll_sketch_agg"><a class="toclink" href="#hll_sketch_agg">hll_sketch_agg</a></h3>
<p>hll_sketch_agg(expr, lgConfigK) - Returns the HllSketch's updatable binary representation.
<code>lgConfigK</code> (optional) the log-base-2 of K, with K is the number of buckets or
slots for the HllSketch.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hll_sketch_estimate(hll_sketch_agg(col, 12)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="hll_sketch_estimate"><a class="toclink" href="#hll_sketch_estimate">hll_sketch_estimate</a></h3>
<p>hll_sketch_estimate(expr) - Returns the estimated number of unique values given the binary representation
of a Datasketches HllSketch.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hll_sketch_estimate(hll_sketch_agg(col)) FROM VALUES (1), (1), (2), (2), (3) tab(col);
3
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="hll_union"><a class="toclink" href="#hll_union">hll_union</a></h3>
<p>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).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="hll_union_agg"><a class="toclink" href="#hll_union_agg">hll_union_agg</a></h3>
<p>hll_union_agg(expr, allowDifferentLgConfigK) - Returns the estimated number of unique values.
<code>allowDifferentLgConfigK</code> (optional) Allow sketches with different lgConfigK values
to be unioned (defaults to false).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="hour"><a class="toclink" href="#hour">hour</a></h3>
<p>hour(timestamp) - Returns the hour component of the string/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hour('2009-07-30 12:58:59');
12
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="hypot"><a class="toclink" href="#hypot">hypot</a></h3>
<p>hypot(expr1, expr2) - Returns sqrt(<code>expr1</code><strong>2 + <code>expr2</code></strong>2).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT hypot(3, 4);
5.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="if"><a class="toclink" href="#if">if</a></h3>
<p>if(expr1, expr2, expr3) - If <code>expr1</code> evaluates to true, then returns <code>expr2</code>; otherwise returns <code>expr3</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT if(1 &lt; 2, 'a', 'b');
a
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="ifnull"><a class="toclink" href="#ifnull">ifnull</a></h3>
<p>ifnull(expr1, expr2) - Returns <code>expr2</code> if <code>expr1</code> is null, or <code>expr1</code> otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ifnull(NULL, array('2'));
[&quot;2&quot;]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="ilike"><a class="toclink" href="#ilike">ilike</a></h3>
<p>str ilike pattern[ ESCAPE escape] - Returns true if str matches <code>pattern</code> with <code>escape</code> case-insensitively, null if any arguments are null, false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>pattern - a string expression. The pattern is a string which is matched literally and
case-insensitively, with exception to the following special symbols:<br><br>
_ matches any one character in the input (similar to . in posix regular expressions)<br><br>
% matches zero or more characters in the input (similar to .* in posix regular
expressions)<br><br>
Since Spark 2.0, string literals are unescaped in our SQL parser, see the unescaping
rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, in order to match "\abc", the pattern should be "\abc".<br><br>
When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, it falls back
to Spark 1.6 behavior regarding string literal parsing. For example, if the config is
enabled, the pattern to match "\abc" should be "\abc".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
<li>escape - an character added since Spark 3.0. The default escape character is the '\'.
If an escape character precedes a special symbol or another escape character, the
following character is matched literally. It is invalid to escape any other character.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ilike('Spark', '_Park');
true
&gt; SELECT '\\abc' AS S, S ilike r'\\abc', S ilike '\\\\abc';
\abc true true
&gt; SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals true
&gt; SELECT '%SystemDrive%\Users\John' ilike '\%SystemDrive\%\\users%';
true
&gt; SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals false
&gt; SELECT '%SystemDrive%\\USERS\\John' ilike r'%SystemDrive%\\Users%';
true
&gt; SELECT '%SystemDrive%/Users/John' ilike '/%SYSTEMDrive/%//Users%' ESCAPE '/';
true
</code></pre>
<p><strong>Note:</strong></p>
<p>Use RLIKE to match with standard regular expressions.</p>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="in"><a class="toclink" href="#in">in</a></h3>
<p>expr1 in(expr2, expr3, ...) - Returns true if <code>expr</code> equals to any valN.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr2, expr3, ... - the arguments must be same type.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 1 in(1, 2, 3);
true
&gt; SELECT 1 in(2, 3, 4);
false
&gt; SELECT named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 1), named_struct('a', 1, 'b', 3));
false
&gt; SELECT named_struct('a', 1, 'b', 2) in(named_struct('a', 1, 'b', 2), named_struct('a', 1, 'b', 3));
true
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="initcap"><a class="toclink" href="#initcap">initcap</a></h3>
<p>initcap(str) - Returns <code>str</code> with the first letter of each word in uppercase.
All other letters are in lowercase. Words are delimited by white space.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT initcap('sPark sql');
Spark Sql
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="inline"><a class="toclink" href="#inline">inline</a></h3>
<p>inline(expr) - Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT inline(array(struct(1, 'a'), struct(2, 'b')));
1 a
2 b
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="inline_outer"><a class="toclink" href="#inline_outer">inline_outer</a></h3>
<p>inline_outer(expr) - Explodes an array of structs into a table. Uses column names col1, col2, etc. by default unless specified otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT inline_outer(array(struct(1, 'a'), struct(2, 'b')));
1 a
2 b
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="input_file_block_length"><a class="toclink" href="#input_file_block_length">input_file_block_length</a></h3>
<p>input_file_block_length() - Returns the length of the block being read, or -1 if not available.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT input_file_block_length();
-1
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="input_file_block_start"><a class="toclink" href="#input_file_block_start">input_file_block_start</a></h3>
<p>input_file_block_start() - Returns the start offset of the block being read, or -1 if not available.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT input_file_block_start();
-1
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="input_file_name"><a class="toclink" href="#input_file_name">input_file_name</a></h3>
<p>input_file_name() - Returns the name of the file being read, or empty string if not available.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT input_file_name();
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="instr"><a class="toclink" href="#instr">instr</a></h3>
<p>instr(str, substr) - Returns the (1-based) index of the first occurrence of <code>substr</code> in <code>str</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT instr('SparkSQL', 'SQL');
6
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="int"><a class="toclink" href="#int">int</a></h3>
<p>int(expr) - Casts the value <code>expr</code> to the target data type <code>int</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="is_variant_null"><a class="toclink" href="#is_variant_null">is_variant_null</a></h3>
<p>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).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT is_variant_null(parse_json('null'));
true
&gt; SELECT is_variant_null(parse_json('&quot;null&quot;'));
false
&gt; SELECT is_variant_null(parse_json('13'));
false
&gt; SELECT is_variant_null(parse_json(null));
false
&gt; SELECT is_variant_null(variant_get(parse_json('{&quot;a&quot;:null, &quot;b&quot;:&quot;spark&quot;}'), &quot;$.c&quot;));
false
&gt; SELECT is_variant_null(variant_get(parse_json('{&quot;a&quot;:null, &quot;b&quot;:&quot;spark&quot;}'), &quot;$.a&quot;));
true
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="isnan"><a class="toclink" href="#isnan">isnan</a></h3>
<p>isnan(expr) - Returns true if <code>expr</code> is NaN, or false otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT isnan(cast('NaN' as double));
true
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="isnotnull"><a class="toclink" href="#isnotnull">isnotnull</a></h3>
<p>isnotnull(expr) - Returns true if <code>expr</code> is not null, or false otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT isnotnull(1);
true
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="isnull"><a class="toclink" href="#isnull">isnull</a></h3>
<p>isnull(expr) - Returns true if <code>expr</code> is null, or false otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT isnull(1);
false
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="java_method"><a class="toclink" href="#java_method">java_method</a></h3>
<p>java_method(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT java_method('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
&gt; SELECT java_method('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="json_array_length"><a class="toclink" href="#json_array_length">json_array_length</a></h3>
<p>json_array_length(jsonArray) - Returns the number of elements in the outermost JSON array.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>jsonArray - A JSON array. <code>NULL</code> is returned in case of any other valid JSON string,
<code>NULL</code> or an invalid JSON.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT json_array_length('[1,2,3,4]');
4
&gt; SELECT json_array_length('[1,2,3,{&quot;f1&quot;:1,&quot;f2&quot;:[5,6]},4]');
5
&gt; SELECT json_array_length('[1,2');
NULL
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="json_object_keys"><a class="toclink" href="#json_object_keys">json_object_keys</a></h3>
<p>json_object_keys(json_object) - Returns all the keys of the outermost JSON object as an array.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>json_object - A JSON object. If a valid JSON object is given, all the keys of the outermost
object will be returned as an array. If it is any other valid JSON string, an invalid JSON
string or an empty string, the function returns null.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT json_object_keys('{}');
[]
&gt; SELECT json_object_keys('{&quot;key&quot;: &quot;value&quot;}');
[&quot;key&quot;]
&gt; SELECT json_object_keys('{&quot;f1&quot;:&quot;abc&quot;,&quot;f2&quot;:{&quot;f3&quot;:&quot;a&quot;, &quot;f4&quot;:&quot;b&quot;}}');
[&quot;f1&quot;,&quot;f2&quot;]
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="json_tuple"><a class="toclink" href="#json_tuple">json_tuple</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT json_tuple('{&quot;a&quot;:1, &quot;b&quot;:2}', 'a', 'b');
1 2
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="kurtosis"><a class="toclink" href="#kurtosis">kurtosis</a></h3>
<p>kurtosis(expr) - Returns the kurtosis value calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT kurtosis(col) FROM VALUES (-10), (-20), (100), (1000) AS tab(col);
-0.7014368047529627
&gt; SELECT kurtosis(col) FROM VALUES (1), (10), (100), (10), (1) as tab(col);
0.19432323191699075
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="lag"><a class="toclink" href="#lag">lag</a></h3>
<p>lag(input[, offset[, default]]) - Returns the value of <code>input</code> at the <code>offset</code>th row
before the current row in the window. The default value of <code>offset</code> is 1 and the default
value of <code>default</code> is null. If the value of <code>input</code> at the <code>offset</code>th row is null,
null is returned. If there is no such offset row (e.g., when the offset is 1, the first
row of the window does not have any previous row), <code>default</code> is returned.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>input - a string expression to evaluate <code>offset</code> rows before the current row.</li>
<li>offset - an int expression which is rows to jump back in the partition.</li>
<li>default - a string expression which is to use when the offset row does not exist.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT a, b, lag(b) OVER (PARTITION BY a ORDER BY b) FROM VALUES ('A1', 2), ('A1', 1), ('A2', 3), ('A1', 1) tab(a, b);
A1 1 NULL
A1 1 1
A1 2 1
A2 3 NULL
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="last"><a class="toclink" href="#last">last</a></h3>
<p>last(expr[, isIgnoreNull]) - Returns the last value of <code>expr</code> for a group of rows.
If <code>isIgnoreNull</code> is true, returns only non-null values</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT last(col) FROM VALUES (10), (5), (20) AS tab(col);
20
&gt; SELECT last(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
&gt; SELECT last(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic because its results depends on the order of the rows
which may be non-deterministic after a shuffle.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="last_day"><a class="toclink" href="#last_day">last_day</a></h3>
<p>last_day(date) - Returns the last day of the month which the date belongs to.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT last_day('2009-01-12');
2009-01-31
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="last_value"><a class="toclink" href="#last_value">last_value</a></h3>
<p>last_value(expr[, isIgnoreNull]) - Returns the last value of <code>expr</code> for a group of rows.
If <code>isIgnoreNull</code> is true, returns only non-null values</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT last_value(col) FROM VALUES (10), (5), (20) AS tab(col);
20
&gt; SELECT last_value(col) FROM VALUES (10), (5), (NULL) AS tab(col);
NULL
&gt; SELECT last_value(col, true) FROM VALUES (10), (5), (NULL) AS tab(col);
5
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic because its results depends on the order of the rows
which may be non-deterministic after a shuffle.</p>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="lcase"><a class="toclink" href="#lcase">lcase</a></h3>
<p>lcase(str) - Returns <code>str</code> with all characters changed to lowercase.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT lcase('SparkSql');
sparksql
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="lead"><a class="toclink" href="#lead">lead</a></h3>
<p>lead(input[, offset[, default]]) - Returns the value of <code>input</code> at the <code>offset</code>th row
after the current row in the window. The default value of <code>offset</code> is 1 and the default
value of <code>default</code> is null. If the value of <code>input</code> at the <code>offset</code>th row is null,
null is returned. If there is no such an offset row (e.g., when the offset is 1, the last
row of the window does not have any subsequent row), <code>default</code> is returned.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>input - a string expression to evaluate <code>offset</code> rows after the current row.</li>
<li>offset - an int expression which is rows to jump ahead in the partition.</li>
<li>default - a string expression which is to use when the offset is larger than the window.
The default value is null.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT a, b, lead(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 2
A1 2 NULL
A2 3 NULL
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="least"><a class="toclink" href="#least">least</a></h3>
<p>least(expr, ...) - Returns the least value of all parameters, skipping null values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT least(10, 9, 2, 4, 3);
2
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="left"><a class="toclink" href="#left">left</a></h3>
<p>left(str, len) - Returns the leftmost <code>len</code>(<code>len</code> can be string type) characters from the string <code>str</code>,if <code>len</code> is less or equal than 0 the result is an empty string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT left('Spark SQL', 3);
Spa
&gt; SELECT left(encode('Spark SQL', 'utf-8'), 3);
Spa
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="len"><a class="toclink" href="#len">len</a></h3>
<p>len(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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT len('Spark SQL ');
10
&gt; SELECT len(x'537061726b2053514c');
9
&gt; SELECT CHAR_LENGTH('Spark SQL ');
10
&gt; SELECT CHARACTER_LENGTH('Spark SQL ');
10
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="length"><a class="toclink" href="#length">length</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT length('Spark SQL ');
10
&gt; SELECT length(x'537061726b2053514c');
9
&gt; SELECT CHAR_LENGTH('Spark SQL ');
10
&gt; SELECT CHARACTER_LENGTH('Spark SQL ');
10
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="levenshtein"><a class="toclink" href="#levenshtein">levenshtein</a></h3>
<p>levenshtein(str1, str2[, threshold]) - Returns the Levenshtein distance between the two given strings. If threshold is set and distance more than it, return -1.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT levenshtein('kitten', 'sitting');
3
&gt; SELECT levenshtein('kitten', 'sitting', 2);
-1
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="like"><a class="toclink" href="#like">like</a></h3>
<p>str like pattern[ ESCAPE escape] - Returns true if str matches <code>pattern</code> with <code>escape</code>, null if any arguments are null, false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>pattern - a string expression. The pattern is a string which is matched literally, with
exception to the following special symbols:<br><br>
_ matches any one character in the input (similar to . in posix regular expressions)\
% matches zero or more characters in the input (similar to .* in posix regular
expressions)<br><br>
Since Spark 2.0, string literals are unescaped in our SQL parser, see the unescaping
rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, in order to match "\abc", the pattern should be "\abc".<br><br>
When SQL config 'spark.sql.parser.escapedStringLiterals' is enabled, it falls back
to Spark 1.6 behavior regarding string literal parsing. For example, if the config is
enabled, the pattern to match "\abc" should be "\abc".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
<li>escape - an character added since Spark 3.0. The default escape character is the '\'.
If an escape character precedes a special symbol or another escape character, the
following character is matched literally. It is invalid to escape any other character.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT like('Spark', '_park');
true
&gt; SELECT '\\abc' AS S, S like r'\\abc', S like '\\\\abc';
\abc true true
&gt; SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals true
&gt; SELECT '%SystemDrive%\Users\John' like '\%SystemDrive\%\\Users%';
true
&gt; SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals false
&gt; SELECT '%SystemDrive%\\Users\\John' like r'%SystemDrive%\\Users%';
true
&gt; SELECT '%SystemDrive%/Users/John' like '/%SystemDrive/%//Users%' ESCAPE '/';
true
</code></pre>
<p><strong>Note:</strong></p>
<p>Use RLIKE to match with standard regular expressions.</p>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="ln"><a class="toclink" href="#ln">ln</a></h3>
<p>ln(expr) - Returns the natural logarithm (base e) of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ln(1);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="localtimestamp"><a class="toclink" href="#localtimestamp">localtimestamp</a></h3>
<p>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.</p>
<p>localtimestamp - Returns the current local date-time at the session time zone at the start of query evaluation.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT localtimestamp();
2020-04-25 15:49:11.914
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="locate"><a class="toclink" href="#locate">locate</a></h3>
<p>locate(substr, str[, pos]) - Returns the position of the first occurrence of <code>substr</code> in <code>str</code> after position <code>pos</code>.
The given <code>pos</code> and return value are 1-based.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT locate('bar', 'foobarbar');
4
&gt; SELECT locate('bar', 'foobarbar', 5);
7
&gt; SELECT POSITION('bar' IN 'foobarbar');
4
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="log"><a class="toclink" href="#log">log</a></h3>
<p>log(base, expr) - Returns the logarithm of <code>expr</code> with <code>base</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT log(10, 100);
2.0
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="log10"><a class="toclink" href="#log10">log10</a></h3>
<p>log10(expr) - Returns the logarithm of <code>expr</code> with base 10.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT log10(10);
1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="log1p"><a class="toclink" href="#log1p">log1p</a></h3>
<p>log1p(expr) - Returns log(1 + <code>expr</code>).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT log1p(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="log2"><a class="toclink" href="#log2">log2</a></h3>
<p>log2(expr) - Returns the logarithm of <code>expr</code> with base 2.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT log2(2);
1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="lower"><a class="toclink" href="#lower">lower</a></h3>
<p>lower(str) - Returns <code>str</code> with all characters changed to lowercase.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT lower('SparkSql');
sparksql
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="lpad"><a class="toclink" href="#lpad">lpad</a></h3>
<p>lpad(str, len[, pad]) - Returns <code>str</code>, left-padded with <code>pad</code> to a length of <code>len</code>.
If <code>str</code> is longer than <code>len</code>, the return value is shortened to <code>len</code> characters or bytes.
If <code>pad</code> is not specified, <code>str</code> will be padded to the left with space characters if it is
a character string, and with zeros if it is a byte sequence.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT lpad('hi', 5, '??');
???hi
&gt; SELECT lpad('hi', 1, '??');
h
&gt; SELECT lpad('hi', 5);
hi
&gt; SELECT hex(lpad(unhex('aabb'), 5));
000000AABB
&gt; SELECT hex(lpad(unhex('aabb'), 5, unhex('1122')));
112211AABB
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="ltrim"><a class="toclink" href="#ltrim">ltrim</a></h3>
<p>ltrim(str) - Removes the leading space characters from <code>str</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>trimStr - the trim string characters to trim, the default value is a single space</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ltrim(' SparkSQL ');
SparkSQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="luhn_check"><a class="toclink" href="#luhn_check">luhn_check</a></h3>
<p>luhn_check(str ) - Checks that a string of digits is valid according to the Luhn algorithm.
This checksum function is widely applied on credit card numbers and government identification
numbers to distinguish valid numbers from mistyped, incorrect numbers.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT luhn_check('8112189876');
true
&gt; SELECT luhn_check('79927398713');
true
&gt; SELECT luhn_check('79927398714');
false
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="make_date"><a class="toclink" href="#make_date">make_date</a></h3>
<p>make_date(year, month, day) - Create date from year, month and day fields. If the configuration <code>spark.sql.ansi.enabled</code> is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>year - the year to represent, from 1 to 9999</li>
<li>month - the month-of-year to represent, from 1 (January) to 12 (December)</li>
<li>day - the day-of-month to represent, from 1 to 31</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_date(2013, 7, 15);
2013-07-15
&gt; SELECT make_date(2019, 7, NULL);
NULL
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="make_dt_interval"><a class="toclink" href="#make_dt_interval">make_dt_interval</a></h3>
<p>make_dt_interval([days[, hours[, mins[, secs]]]]) - Make DayTimeIntervalType duration from days, hours, mins and secs.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>days - the number of days, positive or negative</li>
<li>hours - the number of hours, positive or negative</li>
<li>mins - the number of minutes, positive or negative</li>
<li>secs - the number of seconds with the fractional part in microsecond precision.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_dt_interval(1, 12, 30, 01.001001);
1 12:30:01.001001000
&gt; SELECT make_dt_interval(2);
2 00:00:00.000000000
&gt; SELECT make_dt_interval(100, null, 3);
NULL
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="make_interval"><a class="toclink" href="#make_interval">make_interval</a></h3>
<p>make_interval([years[, months[, weeks[, days[, hours[, mins[, secs]]]]]]]) - Make interval from years, months, weeks, days, hours, mins and secs.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>years - the number of years, positive or negative</li>
<li>months - the number of months, positive or negative</li>
<li>weeks - the number of weeks, positive or negative</li>
<li>days - the number of days, positive or negative</li>
<li>hours - the number of hours, positive or negative</li>
<li>mins - the number of minutes, positive or negative</li>
<li>secs - the number of seconds with the fractional part in microsecond precision.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_interval(100, 11, 1, 1, 12, 30, 01.001001);
100 years 11 months 8 days 12 hours 30 minutes 1.001001 seconds
&gt; SELECT make_interval(100, null, 3);
NULL
&gt; SELECT make_interval(0, 1, 0, 1, 0, 0, 100.000001);
1 months 1 days 1 minutes 40.000001 seconds
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="make_timestamp"><a class="toclink" href="#make_timestamp">make_timestamp</a></h3>
<p>make_timestamp(year, month, day, hour, min, sec[, timezone]) - Create timestamp from year, month, day, hour, min, sec and timezone fields. The result data type is consistent with the value of configuration <code>spark.sql.timestampType</code>. If the configuration <code>spark.sql.ansi.enabled</code> is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>year - the year to represent, from 1 to 9999</li>
<li>month - the month-of-year to represent, from 1 (January) to 12 (December)</li>
<li>day - the day-of-month to represent, from 1 to 31</li>
<li>hour - the hour-of-day to represent, from 0 to 23</li>
<li>min - the minute-of-hour to represent, from 0 to 59</li>
<li>sec - the second-of-minute and its micro-fraction to represent, from 0 to 60.
The value can be either an integer like 13 , or a fraction like 13.123.
If the sec argument equals to 60, the seconds field is set
to 0 and 1 minute is added to the final timestamp.</li>
<li>timezone - the time zone identifier. For example, CET, UTC and etc.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
&gt; SELECT make_timestamp(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
&gt; SELECT make_timestamp(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
&gt; SELECT make_timestamp(2019, 6, 30, 23, 59, 1);
2019-06-30 23:59:01
&gt; SELECT make_timestamp(null, 7, 22, 15, 30, 0);
NULL
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="make_timestamp_ltz"><a class="toclink" href="#make_timestamp_ltz">make_timestamp_ltz</a></h3>
<p>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 timezone fields. If the configuration <code>spark.sql.ansi.enabled</code> is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>year - the year to represent, from 1 to 9999</li>
<li>month - the month-of-year to represent, from 1 (January) to 12 (December)</li>
<li>day - the day-of-month to represent, from 1 to 31</li>
<li>hour - the hour-of-day to represent, from 0 to 23</li>
<li>min - the minute-of-hour to represent, from 0 to 59</li>
<li>sec - the second-of-minute and its micro-fraction to represent, from
0 to 60. If the sec argument equals to 60, the seconds field is set
to 0 and 1 minute is added to the final timestamp.</li>
<li>timezone - the time zone identifier. For example, CET, UTC and etc.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
&gt; SELECT make_timestamp_ltz(2014, 12, 28, 6, 30, 45.887, 'CET');
2014-12-27 21:30:45.887
&gt; SELECT make_timestamp_ltz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
&gt; SELECT make_timestamp_ltz(null, 7, 22, 15, 30, 0);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="make_timestamp_ntz"><a class="toclink" href="#make_timestamp_ntz">make_timestamp_ntz</a></h3>
<p>make_timestamp_ntz(year, month, day, hour, min, sec) - Create local date-time from year, month, day, hour, min, sec fields. If the configuration <code>spark.sql.ansi.enabled</code> is false, the function returns NULL on invalid inputs. Otherwise, it will throw an error instead.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>year - the year to represent, from 1 to 9999</li>
<li>month - the month-of-year to represent, from 1 (January) to 12 (December)</li>
<li>day - the day-of-month to represent, from 1 to 31</li>
<li>hour - the hour-of-day to represent, from 0 to 23</li>
<li>min - the minute-of-hour to represent, from 0 to 59</li>
<li>sec - the second-of-minute and its micro-fraction to represent, from
0 to 60. If the sec argument equals to 60, the seconds field is set
to 0 and 1 minute is added to the final timestamp.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_timestamp_ntz(2014, 12, 28, 6, 30, 45.887);
2014-12-28 06:30:45.887
&gt; SELECT make_timestamp_ntz(2019, 6, 30, 23, 59, 60);
2019-07-01 00:00:00
&gt; SELECT make_timestamp_ntz(null, 7, 22, 15, 30, 0);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="make_ym_interval"><a class="toclink" href="#make_ym_interval">make_ym_interval</a></h3>
<p>make_ym_interval([years[, months]]) - Make year-month interval from years, months.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>years - the number of years, positive or negative</li>
<li>months - the number of months, positive or negative</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT make_ym_interval(1, 2);
1-2
&gt; SELECT make_ym_interval(1, 0);
1-0
&gt; SELECT make_ym_interval(-1, 1);
-0-11
&gt; SELECT make_ym_interval(2);
2-0
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="map"><a class="toclink" href="#map">map</a></h3>
<p>map(key0, value0, key1, value1, ...) - Creates a map with the given key/value pairs.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map(1.0, '2', 3.0, '4');
{1.0:&quot;2&quot;,3.0:&quot;4&quot;}
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="map_concat"><a class="toclink" href="#map_concat">map_concat</a></h3>
<p>map_concat(map, ...) - Returns the union of all the given maps</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_concat(map(1, 'a', 2, 'b'), map(3, 'c'));
{1:&quot;a&quot;,2:&quot;b&quot;,3:&quot;c&quot;}
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="map_contains_key"><a class="toclink" href="#map_contains_key">map_contains_key</a></h3>
<p>map_contains_key(map, key) - Returns true if the map contains the key.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_contains_key(map(1, 'a', 2, 'b'), 1);
true
&gt; SELECT map_contains_key(map(1, 'a', 2, 'b'), 3);
false
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="map_entries"><a class="toclink" href="#map_entries">map_entries</a></h3>
<p>map_entries(map) - Returns an unordered array of all entries in the given map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_entries(map(1, 'a', 2, 'b'));
[{&quot;key&quot;:1,&quot;value&quot;:&quot;a&quot;},{&quot;key&quot;:2,&quot;value&quot;:&quot;b&quot;}]
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="map_filter"><a class="toclink" href="#map_filter">map_filter</a></h3>
<p>map_filter(expr, func) - Filters entries in a map using the function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_filter(map(1, 0, 2, 2, 3, -1), (k, v) -&gt; k &gt; v);
{1:0,3:-1}
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="map_from_arrays"><a class="toclink" href="#map_from_arrays">map_from_arrays</a></h3>
<p>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</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_from_arrays(array(1.0, 3.0), array('2', '4'));
{1.0:&quot;2&quot;,3.0:&quot;4&quot;}
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="map_from_entries"><a class="toclink" href="#map_from_entries">map_from_entries</a></h3>
<p>map_from_entries(arrayOfEntries) - Returns a map created from the given array of entries.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_from_entries(array(struct(1, 'a'), struct(2, 'b')));
{1:&quot;a&quot;,2:&quot;b&quot;}
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="map_keys"><a class="toclink" href="#map_keys">map_keys</a></h3>
<p>map_keys(map) - Returns an unordered array containing the keys of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_keys(map(1, 'a', 2, 'b'));
[1,2]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="map_values"><a class="toclink" href="#map_values">map_values</a></h3>
<p>map_values(map) - Returns an unordered array containing the values of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_values(map(1, 'a', 2, 'b'));
[&quot;a&quot;,&quot;b&quot;]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="map_zip_with"><a class="toclink" href="#map_zip_with">map_zip_with</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT map_zip_with(map(1, 'a', 2, 'b'), map(1, 'x', 2, 'y'), (k, v1, v2) -&gt; concat(v1, v2));
{1:&quot;ax&quot;,2:&quot;by&quot;}
&gt; SELECT map_zip_with(map('a', 1, 'b', 2), map('b', 3, 'c', 4), (k, v1, v2) -&gt; coalesce(v1, 0) + coalesce(v2, 0));
{&quot;a&quot;:1,&quot;b&quot;:5,&quot;c&quot;:4}
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="mask"><a class="toclink" href="#mask">mask</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>input - string value to mask. Supported types: STRING, VARCHAR, CHAR</li>
<li>upperChar - character to replace upper-case characters with. Specify NULL to retain original character. Default value: 'X'</li>
<li>lowerChar - character to replace lower-case characters with. Specify NULL to retain original character. Default value: 'x'</li>
<li>digitChar - character to replace digit characters with. Specify NULL to retain original character. Default value: 'n'</li>
<li>otherChar - character to replace all other characters with. Specify NULL to retain original character. Default value: NULL</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT mask('abcd-EFGH-8765-4321');
xxxx-XXXX-nnnn-nnnn
&gt; SELECT mask('abcd-EFGH-8765-4321', 'Q');
xxxx-QQQQ-nnnn-nnnn
&gt; SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
&gt; SELECT mask('AbCD123-@$#');
XxXXnnn-@$#
&gt; SELECT mask('AbCD123-@$#', 'Q');
QxQQnnn-@$#
&gt; SELECT mask('AbCD123-@$#', 'Q', 'q');
QqQQnnn-@$#
&gt; SELECT mask('AbCD123-@$#', 'Q', 'q', 'd');
QqQQddd-@$#
&gt; SELECT mask('AbCD123-@$#', 'Q', 'q', 'd', 'o');
QqQQdddoooo
&gt; SELECT mask('AbCD123-@$#', NULL, 'q', 'd', 'o');
AqCDdddoooo
&gt; SELECT mask('AbCD123-@$#', NULL, NULL, 'd', 'o');
AbCDdddoooo
&gt; SELECT mask('AbCD123-@$#', NULL, NULL, NULL, 'o');
AbCD123oooo
&gt; SELECT mask(NULL, NULL, NULL, NULL, 'o');
NULL
&gt; SELECT mask(NULL);
NULL
&gt; SELECT mask('AbCD123-@$#', NULL, NULL, NULL, NULL);
AbCD123-@$#
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="max"><a class="toclink" href="#max">max</a></h3>
<p>max(expr) - Returns the maximum value of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT max(col) FROM VALUES (10), (50), (20) AS tab(col);
50
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="max_by"><a class="toclink" href="#max_by">max_by</a></h3>
<p>max_by(x, y) - Returns the value of <code>x</code> associated with the maximum value of <code>y</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT max_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
b
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="md5"><a class="toclink" href="#md5">md5</a></h3>
<p>md5(expr) - Returns an MD5 128-bit checksum as a hex string of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT md5('Spark');
8cde774d6f7333752ed72cacddb05126
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="mean"><a class="toclink" href="#mean">mean</a></h3>
<p>mean(expr) - Returns the mean calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT mean(col) FROM VALUES (1), (2), (3) AS tab(col);
2.0
&gt; SELECT mean(col) FROM VALUES (1), (2), (NULL) AS tab(col);
1.5
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="median"><a class="toclink" href="#median">median</a></h3>
<p>median(col) - Returns the median of numeric or ANSI interval column <code>col</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT median(col) FROM VALUES (0), (10) AS tab(col);
5.0
&gt; SELECT median(col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-5
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="min"><a class="toclink" href="#min">min</a></h3>
<p>min(expr) - Returns the minimum value of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT min(col) FROM VALUES (10), (-1), (20) AS tab(col);
-1
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="min_by"><a class="toclink" href="#min_by">min_by</a></h3>
<p>min_by(x, y) - Returns the value of <code>x</code> associated with the minimum value of <code>y</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT min_by(x, y) FROM VALUES ('a', 10), ('b', 50), ('c', 20) AS tab(x, y);
a
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="minute"><a class="toclink" href="#minute">minute</a></h3>
<p>minute(timestamp) - Returns the minute component of the string/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT minute('2009-07-30 12:58:59');
58
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="mod"><a class="toclink" href="#mod">mod</a></h3>
<p>expr1 mod expr2 - Returns the remainder after <code>expr1</code>/<code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 2 % 1.8;
0.2
&gt; SELECT MOD(2, 1.8);
0.2
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="mode"><a class="toclink" href="#mode">mode</a></h3>
<p>mode(col[, deterministic]) - Returns the most frequent value for the values within <code>col</code>. 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 <code>deterministic</code> is false or is not defined, or the lowest value is returned if <code>deterministic</code> is true.
mode() WITHIN GROUP (ORDER BY col) - Returns the most frequent value for the values within <code>col</code> (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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT mode(col) FROM VALUES (0), (10), (10) AS tab(col);
10
&gt; SELECT mode(col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-10
&gt; SELECT mode(col) FROM VALUES (0), (10), (10), (null), (null), (null) AS tab(col);
10
&gt; SELECT mode(col, false) FROM VALUES (-10), (0), (10) AS tab(col);
0
&gt; SELECT mode(col, true) FROM VALUES (-10), (0), (10) AS tab(col);
-10
&gt; SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10) AS tab(col);
10
&gt; SELECT mode() WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
10
&gt; SELECT mode() WITHIN GROUP (ORDER BY col DESC) FROM VALUES (0), (10), (10), (20), (20) AS tab(col);
20
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="monotonically_increasing_id"><a class="toclink" href="#monotonically_increasing_id">monotonically_increasing_id</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT monotonically_increasing_id();
0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="month"><a class="toclink" href="#month">month</a></h3>
<p>month(date) - Returns the month component of the date/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT month('2016-07-30');
7
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="monthname"><a class="toclink" href="#monthname">monthname</a></h3>
<p>monthname(date) - Returns the three-letter abbreviated month name from the given date.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT monthname('2008-02-20');
Feb
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="months_between"><a class="toclink" href="#months_between">months_between</a></h3>
<p>months_between(timestamp1, timestamp2[, roundOff]) - If <code>timestamp1</code> is later than <code>timestamp2</code>, then the result
is positive. If <code>timestamp1</code> and <code>timestamp2</code> 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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT months_between('1997-02-28 10:30:00', '1996-10-30');
3.94959677
&gt; SELECT months_between('1997-02-28 10:30:00', '1996-10-30', false);
3.9495967741935485
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="named_struct"><a class="toclink" href="#named_struct">named_struct</a></h3>
<p>named_struct(name1, val1, name2, val2, ...) - Creates a struct with the given field names and values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT named_struct(&quot;a&quot;, 1, &quot;b&quot;, 2, &quot;c&quot;, 3);
{&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3}
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="nanvl"><a class="toclink" href="#nanvl">nanvl</a></h3>
<p>nanvl(expr1, expr2) - Returns <code>expr1</code> if it's not NaN, or <code>expr2</code> otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT nanvl(cast('NaN' as double), 123);
123.0
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="negative"><a class="toclink" href="#negative">negative</a></h3>
<p>negative(expr) - Returns the negated value of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT negative(1);
-1
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="next_day"><a class="toclink" href="#next_day">next_day</a></h3>
<p>next_day(start_date, day_of_week) - Returns the first date which is later than <code>start_date</code> 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 <code>spark.sql.ansi.enabled</code> is set to true, otherwise NULL.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT next_day('2015-01-14', 'TU');
2015-01-20
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="not"><a class="toclink" href="#not">not</a></h3>
<p>not expr - Logical not.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT not true;
false
&gt; SELECT not false;
true
&gt; SELECT not NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="now"><a class="toclink" href="#now">now</a></h3>
<p>now() - Returns the current timestamp at the start of query evaluation.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT now();
2020-04-25 15:49:11.914
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="nth_value"><a class="toclink" href="#nth_value">nth_value</a></h3>
<p>nth_value(input[, offset]) - Returns the value of <code>input</code> at the row that is the <code>offset</code>th row
from beginning of the window frame. Offset starts at 1. If ignoreNulls=true, we will skip
nulls when finding the <code>offset</code>th row. Otherwise, every row counts for the <code>offset</code>. If
there is no such an <code>offset</code>th row (e.g., when the offset is 10, size of the window frame
is less than 10), null is returned.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>input - the target column or expression that the function operates on.</li>
<li>offset - a positive int literal to indicate the offset in the window frame. It starts
with 1.</li>
<li>ignoreNulls - an optional specification that indicates the NthValue should skip null
values in the determination of which row to use.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="ntile"><a class="toclink" href="#ntile">ntile</a></h3>
<p>ntile(n) - Divides the rows for each window partition into <code>n</code> buckets ranging
from 1 to at most <code>n</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>buckets - an int expression which is number of buckets to divide the rows in.
Default value is 1.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="nullif"><a class="toclink" href="#nullif">nullif</a></h3>
<p>nullif(expr1, expr2) - Returns null if <code>expr1</code> equals to <code>expr2</code>, or <code>expr1</code> otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT nullif(2, 2);
NULL
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="nvl"><a class="toclink" href="#nvl">nvl</a></h3>
<p>nvl(expr1, expr2) - Returns <code>expr2</code> if <code>expr1</code> is null, or <code>expr1</code> otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT nvl(NULL, array('2'));
[&quot;2&quot;]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="nvl2"><a class="toclink" href="#nvl2">nvl2</a></h3>
<p>nvl2(expr1, expr2, expr3) - Returns <code>expr2</code> if <code>expr1</code> is not null, or <code>expr3</code> otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT nvl2(NULL, 2, 1);
1
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="octet_length"><a class="toclink" href="#octet_length">octet_length</a></h3>
<p>octet_length(expr) - Returns the byte length of string data or number of bytes of binary data.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT octet_length('Spark SQL');
9
&gt; SELECT octet_length(x'537061726b2053514c');
9
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="or"><a class="toclink" href="#or">or</a></h3>
<p>expr1 or expr2 - Logical OR.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT true or false;
true
&gt; SELECT false or false;
false
&gt; SELECT true or NULL;
true
&gt; SELECT false or NULL;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="overlay"><a class="toclink" href="#overlay">overlay</a></h3>
<p>overlay(input, replace, pos[, len]) - Replace <code>input</code> with <code>replace</code> that starts at <code>pos</code> and is of length <code>len</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT overlay('Spark SQL' PLACING '_' FROM 6);
Spark_SQL
&gt; SELECT overlay('Spark SQL' PLACING 'CORE' FROM 7);
Spark CORE
&gt; SELECT overlay('Spark SQL' PLACING 'ANSI ' FROM 7 FOR 0);
Spark ANSI SQL
&gt; SELECT overlay('Spark SQL' PLACING 'tructured' FROM 2 FOR 4);
Structured SQL
&gt; SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('_', 'utf-8') FROM 6);
Spark_SQL
&gt; SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('CORE', 'utf-8') FROM 7);
Spark CORE
&gt; SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('ANSI ', 'utf-8') FROM 7 FOR 0);
Spark ANSI SQL
&gt; SELECT overlay(encode('Spark SQL', 'utf-8') PLACING encode('tructured', 'utf-8') FROM 2 FOR 4);
Structured SQL
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="parse_json"><a class="toclink" href="#parse_json">parse_json</a></h3>
<p>parse_json(jsonStr) - Parse a JSON string as a Variant value. Throw an exception when the string is not valid JSON value.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT parse_json('{&quot;a&quot;:1,&quot;b&quot;:0.8}');
{&quot;a&quot;:1,&quot;b&quot;:0.8}
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="parse_url"><a class="toclink" href="#parse_url">parse_url</a></h3>
<p>parse_url(url, partToExtract[, key]) - Extracts a part from a URL.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST');
spark.apache.org
&gt; SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY');
query=1
&gt; SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
1
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="percent_rank"><a class="toclink" href="#percent_rank">percent_rank</a></h3>
<p>percent_rank() - Computes the percentage ranking of a value in a group of values.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>children - this is to base the rank on; a change in the value of one the children will
trigger a change in rank. This is an internal parameter and will be assigned by the
Analyser.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="percentile"><a class="toclink" href="#percentile">percentile</a></h3>
<p>percentile(col, percentage [, frequency]) - Returns the exact percentile value of numeric
or ANSI interval column <code>col</code> at the given percentage. The value of percentage must be
between 0.0 and 1.0. The value of frequency should be positive integral</p>
<p>percentile(col, array(percentage1 [, percentage2]...) [, frequency]) - Returns the exact
percentile value array of numeric column <code>col</code> 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</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT percentile(col, 0.3) FROM VALUES (0), (10) AS tab(col);
3.0
&gt; SELECT percentile(col, array(0.25, 0.75)) FROM VALUES (0), (10) AS tab(col);
[2.5,7.5]
&gt; SELECT percentile(col, 0.5) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-5
&gt; 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]
</code></pre>
<p><strong>Since:</strong> 2.1.0</p>
<p><br/></p>
<h3 id="percentile_approx"><a class="toclink" href="#percentile_approx">percentile_approx</a></h3>
<p>percentile_approx(col, percentage [, accuracy]) - Returns the approximate <code>percentile</code> of the numeric or
ansi interval column <code>col</code> which is the smallest value in the ordered <code>col</code> values (sorted
from least to greatest) such that no more than <code>percentage</code> of <code>col</code> values is less than
the value or equal to that value. The value of percentage must be between 0.0 and 1.0.
The <code>accuracy</code> parameter (default: 10000) is a positive numeric literal which controls
approximation accuracy at the cost of memory. Higher value of <code>accuracy</code> yields better
accuracy, <code>1.0/accuracy</code> is the relative error of the approximation.
When <code>percentage</code> 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 <code>col</code> at the given
percentage array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT percentile_approx(col, array(0.5, 0.4, 0.1), 100) FROM VALUES (0), (1), (2), (10) AS tab(col);
[1,1,0]
&gt; SELECT percentile_approx(col, 0.5, 100) FROM VALUES (0), (6), (7), (9), (10) AS tab(col);
7
&gt; 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
&gt; 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]
</code></pre>
<p><strong>Since:</strong> 2.1.0</p>
<p><br/></p>
<h3 id="percentile_cont"><a class="toclink" href="#percentile_cont">percentile_cont</a></h3>
<p>percentile_cont(percentage) WITHIN GROUP (ORDER BY col) - Return a percentile value based on a continuous distribution of numeric or ANSI interval column <code>col</code> at the given <code>percentage</code> (specified in ORDER BY clause).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT percentile_cont(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10) AS tab(col);
2.5
&gt; SELECT percentile_cont(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-2
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="percentile_disc"><a class="toclink" href="#percentile_disc">percentile_disc</a></h3>
<p>percentile_disc(percentage) WITHIN GROUP (ORDER BY col) - Return a percentile value based on a discrete distribution of numeric or ANSI interval column <code>col</code> at the given <code>percentage</code> (specified in ORDER BY clause).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT percentile_disc(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (0), (10) AS tab(col);
0.0
&gt; SELECT percentile_disc(0.25) WITHIN GROUP (ORDER BY col) FROM VALUES (INTERVAL '0' MONTH), (INTERVAL '10' MONTH) AS tab(col);
0-0
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="pi"><a class="toclink" href="#pi">pi</a></h3>
<p>pi() - Returns pi.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT pi();
3.141592653589793
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="pmod"><a class="toclink" href="#pmod">pmod</a></h3>
<p>pmod(expr1, expr2) - Returns the positive value of <code>expr1</code> mod <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT pmod(10, 3);
1
&gt; SELECT pmod(-10, 3);
2
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="posexplode"><a class="toclink" href="#posexplode">posexplode</a></h3>
<p>posexplode(expr) - Separates the elements of array <code>expr</code> into multiple rows with positions, or the elements of map <code>expr</code> into multiple rows and columns with positions. Unless specified otherwise, uses the column name <code>pos</code> for position, <code>col</code> for elements of the array or <code>key</code> and <code>value</code> for elements of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT posexplode(array(10,20));
0 10
1 20
&gt; SELECT * FROM posexplode(array(10,20));
0 10
1 20
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="posexplode_outer"><a class="toclink" href="#posexplode_outer">posexplode_outer</a></h3>
<p>posexplode_outer(expr) - Separates the elements of array <code>expr</code> into multiple rows with positions, or the elements of map <code>expr</code> into multiple rows and columns with positions. Unless specified otherwise, uses the column name <code>pos</code> for position, <code>col</code> for elements of the array or <code>key</code> and <code>value</code> for elements of the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT posexplode_outer(array(10,20));
0 10
1 20
&gt; SELECT * FROM posexplode_outer(array(10,20));
0 10
1 20
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="position"><a class="toclink" href="#position">position</a></h3>
<p>position(substr, str[, pos]) - Returns the position of the first occurrence of <code>substr</code> in <code>str</code> after position <code>pos</code>.
The given <code>pos</code> and return value are 1-based.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT position('bar', 'foobarbar');
4
&gt; SELECT position('bar', 'foobarbar', 5);
7
&gt; SELECT POSITION('bar' IN 'foobarbar');
4
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="positive"><a class="toclink" href="#positive">positive</a></h3>
<p>positive(expr) - Returns the value of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT positive(1);
1
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="pow"><a class="toclink" href="#pow">pow</a></h3>
<p>pow(expr1, expr2) - Raises <code>expr1</code> to the power of <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT pow(2, 3);
8.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="power"><a class="toclink" href="#power">power</a></h3>
<p>power(expr1, expr2) - Raises <code>expr1</code> to the power of <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT power(2, 3);
8.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="printf"><a class="toclink" href="#printf">printf</a></h3>
<p>printf(strfmt, obj, ...) - Returns a formatted string from printf-style format strings.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT printf(&quot;Hello World %d %s&quot;, 100, &quot;days&quot;);
Hello World 100 days
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="quarter"><a class="toclink" href="#quarter">quarter</a></h3>
<p>quarter(date) - Returns the quarter of the year for date, in the range 1 to 4.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT quarter('2016-08-31');
3
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="radians"><a class="toclink" href="#radians">radians</a></h3>
<p>radians(expr) - Converts degrees to radians.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in degrees</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT radians(180);
3.141592653589793
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="raise_error"><a class="toclink" href="#raise_error">raise_error</a></h3>
<p>raise_error( expr ) - Throws a USER_RAISED_EXCEPTION with <code>expr</code> as message.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT raise_error('custom error message');
[USER_RAISED_EXCEPTION] custom error message
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="rand"><a class="toclink" href="#rand">rand</a></h3>
<p>rand([seed]) - Returns a random value with independent and identically distributed (i.i.d.) uniformly distributed values in [0, 1).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT rand();
0.9629742951434543
&gt; SELECT rand(0);
0.7604953758285915
&gt; SELECT rand(null);
0.7604953758285915
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic in general case.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="randn"><a class="toclink" href="#randn">randn</a></h3>
<p>randn([seed]) - Returns a random value with independent and identically distributed (i.i.d.) values drawn from the standard normal distribution.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT randn();
-0.3254147983080288
&gt; SELECT randn(0);
1.6034991609278433
&gt; SELECT randn(null);
1.6034991609278433
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic in general case.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="random"><a class="toclink" href="#random">random</a></h3>
<p>random([seed]) - Returns a random value with independent and identically distributed (i.i.d.) uniformly distributed values in [0, 1).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT random();
0.9629742951434543
&gt; SELECT random(0);
0.7604953758285915
&gt; SELECT random(null);
0.7604953758285915
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic in general case.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="rank"><a class="toclink" href="#rank">rank</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>children - this is to base the rank on; a change in the value of one the children will
trigger a change in rank. This is an internal parameter and will be assigned by the
Analyser.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="reduce"><a class="toclink" href="#reduce">reduce</a></h3>
<p>reduce(expr, start, merge, finish) - Applies a binary operator to an initial state and all
elements in the array, and reduces this to a single state. The final state is converted
into the final result by applying a finish function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT reduce(array(1, 2, 3), 0, (acc, x) -&gt; acc + x);
6
&gt; SELECT reduce(array(1, 2, 3), 0, (acc, x) -&gt; acc + x, acc -&gt; acc * 10);
60
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="reflect"><a class="toclink" href="#reflect">reflect</a></h3>
<p>reflect(class, method[, arg1[, arg2 ..]]) - Calls a method with reflection.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT reflect('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
&gt; SELECT reflect('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="regexp"><a class="toclink" href="#regexp">regexp</a></h3>
<p>regexp(str, regexp) - Returns true if <code>str</code> matches <code>regexp</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>
<p>regexp - a string expression. The regex string should be a Java regular expression.</p>
<p>Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".</p>
<p>There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</p>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals true
&gt; SELECT regexp('%SystemDrive%\Users\John', '%SystemDrive%\\Users.*');
true
&gt; SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals false
&gt; SELECT regexp('%SystemDrive%\\Users\\John', '%SystemDrive%\\\\Users.*');
true
&gt; SELECT regexp('%SystemDrive%\\Users\\John', r'%SystemDrive%\\Users.*');
true
</code></pre>
<p><strong>Note:</strong></p>
<p>Use LIKE to match with simple string pattern.</p>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="regexp_count"><a class="toclink" href="#regexp_count">regexp_count</a></h3>
<p>regexp_count(str, regexp) - Returns a count of the number of times that the regular expression pattern <code>regexp</code> is matched in the string <code>str</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression.</li>
<li>regexp - a string representing a regular expression. The regex string should be a
Java regular expression.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_count('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
2
&gt; SELECT regexp_count('abcdefghijklmnopqrstuvwxyz', '[a-z]{3}');
8
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regexp_extract"><a class="toclink" href="#regexp_extract">regexp_extract</a></h3>
<p>regexp_extract(str, regexp[, idx]) - Extract the first string in the <code>str</code> that match the <code>regexp</code>
expression and corresponding to the regex group index.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression.</li>
<li>regexp - a string representing a regular expression. The regex string should be a
Java regular expression.<br><br>
Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".<br><br>
There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
<li>idx - an integer expression that representing the group index. The regex maybe contains
multiple groups. <code>idx</code> indicates which regex group to extract. The group index should
be non-negative. The minimum value of <code>idx</code> is 0, which means matching the entire
regular expression. If <code>idx</code> is not specified, the default group index value is 1. The
<code>idx</code> parameter is the Java regex Matcher group() method index.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_extract('100-200', '(\\d+)-(\\d+)', 1);
100
&gt; SELECT regexp_extract('100-200', r'(\d+)-(\d+)', 1);
100
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="regexp_extract_all"><a class="toclink" href="#regexp_extract_all">regexp_extract_all</a></h3>
<p>regexp_extract_all(str, regexp[, idx]) - Extract all strings in the <code>str</code> that match the <code>regexp</code>
expression and corresponding to the regex group index.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression.</li>
<li>regexp - a string representing a regular expression. The regex string should be a
Java regular expression.<br><br>
Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".<br><br>
There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
<li>idx - an integer expression that representing the group index. The regex may contains
multiple groups. <code>idx</code> indicates which regex group to extract. The group index should
be non-negative. The minimum value of <code>idx</code> is 0, which means matching the entire
regular expression. If <code>idx</code> is not specified, the default group index value is 1. The
<code>idx</code> parameter is the Java regex Matcher group() method index.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_extract_all('100-200, 300-400', '(\\d+)-(\\d+)', 1);
[&quot;100&quot;,&quot;300&quot;]
&gt; SELECT regexp_extract_all('100-200, 300-400', r'(\d+)-(\d+)', 1);
[&quot;100&quot;,&quot;300&quot;]
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="regexp_instr"><a class="toclink" href="#regexp_instr">regexp_instr</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression.</li>
<li>regexp - a string representing a regular expression. The regex string should be a
Java regular expression.<br><br>
Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".<br><br>
There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_instr(r&quot;\abc&quot;, r&quot;^\\abc$&quot;);
1
&gt; SELECT regexp_instr('user@spark.apache.org', '@[^.]*');
5
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regexp_like"><a class="toclink" href="#regexp_like">regexp_like</a></h3>
<p>regexp_like(str, regexp) - Returns true if <code>str</code> matches <code>regexp</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>
<p>regexp - a string expression. The regex string should be a Java regular expression.</p>
<p>Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".</p>
<p>There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</p>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals true
&gt; SELECT regexp_like('%SystemDrive%\Users\John', '%SystemDrive%\\Users.*');
true
&gt; SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals false
&gt; SELECT regexp_like('%SystemDrive%\\Users\\John', '%SystemDrive%\\\\Users.*');
true
&gt; SELECT regexp_like('%SystemDrive%\\Users\\John', r'%SystemDrive%\\Users.*');
true
</code></pre>
<p><strong>Note:</strong></p>
<p>Use LIKE to match with simple string pattern.</p>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="regexp_replace"><a class="toclink" href="#regexp_replace">regexp_replace</a></h3>
<p>regexp_replace(str, regexp, rep[, position]) - Replaces all substrings of <code>str</code> that match <code>regexp</code> with <code>rep</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression to search for a regular expression pattern match.</li>
<li>regexp - a string representing a regular expression. The regex string should be a
Java regular expression.<br><br>
Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".<br><br>
There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</li>
<li>rep - a string expression to replace matched substrings.</li>
<li>position - a positive integer literal that indicates the position within <code>str</code> to begin searching.
The default is 1. If position is greater than the number of characters in <code>str</code>, the result is <code>str</code>.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_replace('100-200', '(\\d+)', 'num');
num-num
&gt; SELECT regexp_replace('100-200', r'(\d+)', 'num');
num-num
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="regexp_substr"><a class="toclink" href="#regexp_substr">regexp_substr</a></h3>
<p>regexp_substr(str, regexp) - Returns the substring that matches the regular expression <code>regexp</code> within the string <code>str</code>. If the regular expression is not found, the result is null.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression.</li>
<li>regexp - a string representing a regular expression. The regex string should be a Java regular expression.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Ste(v|ph)en');
Steven
&gt; SELECT regexp_substr('Steven Jones and Stephen Smith are the best players', 'Jeck');
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regr_avgx"><a class="toclink" href="#regr_avgx">regr_avgx</a></h3>
<p>regr_avgx(y, x) - Returns the average of the independent variable for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
2.75
&gt; SELECT regr_avgx(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
&gt; SELECT regr_avgx(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
&gt; SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
3.0
&gt; SELECT regr_avgx(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
3.0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="regr_avgy"><a class="toclink" href="#regr_avgy">regr_avgy</a></h3>
<p>regr_avgy(y, x) - Returns the average of the dependent variable for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
1.75
&gt; SELECT regr_avgy(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
&gt; SELECT regr_avgy(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
&gt; SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
1.6666666666666667
&gt; SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.5
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="regr_count"><a class="toclink" href="#regr_count">regr_count</a></h3>
<p>regr_count(y, x) - Returns the number of non-null number pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_count(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
4
&gt; SELECT regr_count(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
3
&gt; SELECT regr_count(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
2
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="regr_intercept"><a class="toclink" href="#regr_intercept">regr_intercept</a></h3>
<p>regr_intercept(y, x) - Returns the intercept of the univariate linear regression line for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_intercept(y, x) FROM VALUES (1,1), (2,2), (3,3) AS tab(y, x);
0.0
&gt; SELECT regr_intercept(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
&gt; SELECT regr_intercept(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regr_r2"><a class="toclink" href="#regr_r2">regr_r2</a></h3>
<p>regr_r2(y, x) - Returns the coefficient of determination for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.2727272727272727
&gt; SELECT regr_r2(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
&gt; SELECT regr_r2(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
&gt; SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
0.7500000000000001
&gt; SELECT regr_r2(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="regr_slope"><a class="toclink" href="#regr_slope">regr_slope</a></h3>
<p>regr_slope(y, x) - Returns the slope of the linear regression line for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_slope(y, x) FROM VALUES (1,1), (2,2), (3,3) AS tab(y, x);
1.0
&gt; SELECT regr_slope(y, x) FROM VALUES (1, null) AS tab(y, x);
NULL
&gt; SELECT regr_slope(y, x) FROM VALUES (null, 1) AS tab(y, x);
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regr_sxx"><a class="toclink" href="#regr_sxx">regr_sxx</a></h3>
<p>regr_sxx(y, x) - Returns REGR_COUNT(y, x) * VAR_POP(x) for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
2.75
&gt; SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
2.0
&gt; SELECT regr_sxx(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
2.0
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regr_sxy"><a class="toclink" href="#regr_sxy">regr_sxy</a></h3>
<p>regr_sxy(y, x) - Returns REGR_COUNT(y, x) * COVAR_POP(y, x) for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.75
&gt; SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
1.0
&gt; SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
1.0
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="regr_syy"><a class="toclink" href="#regr_syy">regr_syy</a></h3>
<p>regr_syy(y, x) - Returns REGR_COUNT(y, x) * VAR_POP(y) for non-null pairs in a group, where <code>y</code> is the dependent variable and <code>x</code> is the independent variable.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS tab(y, x);
0.75
&gt; SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, null), (2, 3), (2, 4) AS tab(y, x);
0.6666666666666666
&gt; SELECT regr_syy(y, x) FROM VALUES (1, 2), (2, null), (null, 3), (2, 4) AS tab(y, x);
0.5
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="repeat"><a class="toclink" href="#repeat">repeat</a></h3>
<p>repeat(str, n) - Returns the string which repeats the given string value n times.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT repeat('123', 2);
123123
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="replace"><a class="toclink" href="#replace">replace</a></h3>
<p>replace(str, search[, replace]) - Replaces all occurrences of <code>search</code> with <code>replace</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>search - a string expression. If <code>search</code> is not found in <code>str</code>, <code>str</code> is returned unchanged.</li>
<li>replace - a string expression. If <code>replace</code> is not specified or is an empty string, nothing replaces
the string that is removed from <code>str</code>.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT replace('ABCabc', 'abc', 'DEF');
ABCDEF
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="reverse"><a class="toclink" href="#reverse">reverse</a></h3>
<p>reverse(array) - Returns a reversed string or an array with reverse order of elements.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT reverse('Spark SQL');
LQS krapS
&gt; SELECT reverse(array(2, 1, 4, 3));
[3,4,1,2]
</code></pre>
<p><strong>Note:</strong></p>
<p>Reverse logic for arrays is available since 2.4.0.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="right"><a class="toclink" href="#right">right</a></h3>
<p>right(str, len) - Returns the rightmost <code>len</code>(<code>len</code> can be string type) characters from the string <code>str</code>,if <code>len</code> is less or equal than 0 the result is an empty string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT right('Spark SQL', 3);
SQL
</code></pre>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="rint"><a class="toclink" href="#rint">rint</a></h3>
<p>rint(expr) - Returns the double value that is closest in value to the argument and is equal to a mathematical integer.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT rint(12.3456);
12.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="rlike"><a class="toclink" href="#rlike">rlike</a></h3>
<p>rlike(str, regexp) - Returns true if <code>str</code> matches <code>regexp</code>, or false otherwise.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>
<p>regexp - a string expression. The regex string should be a Java regular expression.</p>
<p>Since Spark 2.0, string literals (including regex patterns) are unescaped in our SQL
parser, see the unescaping rules at <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal">String Literal</a>.
For example, to match "\abc", a regular expression for <code>regexp</code> can be "^\abc$".</p>
<p>There is a SQL config 'spark.sql.parser.escapedStringLiterals' that can be used to
fallback to the Spark 1.6 behavior regarding string literal parsing. For example,
if the config is enabled, the <code>regexp</code> that can match "\abc" is "^\abc$".<br><br>
It's recommended to use a raw string literal (with the <code>r</code> prefix) to avoid escaping
special characters in the pattern string if exists.</p>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SET spark.sql.parser.escapedStringLiterals=true;
spark.sql.parser.escapedStringLiterals true
&gt; SELECT rlike('%SystemDrive%\Users\John', '%SystemDrive%\\Users.*');
true
&gt; SET spark.sql.parser.escapedStringLiterals=false;
spark.sql.parser.escapedStringLiterals false
&gt; SELECT rlike('%SystemDrive%\\Users\\John', '%SystemDrive%\\\\Users.*');
true
&gt; SELECT rlike('%SystemDrive%\\Users\\John', r'%SystemDrive%\\Users.*');
true
</code></pre>
<p><strong>Note:</strong></p>
<p>Use LIKE to match with simple string pattern.</p>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="round"><a class="toclink" href="#round">round</a></h3>
<p>round(expr, d) - Returns <code>expr</code> rounded to <code>d</code> decimal places using HALF_UP rounding mode.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT round(2.5, 0);
3
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="row_number"><a class="toclink" href="#row_number">row_number</a></h3>
<p>row_number() - Assigns a unique, sequential number to each row, starting with one,
according to the ordering of rows within the window partition.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="rpad"><a class="toclink" href="#rpad">rpad</a></h3>
<p>rpad(str, len[, pad]) - Returns <code>str</code>, right-padded with <code>pad</code> to a length of <code>len</code>.
If <code>str</code> is longer than <code>len</code>, the return value is shortened to <code>len</code> characters.
If <code>pad</code> is not specified, <code>str</code> will be padded to the right with space characters if it is
a character string, and with zeros if it is a binary string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT rpad('hi', 5, '??');
hi???
&gt; SELECT rpad('hi', 1, '??');
h
&gt; SELECT rpad('hi', 5);
hi
&gt; SELECT hex(rpad(unhex('aabb'), 5));
AABB000000
&gt; SELECT hex(rpad(unhex('aabb'), 5, unhex('1122')));
AABB112211
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="rtrim"><a class="toclink" href="#rtrim">rtrim</a></h3>
<p>rtrim(str) - Removes the trailing space characters from <code>str</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>trimStr - the trim string characters to trim, the default value is a single space</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT rtrim(' SparkSQL ');
SparkSQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="schema_of_csv"><a class="toclink" href="#schema_of_csv">schema_of_csv</a></h3>
<p>schema_of_csv(csv[, options]) - Returns schema in the DDL format of CSV string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT schema_of_csv('1,abc');
STRUCT&lt;_c0: INT, _c1: STRING&gt;
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="schema_of_json"><a class="toclink" href="#schema_of_json">schema_of_json</a></h3>
<p>schema_of_json(json[, options]) - Returns schema in the DDL format of JSON string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT schema_of_json('[{&quot;col&quot;:0}]');
ARRAY&lt;STRUCT&lt;col: BIGINT&gt;&gt;
&gt; SELECT schema_of_json('[{&quot;col&quot;:01}]', map('allowNumericLeadingZeros', 'true'));
ARRAY&lt;STRUCT&lt;col: BIGINT&gt;&gt;
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="schema_of_variant"><a class="toclink" href="#schema_of_variant">schema_of_variant</a></h3>
<p>schema_of_variant(v) - Returns schema in the SQL format of a variant.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT schema_of_variant(parse_json('null'));
VOID
&gt; SELECT schema_of_variant(parse_json('[{&quot;b&quot;:true,&quot;a&quot;:0}]'));
ARRAY&lt;STRUCT&lt;a: BIGINT, b: BOOLEAN&gt;&gt;
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="schema_of_variant_agg"><a class="toclink" href="#schema_of_variant_agg">schema_of_variant_agg</a></h3>
<p>schema_of_variant_agg(v) - Returns the merged schema in the SQL format of a variant column.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT schema_of_variant_agg(parse_json(j)) FROM VALUES ('1'), ('2'), ('3') AS tab(j);
BIGINT
&gt; SELECT schema_of_variant_agg(parse_json(j)) FROM VALUES ('{&quot;a&quot;: 1}'), ('{&quot;b&quot;: true}'), ('{&quot;c&quot;: 1.23}') AS tab(j);
STRUCT&lt;a: BIGINT, b: BOOLEAN, c: DECIMAL(3,2)&gt;
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="schema_of_xml"><a class="toclink" href="#schema_of_xml">schema_of_xml</a></h3>
<p>schema_of_xml(xml[, options]) - Returns schema in the DDL format of XML string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT schema_of_xml('&lt;p&gt;&lt;a&gt;1&lt;/a&gt;&lt;/p&gt;');
STRUCT&lt;a: BIGINT&gt;
&gt; SELECT schema_of_xml('&lt;p&gt;&lt;a attr=&quot;2&quot;&gt;1&lt;/a&gt;&lt;a&gt;3&lt;/a&gt;&lt;/p&gt;', map('excludeAttribute', 'true'));
STRUCT&lt;a: ARRAY&lt;BIGINT&gt;&gt;
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="sec"><a class="toclink" href="#sec">sec</a></h3>
<p>sec(expr) - Returns the secant of <code>expr</code>, as if computed by <code>1/java.lang.Math.cos</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sec(0);
1.0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="second"><a class="toclink" href="#second">second</a></h3>
<p>second(timestamp) - Returns the second component of the string/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT second('2009-07-30 12:58:59');
59
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="sentences"><a class="toclink" href="#sentences">sentences</a></h3>
<p>sentences(str[, lang, country]) - Splits <code>str</code> into an array of array of words.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sentences('Hi there! Good morning.');
[[&quot;Hi&quot;,&quot;there&quot;],[&quot;Good&quot;,&quot;morning&quot;]]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="sequence"><a class="toclink" href="#sequence">sequence</a></h3>
<p>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.</p>
<p>Supported types are: byte, short, integer, long, date, timestamp.</p>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>start - an expression. The start of the range.</li>
<li>stop - an expression. The end the range (inclusive).</li>
<li>step - an optional expression. The step of the range.
By default step is 1 if start is less than or equal to stop, otherwise -1.
For the temporal sequences it's 1 day and -1 day respectively.
If start is greater than stop then the step must be negative, and vice versa.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sequence(1, 5);
[1,2,3,4,5]
&gt; SELECT sequence(5, 1);
[5,4,3,2,1]
&gt; SELECT sequence(to_date('2018-01-01'), to_date('2018-03-01'), interval 1 month);
[2018-01-01,2018-02-01,2018-03-01]
&gt; 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]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="session_user"><a class="toclink" href="#session_user">session_user</a></h3>
<p>session_user() - user name of current execution context.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT session_user();
mockingjay
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="session_window"><a class="toclink" href="#session_window">session_window</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>time_column - The column or the expression to use as the timestamp for windowing by time. The time column must be of TimestampType.</li>
<li>gap_duration - A string specifying the timeout of the session represented as "interval value"
(See <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#interval-literal">Interval Literal</a> for more details.) for the fixed gap duration, or
an expression which is applied for each input and evaluated to the "interval value" for the dynamic gap duration.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
&gt; 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
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="sha"><a class="toclink" href="#sha">sha</a></h3>
<p>sha(expr) - Returns a sha1 hash value as a hex string of the <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sha('Spark');
85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="sha1"><a class="toclink" href="#sha1">sha1</a></h3>
<p>sha1(expr) - Returns a sha1 hash value as a hex string of the <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sha1('Spark');
85f5955f4b27a9a4c2aab6ffe5d7189fc298b92c
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="sha2"><a class="toclink" href="#sha2">sha2</a></h3>
<p>sha2(expr, bitLength) - Returns a checksum of SHA-2 family as a hex string of <code>expr</code>.
SHA-224, SHA-256, SHA-384, and SHA-512 are supported. Bit length of 0 is equivalent to 256.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sha2('Spark', 256);
529bc3b07127ecb7e53a4dcf1991d9152c24537d919178022b2c42657f79a26b
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="shiftleft"><a class="toclink" href="#shiftleft">shiftleft</a></h3>
<p>base &lt;&lt; exp - Bitwise left shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftleft(2, 1);
4
&gt; SELECT 2 &lt;&lt; 1;
4
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&lt;&lt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftleft</code>.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="shiftright"><a class="toclink" href="#shiftright">shiftright</a></h3>
<p>base &gt;&gt; expr - Bitwise (signed) right shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftright(4, 1);
2
&gt; SELECT 4 &gt;&gt; 1;
2
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&gt;&gt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftright</code>.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="shiftrightunsigned"><a class="toclink" href="#shiftrightunsigned">shiftrightunsigned</a></h3>
<p>base &gt;&gt;&gt; expr - Bitwise unsigned right shift.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shiftrightunsigned(4, 1);
2
&gt; SELECT 4 &gt;&gt;&gt; 1;
2
</code></pre>
<p><strong>Note:</strong></p>
<p><code>&gt;&gt;&gt;</code> operator is added in Spark 4.0.0 as an alias for <code>shiftrightunsigned</code>.</p>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="shuffle"><a class="toclink" href="#shuffle">shuffle</a></h3>
<p>shuffle(array) - Returns a random permutation of the given array.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT shuffle(array(1, 20, 3, 5));
[3,1,5,20]
&gt; SELECT shuffle(array(1, 20, null, 3));
[20,null,3,1]
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic.</p>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="sign"><a class="toclink" href="#sign">sign</a></h3>
<p>sign(expr) - Returns -1.0, 0.0 or 1.0 as <code>expr</code> is negative, 0 or positive.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sign(40);
1.0
&gt; SELECT sign(INTERVAL -'100' YEAR);
-1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="signum"><a class="toclink" href="#signum">signum</a></h3>
<p>signum(expr) - Returns -1.0, 0.0 or 1.0 as <code>expr</code> is negative, 0 or positive.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT signum(40);
1.0
&gt; SELECT signum(INTERVAL -'100' YEAR);
-1.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="sin"><a class="toclink" href="#sin">sin</a></h3>
<p>sin(expr) - Returns the sine of <code>expr</code>, as if computed by <code>java.lang.Math.sin</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sin(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="sinh"><a class="toclink" href="#sinh">sinh</a></h3>
<p>sinh(expr) - Returns hyperbolic sine of <code>expr</code>, as if computed by <code>java.lang.Math.sinh</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - hyperbolic angle</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sinh(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="size"><a class="toclink" href="#size">size</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT size(array('b', 'd', 'c', 'a'));
4
&gt; SELECT size(map('a', 1, 'b', 2));
2
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="skewness"><a class="toclink" href="#skewness">skewness</a></h3>
<p>skewness(expr) - Returns the skewness value calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT skewness(col) FROM VALUES (-10), (-20), (100), (1000) AS tab(col);
1.1135657469022011
&gt; SELECT skewness(col) FROM VALUES (-1000), (-100), (10), (20) AS tab(col);
-1.1135657469022011
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="slice"><a class="toclink" href="#slice">slice</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT slice(array(1, 2, 3, 4), 2, 2);
[2,3]
&gt; SELECT slice(array(1, 2, 3, 4), -2, 2);
[3,4]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="smallint"><a class="toclink" href="#smallint">smallint</a></h3>
<p>smallint(expr) - Casts the value <code>expr</code> to the target data type <code>smallint</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="some"><a class="toclink" href="#some">some</a></h3>
<p>some(expr) - Returns true if at least one value of <code>expr</code> is true.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT some(col) FROM VALUES (true), (false), (false) AS tab(col);
true
&gt; SELECT some(col) FROM VALUES (NULL), (true), (false) AS tab(col);
true
&gt; SELECT some(col) FROM VALUES (false), (false), (NULL) AS tab(col);
false
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="sort_array"><a class="toclink" href="#sort_array">sort_array</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sort_array(array('b', 'd', null, 'c', 'a'), true);
[null,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;]
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="soundex"><a class="toclink" href="#soundex">soundex</a></h3>
<p>soundex(str) - Returns Soundex code of the string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT soundex('Miller');
M460
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="space"><a class="toclink" href="#space">space</a></h3>
<p>space(n) - Returns a string consisting of <code>n</code> spaces.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT concat(space(2), '1');
1
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="spark_partition_id"><a class="toclink" href="#spark_partition_id">spark_partition_id</a></h3>
<p>spark_partition_id() - Returns the current partition id.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT spark_partition_id();
0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="split"><a class="toclink" href="#split">split</a></h3>
<p>split(str, regex, limit) - Splits <code>str</code> around occurrences that match <code>regex</code> and returns an array with a length of at most <code>limit</code></p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression to split.</li>
<li>regex - a string representing a regular expression. The regex string should be a
Java regular expression.</li>
<li>limit - an integer expression which controls the number of times the regex is applied.<ul>
<li>limit &gt; 0: The resulting array's length will not be more than <code>limit</code>,
and the resulting array's last entry will contain all input
beyond the last matched regex.</li>
<li>limit &lt;= 0: <code>regex</code> will be applied as many times as possible, and
the resulting array can be of any size.</li>
</ul>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT split('oneAtwoBthreeC', '[ABC]');
[&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;&quot;]
&gt; SELECT split('oneAtwoBthreeC', '[ABC]', -1);
[&quot;one&quot;,&quot;two&quot;,&quot;three&quot;,&quot;&quot;]
&gt; SELECT split('oneAtwoBthreeC', '[ABC]', 2);
[&quot;one&quot;,&quot;twoBthreeC&quot;]
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="split_part"><a class="toclink" href="#split_part">split_part</a></h3>
<p>split_part(str, delimiter, partNum) - Splits <code>str</code> by delimiter and return
requested part of the split (1-based). If any input is null, returns null.
if <code>partNum</code> is out of range of split parts, returns empty string. If <code>partNum</code> is 0,
throws an error. If <code>partNum</code> is negative, the parts are counted backward from the
end of the string. If the <code>delimiter</code> is an empty string, the <code>str</code> is not split.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT split_part('11.12.13', '.', 3);
13
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="sqrt"><a class="toclink" href="#sqrt">sqrt</a></h3>
<p>sqrt(expr) - Returns the square root of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sqrt(4);
2.0
</code></pre>
<p><strong>Since:</strong> 1.1.1</p>
<p><br/></p>
<h3 id="stack"><a class="toclink" href="#stack">stack</a></h3>
<p>stack(n, expr1, ..., exprk) - Separates <code>expr1</code>, ..., <code>exprk</code> into <code>n</code> rows. Uses column names col0, col1, etc. by default unless specified otherwise.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT stack(2, 1, 2, 3);
1 2
3 NULL
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="startswith"><a class="toclink" href="#startswith">startswith</a></h3>
<p>startswith(left, right) - Returns a boolean. The value is True if left starts with right.
Returns NULL if either input expression is NULL. Otherwise, returns False.
Both left or right must be of STRING or BINARY type.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT startswith('Spark SQL', 'Spark');
true
&gt; SELECT startswith('Spark SQL', 'SQL');
false
&gt; SELECT startswith('Spark SQL', null);
NULL
&gt; SELECT startswith(x'537061726b2053514c', x'537061726b');
true
&gt; SELECT startswith(x'537061726b2053514c', x'53514c');
false
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="std"><a class="toclink" href="#std">std</a></h3>
<p>std(expr) - Returns the sample standard deviation calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT std(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="stddev"><a class="toclink" href="#stddev">stddev</a></h3>
<p>stddev(expr) - Returns the sample standard deviation calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT stddev(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="stddev_pop"><a class="toclink" href="#stddev_pop">stddev_pop</a></h3>
<p>stddev_pop(expr) - Returns the population standard deviation calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT stddev_pop(col) FROM VALUES (1), (2), (3) AS tab(col);
0.816496580927726
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="stddev_samp"><a class="toclink" href="#stddev_samp">stddev_samp</a></h3>
<p>stddev_samp(expr) - Returns the sample standard deviation calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT stddev_samp(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="str_to_map"><a class="toclink" href="#str_to_map">str_to_map</a></h3>
<p>str_to_map(text[, pairDelim[, keyValueDelim]]) - Creates a map after splitting the text into key/value pairs using delimiters. Default delimiters are ',' for <code>pairDelim</code> and ':' for <code>keyValueDelim</code>. Both <code>pairDelim</code> and <code>keyValueDelim</code> are treated as regular expressions.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT str_to_map('a:1,b:2,c:3', ',', ':');
{&quot;a&quot;:&quot;1&quot;,&quot;b&quot;:&quot;2&quot;,&quot;c&quot;:&quot;3&quot;}
&gt; SELECT str_to_map('a');
{&quot;a&quot;:null}
</code></pre>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="string"><a class="toclink" href="#string">string</a></h3>
<p>string(expr) - Casts the value <code>expr</code> to the target data type <code>string</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="struct"><a class="toclink" href="#struct">struct</a></h3>
<p>struct(col1, col2, col3, ...) - Creates a struct with the given field values.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT struct(1, 2, 3);
{&quot;col1&quot;:1,&quot;col2&quot;:2,&quot;col3&quot;:3}
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="substr"><a class="toclink" href="#substr">substr</a></h3>
<p>substr(str, pos[, len]) - Returns the substring of <code>str</code> that starts at <code>pos</code> and is of length <code>len</code>, or the slice of byte array that starts at <code>pos</code> and is of length <code>len</code>.</p>
<p>substr(str FROM pos[ FOR len]]) - Returns the substring of <code>str</code> that starts at <code>pos</code> and is of length <code>len</code>, or the slice of byte array that starts at <code>pos</code> and is of length <code>len</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT substr('Spark SQL', 5);
k SQL
&gt; SELECT substr('Spark SQL', -3);
SQL
&gt; SELECT substr('Spark SQL', 5, 1);
k
&gt; SELECT substr('Spark SQL' FROM 5);
k SQL
&gt; SELECT substr('Spark SQL' FROM -3);
SQL
&gt; SELECT substr('Spark SQL' FROM 5 FOR 1);
k
&gt; SELECT substr(encode('Spark SQL', 'utf-8'), 5);
k SQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="substring"><a class="toclink" href="#substring">substring</a></h3>
<p>substring(str, pos[, len]) - Returns the substring of <code>str</code> that starts at <code>pos</code> and is of length <code>len</code>, or the slice of byte array that starts at <code>pos</code> and is of length <code>len</code>.</p>
<p>substring(str FROM pos[ FOR len]]) - Returns the substring of <code>str</code> that starts at <code>pos</code> and is of length <code>len</code>, or the slice of byte array that starts at <code>pos</code> and is of length <code>len</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT substring('Spark SQL', 5);
k SQL
&gt; SELECT substring('Spark SQL', -3);
SQL
&gt; SELECT substring('Spark SQL', 5, 1);
k
&gt; SELECT substring('Spark SQL' FROM 5);
k SQL
&gt; SELECT substring('Spark SQL' FROM -3);
SQL
&gt; SELECT substring('Spark SQL' FROM 5 FOR 1);
k
&gt; SELECT substring(encode('Spark SQL', 'utf-8'), 5);
k SQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="substring_index"><a class="toclink" href="#substring_index">substring_index</a></h3>
<p>substring_index(str, delim, count) - Returns the substring from <code>str</code> before <code>count</code> occurrences of the delimiter <code>delim</code>.
If <code>count</code> is positive, everything to the left of the final delimiter (counting from the
left) is returned. If <code>count</code> 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 <code>delim</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT substring_index('www.apache.org', '.', 2);
www.apache
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="sum"><a class="toclink" href="#sum">sum</a></h3>
<p>sum(expr) - Returns the sum calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT sum(col) FROM VALUES (5), (10), (15) AS tab(col);
30
&gt; SELECT sum(col) FROM VALUES (NULL), (10), (15) AS tab(col);
25
&gt; SELECT sum(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.0</p>
<p><br/></p>
<h3 id="tan"><a class="toclink" href="#tan">tan</a></h3>
<p>tan(expr) - Returns the tangent of <code>expr</code>, as if computed by <code>java.lang.Math.tan</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - angle in radians</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT tan(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="tanh"><a class="toclink" href="#tanh">tanh</a></h3>
<p>tanh(expr) - Returns the hyperbolic tangent of <code>expr</code>, as if computed by
<code>java.lang.Math.tanh</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr - hyperbolic angle</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT tanh(0);
0.0
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="timestamp"><a class="toclink" href="#timestamp">timestamp</a></h3>
<p>timestamp(expr) - Casts the value <code>expr</code> to the target data type <code>timestamp</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="timestamp_micros"><a class="toclink" href="#timestamp_micros">timestamp_micros</a></h3>
<p>timestamp_micros(microseconds) - Creates timestamp from the number of microseconds since UTC epoch.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT timestamp_micros(1230219000123123);
2008-12-25 07:30:00.123123
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="timestamp_millis"><a class="toclink" href="#timestamp_millis">timestamp_millis</a></h3>
<p>timestamp_millis(milliseconds) - Creates timestamp from the number of milliseconds since UTC epoch.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT timestamp_millis(1230219000123);
2008-12-25 07:30:00.123
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="timestamp_seconds"><a class="toclink" href="#timestamp_seconds">timestamp_seconds</a></h3>
<p>timestamp_seconds(seconds) - Creates timestamp from the number of seconds (can be fractional) since UTC epoch.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT timestamp_seconds(1230219000);
2008-12-25 07:30:00
&gt; SELECT timestamp_seconds(1230219000.123);
2008-12-25 07:30:00.123
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="tinyint"><a class="toclink" href="#tinyint">tinyint</a></h3>
<p>tinyint(expr) - Casts the value <code>expr</code> to the target data type <code>tinyint</code>.</p>
<p><strong>Since:</strong> 2.0.1</p>
<p><br/></p>
<h3 id="to_binary"><a class="toclink" href="#to_binary">to_binary</a></h3>
<p>to_binary(str[, fmt]) - Converts the input <code>str</code> to a binary value based on the supplied <code>fmt</code>.
<code>fmt</code> can be a case-insensitive string literal of "hex", "utf-8", "utf8", or "base64".
By default, the binary format for conversion is "hex" if <code>fmt</code> is omitted.
The function returns NULL if at least one of the input parameters is NULL.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_binary('abc', 'utf-8');
abc
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="to_char"><a class="toclink" href="#to_char">to_char</a></h3>
<p>to_char(expr, format) - Convert <code>expr</code> to a string based on the <code>format</code>.
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.
('&lt;1&gt;').
If <code>expr</code> is a datetime, <code>format</code> shall be a valid datetime pattern, see <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>.
If <code>expr</code> 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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_char(454, '999');
454
&gt; SELECT to_char(454.00, '000D00');
454.00
&gt; SELECT to_char(12454, '99G999');
12,454
&gt; SELECT to_char(78.12, '$99.99');
$78.12
&gt; SELECT to_char(-12454.8, '99G999D9S');
12,454.8-
&gt; SELECT to_char(date'2016-04-08', 'y');
2016
&gt; SELECT to_char(x'537061726b2053514c', 'base64');
U3BhcmsgU1FM
&gt; SELECT to_char(x'537061726b2053514c', 'hex');
537061726B2053514C
&gt; SELECT to_char(encode('abc', 'utf-8'), 'utf-8');
abc
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="to_csv"><a class="toclink" href="#to_csv">to_csv</a></h3>
<p>to_csv(expr[, options]) - Returns a CSV string with a given struct value</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_csv(named_struct('a', 1, 'b', 2));
1,2
&gt; SELECT to_csv(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
26/08/2015
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="to_date"><a class="toclink" href="#to_date">to_date</a></h3>
<p>to_date(date_str[, fmt]) - Parses the <code>date_str</code> expression with the <code>fmt</code> expression to
a date. Returns null with invalid input. By default, it follows casting rules to a date if
the <code>fmt</code> is omitted.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>date_str - A string to be parsed to date.</li>
<li>fmt - Date format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid
date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_date('2009-07-30 04:17:52');
2009-07-30
&gt; SELECT to_date('2016-12-31', 'yyyy-MM-dd');
2016-12-31
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="to_json"><a class="toclink" href="#to_json">to_json</a></h3>
<p>to_json(expr[, options]) - Returns a JSON string with a given struct value</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_json(named_struct('a', 1, 'b', 2));
{&quot;a&quot;:1,&quot;b&quot;:2}
&gt; SELECT to_json(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
{&quot;time&quot;:&quot;26/08/2015&quot;}
&gt; SELECT to_json(array(named_struct('a', 1, 'b', 2)));
[{&quot;a&quot;:1,&quot;b&quot;:2}]
&gt; SELECT to_json(map('a', named_struct('b', 1)));
{&quot;a&quot;:{&quot;b&quot;:1}}
&gt; SELECT to_json(map(named_struct('a', 1),named_struct('b', 2)));
{&quot;[1]&quot;:{&quot;b&quot;:2}}
&gt; SELECT to_json(map('a', 1));
{&quot;a&quot;:1}
&gt; SELECT to_json(array(map('a', 1)));
[{&quot;a&quot;:1}]
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="to_number"><a class="toclink" href="#to_number">to_number</a></h3>
<p>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.
('&lt;1&gt;').</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_number('454', '999');
454
&gt; SELECT to_number('454.00', '000.00');
454.00
&gt; SELECT to_number('12,454', '99,999');
12454
&gt; SELECT to_number('$78.12', '$99.99');
78.12
&gt; SELECT to_number('12,454.8-', '99,999.9S');
-12454.8
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="to_timestamp"><a class="toclink" href="#to_timestamp">to_timestamp</a></h3>
<p>to_timestamp(timestamp_str[, fmt]) - Parses the <code>timestamp_str</code> expression with the <code>fmt</code> expression
to a timestamp. Returns null with invalid input. By default, it follows casting rules to
a timestamp if the <code>fmt</code> is omitted. The result data type is consistent with the value of
configuration <code>spark.sql.timestampType</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timestamp_str - A string to be parsed to timestamp.</li>
<li>fmt - Timestamp format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid
date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
&gt; SELECT to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
</code></pre>
<p><strong>Since:</strong> 2.2.0</p>
<p><br/></p>
<h3 id="to_timestamp_ltz"><a class="toclink" href="#to_timestamp_ltz">to_timestamp_ltz</a></h3>
<p>to_timestamp_ltz(timestamp_str[, fmt]) - Parses the <code>timestamp_str</code> expression with the <code>fmt</code> expression
to a timestamp with local time zone. Returns null with invalid input. By default, it follows casting rules to
a timestamp if the <code>fmt</code> is omitted.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timestamp_str - A string to be parsed to timestamp with local time zone.</li>
<li>fmt - Timestamp format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid
date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_timestamp_ltz('2016-12-31 00:12:00');
2016-12-31 00:12:00
&gt; SELECT to_timestamp_ltz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="to_timestamp_ntz"><a class="toclink" href="#to_timestamp_ntz">to_timestamp_ntz</a></h3>
<p>to_timestamp_ntz(timestamp_str[, fmt]) - Parses the <code>timestamp_str</code> expression with the <code>fmt</code> expression
to a timestamp without time zone. Returns null with invalid input. By default, it follows casting rules to
a timestamp if the <code>fmt</code> is omitted.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timestamp_str - A string to be parsed to timestamp without time zone.</li>
<li>fmt - Timestamp format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid
date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_timestamp_ntz('2016-12-31 00:12:00');
2016-12-31 00:12:00
&gt; SELECT to_timestamp_ntz('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="to_unix_timestamp"><a class="toclink" href="#to_unix_timestamp">to_unix_timestamp</a></h3>
<p>to_unix_timestamp(timeExp[, fmt]) - Returns the UNIX timestamp of the given time.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timeExp - A date/timestamp or string which is returned as a UNIX timestamp.</li>
<li>fmt - Date/time format pattern to follow. Ignored if <code>timeExp</code> is not a string.
Default value is "yyyy-MM-dd HH:mm:ss". See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>
for valid date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_unix_timestamp('2016-04-08', 'yyyy-MM-dd');
1460098800
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="to_utc_timestamp"><a class="toclink" href="#to_utc_timestamp">to_utc_timestamp</a></h3>
<p>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'.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_utc_timestamp('2016-08-31', 'Asia/Seoul');
2016-08-30 15:00:00
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="to_varchar"><a class="toclink" href="#to_varchar">to_varchar</a></h3>
<p>to_varchar(expr, format) - Convert <code>expr</code> to a string based on the <code>format</code>.
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.
('&lt;1&gt;').
If <code>expr</code> is a datetime, <code>format</code> shall be a valid datetime pattern, see <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a>.
If <code>expr</code> 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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_varchar(454, '999');
454
&gt; SELECT to_varchar(454.00, '000D00');
454.00
&gt; SELECT to_varchar(12454, '99G999');
12,454
&gt; SELECT to_varchar(78.12, '$99.99');
$78.12
&gt; SELECT to_varchar(-12454.8, '99G999D9S');
12,454.8-
&gt; SELECT to_varchar(date'2016-04-08', 'y');
2016
&gt; SELECT to_varchar(x'537061726b2053514c', 'base64');
U3BhcmsgU1FM
&gt; SELECT to_varchar(x'537061726b2053514c', 'hex');
537061726B2053514C
&gt; SELECT to_varchar(encode('abc', 'utf-8'), 'utf-8');
abc
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="to_xml"><a class="toclink" href="#to_xml">to_xml</a></h3>
<p>to_xml(expr[, options]) - Returns a XML string with a given struct value</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT to_xml(named_struct('a', 1, 'b', 2));
&lt;ROW&gt;
&lt;a&gt;1&lt;/a&gt;
&lt;b&gt;2&lt;/b&gt;
&lt;/ROW&gt;
&gt; SELECT to_xml(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
&lt;ROW&gt;
&lt;time&gt;26/08/2015&lt;/time&gt;
&lt;/ROW&gt;
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="transform"><a class="toclink" href="#transform">transform</a></h3>
<p>transform(expr, func) - Transforms elements in an array using the function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT transform(array(1, 2, 3), x -&gt; x + 1);
[2,3,4]
&gt; SELECT transform(array(1, 2, 3), (x, i) -&gt; x + i);
[1,3,5]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="transform_keys"><a class="toclink" href="#transform_keys">transform_keys</a></h3>
<p>transform_keys(expr, func) - Transforms elements in a map using the function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -&gt; k + 1);
{2:1,3:2,4:3}
&gt; SELECT transform_keys(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -&gt; k + v);
{2:1,4:2,6:3}
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="transform_values"><a class="toclink" href="#transform_values">transform_values</a></h3>
<p>transform_values(expr, func) - Transforms values in the map using the function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -&gt; v + 1);
{1:2,2:3,3:4}
&gt; SELECT transform_values(map_from_arrays(array(1, 2, 3), array(1, 2, 3)), (k, v) -&gt; k + v);
{1:2,2:4,3:6}
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="translate"><a class="toclink" href="#translate">translate</a></h3>
<p>translate(input, from, to) - Translates the <code>input</code> string by replacing the characters present in the <code>from</code> string with the corresponding characters in the <code>to</code> string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT translate('AaBbCc', 'abc', '123');
A1B2C3
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="trim"><a class="toclink" href="#trim">trim</a></h3>
<p>trim(str) - Removes the leading and trailing space characters from <code>str</code>.</p>
<p>trim(BOTH FROM str) - Removes the leading and trailing space characters from <code>str</code>.</p>
<p>trim(LEADING FROM str) - Removes the leading space characters from <code>str</code>.</p>
<p>trim(TRAILING FROM str) - Removes the trailing space characters from <code>str</code>.</p>
<p>trim(trimStr FROM str) - Remove the leading and trailing <code>trimStr</code> characters from <code>str</code>.</p>
<p>trim(BOTH trimStr FROM str) - Remove the leading and trailing <code>trimStr</code> characters from <code>str</code>.</p>
<p>trim(LEADING trimStr FROM str) - Remove the leading <code>trimStr</code> characters from <code>str</code>.</p>
<p>trim(TRAILING trimStr FROM str) - Remove the trailing <code>trimStr</code> characters from <code>str</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression</li>
<li>trimStr - the trim string characters to trim, the default value is a single space</li>
<li>BOTH, FROM - these are keywords to specify trimming string characters from both ends of
the string</li>
<li>LEADING, FROM - these are keywords to specify trimming string characters from the left
end of the string</li>
<li>TRAILING, FROM - these are keywords to specify trimming string characters from the right
end of the string</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT trim(' SparkSQL ');
SparkSQL
&gt; SELECT trim(BOTH FROM ' SparkSQL ');
SparkSQL
&gt; SELECT trim(LEADING FROM ' SparkSQL ');
SparkSQL
&gt; SELECT trim(TRAILING FROM ' SparkSQL ');
SparkSQL
&gt; SELECT trim('SL' FROM 'SSparkSQLS');
parkSQ
&gt; SELECT trim(BOTH 'SL' FROM 'SSparkSQLS');
parkSQ
&gt; SELECT trim(LEADING 'SL' FROM 'SSparkSQLS');
parkSQLS
&gt; SELECT trim(TRAILING 'SL' FROM 'SSparkSQLS');
SSparkSQ
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="trunc"><a class="toclink" href="#trunc">trunc</a></h3>
<p>trunc(date, fmt) - Returns <code>date</code> with the time portion of the day truncated to the unit specified by the format model <code>fmt</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>date - date value or valid date string</li>
<li>fmt - the format representing the unit to be truncated to<ul>
<li>"YEAR", "YYYY", "YY" - truncate to the first date of the year that the <code>date</code> falls in</li>
<li>"QUARTER" - truncate to the first date of the quarter that the <code>date</code> falls in</li>
<li>"MONTH", "MM", "MON" - truncate to the first date of the month that the <code>date</code> falls in</li>
<li>"WEEK" - truncate to the Monday of the week that the <code>date</code> falls in</li>
</ul>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT trunc('2019-08-04', 'week');
2019-07-29
&gt; SELECT trunc('2019-08-04', 'quarter');
2019-07-01
&gt; SELECT trunc('2009-02-12', 'MM');
2009-02-01
&gt; SELECT trunc('2015-10-27', 'YEAR');
2015-01-01
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="try_add"><a class="toclink" href="#try_add">try_add</a></h3>
<p>try_add(expr1, expr2) - Returns the sum of <code>expr1</code>and <code>expr2</code> and the result is null on overflow. The acceptable input types are the same with the <code>+</code> operator.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_add(1, 2);
3
&gt; SELECT try_add(2147483647, 1);
NULL
&gt; SELECT try_add(date'2021-01-01', 1);
2021-01-02
&gt; SELECT try_add(date'2021-01-01', interval 1 year);
2022-01-01
&gt; SELECT try_add(timestamp'2021-01-01 00:00:00', interval 1 day);
2021-01-02 00:00:00
&gt; SELECT try_add(interval 1 year, interval 2 year);
3-0
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="try_aes_decrypt"><a class="toclink" href="#try_aes_decrypt">try_aes_decrypt</a></h3>
<p>try_aes_decrypt(expr, key[, mode[, padding[, aad]]]) - This is a special version of <code>aes_decrypt</code> that performs the same operation, but returns a NULL value instead of raising an error if the decryption cannot be performed.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_aes_decrypt(unhex('6E7CA17BBB468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
Spark SQL
&gt; SELECT try_aes_decrypt(unhex('----------468D3084B5744BCA729FB7B2B7BCB8E4472847D02670489D95FA97DBBA7D3210'), '0000111122223333', 'GCM');
NULL
</code></pre>
<p><strong>Since:</strong> 3.5.0</p>
<p><br/></p>
<h3 id="try_avg"><a class="toclink" href="#try_avg">try_avg</a></h3>
<p>try_avg(expr) - Returns the mean calculated from values of a group and the result is null on overflow.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_avg(col) FROM VALUES (1), (2), (3) AS tab(col);
2.0
&gt; SELECT try_avg(col) FROM VALUES (1), (2), (NULL) AS tab(col);
1.5
&gt; SELECT try_avg(col) FROM VALUES (interval '2147483647 months'), (interval '1 months') AS tab(col);
NULL
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_divide"><a class="toclink" href="#try_divide">try_divide</a></h3>
<p>try_divide(dividend, divisor) - Returns <code>dividend</code>/<code>divisor</code>. It always performs floating point division. Its result is always null if <code>expr2</code> is 0. <code>dividend</code> must be a numeric or an interval. <code>divisor</code> must be a numeric.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_divide(3, 2);
1.5
&gt; SELECT try_divide(2L, 2L);
1.0
&gt; SELECT try_divide(1, 0);
NULL
&gt; SELECT try_divide(interval 2 month, 2);
0-1
&gt; SELECT try_divide(interval 2 month, 0);
NULL
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="try_element_at"><a class="toclink" href="#try_element_at">try_element_at</a></h3>
<p>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 &lt; 0, accesses elements from the last to the first.
The function always returns NULL if the index exceeds the length of the array.</p>
<p>try_element_at(map, key) - Returns value for given key. The function always returns NULL
if the key is not contained in the map.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_element_at(array(1, 2, 3), 2);
2
&gt; SELECT try_element_at(map(1, 'a', 2, 'b'), 2);
b
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_multiply"><a class="toclink" href="#try_multiply">try_multiply</a></h3>
<p>try_multiply(expr1, expr2) - Returns <code>expr1</code>*<code>expr2</code> and the result is null on overflow. The acceptable input types are the same with the <code>*</code> operator.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_multiply(2, 3);
6
&gt; SELECT try_multiply(-2147483648, 10);
NULL
&gt; SELECT try_multiply(interval 2 year, 3);
6-0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_parse_json"><a class="toclink" href="#try_parse_json">try_parse_json</a></h3>
<p>try_parse_json(jsonStr) - Parse a JSON string as a Variant value. Return NULL when the string is not valid JSON value.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_parse_json('{&quot;a&quot;:1,&quot;b&quot;:0.8}');
{&quot;a&quot;:1,&quot;b&quot;:0.8}
&gt; SELECT try_parse_json('{&quot;a&quot;:1,');
NULL
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="try_reflect"><a class="toclink" href="#try_reflect">try_reflect</a></h3>
<p>try_reflect(class, method[, arg1[, arg2 ..]]) - This is a special version of <code>reflect</code> that performs the same operation, but returns a NULL value instead of raising an error if the invoke method thrown exception.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_reflect('java.util.UUID', 'randomUUID');
c33fb387-8500-4bfa-81d2-6e0e3e930df2
&gt; SELECT try_reflect('java.util.UUID', 'fromString', 'a5cf6c42-0c85-418f-af6c-3e4e5b1328f2');
a5cf6c42-0c85-418f-af6c-3e4e5b1328f2
&gt; SELECT try_reflect('java.net.URLDecoder', 'decode', '%');
NULL
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="try_remainder"><a class="toclink" href="#try_remainder">try_remainder</a></h3>
<p>try_remainder(dividend, divisor) - Returns the remainder after <code>expr1</code>/<code>expr2</code>. <code>dividend</code> must be a numeric. <code>divisor</code> must be a numeric.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_remainder(3, 2);
1
&gt; SELECT try_remainder(2L, 2L);
0
&gt; SELECT try_remainder(3.0, 2.0);
1.0
&gt; SELECT try_remainder(1, 0);
NULL
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="try_subtract"><a class="toclink" href="#try_subtract">try_subtract</a></h3>
<p>try_subtract(expr1, expr2) - Returns <code>expr1</code>-<code>expr2</code> and the result is null on overflow. The acceptable input types are the same with the <code>-</code> operator.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_subtract(2, 1);
1
&gt; SELECT try_subtract(-2147483648, 1);
NULL
&gt; SELECT try_subtract(date'2021-01-02', 1);
2021-01-01
&gt; SELECT try_subtract(date'2021-01-01', interval 1 year);
2020-01-01
&gt; SELECT try_subtract(timestamp'2021-01-02 00:00:00', interval 1 day);
2021-01-01 00:00:00
&gt; SELECT try_subtract(interval 2 year, interval 1 year);
1-0
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_sum"><a class="toclink" href="#try_sum">try_sum</a></h3>
<p>try_sum(expr) - Returns the sum calculated from values of a group and the result is null on overflow.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_sum(col) FROM VALUES (5), (10), (15) AS tab(col);
30
&gt; SELECT try_sum(col) FROM VALUES (NULL), (10), (15) AS tab(col);
25
&gt; SELECT try_sum(col) FROM VALUES (NULL), (NULL) AS tab(col);
NULL
&gt; SELECT try_sum(col) FROM VALUES (9223372036854775807L), (1L) AS tab(col);
NULL
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_to_binary"><a class="toclink" href="#try_to_binary">try_to_binary</a></h3>
<p>try_to_binary(str[, fmt]) - This is a special version of <code>to_binary</code> that performs the same operation, but returns a NULL value instead of raising an error if the conversion cannot be performed.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_to_binary('abc', 'utf-8');
abc
&gt; select try_to_binary('a!', 'base64');
NULL
&gt; select try_to_binary('abc', 'invalidFormat');
NULL
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_to_number"><a class="toclink" href="#try_to_number">try_to_number</a></h3>
<p>try_to_number(expr, fmt) - Convert string 'expr' to a number based on the string format <code>fmt</code>.
Returns NULL if the string 'expr' does not match the expected format. The format follows the
same semantics as the to_number function.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_to_number('454', '999');
454
&gt; SELECT try_to_number('454.00', '000.00');
454.00
&gt; SELECT try_to_number('12,454', '99,999');
12454
&gt; SELECT try_to_number('$78.12', '$99.99');
78.12
&gt; SELECT try_to_number('12,454.8-', '99,999.9S');
-12454.8
</code></pre>
<p><strong>Since:</strong> 3.3.0</p>
<p><br/></p>
<h3 id="try_to_timestamp"><a class="toclink" href="#try_to_timestamp">try_to_timestamp</a></h3>
<p>try_to_timestamp(timestamp_str[, fmt]) - Parses the <code>timestamp_str</code> expression with the <code>fmt</code> 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 <code>fmt</code> is omitted.
The result data type is consistent with the value of configuration <code>spark.sql.timestampType</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timestamp_str - A string to be parsed to timestamp.</li>
<li>fmt - Timestamp format pattern to follow. See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html">Datetime Patterns</a> for valid
date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_to_timestamp('2016-12-31 00:12:00');
2016-12-31 00:12:00
&gt; SELECT try_to_timestamp('2016-12-31', 'yyyy-MM-dd');
2016-12-31 00:00:00
&gt; SELECT try_to_timestamp('foo', 'yyyy-MM-dd');
NULL
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="try_variant_get"><a class="toclink" href="#try_variant_get">try_variant_get</a></h3>
<p>try_variant_get(v, path[, type]) - Extracts a sub-variant from <code>v</code> according to <code>path</code>, and then cast the sub-variant to <code>type</code>. When <code>type</code> is omitted, it is default to <code>variant</code>. Returns null if the path does not exist or the cast fails.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT try_variant_get(parse_json('{&quot;a&quot;: 1}'), '$.a', 'int');
1
&gt; SELECT try_variant_get(parse_json('{&quot;a&quot;: 1}'), '$.b', 'int');
NULL
&gt; SELECT try_variant_get(parse_json('[1, &quot;2&quot;]'), '$[1]', 'string');
2
&gt; SELECT try_variant_get(parse_json('[1, &quot;2&quot;]'), '$[2]', 'string');
NULL
&gt; SELECT try_variant_get(parse_json('[1, &quot;hello&quot;]'), '$[1]');
&quot;hello&quot;
&gt; SELECT try_variant_get(parse_json('[1, &quot;hello&quot;]'), '$[1]', 'int');
NULL
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="typeof"><a class="toclink" href="#typeof">typeof</a></h3>
<p>typeof(expr) - Return DDL-formatted type string for the data type of the input.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT typeof(1);
int
&gt; SELECT typeof(array(1));
array&lt;int&gt;
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="ucase"><a class="toclink" href="#ucase">ucase</a></h3>
<p>ucase(str) - Returns <code>str</code> with all characters changed to uppercase.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ucase('SparkSql');
SPARKSQL
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="unbase64"><a class="toclink" href="#unbase64">unbase64</a></h3>
<p>unbase64(str) - Converts the argument from a base 64 string <code>str</code> to a binary.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unbase64('U3BhcmsgU1FM');
Spark SQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="unhex"><a class="toclink" href="#unhex">unhex</a></h3>
<p>unhex(expr) - Converts hexadecimal <code>expr</code> to binary.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT decode(unhex('537061726B2053514C'), 'UTF-8');
Spark SQL
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="unix_date"><a class="toclink" href="#unix_date">unix_date</a></h3>
<p>unix_date(date) - Returns the number of days since 1970-01-01.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unix_date(DATE(&quot;1970-01-02&quot;));
1
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="unix_micros"><a class="toclink" href="#unix_micros">unix_micros</a></h3>
<p>unix_micros(timestamp) - Returns the number of microseconds since 1970-01-01 00:00:00 UTC.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unix_micros(TIMESTAMP('1970-01-01 00:00:01Z'));
1000000
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="unix_millis"><a class="toclink" href="#unix_millis">unix_millis</a></h3>
<p>unix_millis(timestamp) - Returns the number of milliseconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unix_millis(TIMESTAMP('1970-01-01 00:00:01Z'));
1000
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="unix_seconds"><a class="toclink" href="#unix_seconds">unix_seconds</a></h3>
<p>unix_seconds(timestamp) - Returns the number of seconds since 1970-01-01 00:00:00 UTC. Truncates higher levels of precision.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unix_seconds(TIMESTAMP('1970-01-01 00:00:01Z'));
1
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="unix_timestamp"><a class="toclink" href="#unix_timestamp">unix_timestamp</a></h3>
<p>unix_timestamp([timeExp[, fmt]]) - Returns the UNIX timestamp of current or specified time.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>timeExp - A date/timestamp or string. If not provided, this defaults to current time.</li>
<li>fmt - Date/time format pattern to follow. Ignored if <code>timeExp</code> is not a string.
Default value is "yyyy-MM-dd HH:mm:ss". See <a href="https://spark.apache.org/docs/latest/sql-ref-datetime-pattern.html"> Datetime Patterns</a>
for valid date and time format patterns.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT unix_timestamp();
1476884637
&gt; SELECT unix_timestamp('2016-04-08', 'yyyy-MM-dd');
1460041200
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="upper"><a class="toclink" href="#upper">upper</a></h3>
<p>upper(str) - Returns <code>str</code> with all characters changed to uppercase.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT upper('SparkSql');
SPARKSQL
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="url_decode"><a class="toclink" href="#url_decode">url_decode</a></h3>
<p>url_decode(str) - Decodes a <code>str</code> in 'application/x-www-form-urlencoded' format using a specific encoding scheme.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>str - a string expression to decode</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT url_decode('https%3A%2F%2Fspark.apache.org');
https://spark.apache.org
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="url_encode"><a class="toclink" href="#url_encode">url_encode</a></h3>
<p>url_encode(str) - Translates a string into 'application/x-www-form-urlencoded' format using a specific encoding scheme.</p>
<p><strong>Arguments:</strong></p>
<p>str - a string expression to be translated</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT url_encode('https://spark.apache.org');
https%3A%2F%2Fspark.apache.org
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="user"><a class="toclink" href="#user">user</a></h3>
<p>user() - user name of current execution context.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT user();
mockingjay
</code></pre>
<p><strong>Since:</strong> 3.2.0</p>
<p><br/></p>
<h3 id="uuid"><a class="toclink" href="#uuid">uuid</a></h3>
<p>uuid() - Returns an universally unique identifier (UUID) string. The value is returned as a canonical UUID 36-character string.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT uuid();
46707d92-02f4-4817-8116-a4c3b23e6266
</code></pre>
<p><strong>Note:</strong></p>
<p>The function is non-deterministic.</p>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="var_pop"><a class="toclink" href="#var_pop">var_pop</a></h3>
<p>var_pop(expr) - Returns the population variance calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT var_pop(col) FROM VALUES (1), (2), (3) AS tab(col);
0.6666666666666666
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="var_samp"><a class="toclink" href="#var_samp">var_samp</a></h3>
<p>var_samp(expr) - Returns the sample variance calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT var_samp(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="variance"><a class="toclink" href="#variance">variance</a></h3>
<p>variance(expr) - Returns the sample variance calculated from values of a group.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT variance(col) FROM VALUES (1), (2), (3) AS tab(col);
1.0
</code></pre>
<p><strong>Since:</strong> 1.6.0</p>
<p><br/></p>
<h3 id="variant_get"><a class="toclink" href="#variant_get">variant_get</a></h3>
<p>variant_get(v, path[, type]) - Extracts a sub-variant from <code>v</code> according to <code>path</code>, and then cast the sub-variant to <code>type</code>. When <code>type</code> is omitted, it is default to <code>variant</code>. Returns null if the path does not exist. Throws an exception if the cast fails.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT variant_get(parse_json('{&quot;a&quot;: 1}'), '$.a', 'int');
1
&gt; SELECT variant_get(parse_json('{&quot;a&quot;: 1}'), '$.b', 'int');
NULL
&gt; SELECT variant_get(parse_json('[1, &quot;2&quot;]'), '$[1]', 'string');
2
&gt; SELECT variant_get(parse_json('[1, &quot;2&quot;]'), '$[2]', 'string');
NULL
&gt; SELECT variant_get(parse_json('[1, &quot;hello&quot;]'), '$[1]');
&quot;hello&quot;
</code></pre>
<p><strong>Since:</strong> 4.0.0</p>
<p><br/></p>
<h3 id="version"><a class="toclink" href="#version">version</a></h3>
<p>version() - Returns the Spark version. The string contains 2 fields, the first being a release version and the second being a git revision.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT version();
3.1.0 a6d6ea3efedbad14d99c24143834cd4e2e52fb40
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="weekday"><a class="toclink" href="#weekday">weekday</a></h3>
<p>weekday(date) - Returns the day of the week for date/timestamp (0 = Monday, 1 = Tuesday, ..., 6 = Sunday).</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT weekday('2009-07-30');
3
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="weekofyear"><a class="toclink" href="#weekofyear">weekofyear</a></h3>
<p>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 &gt;3 days.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT weekofyear('2008-02-20');
8
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="when"><a class="toclink" href="#when">when</a></h3>
<p>CASE WHEN expr1 THEN expr2 [WHEN expr3 THEN expr4]* [ELSE expr5] END - When <code>expr1</code> = true, returns <code>expr2</code>; else when <code>expr3</code> = true, returns <code>expr4</code>; else returns <code>expr5</code>.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>expr1, expr3 - the branch condition expressions should all be boolean type.</li>
<li>expr2, expr4, expr5 - the branch value expressions and else value expression should all be
same type or coercible to a common type.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT CASE WHEN 1 &gt; 0 THEN 1 WHEN 2 &gt; 0 THEN 2.0 ELSE 1.2 END;
1.0
&gt; SELECT CASE WHEN 1 &lt; 0 THEN 1 WHEN 2 &gt; 0 THEN 2.0 ELSE 1.2 END;
2.0
&gt; SELECT CASE WHEN 1 &lt; 0 THEN 1 WHEN 2 &lt; 0 THEN 2.0 END;
NULL
</code></pre>
<p><strong>Since:</strong> 1.0.1</p>
<p><br/></p>
<h3 id="width_bucket"><a class="toclink" href="#width_bucket">width_bucket</a></h3>
<p>width_bucket(value, min_value, max_value, num_bucket) - Returns the bucket number to which
<code>value</code> would be assigned in an equiwidth histogram with <code>num_bucket</code> buckets,
in the range <code>min_value</code> to <code>max_value</code>."</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT width_bucket(5.3, 0.2, 10.6, 5);
3
&gt; SELECT width_bucket(-2.1, 1.3, 3.4, 3);
0
&gt; SELECT width_bucket(8.1, 0.0, 5.7, 4);
5
&gt; SELECT width_bucket(-0.9, 5.2, 0.5, 2);
3
&gt; SELECT width_bucket(INTERVAL '0' YEAR, INTERVAL '0' YEAR, INTERVAL '10' YEAR, 10);
1
&gt; SELECT width_bucket(INTERVAL '1' YEAR, INTERVAL '0' YEAR, INTERVAL '10' YEAR, 10);
2
&gt; SELECT width_bucket(INTERVAL '0' DAY, INTERVAL '0' DAY, INTERVAL '10' DAY, 10);
1
&gt; SELECT width_bucket(INTERVAL '1' DAY, INTERVAL '0' DAY, INTERVAL '10' DAY, 10);
2
</code></pre>
<p><strong>Since:</strong> 3.1.0</p>
<p><br/></p>
<h3 id="window"><a class="toclink" href="#window">window</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>time_column - The column or the expression to use as the timestamp for windowing by time. The time column must be of TimestampType.</li>
<li>window_duration - A string specifying the width of the window represented as "interval value".
(See <a href="https://spark.apache.org/docs/latest/sql-ref-literals.html#interval-literal">Interval Literal</a> for more details.)
Note that the duration is a fixed length of time, and does not vary over time according to a calendar.</li>
<li>slide_duration - A string specifying the sliding interval of the window represented as "interval value".
A new window will be generated every <code>slide_duration</code>. Must be less than or equal to the <code>window_duration</code>.
This duration is likewise absolute, and does not vary according to a calendar.</li>
<li>start_time - The offset with respect to 1970-01-01 00:00:00 UTC with which to start window intervals.
For example, in order to have hourly tumbling windows that start 15 minutes past the hour,
e.g. 12:15-13:15, 13:15-14:15... provide <code>start_time</code> as <code>15 minutes</code>.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
&gt; 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
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="window_time"><a class="toclink" href="#window_time">window_time</a></h3>
<p>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.</p>
<p><strong>Arguments:</strong></p>
<ul>
<li>window_column - The column representing time/session window.</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code>&gt; 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
</code></pre>
<p><strong>Since:</strong> 3.4.0</p>
<p><br/></p>
<h3 id="xpath"><a class="toclink" href="#xpath">xpath</a></h3>
<p>xpath(xml, xpath) - Returns a string array of values within the nodes of xml that match the XPath expression.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath('&lt;a&gt;&lt;b&gt;b1&lt;/b&gt;&lt;b&gt;b2&lt;/b&gt;&lt;b&gt;b3&lt;/b&gt;&lt;c&gt;c1&lt;/c&gt;&lt;c&gt;c2&lt;/c&gt;&lt;/a&gt;','a/b/text()');
[&quot;b1&quot;,&quot;b2&quot;,&quot;b3&quot;]
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_boolean"><a class="toclink" href="#xpath_boolean">xpath_boolean</a></h3>
<p>xpath_boolean(xml, xpath) - Returns true if the XPath expression evaluates to true, or if a matching node is found.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_boolean('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;/a&gt;','a/b');
true
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_double"><a class="toclink" href="#xpath_double">xpath_double</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_double('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3.0
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_float"><a class="toclink" href="#xpath_float">xpath_float</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_float('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3.0
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_int"><a class="toclink" href="#xpath_int">xpath_int</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_int('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_long"><a class="toclink" href="#xpath_long">xpath_long</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_long('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_number"><a class="toclink" href="#xpath_number">xpath_number</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_number('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3.0
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_short"><a class="toclink" href="#xpath_short">xpath_short</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_short('&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;b&gt;2&lt;/b&gt;&lt;/a&gt;', 'sum(a/b)');
3
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xpath_string"><a class="toclink" href="#xpath_string">xpath_string</a></h3>
<p>xpath_string(xml, xpath) - Returns the text contents of the first xml node that matches the XPath expression.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xpath_string('&lt;a&gt;&lt;b&gt;b&lt;/b&gt;&lt;c&gt;cc&lt;/c&gt;&lt;/a&gt;','a/c');
cc
</code></pre>
<p><strong>Since:</strong> 2.0.0</p>
<p><br/></p>
<h3 id="xxhash64"><a class="toclink" href="#xxhash64">xxhash64</a></h3>
<p>xxhash64(expr1, expr2, ...) - Returns a 64-bit hash value of the arguments. Hash seed is 42.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT xxhash64('Spark', array(123), 2);
5602566077635097486
</code></pre>
<p><strong>Since:</strong> 3.0.0</p>
<p><br/></p>
<h3 id="year"><a class="toclink" href="#year">year</a></h3>
<p>year(date) - Returns the year component of the date/timestamp.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT year('2016-07-30');
2016
</code></pre>
<p><strong>Since:</strong> 1.5.0</p>
<p><br/></p>
<h3 id="zip_with"><a class="toclink" href="#zip_with">zip_with</a></h3>
<p>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.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT zip_with(array(1, 2, 3), array('a', 'b', 'c'), (x, y) -&gt; (y, x));
[{&quot;y&quot;:&quot;a&quot;,&quot;x&quot;:1},{&quot;y&quot;:&quot;b&quot;,&quot;x&quot;:2},{&quot;y&quot;:&quot;c&quot;,&quot;x&quot;:3}]
&gt; SELECT zip_with(array(1, 2), array(3, 4), (x, y) -&gt; x + y);
[4,6]
&gt; SELECT zip_with(array('a', 'b', 'c'), array('d', 'e', 'f'), (x, y) -&gt; concat(x, y));
[&quot;ad&quot;,&quot;be&quot;,&quot;cf&quot;]
</code></pre>
<p><strong>Since:</strong> 2.4.0</p>
<p><br/></p>
<h3 id="_20"><a class="toclink" href="#_20">|</a></h3>
<p>expr1 | expr2 - Returns the result of bitwise OR of <code>expr1</code> and <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 3 | 5;
7
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
<h3 id="_21"><a class="toclink" href="#_21">||</a></h3>
<p>expr1 || expr2 - Returns the concatenation of <code>expr1</code> and <code>expr2</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT 'Spark' || 'SQL';
SparkSQL
&gt; SELECT array(1, 2, 3) || array(4, 5) || array(6);
[1,2,3,4,5,6]
</code></pre>
<p><strong>Note:</strong></p>
<p>|| for arrays is available since 2.4.0.</p>
<p><strong>Since:</strong> 2.3.0</p>
<p><br/></p>
<h3 id="_22"><a class="toclink" href="#_22">~</a></h3>
<p>~ expr - Returns the result of bitwise NOT of <code>expr</code>.</p>
<p><strong>Examples:</strong></p>
<pre><code>&gt; SELECT ~ 0;
-1
</code></pre>
<p><strong>Since:</strong> 1.4.0</p>
<p><br/></p>
</div>
</div><footer>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="Versions">
<span class="rst-current-version" data-toggle="rst-current-version">
</span>
</div>
<script src="js/jquery-3.6.0.min.js"></script>
<script>var base_url = ".";</script>
<script src="js/theme_extra.js"></script>
<script src="js/theme.js"></script>
<script src="search/main.js"></script>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>
<!--
MkDocs version : 1.6.0
Build Date UTC : 2024-05-28 17:28:26.100399+00:00
-->