Skip to content
Merged
Show file tree
Hide file tree
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 @@ -21,6 +21,7 @@ public class ObTableLSOpFlag {
private static final int FLAG_IS_SAME_TYPE = 1 << 0;
private static final int FLAG_IS_SAME_PROPERTIES_NAMES = 1 << 1;
private static final int FLAG_RETURN_ONE_RESULT = 1 << 2;
private static final int FLAG_NEED_ALL_PROP = 1 << 3;
private long flags = 0;

public void setFlagIsSameType(boolean isSameType) {
Expand All @@ -47,6 +48,14 @@ public void setReturnOneResult(boolean returnOneResult) {
}
}

public void setFlagNeedAllProp(boolean needAllProp) {
if (needAllProp) {
flags |= FLAG_NEED_ALL_PROP;
} else {
flags &= ~FLAG_NEED_ALL_PROP;
}
}

public long getValue() {
return flags;
}
Expand All @@ -62,4 +71,6 @@ public boolean getFlagIsSameType() {
public boolean getFlagIsSamePropertiesNames() {
return (flags & FLAG_IS_SAME_PROPERTIES_NAMES) != 0;
}

public boolean getFlagNeedAllProp() { return (flags & FLAG_NEED_ALL_PROP) != 0;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public void setIsSamePropertiesNames(boolean isSamePropertiesNames) {
optionFlag.setFlagIsSamePropertiesNames(isSamePropertiesNames);
}

public void setNeedAllProp(boolean needAllProp) { optionFlag.setFlagNeedAllProp(needAllProp);}

public boolean isNeedAllProp() { return optionFlag.getFlagNeedAllProp(); }

public long getTableId() {
return tableId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
private final ObTableClient obTableClient;
private ExecutorService executorService;
private boolean returningAffectedEntity = false;
private boolean needAllProp = false;
private List<ObTableSingleOp> batchOperation;

/*
Expand Down Expand Up @@ -187,7 +188,9 @@ public void addOperation(TableQuery query) throws Exception {
String[] propertiesNames = query.getSelectColumns().toArray(new String[0]);
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKey,
propertiesNames, null);

if (propertiesNames.length == 0) {
needAllProp = true;
}
ObTableSingleOp singleOp = new ObTableSingleOp();
singleOp.setSingleOpType(ObTableOperationType.GET);
singleOp.addEntity(entity);
Expand Down Expand Up @@ -379,6 +382,7 @@ public void partitionExecute(ObTableSingleOpResult[] results,
ObTableLSOperation tableLsOp = new ObTableLSOperation();
tableLsOp.setLsId(lsId);
tableLsOp.setReturnOneResult(returnOneResult);
tableLsOp.setNeedAllProp(needAllProp);
tableLsOp.setTableName(tableName);
// fetch the following parameters in first entry for routing
long tableId = 0;
Expand Down
49 changes: 49 additions & 0 deletions src/test/java/com/alipay/oceanbase/rpc/ObTableClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2517,4 +2517,53 @@ public void testQueryWithScanOrder() throws Exception {
client.delete(tableName, new Object[] { 0, 2 });
}
}

@Test
public void testBatchQuery() throws Exception {
String tableName = "test_batch_get";
final int COUNT_SIZE = 20;
try {
int count = COUNT_SIZE;
// prepare data
for (int i = 0; i < count; i++) {
client.insertOrUpdate(tableName).setRowKey(row(colVal("c1", 1), colVal("c2", i)))
.addMutateRow(row(colVal("c3", i + 1), colVal("c4", i + 2))).execute();
}

BatchOperation batchOperation = client.batchOperation(tableName);
while (count-- > 0) {
Row rowKey = row(colVal("c1", 1), colVal("c2", count));
TableQuery query = null;
if (count % 2 == 0) {
query = query().setRowKey(rowKey);
} else {
query = query().setRowKey(rowKey).select("c2", "c3");
}
batchOperation.addOperation(query);
}

BatchOperationResult result = batchOperation.execute();
int index = COUNT_SIZE;
while (index-- > 0) {
Row row = result.get(index).getOperationRow();
int c2Val = (int) row.get("c2");
if (c2Val % 2 == 0) {
assertEquals(4, row.size());
assertEquals(1, row.get("c1"));
assertEquals(c2Val + 1, row.get("c3"));
assertEquals(c2Val + 2, row.get("c4"));

} else {
assertEquals(2, row.size());
assertEquals(c2Val + 1, row.get("c3"));
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
for (int i=0; i < COUNT_SIZE; i++) {
client.delete(tableName).setRowKey(row(colVal("c1", 1), colVal("c2", i))).execute();
}
}
}
}
8 changes: 8 additions & 0 deletions src/test/resources/ci.sql
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,12 @@ CREATE TABLE `test2$family1` (
PRIMARY KEY (`K`, `Q`, `T`)
) TABLEGROUP = test2;

CREATE TABLE `test_batch_get` (
`c1` int(11) NOT NULL,
`c2` int(11) NOT NULL,
`c3` int(11) DEFAULT NULL,
`c4` int(11) DEFAULT NULL,
PRIMARY KEY (`c1`, `c2`)
) partition by key(`c2`) partitions 3;

alter system set kv_hotkey_throttle_threshold = 50;