|
20 | 20 | import org.apache.hadoop.conf.Configuration;
|
21 | 21 | import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
|
22 | 22 | import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
|
| 23 | +import org.apache.hadoop.hbase.Cell; |
| 24 | +import org.apache.hadoop.hbase.CellUtil; |
23 | 25 | import org.apache.hadoop.hbase.KeyValue;
|
24 | 26 | import org.apache.hadoop.hbase.TableName;
|
25 | 27 | import org.apache.hadoop.hbase.client.*;
|
|
29 | 31 | import org.junit.*;
|
30 | 32 | import org.junit.rules.ExpectedException;
|
31 | 33 |
|
| 34 | +import java.io.IOException; |
32 | 35 | import java.util.*;
|
33 | 36 |
|
34 | 37 | import static org.apache.hadoop.hbase.util.Bytes.toBytes;
|
@@ -1261,4 +1264,111 @@ public void testMultiColumnFamilyDelete() throws Exception {
|
1261 | 1264 | .getTimestamp());
|
1262 | 1265 | assertTrue(lastTimestamp > oldTimestamp);
|
1263 | 1266 | }
|
| 1267 | + |
| 1268 | + private void prepare_time_range_test_data() throws IOException { |
| 1269 | + byte[] family1 = "family_with_group1".getBytes(); |
| 1270 | + byte[] family2 = "family_with_group2".getBytes(); |
| 1271 | + byte[] family3 = "family_with_group3".getBytes(); |
| 1272 | + byte[] key = "KEY".getBytes(); |
| 1273 | + byte[] column = "COLUMN".getBytes(); |
| 1274 | + |
| 1275 | + Put put = new Put(key); |
| 1276 | + for (int i = 0; i < 60; i += 3) { |
| 1277 | + put.addColumn(family1, column, i, ("value" + i).getBytes()); |
| 1278 | + } |
| 1279 | + multiCfHTable.put(put); |
| 1280 | + put = new Put(key); |
| 1281 | + for (int i = 0; i < 60; i += 3) { |
| 1282 | + put.addColumn(family2, column, i, ("value" + i).getBytes()); |
| 1283 | + } |
| 1284 | + multiCfHTable.put(put); |
| 1285 | + put = new Put(key); |
| 1286 | + for (int i = 0; i < 60; i += 3) { |
| 1287 | + put.addColumn(family3, column, i, ("value" + i).getBytes()); |
| 1288 | + } |
| 1289 | + multiCfHTable.put(put); |
| 1290 | + } |
| 1291 | + |
| 1292 | + @Test |
| 1293 | + public void test_column_family_time_range() throws IOException { |
| 1294 | + byte[] family1 = "family_with_group1".getBytes(); |
| 1295 | + byte[] family2 = "family_with_group2".getBytes(); |
| 1296 | + byte[] family3 = "family_with_group3".getBytes(); |
| 1297 | + prepare_time_range_test_data(); |
| 1298 | + // 20 cell for every family. |
| 1299 | + |
| 1300 | + long min = 10; |
| 1301 | + long max = 20; |
| 1302 | + Get get = new Get(toBytes("KEY")); |
| 1303 | + get.setMaxVersions(999); |
| 1304 | + get.addFamily(family1); |
| 1305 | + get.setColumnFamilyTimeRange(family1, min, max); |
| 1306 | + Result result = multiCfHTable.get(get); |
| 1307 | + System.out.println("test1 start:"); |
| 1308 | + for (Cell keyValue : result.rawCells()) { |
| 1309 | + System.out |
| 1310 | + .printf( |
| 1311 | + "Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n", |
| 1312 | + Bytes.toString(result.getRow()), |
| 1313 | + Bytes.toString(CellUtil.cloneFamily(keyValue)), |
| 1314 | + Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(), |
| 1315 | + Bytes.toString(CellUtil.cloneValue(keyValue))); |
| 1316 | + assert(keyValue.getTimestamp() >= min && keyValue.getTimestamp() < max); |
| 1317 | + } |
| 1318 | + assertEquals(3, result.rawCells().length); |
| 1319 | + |
| 1320 | + get = new Get(toBytes("KEY")); |
| 1321 | + get.setMaxVersions(999); |
| 1322 | + get.setColumnFamilyTimeRange(family1, 0, 10); |
| 1323 | + get.setColumnFamilyTimeRange(family2, 0, 20); |
| 1324 | + get.setColumnFamilyTimeRange(family3, 0, 30); |
| 1325 | + result = multiCfHTable.get(get); |
| 1326 | + System.out.println("\ntest2 start:"); |
| 1327 | + for (Cell keyValue : result.rawCells()) { |
| 1328 | + System.out |
| 1329 | + .printf( |
| 1330 | + "Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n", |
| 1331 | + Bytes.toString(result.getRow()), |
| 1332 | + Bytes.toString(CellUtil.cloneFamily(keyValue)), |
| 1333 | + Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(), |
| 1334 | + Bytes.toString(CellUtil.cloneValue(keyValue))); |
| 1335 | + } |
| 1336 | + assertEquals(21, result.rawCells().length); |
| 1337 | + |
| 1338 | + get = new Get(toBytes("KEY")); |
| 1339 | + get.setMaxVersions(999); |
| 1340 | + get.setColumnFamilyTimeRange(family1, 0, 10); |
| 1341 | + get.setColumnFamilyTimeRange(family3, 0, 30); |
| 1342 | + get.setTimeRange(54, 60); |
| 1343 | + result = multiCfHTable.get(get); |
| 1344 | + System.out.println("\ntest3 start:"); |
| 1345 | + for (Cell keyValue : result.rawCells()) { |
| 1346 | + System.out |
| 1347 | + .printf( |
| 1348 | + "Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n", |
| 1349 | + Bytes.toString(result.getRow()), |
| 1350 | + Bytes.toString(CellUtil.cloneFamily(keyValue)), |
| 1351 | + Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(), |
| 1352 | + Bytes.toString(CellUtil.cloneValue(keyValue))); |
| 1353 | + } |
| 1354 | + assertEquals(16, result.rawCells().length); |
| 1355 | + |
| 1356 | + get = new Get(toBytes("KEY")); |
| 1357 | + get.setMaxVersions(6); |
| 1358 | + get.setColumnFamilyTimeRange(family1, 0, 10); |
| 1359 | + get.setColumnFamilyTimeRange(family3, 0, 30); |
| 1360 | + get.setTimeRange(54, 60); |
| 1361 | + result = multiCfHTable.get(get); |
| 1362 | + System.out.println("\ntest3 start:"); |
| 1363 | + for (Cell keyValue : result.rawCells()) { |
| 1364 | + System.out |
| 1365 | + .printf( |
| 1366 | + "Rowkey: %s, Column Family: %s, Column Qualifier: %s, Timestamp: %d, Value: %s%n", |
| 1367 | + Bytes.toString(result.getRow()), |
| 1368 | + Bytes.toString(CellUtil.cloneFamily(keyValue)), |
| 1369 | + Bytes.toString(CellUtil.cloneQualifier(keyValue)), keyValue.getTimestamp(), |
| 1370 | + Bytes.toString(CellUtil.cloneValue(keyValue))); |
| 1371 | + } |
| 1372 | + assertEquals(12, result.rawCells().length); |
| 1373 | + } |
1264 | 1374 | }
|
0 commit comments