1create table t1 ( 2pk int primary key, 3a int, 4b int 5); 6create table t2 ( 7pk int primary key, 8a int, 9b int 10); 11insert 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); 20insert 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. 30select pk, a, b, 31bit_or(b) over (order by pk) as bit_or, 32bit_and(b) over (order by pk) as bit_and, 33bit_xor(b) over (order by pk) as bit_xor 34from t1; 35pk a b bit_or bit_and bit_xor 361 0 1 1 1 1 372 0 2 3 0 3 383 1 4 7 0 7 394 1 8 15 0 15 405 2 32 47 0 47 416 2 64 111 0 111 427 2 128 239 0 239 438 2 16 255 0 255 44select pk, a, b, 45bit_or(b) over (order by pk) as bit_or, 46bit_and(b) over (order by pk) as bit_and, 47bit_xor(b) over (order by pk) as bit_xor 48from t2; 49pk a b bit_or bit_and bit_xor 501 0 2 2 2 2 512 0 2 2 2 0 523 1 4 6 0 4 534 1 4 6 0 0 545 2 16 22 0 16 556 2 64 86 0 80 567 2 128 214 0 208 578 2 16 214 0 192 58# Test multiple partitions with bit functions. 59select pk, a, b, 60bit_or(b) over (partition by a order by pk) as bit_or, 61bit_and(b) over (partition by a order by pk) as bit_and, 62bit_xor(b) over (partition by a order by pk) as bit_xor 63from t1; 64pk a b bit_or bit_and bit_xor 651 0 1 1 1 1 662 0 2 3 0 3 673 1 4 4 4 4 684 1 8 12 0 12 695 2 32 32 32 32 706 2 64 96 0 96 717 2 128 224 0 224 728 2 16 240 0 240 73select pk, a, b, 74bit_or(b) over (partition by a order by pk) as bit_or, 75bit_and(b) over (partition by a order by pk) as bit_and, 76bit_xor(b) over (partition by a order by pk) as bit_xor 77from t2; 78pk a b bit_or bit_and bit_xor 791 0 2 2 2 2 802 0 2 2 2 0 813 1 4 4 4 4 824 1 4 4 4 0 835 2 16 16 16 16 846 2 64 80 0 80 857 2 128 208 0 208 868 2 16 208 0 192 87# Test remove function for bit functions using a sliding window. 88select pk, a, b, 89bit_or(b) over (partition by a order by pk ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) as bit_or, 90bit_and(b) over (partition by a order by pk) as bit_and, 91bit_xor(b) over (partition by a order by pk) as bit_xor 92from t1; 93pk a b bit_or bit_and bit_xor 941 0 1 3 1 1 952 0 2 3 0 3 963 1 4 12 4 4 974 1 8 12 0 12 985 2 32 96 32 32 996 2 64 224 0 96 1007 2 128 208 0 224 1018 2 16 144 0 240 102select pk, a, b, 103bit_or(b) over (partition by a order by pk) as bit_or, 104bit_and(b) over (partition by a order by pk) as bit_and, 105bit_xor(b) over (partition by a order by pk) as bit_xor 106from t2; 107pk a b bit_or bit_and bit_xor 1081 0 2 2 2 2 1092 0 2 2 2 0 1103 1 4 4 4 4 1114 1 4 4 4 0 1125 2 16 16 16 16 1136 2 64 80 0 80 1147 2 128 208 0 208 1158 2 16 208 0 192 116drop table t1; 117drop table t2; 118