Starting from V3.1, Hologres supports various Spark-compatible functions by introducing the hg_spark_funcs extension. This topic describes the Spark-compatible functions in Hologres and provides usage examples.
Function | Feature |
Calculates the inverse hyperbolic cosine. | |
Calculates the inverse hyperbolic sine. | |
Calculates the hyperbolic tangent. | |
Checks whether a specified value x is within the specified range [min, max]. | |
Calculates the binary value. | |
Gets the number of bits after binary calculation. | |
Performs a bitwise logical AND operation. | |
Performs a bitwise logical NOT operation. | |
Performs a bitwise logical OR operation. | |
Performs a bitwise logical XOR operation. | |
Performs addition. This function reports an error when a numeric overflow occurs, instead of silently overflowing. | |
Performs division. This function reports an error when a numeric overflow occurs, instead of silently overflowing. | |
Performs multiplication. This function reports an error when a numeric overflow occurs, instead of silently overflowing. | |
Performs subtraction. This function reports an error when a numeric overflow occurs, instead of silently overflowing. | |
Checks whether parameter x contains parameter y. | |
Converts a string number from one base (source base) to another base (target base). | |
Calculates the hyperbolic cosine. | |
Calculates the CRC32 hash value. | |
Calculates the cosecant value. | |
Checks whether the first input parameter ends with the second input parameter. | |
Calculates the power of Euler's number (the base of natural logarithm) minus 1, which is "exp(x) - 1". | |
Finds the position of a specified string in a comma-separated array string and returns its 1-based index value. | |
Converts the number of seconds (BIGINT type) since the UNIX epoch (1970-01-01 00:00:00 UTC) to the specified time format. | |
Converts input data to the hexadecimal format. | |
Calculates the square root of the sum of squares of two values. | |
Checks whether a specified value exists in a specified array. | |
Checks whether data is Not a Number (NaN). | |
Calculates the LEVENSHTEIN distance (edit distance) between two strings, representing the minimum number of single-character edit operations required to transform one string into the other. | |
Calculates the base-10 logarithm of a specified value. | |
Calculates the natural logarithm of a specified value plus 1. | |
Calculates the base-2 logarithm of a specified value. | |
Checks whether a specified value might exist in a Bloom Filter. | |
Generates monotonically increasing and unique 64-bit integers. These integers are not consecutive. | |
Calculates the positive remainder of parameter x divided by y. | |
Calculates the modulus (remainder) in a division operation. | |
Calculates the closest integer. | |
Calculates the secant value. This function is a type of trigonometric function, represented as the reciprocal of the cosine of an angle. | |
Calculates the SHA-1 hash value of a string and converts the result to a hexadecimal string. | |
Calculates the SHA-2 hash value of a string (SHA-224, SHA-256, SHA-384, and SHA-512) and converts the result to a hexadecimal string. | |
Performs a left shift on the target value. | |
Performs a right shift on the target value. | |
Calculates the hyperbolic sine. | |
Generates the Soundex code of a string. | |
Checks whether the first parameter starts with the second parameter. | |
Gets the part of a string before the nth occurrence of a separator. | |
Converts a hexadecimal string to VARBIT. | |
Unescapes the encoded values of a URL. | |
Escapes through encoding. |
Install the extension
Before using Spark functions, you must execute the following statement in a database as a Superuser to install the required extension. This statement only needs to be executed once for each database. If you create a new database, you must execute the statement again.
CREATE extension hg_spark_funcs;This extension can only be created in the hg_spark_funcs schema. You cannot manually specify another schema.
Sample data
The Spark function parameter x in this topic does not support constant input parameters. All examples in this topic use the following sample data.
CREATE TABLE public.spark_test(a INT);
INSERT INTO public.spark_test VALUES (3);Spark functions
You can call functions in the hg_spark_funcs schema in one of the following two ways. Method 1 is recommended.
Method 1: Explicitly specify the schema (Recommended)
Call the function by adding thehg_spark_funcs.prefix to its name.SELECT hg_spark_funcs.ACOSH(a) FROM public.spark_test;Method 2: Set the search path
Addhg_spark_funcsto the search path of the current session. Then, you can call the function directly without a prefix.-- 1. Add hg_spark_funcs to the search path. SET search_path = 'hg_spark_funcs'; -- 2. Call the function directly. SELECT ACOSH(a) FROM public.spark_test;
For more information about Spark compatible functions, see Spark functions.
ACOSH
Description: Calculates the inverse hyperbolic cosine.
ACOSH(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.ACOSH(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT ACOSH(a) FROM public.spark_test;The following result is returned.
acosh ------------------ 1.762747174039086
ASINH
Description: Calculates the inverse hyperbolic sine.
ASINH(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.ASINH(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT ASINH(a) FROM public.spark_test;The following result is returned.
asinh ------------------ 1.8184464592320668
ATANH
Description: Calculates the hyperbolic tangent of a value.
ATANH(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.ATANH(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT ATANH(a) FROM public.spark_test;The following result is returned.
atanh ------- NaN
BETWEEN
Description: Checks whether a value x is within the specified [min, max] range.
hg_spark_funcs.BETWEEN(x, min, max)Note
Because BETWEEN is a Hologres keyword, you must add the hg_spark_funcs. prefix when you use this function.
Parameters
x: Required. The BIGINT type is supported.
min: Required. The minimum value of the specified range. The BIGINT type is supported.
max: Required. The maximum value of the specified range. The BIGINT type is supported.
Return value
Returns a value of the BOOLEAN type. If x is within the specified range, true is returned. Otherwise, false is returned.
Example
SELECT hg_spark_funcs.BETWEEN(a,2 ,4) FROM public.spark_test;The following result is returned.
between --------- t
BIN
Description: Converts a number to its binary string representation.
BIN(x)Parameters
x: Required. The BIGINT type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BIN(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BIN(a) FROM public.spark_test;The following result is returned.
bin ----- 11
BIT_COUNT
Description: Returns the number of bits set to 1 in the binary representation of a number.
BIT_COUNT(x)Parameters
x: Required. The BIGINT type is supported.
Return value
Returns a value of the INTEGER type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BIT_COUNT(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BIT_COUNT(a) FROM public.spark_test;The following result is returned.
bit_count ----------- 2
BITWISE_AND
Description: Performs a bitwise logical AND operation.
BITWISE_AND(x, y)Parameters
x and y: Required. The INTEGER type is supported.
Return value
Returns a value of the INTEGER type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BITWISE_AND(a, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BITWISE_AND(a, 2) FROM public.spark_test;The following result is returned.
bitwise_and ------------- 2
BITWISE_NOT
Description: Performs a bitwise logical NOT operation.
BITWISE_NOT(x)Parameters
x: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BITWISE_NOT(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BITWISE_NOT(a) FROM public.spark_test;The following result is returned.
bitwise_not ------------- -4
BITWISE_OR
Description: Performs a bitwise logical OR operation.
BITWISE_OR(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BITWISE_OR(a, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BITWISE_OR(a, 2) FROM public.spark_test;The following result is returned.
bitwise_or ------------ 3
BITWISE_XOR
Description: Performs a bitwise logical XOR operation.
BITWISE_XOR(x, y)Parameters
x and y: Required. The INTEGER type is supported.
Return value
Returns a value of the INTEGER type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.BITWISE_XOR(a, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT BITWISE_XOR(a, 2) FROM public.spark_test;The following result is returned.
bitwise_xor ------------- 1
CHECKED_ADD
Description: Performs addition and reports an error if a numeric overflow occurs. This prevents silent overflows.
CHECKED_ADD(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CHECKED_ADD(a, 2147483647) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CHECKED_ADD(a, 2147483647) FROM public.spark_test;The following result is returned.
--Part of the error message is as follows. ERROR: internal error: Run func: spark_checked_add fails with Exception: VeloxUserError
CHECKED_DIVIDE
Description: Performs division and reports an error if a numeric overflow occurs. This prevents silent overflows.
CHECKED_DIVIDE(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CHECKED_DIVIDE(a, 1/2147483647) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CHECKED_DIVIDE(a, 1/2147483647) FROM public.spark_test;The following result is returned.
--Part of the error message is as follows. ERROR: internal error: Run func: spark_checked_divide fails with Exception: VeloxUserError
CHECKED_MULTIPLY
Description: Performs multiplication and reports an error if a numeric overflow occurs. This prevents silent overflows.
CHECKED_MULTIPLY(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CHECKED_MULTIPLY(a, 2147483647) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CHECKED_MULTIPLY(a, 2147483647) FROM public.spark_test;The following result is returned.
--Part of the error message is as follows. ERROR: internal error: Run func: spark_checked_multiply fails with Exception: VeloxUserError
CHECKED_SUBTRACT
Description: Performs subtraction and reports an error if a numeric overflow occurs. This prevents silent overflows.
CHECKED_SUBTRACT(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CHECKED_SUBTRACT(a, -2147483647) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CHECKED_SUBTRACT(a, -2147483647) FROM public.spark_test;The following result is returned.
--Part of the error message is as follows. ERROR: internal error: Run func: spark_checked_subtract fails with Exception: VeloxUserError
CONTAINS
Description: Checks whether string x contains string y.
CONTAINS(x, y)Parameters
x and y: Required. The TEXT type is supported.
Return value
Returns a value of the BOOLEAN type. If x contains y, true is returned. Otherwise, false is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CONTAINS(a::text, '3') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CONTAINS(a::text, '3') FROM public.spark_test;The following result is returned.
contains ---------- t
CONV
Description: Converts a string that represents a number from a source base to a target base.
CONV(x, n, m)Parameters
x: Required. A string number. The TEXT type is supported.
n: Required. The source base. The INTEGER type is supported.
m: Required. The target base. The INTEGER type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CONV(a::text, 10, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CONV(a::text, 10, 2) FROM public.spark_test;The following result is returned.
conv ------ 11
COSH
Description: Calculates the hyperbolic cosine.
COSH(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.COSH(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT COSH(a) FROM public.spark_test;The following result is returned.
cosh ------------------ 10.0676619957778
CRC32
Description: Calculates the 32-bit cyclic redundancy check (CRC32) hash value.
CRC32(x)Parameters
x: Required. The BYTEA type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CRC32(hg_spark_funcs.bin(a)::bytea) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CRC32(bin(a)::bytea) FROM public.spark_test;The following result is returned.
crc32 ------------ 3596227959
CSC
Description: Calculates the cosecant value.
CSC(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.CSC(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT CSC(a) FROM public.spark_test;The following result is returned.
csc ------------------ 7.08616739573719
ENDSWITH
Description: Checks whether string x ends with string y.
ENDSWITH(x, y)Parameters
x and y: Required. The TEXT type is supported.
Return value
Returns a value of the BOOLEAN type. If string x ends with string y, true is returned. Otherwise, false is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.ENDSWITH(concat(a, 'hologres'), 'gres') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT ENDSWITH(concat(a, 'hologres'), 'gres') FROM public.spark_test;The following result is returned.
endswith ---------- t
EXPM1
Description: Calculates exp(x) - 1, where exp(x) is Euler's number raised to the power of x.
EXPM1(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.EXPM1(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT EXPM1(a) FROM public.spark_test;The following result is returned.
expm1 ------------------ 19.0855369231877
FIND_IN_SET
Description: Returns the 1-based index of a string within a comma-separated list of strings.
FIND_IN_SET(x, y)Parameters
x and y: Required. The TEXT type is supported.
Return value
Returns a value of the INTEGER type. If the specified string is not found, 0 is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.FIND_IN_SET(a::text, 'a,b,c,2') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT FIND_IN_SET(a::text, 'a,b,c,2') FROM public.spark_test;The following result is returned.
find_in_set ------------- 4
FROM_UNIXTIME
Description: Converts the number of seconds since the UNIX epoch (1970-01-01 00:00:00 UTC) to a string in the specified format.
FROM_UNIXTIME(x, y)Parameters
x: Required. The number of seconds. The BIGINT type is supported.
y: Required. The time format. The TEXT type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.FROM_UNIXTIME(a, 'yyyy-MM-dd HH:mm:ss') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT FROM_UNIXTIME(a, 'yyyy-MM-dd HH:mm:ss') FROM public.spark_test;The following result is returned.
from_unixtime --------------------- 1970-01-01 00:00:03
HEX
Description: Converts a number to its hexadecimal string representation.
HEX(x)Parameters
x: Required. The BIGINT type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.HEX(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT HEX(a) FROM public.spark_test;The following result is returned.
hex ----- 3
HYPOT
Description: Calculates the square root of the sum of squares of two values.
HYPOT(x, y)Parameters
x and y: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.HYPOT(a, 4) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT HYPOT(a, 4) FROM public.spark_test;The following result is returned.
hypot ------- 5
IN
Description: Checks whether a value exists in an array.
IN(x, y)Parameters
x: Required. The BIGINT type is supported.
y: Required. The target array. The BIGINT[] type is supported.
Return value
Returns a value of the BOOLEAN type. If the array y contains the value x, true is returned. Otherwise, false is returned.
Example
SELECT hg_spark_funcs.IN(a, ARRAY[2,5,3]) FROM public.spark_test;The following result is returned.
in ---- t
ISNAN
Description: Checks whether a value is Not a Number (NaN).
ISNAN(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the BOOLEAN type. If the value of x is NaN, true is returned. Otherwise, false is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.ISNAN(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT ISNAN(a) FROM public.spark_test;The following result is returned.
isnan ------- f
LEVENSHTEIN
Description: Calculates the Levenshtein distance, also known as edit distance, between two strings. The Levenshtein distance is the minimum number of single-character edits required to change one string into the other.
LEVENSHTEIN(x, y)Parameters
x and y: Required. The TEXT type is supported.
Return value
Returns a value of the INTEGER type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.LEVENSHTEIN(a::text, 'hologres') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT LEVENSHTEIN(a::text, 'hologres') FROM public.spark_test;The following result is returned.
levenshtein ------------- 8
LOG10
Description: Calculates the base-10 logarithm (decimal logarithm) of a value.
LOG10(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.LOG10(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT LOG10(a) FROM public.spark_test;The following result is returned.
log10 ------------------- 0.477121254719662
LOG1P
Description: Calculates the natural logarithm of a value plus 1.
LOG1P(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.LOG1P(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT LOG1P(a) FROM public.spark_test;The following result is returned.
log1p ------------------ 1.38629436111989
LOG2
Description: Calculates the base-2 logarithm (binary logarithm) of a value.
LOG2(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.LOG2(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT LOG2(a) FROM public.spark_test;The following result is returned.
log2 ------------------ 1.58496250072116
MIGHT_CONTAIN
Description: Checks whether a value might exist in a Bloom filter.
MIGHT_CONTAIN(x, y)Parameters
x: Required. The BYTEA type is supported.
y: Required. The BIGINT type is supported.
Return value
Returns a value of the BOOLEAN type. If the value might exist in the Bloom filter, true is returned. Otherwise, false is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.MIGHT_CONTAIN(a::text::bytea, 3) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT MIGHT_CONTAIN(a::text::bytea, 3) FROM public.spark_test;The following result is returned.
might_contain --------------- f
MONOTONICALLY_INCREASING_ID
Description: Generates monotonically increasing and unique 64-bit integers. These integers are not consecutive.
MONOTONICALLY_INCREASING_ID()Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.MONOTONICALLY_INCREASING_ID() FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT MONOTONICALLY_INCREASING_ID() FROM public.spark_test;The following result is returned.
monotonically_increasing_id ----------------------------- 0
PMOD
Description: Calculates the positive remainder of x divided by y.
PMOD(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.PMOD(a, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT PMOD(a, 2) FROM public.spark_test;The following result is returned.
pmod ------ 1
REMAINDER
Description: Calculates the remainder of x divided by y.
REMAINDER(x, y)Parameters
x and y: Required. The BIGINT type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.REMAINDER(a, 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT REMAINDER(a, 2) FROM public.spark_test;The following result is returned.
remainder ----------- 1
RINT
Description: Returns the closest integer to a value.
RINT(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.RINT(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT RINT(a) FROM public.spark_test;The following result is returned.
rint ------ 3
SEC
Description: Calculates the secant value. This is a trigonometric function that returns the reciprocal of the cosine of an angle.
SEC(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SEC(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SEC(a) FROM public.spark_test;The following result is returned.
sec ------------------- -1.01010866590799
SHA1
Description: Calculates the Secure Hash Algorithm 1 (SHA-1) hash of a binary string and returns the result as a hexadecimal string.
SHA1(x)Parameters
x: Required. The BYTEA type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SHA1(a::text::bytea) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SHA1(a::text::bytea) FROM public.spark_test;The following result is returned.
sha1 ------------------------------------------ 77de68daecd823babbb58edb1c8e14d7106e83bb
SHA2
Description: Calculates the SHA-2 hash of a binary string (SHA-224, SHA-256, SHA-384, or SHA-512) and returns the result as a hexadecimal string.
SHA2(x, y)Parameters
x: Required. The BYTEA type is supported.
y: Required. The INTEGER type is supported.
Return value
Returns a value of the TEXT type.
Note
Unsupported bit lengths return NULL.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SHA2(a::text::bytea, 3) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SHA2(a::text::bytea, 3) FROM public.spark_test;The following result is returned.
sha2 ------ NaN
SHIFTLEFT
Description: Performs a bitwise left shift on a value.
SHIFTLEFT(x, y)Parameters
x: Required. The value to be shifted. The BIGINT type is supported.
y: Required. The number of bits to shift the value to the left. The INTEGER type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SHIFTLEFT(a, 1) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SHIFTLEFT(a, 1) FROM public.spark_test;The following result is returned.
shiftleft ----------- 6
SHIFTRIGHT
Description: Performs a bitwise right shift on a value.
SHIFTRIGHT(x, y)Parameters
x: Required. The value to be shifted. The BIGINT type is supported.
y: Required. The number of bits to shift the value to the right. The INTEGER type is supported.
Return value
Returns a value of the BIGINT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SHIFTRIGHT(a, 1) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SHIFTRIGHT(a, 1) FROM public.spark_test;The following result is returned.
shiftright ------------ 1
SINH
Description: Calculates the hyperbolic sine.
SINH(x)Parameters
x: Required. The DOUBLE PRECISION type is supported.
Return value
Returns a value of the DOUBLE PRECISION type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SINH(a) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SINH(a) FROM public.spark_test;The following result is returned.
sinh ------------------ 10.0178749274099
SOUNDEX
Description: Returns the Soundex code of a string.
SOUNDEX(x)Parameters
x: Required. The TEXT type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SOUNDEX(concat('holo', a)) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SOUNDEX(concat('holo', a)) FROM public.spark_test;The following result is returned.
soundex --------- H400
STARTSWITH
Description: Checks whether string x starts with string y.
STARTSWITH(x, y)Parameters
x and y: Required. The TEXT type is supported.
Return value
Returns a value of the BOOLEAN type. If string x starts with string y, true is returned. Otherwise, false is returned.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.STARTSWITH(concat(a, 'hologres'), 'gres') FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT STARTSWITH(concat(a, 'hologres'), 'gres') FROM public.spark_test;The following result is returned.
startswith ------------ f
SUBSTRING_INDEX
Description: Returns the substring from a string before the n-th occurrence of a separator.
SUBSTRING_INDEX(x, y, n)Parameters
x: Required. The source string. The TEXT type is supported.
y: Required. The separator. The TEXT type is supported.
n: Required. The number of occurrences of the separator. The INTEGER type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.SUBSTRING_INDEX(concat(a, 'hologres'), 'o', 2) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT SUBSTRING_INDEX(concat(a, 'hologres'), 'o', 2) FROM public.spark_test;The following result is returned.
substring_index ----------------- 3hol
UNHEX
Description: Converts a hexadecimal string to its binary representation.
UNHEX(x)Parameters
x: Required. The TEXT type is supported.
Return value
Returns a value of the TEXT type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.UNHEX(a::text) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT UNHEX(a::text) FROM public.spark_test;The following result is returned.
unhex ------- \x03
URL_DECODE
Description: Decodes a URL-encoded string.
URL_DECODE(x)Parameters
x: Required. The VARCHAR type is supported.
Return value
Returns a value of the VARCHAR type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.URL_DECODE(hg_spark_funcs.URL_ENCODE(CONCAT('www.','Chinese',a,'.com'))) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT URL_DECODE(URL_ENCODE(CONCAT('www.','Chinese',a,'.com'))) FROM public.spark_test;The following result is returned.
url_decode --------------- www.chinese3.com
URL_ENCODE
Description: Encodes a string into a URL-safe format.
URL_ENCODE(x)Parameters
x: Required. The VARCHAR type is supported.
Return value
Returns a value of the VARCHAR type.
Example
-- Method 1: Direct call (Recommended) SELECT hg_spark_funcs.URL_ENCODE(CONCAT('www.','Chinese',a,'.com')) FROM public.spark_test; -- Method 2: Set the search path and then call the function SET search_path = 'hg_spark_funcs'; SELECT URL_ENCODE(CONCAT('www.','Chinese',a,'.com')) FROM public.spark_test;The following result is returned.
url_encode ----------------------------- www.%E4%B8%AD%E6%96%873.com