提交 7608cd28 authored 作者: Steve McLeod's avatar Steve McLeod

Added new BITGET function, that returns true if and only if a specified bit in a…

Added new BITGET function, that returns true if and only if a specified bit in a long is set. This helps simulate bit fields in H2, which is an approach I'm using to significantly shrink database size.
上级 425b21aa
...@@ -2796,6 +2796,17 @@ See also Java operator &. ...@@ -2796,6 +2796,17 @@ See also Java operator &.
BITAND(A, B) BITAND(A, B)
" "
"Functions (Numeric)","BITGET","
BITGET(long, int)
","
Returns true if and only if the first parameter has a bit set in the
position specified by the second parameter.
This method returns a boolean.
The second parameter is zero-indexed; the least significant bit has position 0.
","
BITGET(A, 1)
"
"Functions (Numeric)","BITOR"," "Functions (Numeric)","BITOR","
BITOR(long, long) BITOR(long, long)
"," ","
......
...@@ -21,9 +21,11 @@ Change Log ...@@ -21,9 +21,11 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <ul>
<li>Added BITGET function
</li>
<li>Fixed bug in FilePathRetryOnInterrupt that caused infinite loop <li>Fixed bug in FilePathRetryOnInterrupt that caused infinite loop
</li> </li>
<li>PR #389, Handle LocalTime with nanosecond resolution, patch by katzyn <li>PR #389, Handle LocalTime with nanosecond resolution, patch by katzyn
</li> </li>
<li>PR #382, Recover for "page store" H2 breaks LOBs consistency, patch by vitalus <li>PR #382, Recover for "page store" H2 breaks LOBs consistency, patch by vitalus
</li> </li>
......
...@@ -82,7 +82,8 @@ public class Function extends Expression implements FunctionCall { ...@@ -82,7 +82,8 @@ public class Function extends Expression implements FunctionCall {
ROUNDMAGIC = 22, SIGN = 23, SIN = 24, SQRT = 25, TAN = 26, ROUNDMAGIC = 22, SIGN = 23, SIN = 24, SQRT = 25, TAN = 26,
TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30, TRUNCATE = 27, SECURE_RAND = 28, HASH = 29, ENCRYPT = 30,
DECRYPT = 31, COMPRESS = 32, EXPAND = 33, ZERO = 34, DECRYPT = 31, COMPRESS = 32, EXPAND = 33, ZERO = 34,
RANDOM_UUID = 35, COSH = 36, SINH = 37, TANH = 38, LN = 39; RANDOM_UUID = 35, COSH = 36, SINH = 37, TANH = 38, LN = 39,
BITGET=40;
public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52, public static final int ASCII = 50, BIT_LENGTH = 51, CHAR = 52,
CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55, HEXTORAW = 56, CHAR_LENGTH = 53, CONCAT = 54, DIFFERENCE = 55, HEXTORAW = 56,
...@@ -208,6 +209,7 @@ public class Function extends Expression implements FunctionCall { ...@@ -208,6 +209,7 @@ public class Function extends Expression implements FunctionCall {
addFunction("ATAN", ATAN, 1, Value.DOUBLE); addFunction("ATAN", ATAN, 1, Value.DOUBLE);
addFunction("ATAN2", ATAN2, 2, Value.DOUBLE); addFunction("ATAN2", ATAN2, 2, Value.DOUBLE);
addFunction("BITAND", BITAND, 2, Value.LONG); addFunction("BITAND", BITAND, 2, Value.LONG);
addFunction("BITGET", BITGET, 2, Value.BOOLEAN);
addFunction("BITOR", BITOR, 2, Value.LONG); addFunction("BITOR", BITOR, 2, Value.LONG);
addFunction("BITXOR", BITXOR, 2, Value.LONG); addFunction("BITXOR", BITXOR, 2, Value.LONG);
addFunction("CEILING", CEILING, 1, Value.DOUBLE); addFunction("CEILING", CEILING, 1, Value.DOUBLE);
...@@ -1208,6 +1210,9 @@ public class Function extends Expression implements FunctionCall { ...@@ -1208,6 +1210,9 @@ public class Function extends Expression implements FunctionCall {
case BITAND: case BITAND:
result = ValueLong.get(v0.getLong() & v1.getLong()); result = ValueLong.get(v0.getLong() & v1.getLong());
break; break;
case BITGET:
result = ValueBoolean.get((v0.getLong() & (1L << v1.getInt())) != 0);
break;
case BITOR: case BITOR:
result = ValueLong.get(v0.getLong() | v1.getLong()); result = ValueLong.get(v0.getLong() | v1.getLong());
break; break;
......
...@@ -3055,6 +3055,13 @@ select min(8=bitand(12, PARSE_INT2(SUBSTRING(random_uuid(), 20,1), 16))) from sy ...@@ -3055,6 +3055,13 @@ select min(8=bitand(12, PARSE_INT2(SUBSTRING(random_uuid(), 20,1), 16))) from sy
> TRUE > TRUE
> rows: 1 > rows: 1
select BITGET(x, 0) AS IS_SET from system_range(1, 2);
> IS_SET
> ---------------------------------------------------------------------------
> TRUE
> FALSE
> rows: 2
drop alias PARSE_INT2; drop alias PARSE_INT2;
> ok > ok
......
...@@ -728,4 +728,4 @@ experiment throughout staging booth akkuzin observed maxinplace russian ...@@ -728,4 +728,4 @@ experiment throughout staging booth akkuzin observed maxinplace russian
ema sch bodewig forbid compat calc midway prohibit measuring playing kostya ema sch bodewig forbid compat calc midway prohibit measuring playing kostya
pstmt rosenbaum pretending inverse safer lived blo sane othe multiplicative pstmt rosenbaum pretending inverse safer lived blo sane othe multiplicative
introduces bcd nave picking templating clamp temporal berlin intermittently introduces bcd nave picking templating clamp temporal berlin intermittently
pstat props pstat props bitget travis
\ No newline at end of file \ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论