Skip to content

fix reverse scan case #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
import org.apache.hadoop.hbase.filter.ValueFilter;
import org.junit.*;

import java.io.IOException;
import java.util.*;

import static com.alipay.oceanbase.hbase.util.ObHTableSecondaryPartUtil.*;
import static com.alipay.oceanbase.hbase.util.ObHTableTestUtil.FOR_EACH;
import static org.apache.hadoop.hbase.util.Bytes.toBytes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

public class OHTableSecondaryPartScanTest {
private static List<String> tableNames = new LinkedList<String>();
Expand Down Expand Up @@ -220,19 +221,49 @@ public static void testScanImpl(String tableName) throws Exception {
Result result = scanner.next();
Assert.assertEquals(null, result);
}

// 8. scan in reverse
{
Scan scan = new Scan(keys[1].getBytes(), "putKey".getBytes());
scan.addFamily(family.getBytes());
scan.setReversed(true);

hTable.close();
}

public static void testReverseScanImpl(String tableName) throws Exception {
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(getTableName(tableName));
hTable.init();
// 0. prepare data
String family = getColumnFamilyName(tableName);
long ts = System.currentTimeMillis();
String keys[] = { "putKey1", "putKey2", "putKey3", "putKey4", "putKey5" };
String columns[] = { "putColumn1", "putColumn2" };
for (String key : keys) {
for (String column : columns) {
Put put = new Put(toBytes(key));
put.add(family.getBytes(), column.getBytes(), ts, toBytes("value" + key + column));
hTable.put(put);
}
}

// 1. scan in reverse
Scan scan = new Scan();
scan.setReversed(true);
if (tableName.contains("secondary")) {
try {
hTable.getScanner(scan);
ResultScanner scanner = hTable.getScanner(scan);
fail("unexpected, should failed before");
} catch (Exception e) {
Assert.assertTrue(e.getCause().getMessage().contains("secondary partitioned hbase table with reverse query not supported"));
assertTrue(e.getCause().getMessage().contains("secondary partitioned hbase table with reverse query not supported"));
}
} else {
ResultScanner scanner = hTable.getScanner(scan);
List<Cell> cells = getCellsFromScanner(scanner);
Assert.assertEquals(keys.length * columns.length, cells.size());
// check value
System.out.println(cells);
int cellidx = 0;
for (int i = keys.length - 1; i >= 0; i --) {
for (String column : columns) {
AssertKeyValue(keys[i], family, column, ts, "value" + keys[i] + column, cells.get(cellidx++));
}
}
}
hTable.close();
}

public static void testMultiCFScanImpl(Map.Entry<String, List<String>> entry) throws Exception {
Expand Down Expand Up @@ -486,14 +517,78 @@ public static void testMultiCFScanImpl(Map.Entry<String, List<String>> entry) th
}
hTable.close();
}

public static void testMultiCFReverseScanImpl(Map.Entry<String, List<String>> entry) throws Exception {
String groupName = getTableName(entry.getKey());
OHTableClient hTable = ObHTableTestUtil.newOHTableClient(groupName);
hTable.init();
long ts = System.currentTimeMillis();

String keys[] = { "putKey1", "putKey2", "putKey3", "putKey4", "putKey5" };
String columns[] = { "putColumn1", "putColumn2" };
String values[] = { "putValue1", "putValue2" };
long tss[] = { ts, ts + 1 };
long lastTs = tss[1];
String latestValue = values[1];
List<String> tableNames = entry.getValue();

for (String key : keys) {
Put put = new Put(toBytes(key));
for (String tableName : tableNames) {
String family = getColumnFamilyName(tableName);
for (String column : columns) {
put.addColumn(toBytes(family), toBytes(column), ts, toBytes("value" + key + family + column));
}
}
hTable.put(put);
}

if (groupName.contains("secondary")) {
try {
Scan scan = new Scan();
scan.setReversed(true);
ResultScanner scanner = hTable.getScanner(scan);
fail("unexpected, should failed before");
} catch (IOException e) {
assertTrue(e.getCause().getMessage().contains("secondary partitioned hbase table with reverse query not supported"));
}
} else {
Scan scan = new Scan();
scan.setReversed(true);
ResultScanner scanner = hTable.getScanner(scan);
List<Cell> cells = getCellsFromScanner(scanner);
assertEquals(keys.length * 2 * tableNames.size(), cells.size());
System.out.println(cells);
int cellidx = 0;
for (int i = keys.length - 1; i >= 0; i --) {
for (String tableName : tableNames) {
String family = getColumnFamilyName(tableName);
for (String column : columns) {
AssertKeyValue(keys[i], family, column, ts, "value" + keys[i] + family + column, cells.get(cellidx++));
}
}
}
}

}

@Test
public void testScan() throws Throwable {
FOR_EACH(tableNames, OHTableSecondaryPartScanTest::testScanImpl);
}

@Test
public void testReverseScan() throws Throwable {
FOR_EACH(tableNames, OHTableSecondaryPartScanTest::testReverseScanImpl);
}

@Test
public void testMultiCFScan() throws Throwable {
FOR_EACH(group2tableNames, OHTableSecondaryPartScanTest::testMultiCFScanImpl);
}

@Test
public void testMiltiCFReverseScan() throws Throwable {
FOR_EACH(group2tableNames, OHTableSecondaryPartScanTest::testMultiCFReverseScanImpl);
}
}