Skip to content

Commit 9566d42

Browse files
authored
Merge pull request #254 from oceanbase/add-case-for-secondary-partition-regionlocator
fix add case for secondary partition region locator
2 parents 3f5d26b + fd0931d commit 9566d42

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

src/test/java/com/alipay/oceanbase/hbase/OHConnectionTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,39 @@ public void testKeyPartitionWithRegionLocator() throws IOException {
10501050
Assert.assertEquals(startKeys[0], endKeys[0]);
10511051
Assert.assertEquals(startKeys[0], HConstants.EMPTY_BYTE_ARRAY);
10521052
}
1053+
1054+
@Test
1055+
public void testRangeKeySecondaryPartitionWithRegionLocator() throws IOException {
1056+
final String tableNameStr = "test_secondary_range_key";
1057+
final TableName tableName = TableName.valueOf(tableNameStr);
1058+
final Configuration conf = ObHTableTestUtil.newConfiguration();
1059+
connection = ConnectionFactory.createConnection(conf);
1060+
hTable = connection.getTable(tableName);
1061+
RegionLocator locator = connection.getRegionLocator(tableName);
1062+
byte[][] startKeys = locator.getStartKeys();
1063+
byte[][] endKeys = locator.getEndKeys();
1064+
Assert.assertEquals("Should have 1 region", 1, startKeys.length);
1065+
Assert.assertEquals("Should have 1 region", 1, endKeys.length);
1066+
Assert.assertEquals(startKeys[0], endKeys[0]);
1067+
Assert.assertEquals(startKeys[0], HConstants.EMPTY_BYTE_ARRAY);
1068+
}
1069+
1070+
@Test
1071+
public void testKeyRangeSecondaryPartitionWithRegionLocator() throws IOException {
1072+
final String tableNameStr = "test_secondary_key_range";
1073+
final TableName tableName = TableName.valueOf(tableNameStr);
1074+
final Configuration conf = ObHTableTestUtil.newConfiguration();
1075+
connection = ConnectionFactory.createConnection(conf);
1076+
hTable = connection.getTable(tableName);
1077+
RegionLocator locator = connection.getRegionLocator(tableName);
1078+
byte[][] startKeys = locator.getStartKeys();
1079+
byte[][] endKeys = locator.getEndKeys();
1080+
Assert.assertEquals("Should have 1 region", 1, startKeys.length);
1081+
Assert.assertEquals("Should have 1 region", 1, endKeys.length);
1082+
Assert.assertEquals(startKeys[0], endKeys[0]);
1083+
Assert.assertEquals(startKeys[0], HConstants.EMPTY_BYTE_ARRAY);
1084+
}
1085+
10531086

10541087
@Test
10551088
public void testBufferedMutatorPeriodicFlush() throws Exception {

src/test/java/unit_test_db.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,46 @@ PARTITION BY RANGE COLUMNS(K) (
339339
PARTITION p9 VALUES LESS THAN ('v'),
340340
PARTITION p10 VALUES LESS THAN (MAXVALUE)
341341
);
342+
343+
CREATE TABLEGROUP test_secondary_key_range SHARDING = 'ADAPTIVE';
344+
CREATE TABLE IF NOT EXISTS `test_secondary_key_range$family1` (
345+
`K` varbinary(1024) NOT NULL,
346+
`Q` varbinary(256) NOT NULL,
347+
`T` bigint(20) NOT NULL,
348+
`V` varbinary(1024) DEFAULT NULL,
349+
`G` bigint(20) GENERATED ALWAYS AS (ABS(T)),
350+
PRIMARY KEY (`K`, `Q`, `T`)
351+
) TABLEGROUP = test_secondary_key_range PARTITION BY KEY(`K`) PARTITIONS 3
352+
SUBPARTITION BY RANGE COLUMNS(`G`) SUBPARTITION TEMPLATE (
353+
SUBPARTITION `p1` VALUES LESS THAN (100),
354+
SUBPARTITION `p2` VALUES LESS THAN (200),
355+
SUBPARTITION `p3` VALUES LESS THAN MAXVALUE
356+
);
357+
CREATE TABLE IF NOT EXISTS `test_secondary_key_range$family2` (
358+
`K` varbinary(1024) NOT NULL,
359+
`Q` varbinary(256) NOT NULL,
360+
`T` bigint(20) NOT NULL,
361+
`V` varbinary(1024) DEFAULT NULL,
362+
`G` bigint(20) GENERATED ALWAYS AS (ABS(T)),
363+
PRIMARY KEY (`K`, `Q`, `T`)
364+
) TABLEGROUP = test_secondary_key_range PARTITION BY KEY(`K`) PARTITIONS 3
365+
SUBPARTITION BY RANGE COLUMNS(`G`) SUBPARTITION TEMPLATE (
366+
SUBPARTITION `p1` VALUES LESS THAN (100),
367+
SUBPARTITION `p2` VALUES LESS THAN (200),
368+
SUBPARTITION `p3` VALUES LESS THAN MAXVALUE
369+
);
370+
371+
CREATE TABLEGROUP test_secondary_range_key SHARDING = 'ADAPTIVE';
372+
CREATE TABLE IF NOT EXISTS `test_secondary_range_key$family1` (
373+
`K` varbinary(1024) NOT NULL,
374+
`Q` varbinary(256) NOT NULL,
375+
`T` bigint(20) NOT NULL,
376+
`V` varbinary(1024) DEFAULT NULL,
377+
`G` bigint(20) GENERATED ALWAYS AS (ABS(T)),
378+
PRIMARY KEY (`K`, `Q`, `T`)
379+
) TABLEGROUP = test_secondary_range_key PARTITION BY RANGE COLUMNS(`G`)
380+
SUBPARTITION BY KEY(`K`) SUBPARTITIONS 3
381+
( PARTITION `p1` VALUES LESS THAN (100),
382+
PARTITION `p2` VALUES LESS THAN (200),
383+
PARTITION `p3` VALUES LESS THAN MAXVALUE
384+
);

0 commit comments

Comments
 (0)