Logical operators and functions

Operator/FunctionDescription
! or notLogical 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_overlapReturns the common elements
assert_trueAsserts if the expression is true
ifIf the expression evaluates to true, return the second expression. Otherwise, return the third expression.
ifnullIf the expression is null, it returns the second expression. Otherwise, it returns the first expression.
inReturns true if the first expression is in any of the subsequent expressions.
isnanReturns true if the value is not a number
isnotnullReturns true if the value is not null
isnullReturns true if the value is null
nanvlReturns the first expression if not a number, returns the second expression otherwise
orLogical or
whenWhen can be used to create branch conditions for comparison
xpath_booleanReturns true if the XPath expression evaluates to true or if a matching node is found

Date/time functions

FunctionDescription
add_monthsAdd months to date
date_addAdd days to date
date_formatModify date format
date_subSubtract days from date
date_truncReturns the date truncated to the specified unit
datediffReturns the difference between dates in days
day, dayofmonthReturns the day of the month
dayofweekReturns the day of week (1-7)
dayofyearReturns the day of year
from_unixtimeReturns date in UNIX® time
from_utc_timestampReturns date in UTC time
hourReturns the hour of the input
last_dayReturns the last day of the month that the date belongs to
minuteReturns the minute of the input
monthReturns the month of the input
months_betweenNumber of months between
next_dayReturns the first day later than the input
quarterReturns the quarter of the input
secondReturns the second of the string
to_dateConverts the string to a date. Note: The string must be in the format yyyy-mm-ddTHH24:MM:SS.
to_timestampConverts the string to a timestamp. Note: The string must be in the format yyyy-mm-ddTHH24:MM:SS.
to_unix_timestampConverts the string to a UNIX® timestamp
to_utc_timestampConverts the string to a UTC timestamp
truncTruncates the date
unix_timestampReturns the UNIX® timestamp
weekdayDay of the week (0-6)
weekofyearReturns the week of the year for a given date
yearReturns the year of the string

Arrays

FunctionDescription
arrayCreates an array with the given elements
array_containsChecks if the array contains the value
array_distinctRemoves duplicate values from the array
array_exceptReturns an array of the elements in the first array, but not the second
array_intersectReturns the intersection of the two arrays
array_joinJoins two arrays together
array_maxReturns the maximum value of the array
array_minReturns the minimum value of the array
array_positionReturns the 1-based position of the element
array_removeRemoves all elements that are equal to the element
array_repeatCreates an array containing the value counted times
array_sortSorts the array
array_unionJoins the array together, without any duplicates
arrays_zipCombines the values of given arrays with the values of the original collection at a given index
cardinalityReturn the size of the array
element_atReturn the element at position
explodeSeparate elements of array into multiple rows, excluding null
explode_outerSeparate elements of array into multiple rows, including null
find_in_setReturns the 1 based position of array
flattenFlattens an array of arrays
inlineSeparate array of structs into a table, excluding null
inline_outerSeparate array of structs into a table, including null
posexplodeSeparate elements of an array into multiple rows with positions, excluding null
reverseReverse elements of the array
shuffleReturn a random permutation of the array
sliceSubsets an array
sort_arraySort an array, given an order
zip_withMerges the two arrays into a single array, before applying a function

Datatype casting functions

FunctionDescription
bigintChange the data type to bigint
binaryChange the data type to binary
booleanChange the data type to boolean
typeChange the data type to the specified type
dateChange the data type to date
decimalChange the data type to decimal
doubleChange the data type to double
floatChange the data type to float
intChange the data type to int
smallintChange the data type to smallint
str_to_mapCreate a map from a string
stringChange the data type to string
structCreate a struct
tinyintChange the data type to tinyint

Conversion and formatting functions

FunctionDescription
asciiReturn the numeric (ASCII) value
base64Change the argument to a base64 string
binChange the argument to a binary value
bit_lengthReturn the bit length
char, chrReturn the ASCII character
char_length, character_lengthReturn the string length
crc32Returns the cyclic redundancy check value
degreesConvert radians to degrees
format_numberChange the number’s format
from_json, get_json_objectGet data from JSON
hashReturn the hash value
hexConvert the argument to a hexadecimal value
initcapChanges the string to be title case
lcase, lowerChanges the string to be all lowercase
lpadPads the left side of a string
mapCreate a map
map_from_arraysCreate a map from an array
map_from_entriesCreate a map from an array of structs
md5Return the md5 value
rpadPads the right side of a string
rtrimRemoves trailing spaces
sha, sha1Return the SHA1 value
sha2Return the SHA2 value
soundexReturn the soundex code
stackSeparate values into rows
substr, substringReturn the substring
to_jsonReturns a JSON string
translateReplace values within string
trimRemove leading and trailing characters
ucase, upperChange the string to be all uppercase
unbase64Convert the base64 string to binary
unhexConvert the hexadecimal to binary
uuidReturn a UUID

Data evaluation

FunctionDescription
coalesceReturn the first non-null argument
collect_listReturn a list of non-unique elements
collect_setReturn a set of unique elements
concatConcatenation
concat_wsConcatenation with separator
countReturns the total count for rows
decodeDecode using a character set
eltReturn the nth input
encodeEncode using a character set
first, first_valueReturns the first value
groupingIndicates if a column is grouped
grouping_idReturns the level of grouping
instrReturns a 1-based index of character occurrence
json_tupleReturns a tuple from a JSON input
lag, leadReturns the value before the offset
last, last_valueReturns the last value
leftReturns the first n characters
lengthReturns the length of the string
levenshteinReturns the Levenshtein distance between strings
locate, positionReturns the position of the first occurrence of a substring
map_concatConcatenate a map
map_keysReturn a map’s keys
map_valuesReturn a map’s values
ntileDivide rows into partitions
nullifReturns null if true
nvlReturns value if null
nvl2Returns value if not null
parse_urlExtracts part of a URL
rankComputes rank of a value
regexp_extractExtracts something that matches the regex
regex_replaceReplaces something that matches the regex
repeatReturns a string that repeats
replaceReplace all instances of a string
rollupCreate a multi-dimensional rollup
row_numberAssigns a unique row number
schema_of_jsonReturns the schema of the JSON
sentencesSplits string into an array of words
sequenceGenerates an array of elements
shiftleftSigned bitwise shift left
shiftrightSigned bitwise shift right
shiftrightunsignedUnsigned bitwise shift right
sizeReturn the size of the array
spaceReturn a string with n spaces
splitSplit string
substring_indexReturn index of substring
windowWindow
xpathParse XML nodes
xpath_double, xpath_numberParse XML nodes for double
xpath_floatParse XML nodes for float
xpath_intParse XML nodes for integer
xpath_longParse XML nodes for long
xpath_shortParse XML nodes for short integer
xpath_stringParse XML nodes for string