Spark函数



文章目录

!

! expr - Logical not.

Examples:

sql 复制代码
> SELECT ! true;
 false
> SELECT ! false;
 true
> SELECT ! NULL;
 NULL

Since: 1.0.0


!=

expr1 != expr2 - Returns true if expr1 is not equal to 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:

sql 复制代码
> SELECT 1 != 2;
 true
> SELECT 1 != '2';
 true
> SELECT true != NULL;
 NULL
> SELECT NULL != NULL;
 NULL

Since: 1.0.0


%

expr1 % expr2, or mod(expr1, expr2) - Returns the remainder after expr1/expr2.

Examples:

sql 复制代码
> SELECT 2 % 1.8;
 0.2
> SELECT MOD(2, 1.8);
 0.2

Since: 1.0.0


&

expr1 & expr2 - Returns the result of bitwise AND of expr1 and expr2.

Examples:

sql 复制代码
> SELECT 3 & 5;
 1

Since: 1.4.0


*

expr1 * expr2 - Returns expr1*expr2.

Examples:

sql 复制代码
> SELECT 2 * 3;
 6

Since: 1.0.0


+

expr1 + expr2 - Returns expr1+expr2.

Examples:

sql 复制代码
> SELECT 1 + 2;
 3

Since: 1.0.0


-

expr1 - expr2 - Returns expr1-expr2.

Examples:

sql 复制代码
> SELECT 2 - 1;
 1

Since: 1.0.0


/

expr1 / expr2 - Returns expr1/expr2. It always performs floating point division.

Examples:

sql 复制代码
> SELECT 3 / 2;
 1.5
> SELECT 2L / 2L;
 1.0

Since: 1.0.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:

sql 复制代码
> 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

Since: 1.0.0


<<

base << exp - Bitwise left shift.

Examples:

sql 复制代码
> SELECT shiftleft(2, 1);
 4
> SELECT 2 << 1;
 4

Note:

<< operator is added in Spark 4.0.0 as an alias for shiftleft.

Since: 4.0.0


<=

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:

sql 复制代码
> 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

Since: 1.0.0


<=>

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:

sql 复制代码
> SELECT 2 <=> 2;
 true
> SELECT 1 <=> '1';
 true
> SELECT true <=> NULL;
 false
> SELECT NULL <=> NULL;
 true

Since: 1.1.0


<>

expr1 != expr2 - Returns true if expr1 is not equal to 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:

sql 复制代码
> SELECT 1 != 2;
 true
> SELECT 1 != '2';
 true
> SELECT true != NULL;
 NULL
> SELECT NULL != NULL;
 NULL

Since: 1.0.0


=

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:

sql 复制代码
> SELECT 2 = 2;
 true
> SELECT 1 = '1';
 true
> SELECT true = NULL;
 NULL
> SELECT NULL = NULL;
 NULL

Since: 1.0.0


==

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:

sql 复制代码
> SELECT 2 == 2;
 true
> SELECT 1 == '1';
 true
> SELECT true == NULL;
 NULL
> SELECT NULL == NULL;
 NULL

Since: 1.0.0


>

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:

sql 复制代码
> 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

Since: 1.0.0


>=

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:

sql 复制代码
> 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

Since: 1.0.0


>>

base >> expr - Bitwise (signed) right shift.

Examples:

sql 复制代码
> SELECT shiftright(4, 1);
 2
> SELECT 4 >> 1;
 2

Note:

>> operator is added in Spark 4.0.0 as an alias for shiftright.

Since: 4.0.0


>>>

base >>> expr - Bitwise unsigned right shift.

Examples:

sql 复制代码
> SELECT shiftrightunsigned(4, 1);
 2
> SELECT 4 >>> 1;
 2

Note:

>>> operator is added in Spark 4.0.0 as an alias for shiftrightunsigned.

Since: 4.0.0


^

expr1 ^ expr2 - Returns the result of bitwise exclusive OR of expr1 and expr2.

Examples:

sql 复制代码
> SELECT 3 ^ 5;
 6

Since: 1.4.0


|

expr1 | expr2 - Returns the result of bitwise OR of expr1 and expr2.

Examples:

sql 复制代码
> SELECT 3 | 5;
 7

Since: 1.4.0


||

expr1 || expr2 - Returns the concatenation of expr1 and expr2.

Examples:

sql 复制代码
> SELECT 'Spark' || 'SQL';
 SparkSQL
> SELECT array(1, 2, 3) || array(4, 5) || array(6);
 [1,2,3,4,5,6]

Note:

|| for arrays is available since 2.4.0.

Since: 2.3.0


~

~ expr - Returns the result of bitwise NOT of expr.

Examples:

sql 复制代码
> SELECT ~ 0;
 -1

Since: 1.4.0


相关推荐
焦耳热科技前沿17 小时前
西华大学Adv. Sci.:超高温焦耳热冲击制备拓扑缺陷碳,用于催化碳纳米管可控生长
大数据·人工智能·能源·材料工程·电池
故乡de云17 小时前
Google Cloud与AWS大数据AI服务对比:2026年企业选型指南
大数据·人工智能·aws
IT 行者18 小时前
Spring Security 7 OAuth2 授权码分布式存储之Redis存储方案
redis·分布式·spring
米粒118 小时前
操作系统原理--处理机调度
大数据
数说星榆18118 小时前
在线高清泳道图制作工具 无水印 PC
大数据·人工智能·架构·机器人·流程图
潇凝子潇18 小时前
kafka之监控告警
分布式·kafka
老胡全房源系统18 小时前
2026年1月适合房产经纪人用的房产中介管理系统
大数据·人工智能·房产经纪人培训
杭州龙立智能科技19 小时前
专业的厂内运输车智能化厂家
大数据·人工智能·python
securitypaper19 小时前
2026年最新发布的 安全生产 行业标准 列表 下载
大数据·安全
Light6019 小时前
从“报告”到“能力”——构建智能化、可审计的数据治理闭环——领码 SPARK 数据质量平台白皮书
大数据·分布式·spark