DataFusion Functions

This page is generated from the Apache DataFusion project’s documents:

Scalar Functions

Math Functions

abs

Returns the absolute value of a number.

1. abs(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
acos

Returns the arc cosine or inverse cosine of a number.

1. acos(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
acosh

Returns the area hyperbolic cosine or inverse hyperbolic cosine of a number.

1. acosh(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
asin

Returns the arc sine or inverse sine of a number.

1. asin(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
asinh

Returns the area hyperbolic sine or inverse hyperbolic sine of a number.

1. asinh(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
atan

Returns the arc tangent or inverse tangent of a number.

1. atan(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
atanh

Returns the area hyperbolic tangent or inverse hyperbolic tangent of a number.

1. atanh(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
atan2

Returns the arc tangent or inverse tangent of expression_y / expression_x.

1. atan2(expression_y, expression_x)
Arguments
  • expression_y: First numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression_x: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
cbrt

Returns the cube root of a number.

1. cbrt(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
ceil

Returns the nearest integer greater than or equal to a number.

1. ceil(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
cos

Returns the cosine of a number.

1. cos(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
cosh

Returns the hyperbolic cosine of a number.

1. cosh(numeric_expression)
degrees

Converts radians to degrees.

1. degrees(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
exp

Returns the base-e exponential of a number.

1. exp(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to use as the exponent. Can be a constant, column, or function, and any combination of arithmetic operators.
factorial

Factorial. Returns 1 if value is less than 2.

1. factorial(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
floor

Returns the nearest integer less than or equal to a number.

1. floor(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
gcd

Returns the greatest common divisor of expression_x and expression_y. Returns 0 if both inputs are zero.

1. gcd(expression_x, expression_y)
Arguments
  • expression_x: First numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression_y: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
isnan

Returns true if a given number is +NaN or -NaN otherwise returns false.

1. isnan(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
iszero

Returns true if a given number is +0.0 or -0.0 otherwise returns false.

1. iszero(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
lcm

Returns the least common multiple of expression_x and expression_y. Returns 0 if either input is zero.

1. lcm(expression_x, expression_y)
Arguments
  • expression_x: First numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression_y: Second numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
ln

Returns the natural logarithm of a number.

1. ln(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
log

Returns the base-x logarithm of a number. Can either provide a specified base, or if omitted then takes the base-10 of a number.

1. log(base, numeric_expression)
2. log(numeric_expression)
Arguments
  • base: Base numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
log10

Returns the base-10 logarithm of a number.

1. log10(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
log2

Returns the base-2 logarithm of a number.

1. log2(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
nanvl

Returns the first argument if it’s not NaN. Returns the second argument otherwise.

1. nanvl(expression_x, expression_y)
Arguments
  • expression_x: Numeric expression to return if it’s not NaN. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression_y: Numeric expression to return if the first expression is NaN. Can be a constant, column, or function, and any combination of arithmetic operators.
pi

Returns an approximate value of π.

1. pi()
power

Returns a base expression raised to the power of an exponent.

1. power(base, exponent)
Arguments
  • base: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • exponent: Exponent numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
Aliases
  • pow
pow

Alias of power.

radians

Converts degrees to radians.

1. radians(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
random

Returns a random float value in the range [0, 1). The random seed is unique to each row.

1. random()
round

Rounds a number to the nearest integer.

1. round(numeric_expression[, decimal_places])
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • decimal_places: Optional. The number of decimal places to round to. Defaults to 0.
signum

Returns the sign of a number. Negative numbers return -1. Zero and positive numbers return 1.

1. signum(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
sin

Returns the sine of a number.

1. sin(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
sinh

Returns the hyperbolic sine of a number.

1. sinh(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
sqrt

Returns the square root of a number.

1. sqrt(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
tan

Returns the tangent of a number.

1. tan(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
tanh

Returns the hyperbolic tangent of a number.

1. tanh(numeric_expression)
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
trunc

Truncates a number to a whole number or truncated to the specified decimal places.

1. trunc(numeric_expression[, decimal_places])
Arguments
  • numeric_expression: Numeric expression to operate on. Can be a constant, column, or function, and any combination of arithmetic operators.
  • decimal_places: Optional. The number of decimal places to truncate to. Defaults to 0 (truncate to a whole number). If decimal_places is a positive integer, truncates digits to the right of the decimal point. If decimal_places is a negative integer, replaces digits to the left of the decimal point with 0.

Conditional Functions

coalesce

Returns the first of its arguments that is not null. Returns null if all arguments are null. This function is often used to substitute a default value for null values.

1. coalesce(expression1[, ..., expression_n])
Arguments
  • expression1, expression_n: Expression to use if previous expressions are null. Can be a constant, column, or function, and any combination of arithmetic operators. Pass as many expression arguments as necessary.
nullif

Returns null if expression1 equals expression2; otherwise it returns expression1. This can be used to perform the inverse operation of coalesce.

1. nullif(expression1, expression2)
Arguments
  • expression1: Expression to compare and return if equal to expression2. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression2: Expression to compare to expression1. Can be a constant, column, or function, and any combination of arithmetic operators.
nvl

Returns expression2 if expression1 is NULL; otherwise it returns expression1.

1. nvl(expression1, expression2)
Arguments
  • expression1: return if expression1 not is NULL. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression2: return if expression1 is NULL. Can be a constant, column, or function, and any combination of arithmetic operators.
nvl2

Returns expression2 if expression1 is not NULL; otherwise it returns expression3.

1. nvl2(expression1, expression2, expression3)
Arguments
  • expression1: conditional expression. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression2: return if expression1 is not NULL. Can be a constant, column, or function, and any combination of arithmetic operators.
  • expression3: return if expression1 is NULL. Can be a constant, column, or function, and any combination of arithmetic operators.
ifnull

Alias of nvl.

String Functions

ascii

Returns the ASCII value of the first character in a string.

1. ascii(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: chr

bit_length

Returns the bit length of a string.

1. bit_length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: length, octet_length

btrim

Trims the specified trim string from the start and end of a string. If no trim string is provided, all whitespace is removed from the start and end of the input string.

1. btrim(str[, trim_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • trim_str: String expression to trim from the beginning and end of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. Default is whitespace characters.

Related functions: ltrim, rtrim

Aliases
  • trim
char_length

Alias of length.

character_length

Alias of length.

concat

Concatenates multiple strings together.

1. concat(str[, ..., str_n])
Arguments
  • str: String expression to concatenate. Can be a constant, column, or function, and any combination of string operators.
  • str_n: Subsequent string column or literal string to concatenate.

Related functions: concat_ws

concat_ws

Concatenates multiple strings together with a specified separator.

1. concat(separator, str[, ..., str_n])
Arguments
  • separator: Separator to insert between concatenated strings.
  • str: String expression to concatenate. Can be a constant, column, or function, and any combination of string operators.
  • str_n: Subsequent string column or literal string to concatenate.

Related functions: concat

chr

Returns the character with the specified ASCII or Unicode code value.

1. chr(expression)
Arguments
  • expression: Expression containing the ASCII or Unicode code value to operate on. Can be a constant, column, or function, and any combination of arithmetic or string operators.

Related functions: ascii

ends_with

Tests if a string ends with a substring.

1. ends_with(str, substr)
Arguments
  • str: String expression to test. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring to test for.
initcap

Capitalizes the first character in each word in the input string. Words are delimited by non-alphanumeric characters.

1. initcap(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: lower, upper

instr

Alias of strpos.

Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to search for. Can be a constant, column, or function, and any combination of string operators.
left

Returns a specified number of characters from the left side of a string.

1. left(str, n)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of characters to return.

Related functions: right

length

Returns the number of characters in a string.

1. length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
Aliases
  • char_length
  • character_length

Related functions: bit_length, octet_length

lower

Converts a string to lower-case.

1. lower(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: initcap, upper

lpad

Pads the left side of a string with another string to a specified string length.

1. lpad(str, n[, padding_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: String length to pad to.
  • padding_str: String expression to pad with. Can be a constant, column, or function, and any combination of string operators. Default is a space.

Related functions: rpad

ltrim

Trims the specified trim string from the beginning of a string. If no trim string is provided, all whitespace is removed from the start of the input string.

1. ltrim(str[, trim_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • trim_str: String expression to trim from the beginning of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. Default is whitespace characters.

Related functions: btrim, rtrim

octet_length

Returns the length of a string in bytes.

1. octet_length(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: bit_length, length

repeat

Returns a string with an input string repeated a specified number.

1. repeat(str, n)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of times to repeat the input string.
replace

Replaces all occurrences of a specified substring in a string with a new substring.

1. replace(str, substr, replacement)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to replace in the input string. Can be a constant, column, or function, and any combination of string operators.
  • replacement: Replacement substring expression. Can be a constant, column, or function, and any combination of string operators.
reverse

Reverses the character order of a string.

1. reverse(str)
Arguments
  • str: String expression to repeat. Can be a constant, column, or function, and any combination of string operators.

Returns a specified number of characters from the right side of a string.

1. right(str, n)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: Number of characters to return.

Related functions: left

rpad

Pads the right side of a string with another string to a specified string length.

1. rpad(str, n[, padding_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • n: String length to pad to.
  • padding_str: String expression to pad with. Can be a constant, column, or function, and any combination of string operators. Default is a space.

Related functions: lpad

rtrim

Trims the specified trim string from the end of a string. If no trim string is provided, all whitespace is removed from the end of the input string.

1. rtrim(str[, trim_str])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • trim_str: String expression to trim from the end of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. Default is whitespace characters.

Related functions: btrim, ltrim

split_part

Splits a string based on a specified delimiter and returns the substring in the specified position.

1. split_part(str, delimiter, pos)
Arguments
  • str: String expression to spit. Can be a constant, column, or function, and any combination of string operators.
  • delimiter: String or character to split on.
  • pos: Position of the part to return.
starts_with

Tests if a string starts with a substring.

1. starts_with(str, substr)
Arguments
  • str: String expression to test. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring to test for.
strpos

Returns the starting position of a specified substring in a string. Positions begin at 1. If the substring does not exist in the string, the function returns 0.

1. strpos(str, substr)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • substr: Substring expression to search for. Can be a constant, column, or function, and any combination of string operators.
Aliases
  • instr
substr

Extracts a substring of a specified number of characters from a specific starting position in a string.

1. substr(str, start_pos[, length])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • start_pos: Character position to start the substring at. The first character in the string has a position of 1.
  • length: Number of characters to extract. If not specified, returns the rest of the string after the start position.
Aliases
  • substring
substring

Alias of substr.

translate

Translates characters in a string to specified translation characters.

1. translate(str, chars, translation)
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • chars: Characters to translate.
  • translation: Translation characters. Translation characters replace only characters at the same position in the chars string.
to_hex

Converts an integer to a hexadecimal string.

1. to_hex(int)
Arguments
  • int: Integer expression to convert. Can be a constant, column, or function, and any combination of arithmetic operators.
trim

Alias of btrim.

upper

Converts a string to upper-case.

1. upper(str)
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.

Related functions: initcap, lower

uuid

Returns UUID v4 string value which is unique per row.

1. uuid()
overlay

Returns the string which is replaced by another string from the specified position and specified count length. For example, overlay('Txxxxas' placing 'hom' from 2 for 4) → Thomas

1. overlay(str PLACING substr FROM pos [FOR count])
Arguments
  • str: String expression to operate on.
  • substr: the string to replace part of str.
  • pos: the start position to replace of str.
  • count: the count of characters to be replaced from start position of str. If not specified, will use substr length instead.
levenshtein

Returns the Levenshtein distance between the two given strings. For example, levenshtein('kitten', 'sitting') = 3

1. levenshtein(str1, str2)
Arguments
  • str1: String expression to compute Levenshtein distance with str2.
  • str2: String expression to compute Levenshtein distance with str1.
substr_index

Returns the substring from str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. For example, substr_index('www.apache.org', '.', 1) = www, substr_index('www.apache.org', '.', -1) = org

1. substr_index(str, delim, count)
Arguments
  • str: String expression to operate on.
  • delim: the string to find in str to split str.
  • count: The number of times to search for the delimiter. Can be both a positive or negative number.
find_in_set

Returns a value in the range of 1 to N if the string str is in the string list strlist consisting of N substrings. For example, find_in_set('b', 'a,b,c,d') = 2

1. find_in_set(str, strlist)
Arguments
  • str: String expression to find in strlist.
  • strlist: A string list is a string composed of substrings separated by , characters.

Binary String Functions

encode

Encode binary data into a textual representation.

1. encode(expression, format)
Arguments
  • expression: Expression containing string or binary data
  • format: Supported formats are: base64, hex

Related functions: decode

decode

Decode binary data from textual representation in string.

1. decode(expression, format)
Arguments
  • expression: Expression containing encoded string data
  • format: Same arguments as encode

Related functions: encode

Regular Expression Functions

Apache DataFusion uses a PCRE-like regular expression syntax (minus support for several features including look-around and backreferences). The following regular expression functions are supported:

regexp_like

Returns true if a regular expression has at least one match in a string, false otherwise.

1. regexp_like(str, regexp[, flags])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to test against the string expression. Can be a constant, column, or function.
  • flags: Optional regular expression flags that control the behavior of the regular expression. The following flags are supported:
  • i: case-insensitive: letters match both upper and lower case
  • m: multi-line mode: ^ and $ match begin/end of line
  • s: allow . to match \n
  • R: enables CRLF mode: when multi-line mode is enabled, \r\n is used
  • U: swap the meaning of x* and x*?
Example
1. select regexp_like('Köln', '[a-zA-Z]ö[a-zA-Z]{2}');
2. +--------------------------------------------------------+
3. | regexp_like(Utf8("Köln"),Utf8("[a-zA-Z]ö[a-zA-Z]{2}")) |
4. +--------------------------------------------------------+
5. | true                                                   |
6. +--------------------------------------------------------+
7. SELECT regexp_like('aBc', '(b|d)', 'i');
8. +--------------------------------------------------+
9. | regexp_like(Utf8("aBc"),Utf8("(b|d)"),Utf8("i")) |
10. +--------------------------------------------------+
11. | true                                             |
12. +--------------------------------------------------+

Additional examples can be found here

regexp_match

Returns a list of regular expression matches in a string.

1. regexp_match(str, regexp[, flags])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to match against. Can be a constant, column, or function.
  • flags: Optional regular expression flags that control the behavior of the regular expression. The following flags are supported:
  • i: case-insensitive: letters match both upper and lower case
  • m: multi-line mode: ^ and $ match begin/end of line
  • s: allow . to match \n
  • R: enables CRLF mode: when multi-line mode is enabled, \r\n is used
  • U: swap the meaning of x* and x*?
Example
1. select regexp_match('Köln', '[a-zA-Z]ö[a-zA-Z]{2}');
2. +---------------------------------------------------------+
3. | regexp_match(Utf8("Köln"),Utf8("[a-zA-Z]ö[a-zA-Z]{2}")) |
4. +---------------------------------------------------------+
5. | [Köln]                                                  |
6. +---------------------------------------------------------+
7. SELECT regexp_match('aBc', '(b|d)', 'i');
8. +---------------------------------------------------+
9. | regexp_match(Utf8("aBc"),Utf8("(b|d)"),Utf8("i")) |
10. +---------------------------------------------------+
11. | [B]                                               |
12. +---------------------------------------------------+

Additional examples can be found here

regexp_replace

Replaces substrings in a string that match a regular expression.

1. regexp_replace(str, regexp, replacement[, flags])
Arguments
  • str: String expression to operate on. Can be a constant, column, or function, and any combination of string operators.
  • regexp: Regular expression to match against. Can be a constant, column, or function.
  • replacement: Replacement string expression. Can be a constant, column, or function, and any combination of string operators.
  • flags: Optional regular expression flags that control the behavior of the regular expression. The following flags are supported:
  • g: (global) Search globally and don’t return after the first match
  • i: case-insensitive: letters match both upper and lower case
  • m: multi-line mode: ^ and $ match begin/end of line
  • s: allow . to match \n
  • R: enables CRLF mode: when multi-line mode is enabled, \r\n is used
  • U: swap the meaning of x* and x*?
Example
1. SELECT regexp_replace('foobarbaz', 'b(..)', 'X\\1Y', 'g');
2. +------------------------------------------------------------------------+
3. | regexp_replace(Utf8("foobarbaz"),Utf8("b(..)"),Utf8("X\1Y"),Utf8("g")) |
4. +------------------------------------------------------------------------+
5. | fooXarYXazY                                                            |
6. +------------------------------------------------------------------------+
7. SELECT regexp_replace('aBc', '(b|d)', 'Ab\\1a', 'i');
8. +-------------------------------------------------------------------+
9. | regexp_replace(Utf8("aBc"),Utf8("(b|d)"),Utf8("Ab\1a"),Utf8("i")) |
10. +-------------------------------------------------------------------+
11. | aAbBac                                                            |
12. +-------------------------------------------------------------------+

Additional examples can be found here

position

Returns the position of substr in origstr (counting from 1). If substr does not appear in origstr, return 0.

1. position(substr in origstr)
Arguments
  • substr: The pattern string.
  • origstr: The model string.
contains

Return true if search_string is found within string.

1. contains(string, search_string)
Arguments
  • string: The pattern string.
  • search_string: The model string.

Time and Date Functions

now

Returns the current UTC timestamp.

The now() return value is determined at query time and will return the same timestamp, no matter when in the query plan the function executes.

1. now()
current_date

Returns the current UTC date.

The current_date() return value is determined at query time and will return the same date, no matter when in the query plan the function executes.

1. current_date()
Aliases
  • today
today

Alias of current_date.

current_time

Returns the current UTC time.

The current_time() return value is determined at query time and will return the same time, no matter when in the query plan the function executes.

1. current_time()
date_bin

Calculates time intervals and returns the start of the interval nearest to the specified timestamp. Use date_bin to downsample time series data by grouping rows into time-based “bins” or “windows” and applying an aggregate or selector function to each window.

For example, if you “bin” or “window” data into 15 minute intervals, an input timestamp of 2023-01-01T18:18:18Z will be updated to the start time of the 15 minute bin it is in: 2023-01-01T18:15:00Z.

1. date_bin(interval, expression, origin-timestamp)
Arguments
  • interval: Bin interval.
  • expression: Time expression to operate on. Can be a constant, column, or function.
  • origin-timestamp: Optional. Starting point used to determine bin boundaries. If not specified defaults 1970-01-01T00:00:00Z (the UNIX epoch in UTC).

The following intervals are supported:

  • nanoseconds
  • microseconds
  • milliseconds
  • seconds
  • minutes
  • hours
  • days
  • weeks
  • months
  • years
  • century
date_trunc

Truncates a timestamp value to a specified precision.

1. date_trunc(precision, expression)
Arguments
  • precision: Time precision to truncate to. The following precisions are supported:

  • year / YEAR

  • quarter / QUARTER
  • month / MONTH
  • week / WEEK
  • day / DAY
  • hour / HOUR
  • minute / MINUTE
  • second / SECOND
  • expression: Time expression to operate on

(本文超出站点单文档体积上限,已截断)