Skip to content

Commit 28dc71b

Browse files
authored
[Test] add test for hbase table with local index in T column (#32)
1 parent f908d4f commit 28dc71b

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,24 @@ PRIMARY KEY (`K`, `Q`, `T`)
109109

110110
@Test
111111
public void testBasic() throws Exception {
112+
testBasic("family1");
113+
}
114+
115+
private void testBasic(String family) throws Exception {
112116
String key = "putKey";
113117
String column1 = "putColumn1";
114118
String column2 = "putColumn2";
115119
String value = "value";
116-
String family = "family1";
117120
long timestamp = System.currentTimeMillis();
118121
Delete delete = new Delete(key.getBytes());
119122
delete.deleteFamily(family.getBytes());
120123
hTable.delete(delete);
121124

122125
Put put = new Put(toBytes(key));
123-
put.add("family1".getBytes(), column1.getBytes(), timestamp, toBytes(value));
126+
put.add(family.getBytes(), column1.getBytes(), timestamp, toBytes(value));
124127
hTable.put(put);
125128
Get get = new Get(toBytes(key));
126-
get.addColumn("family1".getBytes(), toBytes(column1));
129+
get.addColumn(family.getBytes(), toBytes(column1));
127130
Result r = hTable.get(get);
128131
Assert.assertEquals(1, r.raw().length);
129132

@@ -137,10 +140,10 @@ public void testBasic() throws Exception {
137140
}
138141

139142
put = new Put(toBytes(key));
140-
put.add("family1".getBytes(), column1.getBytes(), timestamp + 1, toBytes(value));
143+
put.add(family.getBytes(), column1.getBytes(), timestamp + 1, toBytes(value));
141144
hTable.put(put);
142145
get = new Get(toBytes(key));
143-
get.addColumn("family1".getBytes(), toBytes(column1));
146+
get.addColumn(family.getBytes(), toBytes(column1));
144147
get.setMaxVersions(2);
145148
r = hTable.get(get);
146149
Assert.assertEquals(2, r.raw().length);
@@ -165,14 +168,14 @@ public void testBasic() throws Exception {
165168
try {
166169
for (int j = 0; j < 10; j++) {
167170
put = new Put((key + "_" + j).getBytes());
168-
put.add("family1".getBytes(), column1.getBytes(), toBytes(value));
169-
put.add("family1".getBytes(), column2.getBytes(), toBytes(value));
171+
put.add(family.getBytes(), column1.getBytes(), toBytes(value));
172+
put.add(family.getBytes(), column2.getBytes(), toBytes(value));
170173
hTable.put(put);
171174
}
172175

173176
Scan scan = new Scan();
174-
scan.addColumn("family1".getBytes(), column1.getBytes());
175-
scan.addColumn("family1".getBytes(), column2.getBytes());
177+
scan.addColumn(family.getBytes(), column1.getBytes());
178+
scan.addColumn(family.getBytes(), column2.getBytes());
176179
scan.setStartRow(toBytes(key + "_" + 0));
177180
scan.setStopRow(toBytes(key + "_" + 9));
178181
scan.setMaxVersions(9);
@@ -2171,4 +2174,10 @@ public void testIncrementConcurrency() throws Exception {
21712174
result = hTable.get(get);
21722175
assertEquals(101, result.raw().length);
21732176
}
2177+
2178+
// Test operation in hbase table with local index
2179+
@Test
2180+
public void testHtableWithIndex() throws Exception {
2181+
testBasic("family_with_local_index");
2182+
}
21742183
}

src/test/java/unit_test_db.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,21 @@ partition by range columns (`K`) (
127127
PARTITION p1 VALUES LESS THAN ('w'),
128128
PARTITION p2 VALUES LESS THAN MAXVALUE
129129
);
130+
131+
CREATE TABLE `test$family_with_local_index` (
132+
`K` varbinary(1024) NOT NULL,
133+
`Q` varbinary(256) NOT NULL,
134+
`T` bigint(20) NOT NULL,
135+
`V` varbinary(1024) DEFAULT NULL,
136+
key `idx1`(T) local,
137+
PRIMARY KEY (`K`, `Q`, `T`)
138+
);
139+
140+
CREATE TABLE `test_t$family_with_local_index` (
141+
`K` varbinary(1024) NOT NULL,
142+
`Q` varbinary(256) NOT NULL,
143+
`T` bigint(20) NOT NULL,
144+
`V` varbinary(1024) DEFAULT NULL,
145+
key `idx1`(T) local,
146+
PRIMARY KEY (`K`, `Q`, `T`)
147+
);

0 commit comments

Comments
 (0)