Bitwise Functions¶
This page lists all bitwise functions available in Spark SQL.
&¶
expr1 & expr2 - Returns the result of bitwise AND of expr1 and expr2.
Examples:
> SELECT 3 & 5;
1
Since: 1.4.0
<<¶
base << exp - Bitwise left shift.
Examples:
> 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
>>¶
base >> expr - Bitwise (signed) right shift.
Examples:
> 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:
> 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:
> SELECT 3 ^ 5;
6
Since: 1.4.0
bit_count¶
bit_count(expr) - Returns the number of bits that are set in the argument expr as an unsigned 64-bit integer, or NULL if the argument is NULL.
Examples:
> SELECT bit_count(0);
0
Since: 3.0.0
bit_get¶
bit_get(expr, pos) - Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative.
Examples:
> SELECT bit_get(11, 0);
1
> SELECT bit_get(11, 2);
0
Since: 3.2.0
getbit¶
getbit(expr, pos) - Returns the value of the bit (0 or 1) at the specified position. The positions are numbered from right to left, starting at zero. The position argument cannot be negative.
Examples:
> SELECT getbit(11, 0);
1
> SELECT getbit(11, 2);
0
Since: 3.2.0
shiftleft¶
base shiftleft exp - Bitwise left shift.
Examples:
> SELECT shiftleft(2, 1);
4
> SELECT 2 << 1;
4
Note:
<< operator is added in Spark 4.0.0 as an alias for shiftleft.
Since: 1.5.0
shiftright¶
base shiftright expr - Bitwise (signed) right shift.
Examples:
> SELECT shiftright(4, 1);
2
> SELECT 4 >> 1;
2
Note:
>> operator is added in Spark 4.0.0 as an alias for shiftright.
Since: 1.5.0
shiftrightunsigned¶
base shiftrightunsigned expr - Bitwise unsigned right shift.
Examples:
> SELECT shiftrightunsigned(4, 1);
2
> SELECT 4 >>> 1;
2
Note:
>>> operator is added in Spark 4.0.0 as an alias for shiftrightunsigned.
Since: 1.5.0
|¶
expr1 | expr2 - Returns the result of bitwise OR of expr1 and expr2.
Examples:
> SELECT 3 | 5;
7
Since: 1.4.0
~¶
~ expr - Returns the result of bitwise NOT of expr.
Examples:
> SELECT ~ 0;
-1
Since: 1.4.0