|
| 1 | +create table t1 ( |
| 2 | +pk int primary key, |
| 3 | +a int, |
| 4 | +b int |
| 5 | +); |
| 6 | +create table t2 ( |
| 7 | +pk int primary key, |
| 8 | +a int, |
| 9 | +b int |
| 10 | +); |
| 11 | +insert into t1 values |
| 12 | +( 1 , 0, 1), |
| 13 | +( 2 , 0, 2), |
| 14 | +( 3 , 1, 4), |
| 15 | +( 4 , 1, 8), |
| 16 | +( 5 , 2, 32), |
| 17 | +( 6 , 2, 64), |
| 18 | +( 7 , 2, 128), |
| 19 | +( 8 , 2, 16); |
| 20 | +insert into t2 values |
| 21 | +( 1 , 0, 2), |
| 22 | +( 2 , 0, 2), |
| 23 | +( 3 , 1, 4), |
| 24 | +( 4 , 1, 4), |
| 25 | +( 5 , 2, 16), |
| 26 | +( 6 , 2, 64), |
| 27 | +( 7 , 2, 128), |
| 28 | +( 8 , 2, 16); |
| 29 | +# Test bit functions on only one partition. |
| 30 | +select pk, a, b, |
| 31 | +bit_or(b) over (order by pk) as bit_or, |
| 32 | +bit_and(b) over (order by pk) as bit_and, |
| 33 | +bit_xor(b) over (order by pk) as bit_xor |
| 34 | +from t1; |
| 35 | +pk a b bit_or bit_and bit_xor |
| 36 | +1 0 1 1 1 1 |
| 37 | +2 0 2 3 0 3 |
| 38 | +3 1 4 7 0 7 |
| 39 | +4 1 8 15 0 15 |
| 40 | +5 2 32 47 0 47 |
| 41 | +6 2 64 111 0 111 |
| 42 | +7 2 128 239 0 239 |
| 43 | +8 2 16 255 0 255 |
| 44 | +select pk, a, b, |
| 45 | +bit_or(b) over (order by pk) as bit_or, |
| 46 | +bit_and(b) over (order by pk) as bit_and, |
| 47 | +bit_xor(b) over (order by pk) as bit_xor |
| 48 | +from t2; |
| 49 | +pk a b bit_or bit_and bit_xor |
| 50 | +1 0 2 2 2 2 |
| 51 | +2 0 2 2 2 0 |
| 52 | +3 1 4 6 0 4 |
| 53 | +4 1 4 6 0 0 |
| 54 | +5 2 16 22 0 16 |
| 55 | +6 2 64 86 0 80 |
| 56 | +7 2 128 214 0 208 |
| 57 | +8 2 16 214 0 192 |
| 58 | +# Test multiple partitions with bit functions. |
| 59 | +select pk, a, b, |
| 60 | +bit_or(b) over (partition by a order by pk) as bit_or, |
| 61 | +bit_and(b) over (partition by a order by pk) as bit_and, |
| 62 | +bit_xor(b) over (partition by a order by pk) as bit_xor |
| 63 | +from t1; |
| 64 | +pk a b bit_or bit_and bit_xor |
| 65 | +1 0 1 1 1 1 |
| 66 | +2 0 2 3 0 3 |
| 67 | +3 1 4 4 4 4 |
| 68 | +4 1 8 12 0 12 |
| 69 | +5 2 32 32 32 32 |
| 70 | +6 2 64 96 0 96 |
| 71 | +7 2 128 224 0 224 |
| 72 | +8 2 16 240 0 240 |
| 73 | +select pk, a, b, |
| 74 | +bit_or(b) over (partition by a order by pk) as bit_or, |
| 75 | +bit_and(b) over (partition by a order by pk) as bit_and, |
| 76 | +bit_xor(b) over (partition by a order by pk) as bit_xor |
| 77 | +from t2; |
| 78 | +pk a b bit_or bit_and bit_xor |
| 79 | +1 0 2 2 2 2 |
| 80 | +2 0 2 2 2 0 |
| 81 | +3 1 4 4 4 4 |
| 82 | +4 1 4 4 4 0 |
| 83 | +5 2 16 16 16 16 |
| 84 | +6 2 64 80 0 80 |
| 85 | +7 2 128 208 0 208 |
| 86 | +8 2 16 208 0 192 |
| 87 | +# Test remove function for bit functions using a sliding window. |
| 88 | +select pk, a, b, |
| 89 | +bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or, |
| 90 | +bit_and(b) over (partition by a order by pk) as bit_and, |
| 91 | +bit_xor(b) over (partition by a order by pk) as bit_xor |
| 92 | +from t1; |
| 93 | +pk a b bit_or bit_and bit_xor |
| 94 | +1 0 1 3 1 1 |
| 95 | +2 0 2 3 0 3 |
| 96 | +3 1 4 12 4 4 |
| 97 | +4 1 8 12 0 12 |
| 98 | +5 2 32 96 32 32 |
| 99 | +6 2 64 224 0 96 |
| 100 | +7 2 128 208 0 224 |
| 101 | +8 2 16 144 0 240 |
| 102 | +select pk, a, b, |
| 103 | +bit_or(b) over (partition by a order by pk) as bit_or, |
| 104 | +bit_and(b) over (partition by a order by pk) as bit_and, |
| 105 | +bit_xor(b) over (partition by a order by pk) as bit_xor |
| 106 | +from t2; |
| 107 | +pk a b bit_or bit_and bit_xor |
| 108 | +1 0 2 2 2 2 |
| 109 | +2 0 2 2 2 0 |
| 110 | +3 1 4 4 4 4 |
| 111 | +4 1 4 4 4 0 |
| 112 | +5 2 16 16 16 16 |
| 113 | +6 2 64 80 0 80 |
| 114 | +7 2 128 208 0 208 |
| 115 | +8 2 16 208 0 192 |
| 116 | +drop table t1; |
| 117 | +drop table t2; |
| 118 | + |
0 commit comments