!
! expr - Logical not.
%
expr1 % expr2 - Returns the remainder after expr1/expr2.
Examples:
> SELECT 2 % 1.8;
0.2
> SELECT MOD(2, 1.8);
0.2
&
expr1 & expr2 - Returns the result of bitwise AND of expr1 and expr2.
Examples:
> SELECT 3 & 5;
1
*
expr1 * expr2 - Returns expr1*expr2.
Examples:
> SELECT 2 * 3;
6
+
expr1 + expr2 - Returns expr1+expr2.
Examples:
> SELECT 1 + 2;
3
-
expr1 - expr2 - Returns expr1-expr2.
Examples:
> SELECT 2 - 1;
1
/
expr1 / expr2 - Returns expr1/expr2. It always performs floating point division.
Examples:
> SELECT 3 / 2;
1.5
> SELECT 2L / 2L;
1.0
<
expr1 < expr2 - Returns true if expr1 is less than expr2.
Arguments:
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.
Examples:
> SELECT 1 < 2;
true
> SELECT 1.1 < '1';
false
> SELECT to_date('2009-07-30 04:17:52') < to_date('2009-07-30 04:17:52');
false
> SELECT to_date('2009-07-30 04:17:52') < to_date('2009-08-01 04:17:52');
true
> SELECT 1 < NULL;
NULL
<=
expr1 <= expr2 - Returns true if expr1 is less than or equal to expr2.
Arguments:
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.
Examples:
> SELECT 2 <= 2;
true
> SELECT 1.0 <= '1';
true
> SELECT to_date('2009-07-30 04:17:52') <= to_date('2009-07-30 04:17:52');
true
> SELECT to_date('2009-07-30 04:17:52') <= to_date('2009-08-01 04:17:52');
true
> SELECT 1 <= NULL;
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.
Arguments:
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.
Examples:
> SELECT 2 <=> 2;
true
> SELECT 1 <=> '1';
true
> SELECT true <=> NULL;
false
> SELECT NULL <=> NULL;
true
=
expr1 = expr2 - Returns true if expr1 equals expr2, or false otherwise.
Arguments:
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.
Examples:
> SELECT 2 = 2;
true
> SELECT 1 = '1';
true
> SELECT true = NULL;
NULL
> SELECT NULL = NULL;
NULL
==
expr1 == expr2 - Returns true if expr1 equals expr2, or false otherwise.
Arguments:
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.
Examples:
> SELECT 2 == 2;
true
> SELECT 1 == '1';
true
> SELECT true == NULL;
NULL
> SELECT NULL == NULL;
NULL
>
expr1 > expr2 - Returns true if expr1 is greater than expr2.
Arguments:
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.
Examples:
> SELECT 2 > 1;
true
> SELECT 2 > '1.1';
true
> SELECT to_date('2009-07-30 04:17:52') > to_date('2009-07-30 04:17:52');
false
> SELECT to_date('2009-07-30 04:17:52') > to_date('2009-08-01 04:17:52');
false
> SELECT 1 > NULL;
NULL
>=
expr1 >= expr2 - Returns true if expr1 is greater than or equal to expr2.
Arguments:
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.
Examples:
> SELECT 2 >= 1;
true
> SELECT 2.0 >= '2.1';
false
> SELECT to_date('2009-07-30 04:17:52') >= to_date('2009-07-30 04:17:52');
true
> SELECT to_date('2009-07-30 04:17:52') >= to_date('2009-08-01 04:17:52');
false
> SELECT 1 >= NULL;
NULL
^
expr1 ^ expr2 - Returns the result of bitwise exclusive OR of expr1 and expr2.
Examples:
> SELECT 3 ^ 5;
2
abs
abs(expr) - Returns the absolute value of the numeric value.
Examples:
> SELECT abs(-1);
1
acos
acos(expr) - Returns the inverse cosine (a.k.a. arccosine) of expr if -1<=expr<=1 or NaN otherwise.
Examples:
> SELECT acos(1);
0.0
> SELECT acos(2);
NaN
add_months
add_months(start_date, num_months) - Returns the date that is num_months after start_date.
Examples:
> SELECT add_months('2016-08-31', 1);
2016-09-30
Since: 1.5.0
and
expr1 and expr2 - Logical AND.
approx_count_distinct
approx_count_distinct(expr[, relativeSD]) - Returns the estimated cardinality by HyperLogLog++. relativeSD defines the maximum estimation error allowed.
approx_percentile
approx_percentile(col, percentage [, accuracy]) - Returns the approximate percentile value of numeric column col at the given percentage. The value of percentage must be between 0.0 and 1.0. The accuracy parameter (default: 10000) is a positive numeric literal which controls approximation accuracy at the cost of memory. Higher value of accuracy yields better accuracy, 1.0/accuracy is the relative error of the approximation. When percentage 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 col at the given percentage array.
Examples:
> SELECT approx_percentile(10.0, array(0.5, 0.4, 0.1), 100);
[10.0,10.0,10.0]
> SELECT approx_percentile(10.0, 0.5, 100);
10.0
array
array(expr, ...) - Returns an array with the given elements.
Examples:
> SELECT array(1, 2, 3);
[1,2,3]
array_contains
array_contains(array, value) - Returns true if the array contains the value.
Examples:
> SELECT array_contains(array(1, 2, 3), 2);
true
ascii
ascii(str) - Returns the numeric value of the first character of str.
Examples:
> SELECT ascii('222');
50
> SELECT ascii(2);
50
asin
asin(expr) - Returns the inverse sine (a.k.a. arcsine) the arc sin of expr if -1<=expr<=1 or NaN otherwise.
Examples:
> SELECT asin(0);
0.0
> SELECT asin(2);
NaN
assert_true
assert_true(expr) - Throws an exception if expr is not true.
Examples:
> SELECT assert_true(0 < 1);
NULL
atan
atan(expr) - Returns the inverse tangent (a.k.a. arctangent).
Examples:
> SELECT atan(0);
0.0
atan2
atan2(expr1, expr2) - Returns the angle in radians between the positive x-axis of a plane and the point given by the coordinates (expr1, expr2).
Examples:
> SELECT atan2(0, 0);
0.0
avg
avg(expr) - Returns the mean calculated from values of a group.
base64
base64(bin) - Converts the argument from a binary bin to a base 64 string.
Examples:
> SELECT base64('Spark SQL');
U3BhcmsgU1FM
bigint
bigint(expr) - Casts the value expr to the target data type bigint.
bin
bin(expr) - Returns the string representation of the long value expr represented in binary.
Examples:
> SELECT bin(13);
1101
> SELECT bin(-13);
1111111111111111111111111111111111111111111111111111111111110011
> SELECT bin(13.3);
1101
binary
binary(expr) - Casts the value expr to the target data type binary.
bit_length
bit_length(expr) - Returns the bit length of string data or number of bits of binary data.
Examples:
> SELECT bit_length('Spark SQL');
72
boolean
boolean(expr) - Casts the value expr to the target data type boolean.
bround
bround(expr, d) - Returns expr rounded to d decimal places using HALF_EVEN rounding mode.
Examples:
> SELECT bround(2.5, 0);
2.0
cast
cast(expr AS type) - Casts the value expr to the target data type type.
Examples:
> SELECT cast('10' as int);
10
cbrt
cbrt(expr) - Returns the cube root of expr.
Examples:
> SELECT cbrt(27.0);
3.0
ceil
ceil(expr) - Returns the smallest integer not smaller than expr.
Examples:
> SELECT ceil(-0.1);
0
> SELECT ceil(5);
5
ceiling
ceiling(expr) - Returns the smallest integer not smaller than expr.
Examples:
> SELECT ceiling(-0.1);
0
> SELECT ceiling(5);
5
char
char(expr) - Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)
Examples:
> SELECT char(65);
A
char_length
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.
Examples:
> SELECT char_length('Spark SQL ');
10
> SELECT CHAR_LENGTH('Spark SQL ');
10
> SELECT CHARACTER_LENGTH('Spark SQL ');
10
character_length
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.
Examples:
> SELECT character_length('Spark SQL ');
10
> SELECT CHAR_LENGTH('Spark SQL ');
10
> SELECT CHARACTER_LENGTH('Spark SQL ');
10
chr
chr(expr) - Returns the ASCII character having the binary equivalent to expr. If n is larger than 256 the result is equivalent to chr(n % 256)
Examples:
> SELECT chr(65);
A
coalesce
coalesce(expr1, expr2, ...) - Returns the first non-null argument if exists. Otherwise, null.
Examples:
> SELECT coalesce(NULL, 1, NULL);
1
collect_list
collect_list(expr) - Collects and returns a list of non-unique elements.
collect_set
collect_set(expr) - Collects and returns a set of unique elements.
concat
concat(str1, str2, ..., strN) - Returns the concatenation of str1, str2, ..., strN.
Examples:
> SELECT concat('Spark', 'SQL');
SparkSQL
concat_ws
concat_ws(sep, [str | array(str)]+) - Returns the concatenation of the strings separated by sep.
Examples:
> SELECT concat_ws(' ', 'Spark', 'SQL');
Spark SQL
conv
conv(num, from_base, to_base) - Convert num from from_base to to_base.
Examples:
> SELECT conv('100', 2, 10);
4
> SELECT conv(-10, 16, -10);
-16
corr
corr(expr1, expr2) - Returns Pearson coefficient of correlation between a set of number pairs.
cos
cos(expr) - Returns the cosine of expr.
Examples:
> SELECT cos(0);
1.0
cosh
cosh(expr) - Returns the hyperbolic cosine of expr.
Examples:
> SELECT cosh(0);
1.0
cot
cot(expr) - Returns the cotangent of expr.
Examples:
> SELECT cot(1);
0.6420926159343306
count
count(*) - Returns the total number of retrieved rows, including rows containing null.
count(expr) - Returns the number of rows for which the supplied expression is non-null.
count(DISTINCT expr[, expr...]) - Returns the number of rows for which the supplied expression(s) are unique and non-null.
count_min_sketch
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 CountMinSketch before usage. Count-min sketch is a probabilistic data structure used for cardinality estimation using sub-linear space.
covar_pop
covar_pop(expr1, expr2) - Returns the population covariance of a set of number pairs.
covar_samp
covar_samp(expr1, expr2) - Returns the sample covariance of a set of number pairs.
crc32
crc32(expr) - Returns a cyclic redundancy check value of the expr as a bigint.
Examples:
> SELECT crc32('Spark');
1557323817
cube
cume_dist
cume_dist() - Computes the position of a value relative to all values in the partition.
current_database
current_database() - Returns the current database.
Examples:
> SELECT current_database();
default
current_date
current_date() - Returns the current date at the start of query evaluation.
Since: 1.5.0
current_timestamp
current_timestamp() - Returns the current timestamp at the start of query evaluation.
Since: 1.5.0
date
date(expr) - Casts the value expr to the target data type date.
date_add
date_add(start_date, num_days) - Returns the date that is num_days after start_date.
Examples:
> SELECT date_add('2016-07-30', 1);
2016-07-31
Since: 1.5.0
date_format
date_format(timestamp, fmt) - Converts timestamp to a value of string in the format specified by the date format fmt.
Examples:
> SELECT date_format('2016-04-08', 'y');
2016
Since: 1.5.0
date_sub
date_sub(start_date, num_days) - Returns the date that is num_days before start_date.
Examples:
> SELECT date_sub('2016-07-30', 1);
2016-07-29
Since: 1.5.0
date_trunc
date_trunc(fmt, ts) - Returns timestamp ts truncated to the unit specified by the format model fmt. fmt should be one of ["YEAR", "YYYY", "YY", "MON", "MONTH", "MM", "DAY", "DD", "HOUR", "MINUTE", "SECOND", "WEEK", "QUARTER"]
Examples:
> SELECT date_trunc('2015-03-05T09:32:05.359', 'YEAR');
2015-01-01T00:00:00
> SELECT date_trunc('2015-03-05T09:32:05.359', 'MM');
2015-03-01T00:00:00
> SELECT date_trunc('2015-03-05T09:32:05.359', 'DD');
2015-03-05T00:00:00
> SELECT date_trunc('2015-03-05T09:32:05.359', 'HOUR');
2015-03-05T09:00:00
Since: 2.3.0
datediff
datediff(endDate, startDate) - Returns the number of days from startDate to endDate.
Examples:
> SELECT datediff('2009-07-31', '2009-07-30');
1
> SELECT datediff('2009-07-30', '2009-07-31');
-1
Since: 1.5.0
day
day(date) - Returns the day of month of the date/timestamp.
Examples:
> SELECT day('2009-07-30');
30
Since: 1.5.0
dayofmonth
dayofmonth(date) - Returns the day of month of the date/timestamp.
Examples:
> SELECT dayofmonth('2009-07-30');
30
Since: 1.5.0
dayofweek
dayofweek(date) - Returns the day of the week for date/timestamp (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
Examples:
> SELECT dayofweek('2009-07-30');
5
Since: 2.3.0
dayofyear
dayofyear(date) - Returns the day of year of the date/timestamp.
Examples:
> SELECT dayofyear('2016-04-09');
100
Since: 1.5.0
decimal
decimal(expr) - Casts the value expr to the target data type decimal.
decode
decode(bin, charset) - Decodes the first argument using the second argument character set.
Examples:
> SELECT decode(encode('abc', 'utf-8'), 'utf-8');
abc
degrees
degrees(expr) - Converts radians to degrees.
Examples:
> SELECT degrees(3.141592653589793);
180.0
dense_rank
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.
double
double(expr) - Casts the value expr to the target data type double.
e
e() - Returns Euler's number, e.
Examples:
> SELECT e();
2.718281828459045
elt
elt(n, input1, input2, ...) - Returns the n-th input, e.g., returns input2 when n is 2.
Examples:
> SELECT elt(1, 'scala', 'java');
scala
encode
encode(str, charset) - Encodes the first argument using the second argument character set.
Examples:
> SELECT encode('abc', 'utf-8');
abc
spark sql 函数详见
https://spark.apache.org/docs/2.3.0/api/sql/#ltrim