Logical operators and functions
Operator/Function | Description |
---|---|
! or not | Logical not |
< | Less than |
<= | Less than or equal to |
= | Equal to |
> | Greater than |
>= | Greater than or equal to |
^ | Bitwise exclusive or |
| | Bitwise or |
~ | Bitwise not |
arrays_overlap | Returns the common elements |
assert_true | Asserts if the expression is true |
if | If the expression evaluates to true, return the second expression. Otherwise, return the third expression. |
ifnull | If the expression is null, it returns the second expression. Otherwise, it returns the first expression. |
in | Returns true if the first expression is in any of the subsequent expressions. |
isnan | Returns true if the value is not a number |
isnotnull | Returns true if the value is not null |
isnull | Returns true if the value is null |
nanvl | Returns the first expression if not a number, returns the second expression otherwise |
or | Logical or |
when | When can be used to create branch conditions for comparison |
xpath_boolean | Returns true if the XPath expression evaluates to true or if a matching node is found |
Date/time functions
Function | Description |
---|---|
add_months | Add months to date |
date_add | Add days to date |
date_format | Modify date format |
date_sub | Subtract days from date |
date_trunc | Returns the date truncated to the specified unit |
datediff | Returns the difference between dates in days |
day , dayofmonth | Returns the day of the month |
dayofweek | Returns the day of week (1-7) |
dayofyear | Returns the day of year |
from_unixtime | Returns date in UNIX® time |
from_utc_timestamp | Returns date in UTC time |
hour | Returns the hour of the input |
last_day | Returns the last day of the month that the date belongs to |
minute | Returns the minute of the input |
month | Returns the month of the input |
months_between | Number of months between |
next_day | Returns the first day later than the input |
quarter | Returns the quarter of the input |
second | Returns the second of the string |
to_date | Converts the string to a date. Note: The string must be in the format yyyy-mm-ddTHH24:MM:SS . |
to_timestamp | Converts the string to a timestamp. Note: The string must be in the format yyyy-mm-ddTHH24:MM:SS . |
to_unix_timestamp | Converts the string to a UNIX® timestamp |
to_utc_timestamp | Converts the string to a UTC timestamp |
trunc | Truncates the date |
unix_timestamp | Returns the UNIX® timestamp |
weekday | Day of the week (0-6) |
weekofyear | Returns the week of the year for a given date |
year | Returns the year of the string |
Arrays
Function | Description |
---|---|
array | Creates an array with the given elements |
array_contains | Checks if the array contains the value |
array_distinct | Removes duplicate values from the array |
array_except | Returns an array of the elements in the first array, but not the second |
array_intersect | Returns the intersection of the two arrays |
array_join | Joins two arrays together |
array_max | Returns the maximum value of the array |
array_min | Returns the minimum value of the array |
array_position | Returns the 1-based position of the element |
array_remove | Removes all elements that are equal to the element |
array_repeat | Creates an array containing the value counted times |
array_sort | Sorts the array |
array_union | Joins the array together, without any duplicates |
arrays_zip | Combines the values of given arrays with the values of the original collection at a given index |
cardinality | Return the size of the array |
element_at | Return the element at position |
explode | Separate elements of array into multiple rows, excluding null |
explode_outer | Separate elements of array into multiple rows, including null |
find_in_set | Returns the 1 based position of array |
flatten | Flattens an array of arrays |
inline | Separate array of structs into a table, excluding null |
inline_outer | Separate array of structs into a table, including null |
posexplode | Separate elements of an array into multiple rows with positions, excluding null |
reverse | Reverse elements of the array |
shuffle | Return a random permutation of the array |
slice | Subsets an array |
sort_array | Sort an array, given an order |
zip_with | Merges the two arrays into a single array, before applying a function |
Datatype casting functions
Function | Description |
---|---|
bigint | Change the data type to bigint |
binary | Change the data type to binary |
boolean | Change the data type to boolean |
type | Change the data type to the specified type |
date | Change the data type to date |
decimal | Change the data type to decimal |
double | Change the data type to double |
float | Change the data type to float |
int | Change the data type to int |
smallint | Change the data type to smallint |
str_to_map | Create a map from a string |
string | Change the data type to string |
struct | Create a struct |
tinyint | Change the data type to tinyint |
Conversion and formatting functions
Function | Description |
---|---|
ascii | Return the numeric (ASCII) value |
base64 | Change the argument to a base64 string |
bin | Change the argument to a binary value |
bit_length | Return the bit length |
char , chr | Return the ASCII character |
char_length , character_length | Return the string length |
crc32 | Returns the cyclic redundancy check value |
degrees | Convert radians to degrees |
format_number | Change the number’s format |
from_json , get_json_object | Get data from JSON |
hash | Return the hash value |
hex | Convert the argument to a hexadecimal value |
initcap | Changes the string to be title case |
lcase , lower | Changes the string to be all lowercase |
lpad | Pads the left side of a string |
map | Create a map |
map_from_arrays | Create a map from an array |
map_from_entries | Create a map from an array of structs |
md5 | Return the md5 value |
rpad | Pads the right side of a string |
rtrim | Removes trailing spaces |
sha , sha1 | Return the SHA1 value |
sha2 | Return the SHA2 value |
soundex | Return the soundex code |
stack | Separate values into rows |
substr , substring | Return the substring |
to_json | Returns a JSON string |
translate | Replace values within string |
trim | Remove leading and trailing characters |
ucase , upper | Change the string to be all uppercase |
unbase64 | Convert the base64 string to binary |
unhex | Convert the hexadecimal to binary |
uuid | Return a UUID |
Data evaluation
Function | Description |
---|---|
coalesce | Return the first non-null argument |
collect_list | Return a list of non-unique elements |
collect_set | Return a set of unique elements |
concat | Concatenation |
concat_ws | Concatenation with separator |
count | Returns the total count for rows |
decode | Decode using a character set |
elt | Return the n th input |
encode | Encode using a character set |
first , first_value | Returns the first value |
grouping | Indicates if a column is grouped |
grouping_id | Returns the level of grouping |
instr | Returns a 1-based index of character occurrence |
json_tuple | Returns a tuple from a JSON input |
lag , lead | Returns the value before the offset |
last , last_value | Returns the last value |
left | Returns the first n characters |
length | Returns the length of the string |
levenshtein | Returns the Levenshtein distance between strings |
locate , position | Returns the position of the first occurrence of a substring |
map_concat | Concatenate a map |
map_keys | Return a map’s keys |
map_values | Return a map’s values |
ntile | Divide rows into partitions |
nullif | Returns null if true |
nvl | Returns value if null |
nvl2 | Returns value if not null |
parse_url | Extracts part of a URL |
rank | Computes rank of a value |
regexp_extract | Extracts something that matches the regex |
regex_replace | Replaces something that matches the regex |
repeat | Returns a string that repeats |
replace | Replace all instances of a string |
rollup | Create a multi-dimensional rollup |
row_number | Assigns a unique row number |
schema_of_json | Returns the schema of the JSON |
sentences | Splits string into an array of words |
sequence | Generates an array of elements |
shiftleft | Signed bitwise shift left |
shiftright | Signed bitwise shift right |
shiftrightunsigned | Unsigned bitwise shift right |
size | Return the size of the array |
space | Return a string with n spaces |
split | Split string |
substring_index | Return index of substring |
window | Window |
xpath | Parse XML nodes |
xpath_double , xpath_number | Parse XML nodes for double |
xpath_float | Parse XML nodes for float |
xpath_int | Parse XML nodes for integer |
xpath_long | Parse XML nodes for long |
xpath_short | Parse XML nodes for short integer |
xpath_string | Parse XML nodes for string |