Skip to content

Commit 2d7e826

Browse files
committed
fix
1 parent e32d1d4 commit 2d7e826

File tree

2 files changed

+110
-28
lines changed

2 files changed

+110
-28
lines changed

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,6 @@ public Result call() throws IOException {
767767
// In a Get operation where the family map is greater than 1 or equal to 0,
768768
// we handle this by appending the column family to the qualifier on the client side.
769769
// The server can then use this information to filter the appropriate column families and qualifiers.
770-
if (!get.getColumnFamilyTimeRange().isEmpty()) {
771-
throw new FeatureNotSupportedException("setColumnFamilyTimeRange is only supported in single column family for now");
772-
}
773770
NavigableSet<byte[]> columnFilters = new TreeSet<>(Bytes.BYTES_COMPARATOR);
774771
processColumnFilters(columnFilters, get.getFamilyMap());
775772
obTableQuery = buildObTableQuery(get, columnFilters);
@@ -783,17 +780,6 @@ public Result call() throws IOException {
783780
for (Map.Entry<byte[], NavigableSet<byte[]>> entry : get.getFamilyMap()
784781
.entrySet()) {
785782
family = entry.getKey();
786-
if (!get.getColumnFamilyTimeRange().isEmpty()) {
787-
Map<byte[], TimeRange> colFamTimeRangeMap = get.getColumnFamilyTimeRange();
788-
if (colFamTimeRangeMap.size() > 1) {
789-
throw new FeatureNotSupportedException("setColumnFamilyTimeRange is only supported in single column family for now");
790-
} else if (colFamTimeRangeMap.get(family) == null) {
791-
throw new IllegalArgumentException("Get family is not matched in ColumnFamilyTimeRange");
792-
} else {
793-
TimeRange tr = colFamTimeRangeMap.get(family);
794-
get.setTimeRange(tr.getMin(), tr.getMax());
795-
}
796-
}
797783
obTableQuery = buildObTableQuery(get, entry.getValue());
798784
request = buildObTableQueryAsyncRequest(obTableQuery,
799785
getTargetTableName(tableNameString, Bytes.toString(family),
@@ -864,9 +850,6 @@ public ResultScanner call() throws IOException {
864850
// In a Scan operation where the family map is greater than 1 or equal to 0,
865851
// we handle this by appending the column family to the qualifier on the client side.
866852
// The server can then use this information to filter the appropriate column families and qualifiers.
867-
if (!scan.getColumnFamilyTimeRange().isEmpty()) {
868-
throw new FeatureNotSupportedException("setColumnFamilyTimeRange is only supported in single column family for now");
869-
}
870853
NavigableSet<byte[]> columnFilters = new TreeSet<>(Bytes.BYTES_COMPARATOR);
871854
processColumnFilters(columnFilters, scan.getFamilyMap());
872855
filter = buildObHTableFilter(scan.getFilter(), scan.getTimeRange(),
@@ -883,17 +866,6 @@ public ResultScanner call() throws IOException {
883866
for (Map.Entry<byte[], NavigableSet<byte[]>> entry : scan.getFamilyMap()
884867
.entrySet()) {
885868
family = entry.getKey();
886-
if (!scan.getColumnFamilyTimeRange().isEmpty()) {
887-
Map<byte[], TimeRange> colFamTimeRangeMap = scan.getColumnFamilyTimeRange();
888-
if (colFamTimeRangeMap.size() > 1) {
889-
throw new FeatureNotSupportedException("setColumnFamilyTimeRange is only supported in single column family for now");
890-
} else if (colFamTimeRangeMap.get(family) == null) {
891-
throw new IllegalArgumentException("Scan family is not matched in ColumnFamilyTimeRange");
892-
} else {
893-
TimeRange tr = colFamTimeRangeMap.get(family);
894-
scan.setTimeRange(tr.getMin(), tr.getMax());
895-
}
896-
}
897869
filter = buildObHTableFilter(scan.getFilter(), scan.getTimeRange(),
898870
scan.getMaxVersions(), entry.getValue());
899871
obTableQuery = buildObTableQuery(filter, scan);

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

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.apache.hadoop.conf.Configuration;
2121
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
2222
import com.alipay.oceanbase.hbase.util.ObHTableTestUtil;
23+
import org.apache.hadoop.hbase.Cell;
24+
import org.apache.hadoop.hbase.CellUtil;
2325
import org.apache.hadoop.hbase.KeyValue;
2426
import org.apache.hadoop.hbase.TableName;
2527
import org.apache.hadoop.hbase.client.*;
@@ -29,6 +31,7 @@
2931
import org.junit.*;
3032
import org.junit.rules.ExpectedException;
3133

34+
import java.io.IOException;
3235
import java.util.*;
3336

3437
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
@@ -1261,4 +1264,111 @@ public void testMultiColumnFamilyDelete() throws Exception {
12611264
.getTimestamp());
12621265
assertTrue(lastTimestamp > oldTimestamp);
12631266
}
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+
}
12641374
}

0 commit comments

Comments
 (0)