Skip to content

Commit 3cd9a14

Browse files
authored
Merge pull request #194 from oceanbase/secondary_part-merge-master
Secondary part merge master
2 parents cf09ce6 + 548f503 commit 3cd9a14

21 files changed

+6475
-36
lines changed

src/main/java/com/alipay/oceanbase/hbase/OHTable.java

Lines changed: 187 additions & 31 deletions
Large diffs are not rendered by default.

src/main/java/com/alipay/oceanbase/hbase/util/ObTableClientManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static ObTableClient getOrCreateObTableClient(OHConnectionConfiguration c
5656
obTableClientKey.setDatabase(connectionConfig.getDatabase());
5757
} else {
5858
checkArgument(isNotBlank(connectionConfig.getParamUrl()), HBASE_OCEANBASE_PARAM_URL
59-
+ " is blank");
59+
+ " is blank");
6060
obTableClientKey = new ObTableClientKey();
6161
String paramUrl = connectionConfig.getParamUrl();
6262
if (!paramUrl.contains("database")) {
@@ -71,7 +71,7 @@ public static ObTableClient getOrCreateObTableClient(OHConnectionConfiguration c
7171
}
7272
}
7373
checkArgument(isNotBlank(connectionConfig.getFullUsername()),
74-
HBASE_OCEANBASE_FULL_USER_NAME + " is blank");
74+
HBASE_OCEANBASE_FULL_USER_NAME + " is blank");
7575
obTableClientKey.setFullUserName(connectionConfig.getFullUsername());
7676

7777
if (connectionConfig.getPassword() == null) {
@@ -83,7 +83,7 @@ public static ObTableClient getOrCreateObTableClient(OHConnectionConfiguration c
8383
for (Map.Entry<Object, Object> property : connectionConfig.getProperties().entrySet()) {
8484
obTableClientKey.getProperties().put(property.getKey(), property.getValue());
8585
}
86-
86+
8787
return getOrCreateObTableClient(obTableClientKey, connectionConfig.getRpcConnectTimeout());
8888
}
8989

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/*-
2+
* #%L
3+
* OBKV HBase Client Framework
4+
* %%
5+
* Copyright (C) 2025 OceanBase Group
6+
* %%
7+
* OBKV HBase Client Framework is licensed under Mulan PSL v2.
8+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
9+
* You may obtain a copy of Mulan PSL v2 at:
10+
* http://license.coscl.org.cn/MulanPSL2
11+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+
* See the Mulan PSL v2 for more details.
15+
* #L%
16+
*/
17+
18+
package com.alipay.oceanbase.hbase.secondary;
19+
20+
import com.alipay.oceanbase.hbase.OHTableClient;
21+
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
22+
import com.alipay.oceanbase.hbase.util.TableTemplateManager;
23+
import org.apache.hadoop.hbase.client.*;
24+
import org.apache.hadoop.hbase.filter.PageFilter;
25+
import org.apache.hadoop.hbase.util.Bytes;
26+
import org.junit.AfterClass;
27+
import org.junit.Before;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
31+
import java.io.IOException;
32+
import java.util.*;
33+
34+
import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
35+
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
36+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.SERIES_TABLES;
37+
import static com.alipay.oceanbase.hbase.util.TableTemplateManager.TableType.*;
38+
import static org.junit.Assert.*;
39+
40+
public class OHTableSecondaryPartAbnormal {
41+
private static List<String> tableNames = new LinkedList<String>();
42+
private static Map<String, List<String>> group2tableNames = new LinkedHashMap<String, List<String>>();
43+
private static byte[] ROW = Bytes.toBytes("testRow");
44+
private static byte[] QUALIFIER = Bytes.toBytes("testQualifier");
45+
private static byte[] VALUE_2 = Bytes.toBytes("abcd");
46+
47+
@BeforeClass
48+
public static void before() throws Exception {
49+
openDistributedExecute();
50+
for (TableTemplateManager.TableType type : SERIES_TABLES) {
51+
createTables(type, tableNames, group2tableNames, true);
52+
}
53+
}
54+
55+
@AfterClass
56+
public static void finish() throws Exception {
57+
closeDistributedExecute();
58+
// dropTables(tableNames, group2tableNames);
59+
}
60+
61+
@Before
62+
public void prepareCase() throws Exception {
63+
truncateTables(tableNames, group2tableNames);
64+
}
65+
66+
private static void testSeriesLimit(String tableName) throws Exception {
67+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
68+
hTable.init();
69+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
70+
Put put2 = new Put(ROW);
71+
put2.add(FAMILY, QUALIFIER, VALUE_2);
72+
hTable.put(put2);
73+
Get get = new Get(ROW);
74+
get.addFamily(FAMILY);
75+
get.setFilter(new PageFilter(10));
76+
try {
77+
hTable.get(get);
78+
fail("unexpected, should failed before");
79+
} catch (IOException e) {
80+
assertTrue(e.getCause().getMessage()
81+
.contains("timeseries hbase table with filter query not supported"));
82+
}
83+
get = new Get(ROW);
84+
get.addFamily(FAMILY);
85+
get.setCheckExistenceOnly(true);
86+
try {
87+
hTable.get(get);
88+
fail("unexpected, should failed before");
89+
} catch (IOException e) {
90+
assertTrue(e.getCause().getMessage()
91+
.contains("timeseries hbase table with check existence only query not supported"));
92+
}
93+
get = new Get(ROW);
94+
get.addFamily(FAMILY);
95+
get.setClosestRowBefore(true);
96+
try {
97+
hTable.get(get);
98+
fail("unexpected, should failed before");
99+
} catch (IOException e) {
100+
assertTrue(e.getCause().getMessage()
101+
.contains("timeseries hbase table with reverse query not supported"));
102+
}
103+
Scan scan = new Scan(ROW);
104+
scan.addFamily(FAMILY);
105+
scan.setReversed(true);
106+
try {
107+
hTable.getScanner(scan);
108+
fail("unexpected, should failed before");
109+
} catch (IOException e) {
110+
assertTrue(e.getCause().getMessage()
111+
.contains("timeseries hbase table with reverse query not supported"));
112+
}
113+
scan = new Scan(ROW);
114+
scan.addFamily(FAMILY);
115+
scan.setCaching(1);
116+
try {
117+
hTable.getScanner(scan);
118+
fail("unexpected, should failed before");
119+
} catch (IOException e) {
120+
assertTrue(e.getCause().getMessage()
121+
.contains("timeseries hbase table with caching query not supported"));
122+
}
123+
scan = new Scan(ROW);
124+
scan.addFamily(FAMILY);
125+
scan.setBatch(1);
126+
try {
127+
hTable.getScanner(scan);
128+
fail("unexpected, should failed before");
129+
} catch (IOException e) {
130+
assertTrue(e.getCause().getMessage()
131+
.contains("timeseries hbase table with batch query not supported"));
132+
}
133+
scan = new Scan(ROW);
134+
scan.addFamily(FAMILY);
135+
scan.setAllowPartialResults(true);
136+
try {
137+
hTable.getScanner(scan);
138+
fail("unexpected, should failed before");
139+
} catch (IOException e) {
140+
assertTrue(e.getCause().getMessage()
141+
.contains("timeseries hbase table with allow partial results query not supported"));
142+
}
143+
scan = new Scan(ROW);
144+
scan.addFamily(FAMILY);
145+
scan.setMaxResultsPerColumnFamily(1);
146+
try {
147+
hTable.getScanner(scan);
148+
fail("unexpected, should failed before");
149+
} catch (IOException e) {
150+
assertTrue(e
151+
.getCause()
152+
.getMessage()
153+
.contains(
154+
"timeseries hbase table with max results per column family query not supported"));
155+
}
156+
scan = new Scan(ROW);
157+
scan.addFamily(FAMILY);
158+
scan.setRowOffsetPerColumnFamily(1);
159+
try {
160+
hTable.getScanner(scan);
161+
fail("unexpected, should failed before");
162+
} catch (IOException e) {
163+
assertTrue(e.getCause().getMessage()
164+
.contains("timeseries hbase table with row offset query not supported"));
165+
}
166+
scan = new Scan(ROW);
167+
scan.addFamily(FAMILY);
168+
ResultScanner scanner = hTable.getScanner(scan);
169+
assertEquals(1, scanner.next().size());
170+
hTable.close();
171+
}
172+
173+
private static void testSeriesWithCellTTL(String tableName) throws Exception {
174+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
175+
hTable.init();
176+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
177+
Put put2 = new Put(ROW);
178+
put2.add(FAMILY, QUALIFIER, VALUE_2);
179+
try {
180+
hTable.put(put2);
181+
fail("unexpected, should failed before");
182+
} catch (IOException e) {
183+
assertTrue(e.getCause().getMessage()
184+
.contains("series table not support cell ttl not supported"));
185+
}
186+
hTable.close();
187+
}
188+
189+
private static void testSecondaryPartReverseScan(String tableName) throws Exception {
190+
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
191+
hTable.init();
192+
byte[] FAMILY = getColumnFamilyName(tableName).getBytes();
193+
Put put2 = new Put(ROW);
194+
put2.add(FAMILY, QUALIFIER, VALUE_2);
195+
hTable.put(put2);
196+
Scan scan = new Scan(ROW);
197+
scan.addFamily(FAMILY);
198+
scan.setReversed(true);
199+
try {
200+
hTable.getScanners(scan);
201+
fail("unexpected, should failed before");
202+
} catch (IOException e) {
203+
assertTrue(e.getCause().getMessage()
204+
.contains("secondary partitioned hbase table with reverse query not supported"));
205+
}
206+
hTable.close();
207+
}
208+
209+
@Test
210+
public void testSeriesLimit() throws Throwable {
211+
FOR_EACH(tableNames, com.alipay.oceanbase.hbase.secondary.OHTableSecondaryPartAbnormal::testSeriesLimit);
212+
}
213+
214+
@Test
215+
public void testSeriesWithCellTTL() throws Throwable {
216+
List<String> tmpTable = new ArrayList<>();
217+
createTables(NON_PARTITIONED_TIME_CELL_TTL, tmpTable, null, true);
218+
FOR_EACH(tmpTable, OHTableSecondaryPartAbnormal::testSeriesWithCellTTL);
219+
dropTables(tmpTable, null);
220+
}
221+
222+
@Test
223+
public void testSecondaryPartReverseScan() throws Throwable {
224+
List<String> tmpTable = new ArrayList<>();
225+
createTables(SECONDARY_PARTITIONED_KEY_RANGE_GEN, tmpTable, null, true);
226+
FOR_EACH(tmpTable, OHTableSecondaryPartAbnormal::testSecondaryPartReverseScan);
227+
dropTables(tmpTable, null);
228+
}
229+
}

0 commit comments

Comments
 (0)