remove rowKeyElement dependencies test for code review (#159)

* merged all commits into one

* correct reverse test

* format code

* check whether startRow and endRow contain the refColumn in Hash and Key part

* keep the same format with ObHashPartDesc
This commit is contained in:
Ziyu Shi 2024-09-13 16:22:06 +08:00 committed by GitHub
parent 402b604dc7
commit 7b97f73431
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 1475 additions and 905 deletions

View File

@ -365,4 +365,4 @@
</build>
</profile>
</profiles>
</project>
</project>

View File

@ -55,8 +55,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static com.alipay.oceanbase.rpc.constant.Constants.ALL_DUMMY_TABLE;
import static com.alipay.oceanbase.rpc.constant.Constants.OCEANBASE_DATABASE;
import static com.alipay.oceanbase.rpc.constant.Constants.*;
import static com.alipay.oceanbase.rpc.location.LocationUtil.*;
import static com.alipay.oceanbase.rpc.location.model.ObServerRoute.STRONG_READ;
import static com.alipay.oceanbase.rpc.location.model.TableEntry.HBASE_ROW_KEY_ELEMENT;
@ -588,7 +587,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* Get row key.
*/
public Object[] getRowKey() {
return rowKey;
return this.rowKey;
}
}
@ -625,8 +624,8 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
if (odpMode) {
obPair = new ObPair<Long, ObTableParam>(0L, new ObTableParam(odpTable));
} else {
obPair = getTableBySingleRowKeyWithRoute(tableName, callback.getRowKey(),
needRefreshTableEntry, tableEntryRefreshIntervalWait, needFetchAllRouteInfo, route);
obPair = getTable(tableName, callback.getRowKey(), needRefreshTableEntry,
tableEntryRefreshIntervalWait, route);
}
T t = callback.execute(obPair);
resetExecuteContinuousFailureCount(tableName);
@ -695,10 +694,10 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
}
private abstract class MutationExecuteCallback<T> {
private final Object[] rowKey;
private final Row rowKey;
private final List<ObNewRange> keyRanges;
MutationExecuteCallback(Object[] rowKey, List<ObNewRange> keyRanges) {
MutationExecuteCallback(Row rowKey, List<ObNewRange> keyRanges) {
this.rowKey = rowKey;
this.keyRanges = keyRanges;
}
@ -736,7 +735,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
/*
* Get row key.
*/
public Object[] getRowKey() {
public Row getRowKey() {
return rowKey;
}
@ -788,11 +787,12 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
} else {
if (null != callback.getRowKey()) {
// using row key
obPair = getTableBySingleRowKeyWithRoute(tableName, callback.getRowKey(),
needRefreshTableEntry, tableEntryRefreshIntervalWait, needFetchAllRouteInfo, route);
obPair = getTable(tableName, callback.getRowKey(), needRefreshTableEntry,
tableEntryRefreshIntervalWait, route);
} else if (null != callback.getKeyRanges()) {
// using scan range
obPair = getTableByRowKeyRange(tableName, new ObTableQuery(), callback.getKeyRanges());
obPair = getTable(tableName, new ObTableQuery(), callback.getKeyRanges(),
needRefreshTableEntry, tableEntryRefreshIntervalWait, route);
} else {
throw new ObTableException("rowkey and scan range are null in mutation");
}
@ -833,6 +833,10 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
}
} else if (ex instanceof ObTableException
&& ((ObTableException) ex).isNeedRefreshTableEntry()) {
// if the problem is the lack of row key name, throw directly
if (tableRowKeyElement.get(tableName) == null) {
throw ex;
}
needRefreshTableEntry = true;
logger
@ -884,7 +888,6 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
}
}
/**
* Reset execute continuous failure count.
* @param tableName table name
@ -1265,6 +1268,10 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
tableEntryRefreshContinuousFailureCount.set(0);
} catch (ObTableEntryRefreshException e) {
RUNTIME.error("getOrRefreshTableEntry meet exception", e);
// if the problem is the lack of row key name, throw directly
if (tableRowKeyElement.get(tableName) == null) {
throw e;
}
if (tableEntryRefreshContinuousFailureCount.incrementAndGet() > tableEntryRefreshContinuousFailureCeiling) {
logger.error(LCD.convert("01-00019"),
@ -1339,6 +1346,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
if (tableEntry.isPartitionTable()) {
switch (runningMode) {
case HBASE:
tableRowKeyElement.put(tableName, HBASE_ROW_KEY_ELEMENT);
tableEntry.setRowKeyElement(HBASE_ROW_KEY_ELEMENT);
break;
case NORMAL:
@ -1346,11 +1354,12 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
if (rowKeyElement != null) {
tableEntry.setRowKeyElement(rowKeyElement);
} else {
RUNTIME.error("partition table must has row key element key ="
+ tableEntryKey);
RUNTIME
.error("partition table must add row key element name for table: "
+ tableName + " with table entry key: " + tableEntryKey);
throw new ObTableEntryRefreshException(
"partition table must has row key element key ="
+ tableEntryKey);
"partition table must add row key element name for table: "
+ tableName + " with table entry key: " + tableEntryKey);
}
}
tableEntry.prepare();
@ -1434,31 +1443,29 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
/**
* 根据 rowkey 获取分区 id
* @param tableEntry
* @param rowKey
* @param row
* @return
*/
private long getPartition(TableEntry tableEntry, Object[] rowKey) {
private long getPartition(TableEntry tableEntry, Row row) {
// non partition
if (!tableEntry.isPartitionTable()
|| tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_ZERO) {
return 0L;
}
if (tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_ONE) {
return tableEntry.getPartitionInfo().getFirstPartDesc().getPartId(rowKey);
return tableEntry.getPartitionInfo().getFirstPartDesc().getPartId(row);
}
Long partId1 = tableEntry.getPartitionInfo().getFirstPartDesc().getPartId(rowKey);
Long partId2 = tableEntry.getPartitionInfo().getSubPartDesc().getPartId(rowKey);
Long partId1 = tableEntry.getPartitionInfo().getFirstPartDesc().getPartId(row);
Long partId2 = tableEntry.getPartitionInfo().getSubPartDesc().getPartId(row);
return generatePartId(partId1, partId2);
}
/*
* Get logicId(partition id in 3.x) from giving range
*/
private List<Long> getPartitionsForLevelTwo(TableEntry tableEntry,
List<String> scanRangeColumns, Object[] start,
boolean startIncluded, Object[] end,
private List<Long> getPartitionsForLevelTwo(TableEntry tableEntry, Row startRow,
boolean startIncluded, Row endRow,
boolean endIncluded) throws Exception {
if (tableEntry.getPartitionInfo().getLevel() != ObPartitionLevel.LEVEL_TWO) {
RUNTIME.error("getPartitionsForLevelTwo need ObPartitionLevel LEVEL_TWO");
@ -1466,9 +1473,9 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
}
List<Long> partIds1 = tableEntry.getPartitionInfo().getFirstPartDesc()
.getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded);
.getPartIds(startRow, startIncluded, endRow, endIncluded);
List<Long> partIds2 = tableEntry.getPartitionInfo().getSubPartDesc()
.getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded);
.getPartIds(startRow, startIncluded, endRow, endIncluded);
List<Long> partIds = new ArrayList<Long>();
if (partIds1.isEmpty()) {
@ -1538,15 +1545,13 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @param rowKey row key
* @param refresh whether to refresh
* @param waitForRefresh whether wait for refresh
* @param needFetchAll whether need fetch all
* @return ObPair of partId and table
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTableBySingleRowKey(String tableName, Object[] rowKey,
boolean refresh, boolean waitForRefresh, boolean needFetchAll)
throws Exception {
public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, boolean refresh,
boolean waitForRefresh) throws Exception {
ObServerRoute route = getRoute(false);
return getTableBySingleRowKeyWithRoute(tableName, rowKey, refresh, waitForRefresh, needFetchAll, route);
return getTable(tableName, rowKey, refresh, waitForRefresh, route);
}
/**
@ -1559,16 +1564,33 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return ObPair of partId and table
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTableBySingleRowKeyWithRoute(String tableName,
Object[] rowKey,
boolean refresh,
boolean waitForRefresh,
boolean needFetchAll,
ObServerRoute route)
throws Exception {
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, needFetchAll);
public ObPair<Long, ObTableParam> getTable(String tableName, Object[] rowKey, boolean refresh,
boolean waitForRefresh, ObServerRoute route)
throws Exception {
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, false);
Row row = new Row();
if (tableEntry.isPartitionTable()
&& tableEntry.getPartitionInfo().getLevel() != ObPartitionLevel.LEVEL_ZERO) {
List<String> curTableRowKeyNames = new ArrayList<String>();
Map<String, Integer> tableRowKeyEle = getRowKeyElement(tableName);
if (tableRowKeyEle != null) {
curTableRowKeyNames = new ArrayList<String>(tableRowKeyEle.keySet());
}
if (curTableRowKeyNames.isEmpty()) {
throw new IllegalArgumentException("Please make sure add row key elements");
}
long partId = getPartition(tableEntry, rowKey); // partition id in 3.x, origin partId in 4.x, logicId
// match the correct key to its row key
for (int i = 0; i < rowKey.length; ++i) {
if (i < curTableRowKeyNames.size()) {
row.add(curTableRowKeyNames.get(i), rowKey[i]);
} else { // the rowKey element in the table only contain partition key(s) or the input row key has redundant elements
break;
}
}
}
long partId = getPartition(tableEntry, row); // partition id in 3.x, origin partId in 4.x, logicId
return getTableInternal(tableName, tableEntry, partId, waitForRefresh, route);
}
@ -1577,11 +1599,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* For mutation (queryWithFilter)
* @param tableName table want to get
* @param keyRanges key
* @param refresh whether to refresh
* @param waitForRefresh whether wait for refresh
* @param route ObServer route
* @return ObPair of partId and table
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTableByRowKeyRange(String tableName, ObTableQuery query, List<ObNewRange> keyRanges)
throws Exception {
public ObPair<Long, ObTableParam> getTable(String tableName, ObTableQuery query, List<ObNewRange> keyRanges, boolean refresh,
boolean waitForRefresh, ObServerRoute route)
throws Exception {
Map<Long, ObTableParam> partIdMapObTable = new HashMap<Long, ObTableParam>();
for (ObNewRange rang : keyRanges) {
ObRowKey startKey = rang.getStartKey();
@ -1620,6 +1646,40 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
return ans;
}
/**
* For mutation execute
* @param tableName table want to get
* @param rowKey row key with column names
* @param refresh whether to refresh
* @param waitForRefresh whether wait for refresh
* @return ObPair of partId and table
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey, boolean refresh,
boolean waitForRefresh) throws Exception {
return getTable(tableName, rowKey, refresh, waitForRefresh, getRoute(false));
}
/**
* For mutation execute
* @param tableName table want to get
* @param rowKey row key with column names
* @param refresh whether to refresh
* @param waitForRefresh whether wait for refresh
* @param route ObServer route
* @return ObPair of partId and table
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTable(String tableName, Row rowKey, boolean refresh,
boolean waitForRefresh, ObServerRoute route)
throws Exception {
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, false);
long partId;
partId = getPartition(tableEntry, rowKey); // partition id in 3.x, origin partId in 4.x, logicId
return getTableInternal(tableName, tableEntry, partId, waitForRefresh, route);
}
/**
* get addr by pardId
* @param tableName table want to get
@ -1631,9 +1691,11 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @throws Exception exception
*/
public ObPair<Long, ObTableParam> getTableWithPartId(String tableName, long partId,
boolean refresh, boolean waitForRefresh, boolean needFetchAll,
ObServerRoute route) throws Exception {
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, needFetchAll);
boolean refresh, boolean waitForRefresh,
boolean needFetchAll, ObServerRoute route)
throws Exception {
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh,
needFetchAll);
return getTableInternal(tableName, tableEntry, partId, waitForRefresh, route);
}
@ -1736,19 +1798,18 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
/**
* 根据 start-end 获取 partition id addr
* @param tableEntry
* @param start
* @param startRow
* @param startIncluded
* @param end
* @param endRow
* @param endIncluded
* @param route
* @return
* @throws Exception
*/
private List<ObPair<Long, ReplicaLocation>> getPartitionReplica(TableEntry tableEntry,
List<String> scanRangeColumns,
Object[] start,
Row startRow,
boolean startIncluded,
Object[] end,
Row endRow,
boolean endIncluded,
ObServerRoute route)
throws Exception {
@ -1761,14 +1822,14 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
return replicas;
} else if (tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_ONE) {
List<Long> partIds = tableEntry.getPartitionInfo().getFirstPartDesc()
.getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded);
.getPartIds(startRow, startIncluded, endRow, endIncluded);
for (Long partId : partIds) {
replicas.add(new ObPair<Long, ReplicaLocation>(partId, getPartitionLocation(
tableEntry, partId, route)));
}
} else if (tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_TWO) {
List<Long> partIds = getPartitionsForLevelTwo(tableEntry, scanRangeColumns, start, startIncluded, end,
endIncluded);
List<Long> partIds = getPartitionsForLevelTwo(tableEntry, startRow, startIncluded,
endRow, endIncluded);
for (Long partId : partIds) {
replicas.add(new ObPair<Long, ReplicaLocation>(partId, getPartitionLocation(
tableEntry, partId, route)));
@ -1815,27 +1876,46 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return list of ObPair of partId(logicId) and tableParam
* @throws Exception exception
*/
public List<ObPair<Long, ObTableParam>> getTables(String tableName, ObTableQuery query, Object[] start,
boolean startInclusive, Object[] end,
boolean endInclusive, boolean refresh,
boolean waitForRefresh, ObServerRoute route)
throws Exception {
public List<ObPair<Long, ObTableParam>> getTables(String tableName, ObTableQuery query,
Object[] start, boolean startInclusive,
Object[] end, boolean endInclusive,
boolean refresh, boolean waitForRefresh,
ObServerRoute route) throws Exception {
// 1. get TableEntry information
TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, false);
List<String> scanRangeColumns = query.getScanRangeColumns();
if (scanRangeColumns == null || scanRangeColumns.size() == 0) {
Map<String, Integer> tableRowKeyElement = tableEntry.getRowKeyElement();
if (tableRowKeyElement != null) {
scanRangeColumns = new ArrayList<>(tableRowKeyElement.keySet());
if (scanRangeColumns == null || scanRangeColumns.isEmpty()) {
Map<String, Integer> tableEntryRowKeyElement = getRowKeyElement(tableName);
if (tableEntryRowKeyElement != null) {
scanRangeColumns = new ArrayList<String>(tableEntryRowKeyElement.keySet());
}
}
// 2. get replica location
// partIdWithReplicaList -> List<pair<logicId(partition id in 3.x), replica>>
if (start.length != end.length) {
throw new IllegalArgumentException("length of start key and end key is not equal");
}
Row startRow = new Row();
Row endRow = new Row();
// ensure the format of column names and values if the current table is a table with partition
if (tableEntry.isPartitionTable()
&& tableEntry.getPartitionInfo().getLevel() != ObPartitionLevel.LEVEL_ZERO) {
// scanRangeColumn may be longer than start/end in prefix scanning situation
if (scanRangeColumns == null || scanRangeColumns.size() < start.length) {
throw new IllegalArgumentException(
"length of key and scan range columns do not match, please use addRowKeyElement or set scan range columns");
}
for (int i = 0; i < start.length; i++) {
startRow.add(scanRangeColumns.get(i), start[i]);
endRow.add(scanRangeColumns.get(i), end[i]);
}
}
// 2. get replica location
// partIdWithReplicaList -> List<pair<logicId(partition id in 3.x), replica>>
List<ObPair<Long, ReplicaLocation>> partIdWithReplicaList = getPartitionReplica(tableEntry,
scanRangeColumns, start, startInclusive, end, endInclusive, route);
startRow, startInclusive, endRow, endInclusive, route);
// obTableParams -> List<Pair<logicId, obTableParams>>
List<ObPair<Long, ObTableParam>> obTableParams = new ArrayList<ObPair<Long, ObTableParam>>();
@ -2070,7 +2150,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload updateWithResult(final String tableName, final Object[] rowKey,
public ObPayload updateWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values) throws Exception {
final long start = System.currentTimeMillis();
@ -2085,15 +2165,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, UPDATE, rowKey, columns, values,
tableName, UPDATE, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "UPDATE", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "UPDATE", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2151,7 +2231,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload deleteWithResult(final String tableName, final Object[] rowKey,
public ObPayload deleteWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges) throws Exception {
final long start = System.currentTimeMillis();
return executeMutation(tableName,
@ -2166,14 +2246,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, DEL, rowKey, null, null, obTable.getObTableOperationTimeout());
tableName, DEL, rowKey.getValues(), null, null,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "DELETE", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "DELETE", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2233,7 +2314,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload insertWithResult(final String tableName, final Object[] rowKey,
public ObPayload insertWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values) throws Exception {
final long start = System.currentTimeMillis();
@ -2248,15 +2329,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, INSERT, rowKey, columns, values,
tableName, INSERT, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "INSERT", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "INSERT", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2274,7 +2355,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload putWithResult(final String tableName, final Object[] rowKey,
public ObPayload putWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values) throws Exception {
final long start = System.currentTimeMillis();
@ -2289,15 +2370,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, PUT, rowKey, columns, values,
tableName, PUT, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "PUT", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "PUT", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2357,7 +2438,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload replaceWithResult(final String tableName, final Object[] rowKey,
public ObPayload replaceWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values) throws Exception {
final long start = System.currentTimeMillis();
@ -2372,15 +2453,15 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, REPLACE, rowKey, columns, values,
tableName, REPLACE, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "REPLACE", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "REPLACE", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2441,7 +2522,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload insertOrUpdateWithResult(final String tableName, final Object[] rowKey,
public ObPayload insertOrUpdateWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges,
final String[] columns, final Object[] values,
boolean usePut) throws Exception {
@ -2457,7 +2538,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, INSERT_OR_UPDATE, rowKey, columns, values,
tableName, INSERT_OR_UPDATE, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setTableId(tableParam.getTableId());
// partId/tabletId
@ -2468,7 +2549,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "INERT_OR_UPDATE", endpoint,
rowKey, (ObTableOperationResult) result, TableTime - start,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2547,7 +2628,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload incrementWithResult(final String tableName, final Object[] rowKey,
public ObPayload incrementWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values, final boolean withResult)
throws Exception {
@ -2566,7 +2647,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, INCREMENT, rowKey, columns, values,
tableName, INCREMENT, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setReturningAffectedEntity(withResult);
request.setTableId(tableParam.getTableId());
@ -2574,8 +2655,8 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "INCREMENT", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "INCREMENT", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2632,7 +2713,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload appendWithResult(final String tableName, final Object[] rowKey,
public ObPayload appendWithResult(final String tableName, final Row rowKey,
final List<ObNewRange> keyRanges, final String[] columns,
final Object[] values, final boolean withResult)
throws Exception {
@ -2645,7 +2726,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
ObTableParam tableParam = obPair.getRight();
ObTable obTable = tableParam.getObTable();
ObTableOperationRequest request = ObTableOperationRequest.getInstance(
tableName, APPEND, rowKey, columns, values,
tableName, APPEND, rowKey.getValues(), columns, values,
obTable.getObTableOperationTimeout());
request.setReturningAffectedEntity(withResult);
request.setTableId(tableParam.getTableId());
@ -2653,8 +2734,8 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
request.setPartitionId(tableParam.getPartitionId());
ObPayload result = executeWithRetry(obTable, request, tableName);
String endpoint = obTable.getIp() + ":" + obTable.getPort();
MonitorUtil.info(request, database, tableName, "INCREMENT", endpoint, rowKey,
(ObTableOperationResult) result, TableTime - start,
MonitorUtil.info(request, database, tableName, "INCREMENT", endpoint,
rowKey.getValues(), (ObTableOperationResult) result, TableTime - start,
System.currentTimeMillis() - TableTime, getslowQueryMonitorThreshold());
checkResult(obTable.getIp(), obTable.getPort(), request, result);
return result;
@ -2679,7 +2760,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload mutationWithFilter(final TableQuery tableQuery, final Object[] rowKey,
public ObPayload mutationWithFilter(final TableQuery tableQuery, final Row rowKey,
final List<ObNewRange> keyRanges,
final ObTableOperation operation, final boolean withResult)
throws Exception {
@ -2699,7 +2780,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
* @return execute result
* @throws Exception exception
*/
public ObPayload mutationWithFilter(final TableQuery tableQuery, final Object[] rowKey,
public ObPayload mutationWithFilter(final TableQuery tableQuery, final Row rowKey,
final List<ObNewRange> keyRanges,
final ObTableOperation operation, final boolean withResult,
final boolean checkAndExecute, final boolean checkExists)
@ -2943,9 +3024,9 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
end[i] = endKey.getObj(i).getValue();
}
ObBorderFlag borderFlag = rang.getBorderFlag();
List<ObPair<Long, ObTableParam>> pairList = getTables(request.getTableName(), tableQuery,
start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(),
false, false);
List<ObPair<Long, ObTableParam>> pairList = getTables(request.getTableName(),
tableQuery, start, borderFlag.isInclusiveStart(), end,
borderFlag.isInclusiveEnd(), false, false);
for (ObPair<Long, ObTableParam> pair : pairList) {
partIdMapObTable.put(pair.getLeft(), pair.getRight());
}
@ -3320,7 +3401,7 @@ public class ObTableClient extends AbstractObTableClient implements Lifecycle {
if (tableName == null || tableName.length() == 0) {
throw new IllegalArgumentException("table name is null");
}
Map<String, Integer> rowKeyElement = new LinkedHashMap<>();
Map<String, Integer> rowKeyElement = new LinkedHashMap<String, Integer>();
for (int i = 0; i < columns.length; i++) {
rowKeyElement.put(columns[i], i);
}

View File

@ -21,6 +21,7 @@ import com.alipay.oceanbase.rpc.ObTableClient;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.filter.ObTableFilter;
import com.alipay.oceanbase.rpc.mutation.InsertOrUpdate;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey;
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableOperation;
@ -58,7 +59,7 @@ public class CheckAndInsUp {
this.checkExists = check_exists;
}
public Object[] getRowKey() {
public Row getRowKey() {
return insUp.getRowKey();
}
@ -85,15 +86,15 @@ public class CheckAndInsUp {
TableQuery query = client.query(tableName);
query.setFilter(filter);
Object[] rowKey = getRowKey();
Row rowKey = getRowKey();
List<ObNewRange> ranges = new ArrayList<>();
ObNewRange range = new ObNewRange();
range.setStartKey(ObRowKey.getInstance(insUp.getRowKey()));
range.setEndKey(ObRowKey.getInstance(insUp.getRowKey()));
range.setStartKey(ObRowKey.getInstance(insUp.getRowKey().getValues()));
range.setEndKey(ObRowKey.getInstance(insUp.getRowKey().getValues()));
ranges.add(range);
query.getObTableQuery().setKeyRanges(ranges);
ObTableOperation operation = ObTableOperation.getInstance(ObTableOperationType.INSERT_OR_UPDATE,
insUp.getRowKey(), insUp.getColumns(), insUp.getValues());
insUp.getRowKey().getValues(), insUp.getColumns(), insUp.getValues());
return new MutationResult(((ObTableClient)client).mutationWithFilter(query, rowKey, ranges, operation, false, true, checkExists));
}

View File

@ -21,6 +21,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alipay.oceanbase.rpc.ObClusterTableBatchOps;
import com.alipay.oceanbase.rpc.ObGlobal;
import com.alipay.oceanbase.rpc.constant.Constants;
import com.alipay.oceanbase.rpc.exception.*;
@ -1312,8 +1313,29 @@ public class LocationUtil {
}
// set the property of first part and sub part
setPartDescProperty(info.getFirstPartDesc(), info.getPartColumns(), orderedPartedColumns1);
setPartDescProperty(info.getSubPartDesc(), info.getPartColumns(), orderedPartedColumns2);
List<ObColumn> firstPartColumns = new ArrayList<ObColumn>(), subPartColumns = new ArrayList<ObColumn>();
if (null != info.getFirstPartDesc()) {
for (String partColumnNames : info.getFirstPartDesc().getOrderedPartColumnNames()) {
for (ObColumn curColumn : info.getPartColumns()) {
if (curColumn.getColumnName().equalsIgnoreCase(partColumnNames)) {
firstPartColumns.add(curColumn);
break;
}
}
}
}
if (null != info.getSubPartDesc()) {
for (String partColumnNames : info.getSubPartDesc().getOrderedPartColumnNames()) {
for (ObColumn curColumn : info.getPartColumns()) {
if (curColumn.getColumnName().equalsIgnoreCase(partColumnNames)) {
subPartColumns.add(curColumn);
break;
}
}
}
}
setPartDescProperty(info.getFirstPartDesc(), firstPartColumns, orderedPartedColumns1);
setPartDescProperty(info.getSubPartDesc(), subPartColumns, orderedPartedColumns2);
return info;
}

View File

@ -17,6 +17,7 @@
package com.alipay.oceanbase.rpc.location.model.partition;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.exception.ObTablePartitionConsistentException;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
@ -24,10 +25,12 @@ import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObjType;
import com.alipay.oceanbase.rpc.util.RandomUtil;
import com.alipay.oceanbase.rpc.util.TableClientLoggerFactory;
import com.alipay.oceanbase.rpc.mutation.Row;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -98,39 +101,58 @@ public class ObHashPartDesc extends ObPartDesc {
* Get part ids.
*/
@Override
public List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj,
boolean endInclusive) {
// close set
try {
// verify the type of parameters and convert to Row
if (!(startRowObj instanceof Row) || !(endRowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + startRowObj + ", "
+ endRowObj);
}
Row startRow = (Row) startRowObj, endRow = (Row) endRowObj;
// pre-check start and end
// should remove after remove addRowkeyElement
if (start.length != end.length) {
if (startRow.size() != endRow.size()) {
throw new IllegalArgumentException("length of start key and end key is not equal");
}
if (startRow.size() == 1 && startRow.getValues()[0] instanceof ObObj && ((ObObj) startRow.getValues()[0]).isMinObj() &&
endRow.size() == 1 && endRow.getValues()[0] instanceof ObObj && ((ObObj) endRow.getValues()[0]).isMaxObj()) {
return completeWorks;
}
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
for (ObPair<ObColumn, List<Integer>> pair : orderedPartRefColumnRowKeyRelations) {
for (int refIdx : pair.getRight()) {
if (start.length <= refIdx) {
throw new IllegalArgumentException("rowkey length is " + start.length
for (ObColumn curObcolumn : partColumns) {
for (int refIdx = 0; refIdx < curObcolumn.getRefColumnNames().size(); ++refIdx) {
String curObRefColumnName = curObcolumn.getRefColumnNames().get(refIdx);
if (startRow.size() <= refIdx) {
throw new IllegalArgumentException("rowkey length is " + startRow.size()
+ ", which is shortest than " + refIdx);
}
if (start[refIdx] instanceof ObObj
&& (((ObObj) start[refIdx]).isMinObj() || ((ObObj) start[refIdx])
.isMaxObj())) {
Object startValue = startRow.get(curObRefColumnName);
if (startValue == null) {
throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }");
}
if (startValue instanceof ObObj
&& (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) {
return completeWorks;
}
if (end[refIdx] instanceof ObObj
&& (((ObObj) end[refIdx]).isMinObj() || ((ObObj) end[refIdx]).isMaxObj())) {
Object endValue = endRow.get(curObRefColumnName);
if (endValue == null) {
throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }");
}
if (endValue instanceof ObObj
&& (((ObObj) endValue).isMinObj() || ((ObObj) endValue).isMaxObj())) {
return completeWorks;
}
}
}
// eval partition key
List<Object> startValues = evalRowKeyValues(start);
List<Object> startValues = evalRowKeyValues(startRow);
Object startValue = startValues.get(0);
List<Object> endValues = evalRowKeyValues(end);
List<Object> endValues = evalRowKeyValues(endRow);
Object endValue = endValues.get(0);
Long startLongValue = ObObjType.parseToLongOrNull(startValue);
@ -160,81 +182,6 @@ public class ObHashPartDesc extends ObPartDesc {
}
}
@Override
public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive,
Object[] end, boolean endInclusive) throws IllegalArgumentException {
try {
if (start.length != end.length) {
throw new IllegalArgumentException("length of start key and end key in range is not equal, " +
"the start key: " + start + ", the end key: " + end);
}
if (start.length == 1 && start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() &&
end.length == 1 && end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
return completeWorks;
}
if (scanRangeColumns.size() != start.length) {
throw new IllegalArgumentException("length of start key in range and scan range columns is not equal," +
"the start key: " + start + ", the scan range columns: " + scanRangeColumns);
}
Row startRow = new Row();
Row endRow = new Row();
for (int i = 0; i < scanRangeColumns.size(); i++) {
startRow.add(scanRangeColumns.get(i), start[i]);
endRow.add(scanRangeColumns.get(i), end[i]);
}
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
for (ObColumn partColumn : partColumns) {
List<String> refColumns = partColumn.getRefColumnNames();
for (String column : refColumns) {
if (startRow.get(column) instanceof ObObj
&& (((ObObj) startRow.get(column)).isMinObj() || ((ObObj) startRow.get(column))
.isMaxObj())) {
return completeWorks;
}
if (endRow.get(column) instanceof ObObj
&& (((ObObj) endRow.get(column)).isMinObj() || ((ObObj) endRow.get(column)).isMaxObj())) {
return completeWorks;
}
}
}
// eval partition key
List<Object> startValues = evalRowKeyValues(startRow);
Object startValue = startValues.get(0);
List<Object> endValues = evalRowKeyValues(endRow);
Object endValue = endValues.get(0);
Long startLongValue = ObObjType.parseToLongOrNull(startValue);
Long endLongValue = ObObjType.parseToLongOrNull(endValue);
if (startLongValue == null || endLongValue == null) {
throw new NumberFormatException("can not parseToComparable start value ["
+ startValue + "] or end value [" + endValue
+ "] to long");
}
long startHashValue = startLongValue - (startInclusive ? 0 : -1);
long endHashValue = endLongValue - (endInclusive ? 0 : 1);
if (endHashValue - startHashValue + 1 >= partNum) {
return completeWorks;
} else {
List<Long> partIds = new ArrayList<Long>();
for (long i = startHashValue; i <= endHashValue; i++) {
partIds.add(innerHash(i));
}
return partIds;
}
} catch (IllegalArgumentException e) {
logger.error(LCD.convert("01-00002"), e);
throw new IllegalArgumentException(
"ObHashPartDesc get part id come across illegal params", e);
}
}
/*
* Get random part id.
*/
@ -247,26 +194,30 @@ public class ObHashPartDesc extends ObPartDesc {
* Get part id.
*/
@Override
public Long getPartId(Object... rowKey) {
List<Object[]> rowKeys = new ArrayList<Object[]>();
rowKeys.add(rowKey);
return this.getPartId(rowKeys, false);
public Long getPartId(Object... row) {
List<Object> rows = new ArrayList<Object>();
rows.addAll(Arrays.asList(row));
return this.getPartId(rows, false);
}
/*
* Get part id.
*/
@Override
public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
public Long getPartId(List<Object> rows, boolean consistency) {
if (rowKeys == null || rowKeys.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rowKeys);
if (rows == null || rows.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rows);
}
Long partId = null;
try {
for (Object[] rowKey : rowKeys) {
List<Object> evalValues = evalRowKeyValues(rowKey);
for (Object rowObj : rows) {
if (!(rowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + rowObj);
}
Row row = (Row) rowObj;
List<Object> evalValues = evalRowKeyValues(row);
Object value = evalValues.get(0);// the partition type of hash has one param at most
Long longValue = ObObjType.parseToLongOrNull(value);
@ -285,7 +236,7 @@ public class ObHashPartDesc extends ObPartDesc {
if (!partId.equals(currentPartId)) {
throw new ObTablePartitionConsistentException(
"across partition operation may cause consistent problem " + rowKeys);
"across partition operation may cause consistent problem " + rows);
}
}
} catch (IllegalArgumentException e) {

View File

@ -17,6 +17,7 @@
package com.alipay.oceanbase.rpc.location.model.partition;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.exception.ObTablePartitionConsistentException;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObCollationType;
@ -87,37 +88,56 @@ public class ObKeyPartDesc extends ObPartDesc {
* Get part ids.
*/
@Override
public List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj,
boolean endInclusive) {
try {
// verify the type of parameters and convert to Row
if (!(startRowObj instanceof Row) || !(endRowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + startRowObj + ", "
+ endRowObj);
}
Row startRow = (Row) startRowObj, endRow = (Row) endRowObj;
// pre-check start and end
// should remove after remove addRowkeyElement
if (start.length != end.length) {
if (startRow.size() != endRow.size()) {
throw new IllegalArgumentException("length of start key and end key is not equal");
}
if (startRow.size() == 1 && startRow.getValues()[0] instanceof ObObj && ((ObObj) startRow.getValues()[0]).isMinObj() &&
endRow.size() == 1 && endRow.getValues()[0] instanceof ObObj && ((ObObj) endRow.getValues()[0]).isMaxObj()) {
return completeWorks;
}
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
for (ObPair<ObColumn, List<Integer>> pair : orderedPartRefColumnRowKeyRelations) {
for (int refIdx : pair.getRight()) {
if (start.length <= refIdx) {
throw new IllegalArgumentException("rowkey length is " + start.length
for (ObColumn curObcolumn : partColumns) {
for (int refIdx = 0; refIdx < curObcolumn.getRefColumnNames().size(); ++refIdx) {
String curObRefColumnName = curObcolumn.getRefColumnNames().get(refIdx);
if (startRow.size() <= refIdx) {
throw new IllegalArgumentException("rowkey length is " + startRow.size()
+ ", which is shortest than " + refIdx);
}
if (start[refIdx] instanceof ObObj
&& (((ObObj) start[refIdx]).isMinObj() || ((ObObj) start[refIdx])
.isMaxObj())) {
Object startValue = startRow.get(curObRefColumnName);
if (startValue == null) {
throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }");
}
if (startValue instanceof ObObj
&& (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) {
return completeWorks;
}
if (end[refIdx] instanceof ObObj
&& (((ObObj) end[refIdx]).isMinObj() || ((ObObj) end[refIdx]).isMaxObj())) {
Object endValue = endRow.get(curObRefColumnName);
if (endValue == null) {
throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }");
}
if (endValue instanceof ObObj
&& (((ObObj) endValue).isMinObj() || ((ObObj) endValue).isMaxObj())) {
return completeWorks;
}
}
}
// eval partition key
List<Object> startValues = evalRowKeyValues(start);
List<Object> endValues = evalRowKeyValues(end);
List<Object> startValues = evalRowKeyValues(startRow);
List<Object> endValues = evalRowKeyValues(endRow);
if (startValues == null || endValues == null) {
throw new NumberFormatException("can not parseToComparable start value ["
@ -140,72 +160,6 @@ public class ObKeyPartDesc extends ObPartDesc {
}
}
// get partition ids for query
public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive,
Object[] end, boolean endInclusive) {
try {
if (start.length != end.length) {
throw new IllegalArgumentException("length of start key and end key is not equal");
}
if (start.length == 1 && start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() &&
end.length == 1 && end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
return completeWorks;
}
if (scanRangeColumns.size() != start.length) {
throw new IllegalArgumentException("length of key and scan range columns is not equal");
}
Row startRow = new Row();
Row endRow = new Row();
for (int i = 0; i < scanRangeColumns.size(); i++) {
startRow.add(scanRangeColumns.get(i), start[i]);
endRow.add(scanRangeColumns.get(i), end[i]);
}
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
for (ObColumn partColumn : partColumns) {
List<String> refColumns = partColumn.getRefColumnNames();
for (String column : refColumns) {
if (startRow.get(column) instanceof ObObj
&& (((ObObj) startRow.get(column)).isMinObj() || ((ObObj) startRow.get(column))
.isMaxObj())) {
return completeWorks;
}
if (endRow.get(column) instanceof ObObj
&& (((ObObj) endRow.get(column)).isMinObj() || ((ObObj) endRow.get(column)).isMaxObj())) {
return completeWorks;
}
}
}
// eval partition key
List<Object> startValues = evalRowKeyValues(startRow);
List<Object> endValues = evalRowKeyValues(endRow);
if (startValues == null || endValues == null) {
throw new NumberFormatException("can not parseToComparable start value ["
+ startValues + "] or end value [" + endValues
+ "] to long");
}
if (startValues.equals(endValues)) {
List<Long> partIds = new ArrayList<Long>();
partIds.add(calcPartId(startValues));
return partIds;
} else {
// partition key is different in key partition
return completeWorks;
}
} catch (IllegalArgumentException e) {
logger.error(LCD.convert("01-00002"), e);
throw new IllegalArgumentException(
"ObKeyPartDesc get part id come across illegal params", e);
}
}
/*
* Get random part id.
*/
@ -218,28 +172,32 @@ public class ObKeyPartDesc extends ObPartDesc {
* Get part id.
*/
@Override
public Long getPartId(Object... rowKey) throws IllegalArgumentException {
List<Object[]> rowKeys = new ArrayList<Object[]>();
rowKeys.add(rowKey);
return getPartId(rowKeys, false);
public Long getPartId(Object... row) throws IllegalArgumentException {
List<Object> rows = new ArrayList<Object>();
rows.addAll(Arrays.asList(row));
return getPartId(rows, false);
}
/*
* Get part id.
*/
@Override
public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
public Long getPartId(List<Object> rows, boolean consistency) {
if (rowKeys == null || rowKeys.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rowKeys);
if (rows == null || rows.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rows);
}
try {
int partRefColumnSize = orderedPartRefColumnRowKeyRelations.size();
int partRefColumnSize = partColumns.size();
List<Object> evalValues = null;
for (Object[] rowKey : rowKeys) {
List<Object> currentRowKeyEvalValues = evalRowKeyValues(rowKey);
for (Object rowObj : rows) {
if (!(rowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + rowObj);
}
Row row = (Row) rowObj;
List<Object> currentRowKeyEvalValues = evalRowKeyValues(row);
if (evalValues == null) {
evalValues = currentRowKeyEvalValues;
}
@ -253,11 +211,10 @@ public class ObKeyPartDesc extends ObPartDesc {
}
for (int i = 0; i < evalValues.size(); i++) {
if (!equalsWithCollationType(orderedPartRefColumnRowKeyRelations.get(i)
.getLeft().getObCollationType(), evalValues.get(i),
currentRowKeyEvalValues.get(i))) {
if (!equalsWithCollationType(partColumns.get(i).getObCollationType(),
evalValues.get(i), currentRowKeyEvalValues.get(i))) {
throw new ObTablePartitionConsistentException(
"across partition operation may cause consistent problem " + rowKeys);
"across partition operation may cause consistent problem " + rows);
}
}
}
@ -272,20 +229,19 @@ public class ObKeyPartDesc extends ObPartDesc {
// calc partition id from eval values
private Long calcPartId(List<Object> evalValues) {
if (evalValues == null || evalValues.size() != orderedPartRefColumnRowKeyRelations.size()) {
if (evalValues == null || evalValues.size() != partColumns.size()) {
throw new IllegalArgumentException("invalid eval values :" + evalValues);
}
long hashValue = 0L;
for (int i = 0; i < orderedPartRefColumnRowKeyRelations.size(); i++) {
hashValue = ObHashUtils.toHashcode(evalValues.get(i),
orderedPartRefColumnRowKeyRelations.get(i).getLeft(), hashValue,
this.getPartFuncType());
for (int i = 0; i < partColumns.size(); i++) {
hashValue = ObHashUtils.toHashcode(evalValues.get(i), partColumns.get(i), hashValue,
this.getPartFuncType());
}
hashValue = (hashValue > 0 ? hashValue : -hashValue);
return ((long) partSpace << ObPartConstants.OB_PART_IDS_BITNUM)
| (hashValue % this.partNum);
| (hashValue % this.partNum);
}
private boolean equalsWithCollationType(ObCollationType collationType, Object s, Object t)

View File

@ -17,6 +17,7 @@
package com.alipay.oceanbase.rpc.location.model.partition;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.exception.ObTablePartitionConsistentException;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
@ -26,7 +27,7 @@ import org.apache.commons.lang.builder.ToStringBuilder;
import org.slf4j.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -105,44 +106,37 @@ public class ObListPartDesc extends ObPartDesc {
* Get part ids.
*/
@Override
public List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj,
boolean endInclusive) {
List<Object[]> rowKeys = new ArrayList<Object[]>();
rowKeys.add(start);
rowKeys.add(end);
Long partId = getPartId(rowKeys, true);
List<Long> partIds = new ArrayList<Long>();
partIds.add(partId);
return partIds;
}
@Override
public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive, Object[] end, boolean endInclusive) throws IllegalArgumentException {
throw new IllegalArgumentException("getPartIds for List partition is not supported");
}
/*
* Get part id.
*/
@Override
public Long getPartId(Object... rowKey) {
List<Object[]> rowKeys = new ArrayList<Object[]>();
rowKeys.add(rowKey);
return getPartId(rowKeys, false);
public Long getPartId(Object... row) {
List<Object> rows = new ArrayList<Object>();
rows.addAll(Arrays.asList(row));
return getPartId(rows, false);
}
/*
* Get part id.
*/
@Override
public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
if (rowKeys == null || rowKeys.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rowKeys);
public Long getPartId(List<Object> rows, boolean consistency) {
if (rows == null || rows.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rows);
}
try {
Long partId = null;
for (Object[] rowKey : rowKeys) {
List<Object> currentRowKeyEvalValues = evalRowKeyValues(rowKey);
for (Object rowObj : rows) {
if (!(rowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + rowObj);
}
Row row = (Row) rowObj;
List<Object> currentRowKeyEvalValues = evalRowKeyValues(row);
List<Comparable> values = super.initComparableElementByTypes(
currentRowKeyEvalValues, this.orderCompareColumns);
@ -158,7 +152,7 @@ public class ObListPartDesc extends ObPartDesc {
if (partId != currentPartId) {
throw new ObTablePartitionConsistentException(
"across partition operation may cause consistent problem " + rowKeys);
"across partition operation may cause consistent problem " + rows);
}
}

View File

@ -23,6 +23,7 @@ import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
import com.alipay.oceanbase.rpc.util.StringUtil;
import com.alipay.oceanbase.rpc.util.TableClientLoggerFactory;
import com.alipay.oceanbase.rpc.mutation.Row;
import org.slf4j.Logger;
import java.util.*;
@ -92,7 +93,7 @@ public abstract class ObPartDesc {
*/
public int getPartNum() {
return -1;
};
}
/*
* Get ordered part column names.
@ -169,129 +170,51 @@ public abstract class ObPartDesc {
//to prepare partition calculate resource
//to check partition calculate is ready
public void prepare() throws IllegalArgumentException {
if (orderedPartColumnNames == EMPTY_LIST) {
throw new IllegalArgumentException(
"prepare ObPartDesc failed. orderedPartColumnNames is empty");
}
if (rowKeyElement == null || rowKeyElement.size() == 0) {
throw new IllegalArgumentException("prepare ObPartDesc failed. rowKeyElement is empty");
}
if (partColumns == null || partColumns.size() == 0) {
throw new IllegalArgumentException("prepare ObPartDesc failed. partColumns is empty");
}
List<ObPair<ObColumn, List<Integer>>> orderPartRefColumnRowKeyRelations = new ArrayList<ObPair<ObColumn, List<Integer>>>(
orderedPartColumnNames.size());
for (String partOrderColumnName : orderedPartColumnNames) {
for (ObColumn column : partColumns) {
if (column.getColumnName().equalsIgnoreCase(partOrderColumnName)) {
List<Integer> partRefColumnRowKeyIndexes = new ArrayList<Integer>(column
.getRefColumnNames().size());
for (String refColumn : column.getRefColumnNames()) {
boolean rowKeyElementRefer = false;
for (String rowKeyElementName : rowKeyElement.keySet()) {
if (rowKeyElementName.equalsIgnoreCase(refColumn)) {
partRefColumnRowKeyIndexes
.add(rowKeyElement.get(rowKeyElementName));
rowKeyElementRefer = true;
}
}
if (!rowKeyElementRefer) {
throw new IllegalArgumentException("partition order column "
+ partOrderColumnName
+ " refer to non-row-key column "
+ refColumn);
}
}
orderPartRefColumnRowKeyRelations.add(new ObPair<ObColumn, List<Integer>>(
column, partRefColumnRowKeyIndexes));
}
}
}
this.orderedPartRefColumnRowKeyRelations = orderPartRefColumnRowKeyRelations;
}
public void prepare() throws IllegalArgumentException { /* do nothing now */ }
/*
* Eval row key values.
*/
public List<Object> evalRowKeyValues(Object... rowKey) throws IllegalArgumentException {
int partRefColumnSize = orderedPartRefColumnRowKeyRelations.size();
List<Object> evalValues = new ArrayList<Object>(partRefColumnSize);
public List<Object> evalRowKeyValues(Row row) throws IllegalArgumentException {
int partColumnSize = partColumns.size();
List<Object> evalValues = new ArrayList<Object>(partColumnSize);
Object[] rowValues = row.getValues();
String[] rowColumnNames = row.getColumns();
if (rowValues.length < partColumnSize) {
throw new IllegalArgumentException("Input row key should at least include " + partColumns
+ "but found" + Arrays.toString(rowValues));
}
boolean needEval = true;
// column or generate column
for (int i = 0; i < partRefColumnSize; i++) {
ObPair<ObColumn, List<Integer>> orderedPartRefColumnRowKeyRelation = orderedPartRefColumnRowKeyRelations
.get(i);
Object[] partKey;
if (rowKey.length < rowKeyElement.size()) {
throw new IllegalArgumentException("row key is consist of " + rowKeyElement
+ "but found" + Arrays.toString(rowKey));
} else {
partKey = Arrays.copyOfRange(rowKey, 0, rowKeyElement.size());
}
// row key is consists of multi column
List<Integer> refIndex = orderedPartRefColumnRowKeyRelation.getRight();
Object[] evalParams = new Object[refIndex.size()];
boolean needEval = true;
for (int j = 0; j < refIndex.size(); j++) {
// TODO where get the type of ref column ?
if (refIndex.size() == 1 && partKey[refIndex.get(j)] instanceof ObObj) {
// set min max into eval values directly
// need refactor after addRowkeyElement has removed
ObObj obj = (ObObj) partKey[refIndex.get(j)];
if (obj.isMaxObj() || obj.isMinObj()) {
evalValues.add(obj);
needEval = false;
break;
for (int i = 0; i < partColumns.size(); ++i) {
ObColumn curObColumn = partColumns.get(i);
List<String> curObRefColumnNames = curObColumn.getRefColumnNames();
Object[] evalParams = new Object[curObRefColumnNames.size()];
for (int j = 0; j < curObRefColumnNames.size(); ++j) {
for (int k = 0; k < rowColumnNames.length; ++k) {
if (rowColumnNames[k].equalsIgnoreCase(curObRefColumnNames.get(j))) {
if (curObRefColumnNames.size() == 1 && rowValues[k] instanceof ObObj) {
ObObj obj = (ObObj) rowValues[k];
if (obj.isMaxObj() || obj.isMinObj()) {
evalValues.add(obj);
needEval = false;
break;
}
}
evalParams[j] = rowValues[k];
break;
}
}
}
evalParams[j] = partKey[refIndex.get(j)];
}
if (needEval) {
evalValues.add(orderedPartRefColumnRowKeyRelation.getLeft().evalValue(evalParams));
}
}
return evalValues;
}
public List<Object> evalRowKeyValues(Row rowKey) throws IllegalArgumentException {
// column or generate column
String[] rowkeyNames = rowKey.getColumns();
List<Object> evalValues = new ArrayList<Object>(orderedPartRefColumnRowKeyRelations.size());
for (int i = 0; i < orderedPartRefColumnRowKeyRelations.size(); i++) {
ObColumn partCol = orderedPartRefColumnRowKeyRelations.get(i).getLeft();
List<String> refCols = partCol.getRefColumnNames();
if (rowKey.size() < refCols.size()) {
throw new IllegalArgumentException("part column ref columns is " + refCols
+ "but found " + rowkeyNames);
}
Object[] evalParams = new Object[refCols.size()];
boolean needEval = true;
for (int j = 0; j < refCols.size(); j++) {
Object refObj = rowKey.get(refCols.get(j));
if (refObj == null) {
throw new IllegalArgumentException("cannot find part column: " + refCols.get(j) +
" in rowKey columns: " + rowkeyNames);
if (needEval) {
evalValues.add(curObColumn.evalValue(evalParams));
}
if (refCols.size() == 1 && refObj instanceof ObObj) {
ObObj obj = (ObObj) refObj;
if (obj.isMaxObj() || obj.isMinObj()) {
evalValues.add(obj);
needEval = false;
break;
}
}
evalParams[j] = refObj;
}
if (needEval) {
evalValues.add(partCol.evalValue(evalParams));
}
}
return evalValues;
}
@ -302,16 +225,15 @@ public abstract class ObPartDesc {
* @param end the end row key
* @param endInclusive the end row key inclusive
*/
public abstract List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
boolean endInclusive) throws IllegalArgumentException;
public abstract List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive,
Object[] end, boolean endInclusive) throws IllegalArgumentException;
public abstract List<Long> getPartIds(Object startRowObj, boolean startInclusive,
Object endRowObj, boolean endInclusive)
throws IllegalArgumentException;
public abstract Long getPartId(Object... rowKey) throws IllegalArgumentException;
public abstract Long getPartId(Object... row) throws IllegalArgumentException;
public abstract Long getPartId(List<Object[]> rowKeys, boolean consistency)
throws IllegalArgumentException,
ObTablePartitionConsistentException;
public abstract Long getPartId(List<Object> row, boolean consistency)
throws IllegalArgumentException,
ObTablePartitionConsistentException;
public abstract Long getRandomPartId();

View File

@ -17,6 +17,7 @@
package com.alipay.oceanbase.rpc.location.model.partition;
import com.alipay.oceanbase.rpc.exception.ObTableException;
import com.alipay.oceanbase.rpc.exception.ObTablePartitionConsistentException;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
@ -213,44 +214,24 @@ public class ObRangePartDesc extends ObPartDesc {
* Get part ids.
*/
@Override
public List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj,
boolean endInclusive) {
// can not detail the border effect so that the range is magnified
int startIdx = getBoundsIdx(true, start);
int stopIdx = getBoundsIdx(true, end);
List<Long> partIds = new ArrayList<Long>();
for (int i = startIdx; i <= stopIdx; i++) {
partIds.add(this.bounds.get(i).value);
if (!(startRowObj instanceof Row) || !(endRowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + startRowObj + ", "
+ endRowObj);
}
return partIds;
}
@Override
public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive,
Object[] end, boolean endInclusive) {
if (start.length != end.length) {
Row startRow = (Row) startRowObj, endRow = (Row) endRowObj;
// pre-check start and end
// should remove after remove addRowkeyElement
if (startRow.size() != endRow.size()) {
throw new IllegalArgumentException("length of start key and end key is not equal");
}
if (start.length == 1 && start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() &&
end.length == 1 && end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
if (startRow.size() == 1 && startRow.getValues()[0] instanceof ObObj && ((ObObj) startRow.getValues()[0]).isMinObj() &&
endRow.size() == 1 && endRow.getValues()[0] instanceof ObObj && ((ObObj) endRow.getValues()[0]).isMaxObj()) {
return completeWorks;
}
if (scanRangeColumns.size() != start.length) {
throw new IllegalArgumentException("length of key and scan range columns is not equal");
}
Row startRow = new Row();
Row endRow = new Row();
for (int i = 0; i < scanRangeColumns.size(); i++) {
startRow.add(scanRangeColumns.get(i), start[i]);
endRow.add(scanRangeColumns.get(i), end[i]);
}
// can not detail the border effect so that the range is magnified
int startIdx = getBoundsIdx(true, startRow);
int stopIdx = getBoundsIdx(true, endRow);
List<Long> partIds = new ArrayList<Long>();
@ -264,9 +245,11 @@ public class ObRangePartDesc extends ObPartDesc {
* Get part id.
*/
@Override
public Long getPartId(Object... rowKey) {
public Long getPartId(Object... row) {
try {
return this.bounds.get(getBoundsIdx(false, rowKey)).value;
List<Object> rows = new ArrayList<Object>();
rows.addAll((Arrays.asList(row)));
return this.bounds.get(getBoundsIdx(false, rows)).value;
} catch (IllegalArgumentException e) {
RUNTIME.error(LCD.convert("01-00025"), e);
throw new IllegalArgumentException(
@ -275,14 +258,18 @@ public class ObRangePartDesc extends ObPartDesc {
}
public int getBoundsIdx(boolean isScan, Object... rowKey) {
if (rowKey.length != rowKeyElement.size()) {
throw new IllegalArgumentException("row key is consist of " + rowKeyElement
+ "but found" + Arrays.toString(rowKey));
public int getBoundsIdx(boolean isScan, List<Object> rowObj) {
if (!(rowObj.get(0) instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + rowObj);
}
Row row = (Row) rowObj.get(0);
if (row.size() < partColumns.size()) {
throw new IllegalArgumentException("Input row key should at least include " + partColumns
+ "but found" + Arrays.toString(row.getValues()));
}
try {
List<Object> evalParams = evalRowKeyValues(rowKey);
List<Object> evalParams = evalRowKeyValues(row);
List<Comparable> comparableElement = super.initComparableElementByTypes(evalParams,
this.orderedCompareColumns);
ObPartitionKey searchKey = ObPartitionKey.getInstance(orderedCompareColumns,
@ -340,14 +327,18 @@ public class ObRangePartDesc extends ObPartDesc {
* Get part id.
*/
@Override
public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
if (rowKeys == null || rowKeys.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rowKeys);
public Long getPartId(List<Object> rows, boolean consistency) {
if (rows == null || rows.size() == 0) {
throw new IllegalArgumentException("invalid row keys :" + rows);
}
Long partId = null;
for (Object[] rowKey : rowKeys) {
long currentPartId = getPartId(rowKey);
for (Object rowObj : rows) {
if (!(rowObj instanceof Row)) {
throw new ObTableException("invalid format of rowObj: " + rowObj);
}
Row row = (Row) rowObj;
long currentPartId = getPartId(row);
if (partId == null) {
partId = currentPartId;
}
@ -357,7 +348,7 @@ public class ObRangePartDesc extends ObPartDesc {
if (!partId.equals(currentPartId)) {
throw new ObTablePartitionConsistentException(
"across partition operation may cause consistent problem " + rowKeys);
"across partition operation may cause consistent problem " + rows);
}
}

View File

@ -199,42 +199,42 @@ public class BatchOperation {
+ type);
case INSERT:
((Insert) mutation).removeRowkeyFromMutateColval();
batchOps.insert(mutation.getRowKey(), ((Insert) mutation).getColumns(),
batchOps.insert(((Insert) mutation).getRowKeyValues().toArray(new Object[0]), ((Insert) mutation).getColumns(),
((Insert) mutation).getValues());
break;
case DEL:
batchOps.delete(mutation.getRowKey());
batchOps.delete(((Delete) mutation).getRowKeyValues().toArray(new Object[0]));
break;
case UPDATE:
((Update) mutation).removeRowkeyFromMutateColval();
batchOps.update(mutation.getRowKey(), ((Update) mutation).getColumns(),
batchOps.update(((Update) mutation).getRowKeyValues().toArray(new Object[0]), ((Update) mutation).getColumns(),
((Update) mutation).getValues());
break;
case INSERT_OR_UPDATE:
((InsertOrUpdate) mutation).removeRowkeyFromMutateColval();
batchOps.insertOrUpdate(mutation.getRowKey(),
batchOps.insertOrUpdate(((InsertOrUpdate) mutation).getRowKeyValues().toArray(new Object[0]),
((InsertOrUpdate) mutation).getColumns(),
((InsertOrUpdate) mutation).getValues());
break;
case REPLACE:
((Replace) mutation).removeRowkeyFromMutateColval();
batchOps.replace(mutation.getRowKey(), ((Replace) mutation).getColumns(),
batchOps.replace(((Replace) mutation).getRowKeyValues().toArray(new Object[0]), ((Replace) mutation).getColumns(),
((Replace) mutation).getValues());
break;
case INCREMENT:
((Increment) mutation).removeRowkeyFromMutateColval();
batchOps.increment(mutation.getRowKey(),
batchOps.increment(((Increment) mutation).getRowKeyValues().toArray(new Object[0]),
((Increment) mutation).getColumns(),
((Increment) mutation).getValues(), withResult);
break;
case APPEND:
((Append) mutation).removeRowkeyFromMutateColval();
batchOps.append(mutation.getRowKey(), ((Append) mutation).getColumns(),
batchOps.append(((Append) mutation).getRowKeyValues().toArray(new Object[0]), ((Append) mutation).getColumns(),
((Append) mutation).getValues(), withResult);
break;
case PUT:
((Put) mutation).removeRowkeyFromMutateColval();
batchOps.put(mutation.getRowKey(), ((Put) mutation).getColumns(),
batchOps.put(((Put) mutation).getRowKeyValues().toArray(new Object[0]), ((Put) mutation).getColumns(),
((Put) mutation).getValues());
break;
default:
@ -313,12 +313,12 @@ public class BatchOperation {
}
private void negateHbaseTimestamp(Mutation mutation) {
Object[] rowKey = mutation.getRowKey();
if (rowKey == null || rowKey.length != 3) {
Row rowKey = mutation.getRowKey();
if (rowKey == null || rowKey.size() != 3) {
throw new IllegalArgumentException("hbase rowkey length must be 3");
} else {
long ts = ((long) ((ObObj) mutation.getRowKey()[2]).getValue());
((ObObj) mutation.getRowKey()[2]).setValue(-ts);
long ts = ((long) ((ObObj) mutation.getRowKeyValues().get(2)).getValue());
((ObObj) mutation.getRowKeyValues().get(2)).setValue(-ts);
}
}
}

View File

@ -159,7 +159,7 @@ public class Insert extends Mutation<Insert> {
if (checkMutationWithFilter()) {
// QueryAndInsert
ObTableOperation operation = ObTableOperation.getInstance(
ObTableOperationType.INSERT, getRowKey(), columns.toArray(new String[0]),
ObTableOperationType.INSERT, getRowKeyValues().toArray(), columns.toArray(new String[0]),
values.toArray());
return new MutationResult(((ObTableClient) getClient()).mutationWithFilter(
getQuery(), getRowKey(), getKeyRanges(), operation, true));

View File

@ -32,6 +32,7 @@ import com.alipay.oceanbase.rpc.table.api.Table;
import com.alipay.oceanbase.rpc.table.api.TableQuery;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -39,14 +40,15 @@ import static com.alipay.oceanbase.rpc.mutation.MutationFactory.colVal;
import static com.alipay.oceanbase.rpc.mutation.MutationFactory.row;
public class Mutation<T> {
private String tableName;
private Table client;
protected Object[] rowKey;
private TableQuery query;
private boolean hasSetRowKey = false;
protected List<String> rowKeyNames = null;
protected List<String> columns;
protected List<Object> values;
private String tableName;
private Table client;
protected Row rowKey;
private TableQuery query;
private boolean hasSetRowKey = false;
protected List<String> rowKeyNames = null;
protected List<Object> rowKeyValues = null;
protected List<String> columns;
protected List<Object> values;
/*
* default constructor
@ -58,6 +60,7 @@ public class Mutation<T> {
rowKey = null;
query = null;
rowKeyNames = null;
rowKeyValues = null;
columns = null;
values = null;
}
@ -76,6 +79,7 @@ public class Mutation<T> {
this.rowKey = null;
this.query = null;
this.rowKeyNames = null;
this.rowKeyValues = null;
this.columns = null;
this.values = null;
}
@ -104,7 +108,7 @@ public class Mutation<T> {
/*
* get row key
*/
public Object[] getRowKey() {
public Row getRowKey() {
return rowKey;
}
@ -132,6 +136,11 @@ public class Mutation<T> {
return rowKeyNames;
}
/*
* get rowkey values
*/
public List<Object> getRowKeyValues() { return rowKeyValues; }
/*
* check mutation filter
*/
@ -184,25 +193,22 @@ public class Mutation<T> {
throw new IllegalArgumentException("input row key should not be empty");
}
// set rowKey
this.rowKey = rowKey;
// set row key name into client and set rowKeys
List<String> columnNames = new ArrayList<String>();
List<Object> Keys = new ArrayList<Object>();
for (Map.Entry<String, Object> entry : rowKey.getMap().entrySet()) {
columnNames.add(entry.getKey());
Keys.add(entry.getValue());
}
this.rowKey = Keys.toArray();
this.rowKeyNames = columnNames;
this.rowKeyValues = new ArrayList<>(Arrays.asList(rowKey.getValues()));
this.rowKeyNames = new ArrayList<>(Arrays.asList(rowKey.getColumns()));
// set row key in table
if (null != tableName) {
((ObTableClient) client)
.addRowKeyElement(tableName, columnNames.toArray(new String[0]));
.addRowKeyElement(tableName, this.rowKeyNames.toArray(new String[0]));
}
// renew scan range of QueryAndMutate
if (null != query) {
query.addScanRange(this.rowKey, this.rowKey);
query.addScanRange(rowKeyValues.toArray(), rowKeyValues.toArray());
}
hasSetRowKey = true;
@ -222,20 +228,17 @@ public class Mutation<T> {
throw new IllegalArgumentException("input row key should not be empty");
}
// set rowKey
this.rowKey = rowKey;
// set row key name into client and set rowKeys
List<String> columnNames = new ArrayList<String>();
List<Object> Keys = new ArrayList<Object>();
for (Map.Entry<String, Object> entry : rowKey.getMap().entrySet()) {
columnNames.add(entry.getKey());
Keys.add(entry.getValue());
}
this.rowKey = Keys.toArray();
this.rowKeyNames = columnNames;
this.rowKeyValues = new ArrayList<>(Arrays.asList(rowKey.getValues()));
this.rowKeyNames = new ArrayList<>(Arrays.asList(rowKey.getColumns()));
// set row key in table
if (null != tableName) {
((ObTableClient) client)
.addRowKeyElement(tableName, columnNames.toArray(new String[0]));
.addRowKeyElement(tableName, this.rowKeyNames.toArray(new String[0]));
}
hasSetRowKey = true;
@ -253,28 +256,22 @@ public class Mutation<T> {
throw new IllegalArgumentException("Invalid null rowKey set into Mutation");
}
// set rowKey
this.rowKey = new Row(rowKey);
// set row key name into client and set rowKey
List<String> columnNames = new ArrayList<String>();
List<Object> Keys = new ArrayList<Object>();
for (ColumnValue columnValue : rowKey) {
if (columnNames.contains(columnValue.getColumnName())) {
throw new ObTableException("Duplicate column in Row Key");
}
columnNames.add(columnValue.getColumnName());
Keys.add(columnValue.getValue());
}
this.rowKey = Keys.toArray();
this.rowKeyNames = columnNames;
this.rowKeyValues = new ArrayList<>(Arrays.asList(this.rowKey.getValues()));
this.rowKeyNames = new ArrayList<>(Arrays.asList(this.rowKey.getColumns()));
// set row key in table
if (null != tableName) {
((ObTableClient) client)
.addRowKeyElement(tableName, columnNames.toArray(new String[0]));
.addRowKeyElement(tableName, this.rowKeyNames.toArray(new String[0]));
}
// renew scan range of QueryAndMutate
if (null != query) {
query.addScanRange(this.rowKey, this.rowKey);
query.addScanRange(rowKeyValues.toArray(), rowKeyValues.toArray());
}
hasSetRowKey = true;
@ -292,23 +289,17 @@ public class Mutation<T> {
throw new IllegalArgumentException("Invalid null rowKey set into Mutation");
}
// set rowKey
this.rowKey = new Row(rowKey);
// set row key name into client and set rowKey
List<String> columnNames = new ArrayList<String>();
List<Object> Keys = new ArrayList<Object>();
for (ColumnValue columnValue : rowKey) {
if (columnNames.contains(columnValue.getColumnName())) {
throw new ObTableException("Duplicate column in Row Key");
}
columnNames.add(columnValue.getColumnName());
Keys.add(columnValue.getValue());
}
this.rowKey = Keys.toArray();
this.rowKeyNames = columnNames;
this.rowKeyValues = new ArrayList<>(Arrays.asList(this.rowKey.getValues()));
this.rowKeyNames = new ArrayList<>(Arrays.asList(this.rowKey.getColumns()));
// set row key in table
if (null != tableName) {
((ObTableClient) client)
.addRowKeyElement(tableName, columnNames.toArray(new String[0]));
.addRowKeyElement(tableName, this.rowKeyNames.toArray(new String[0]));
}
hasSetRowKey = true;
@ -329,7 +320,7 @@ public class Mutation<T> {
query = client.query(tableName);
// set scan range if rowKey exist
if (null != rowKey) {
query.addScanRange(this.rowKey, this.rowKey);
query.addScanRange(this.rowKeyValues.toArray(), this.rowKeyValues.toArray());
}
}
// only filter string in query works

View File

@ -158,7 +158,7 @@ public class Put extends Mutation<Put> {
if (checkMutationWithFilter()) {
// QueryAndPut
ObTableOperation operation = ObTableOperation.getInstance(ObTableOperationType.PUT,
getRowKey(), columns.toArray(new String[0]), values.toArray());
getRowKeyValues().toArray(), columns.toArray(new String[0]), values.toArray());
return new MutationResult(((ObTableClient) getClient()).mutationWithFilter(
getQuery(), getRowKey(), getKeyRanges(), operation, true));
} else {

View File

@ -244,8 +244,8 @@ public class ObTableClientBatchOpsImpl extends AbstractTableBatchOps {
for (int j = 0; j < rowKeySize; j++) {
rowKey[j] = rowKeyObject.getObj(j).getValue();
}
ObPair<Long, ObTableParam> tableObPair = obTableClient.getTableBySingleRowKeyWithRoute(
tableName, rowKey, false, false, false,
ObPair<Long, ObTableParam> tableObPair = obTableClient.getTable(
tableName, rowKey, false, false,
obTableClient.getRoute(batchOperation.isReadOnly()));
ObPair<ObTableParam, List<ObPair<Integer, ObTableOperation>>> obTableOperations = partitionOperationsMap
.get(tableObPair.getLeft());

View File

@ -158,17 +158,17 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
ObTableSingleOpQuery query = new ObTableSingleOpQuery();
ObNewRange range = new ObNewRange();
range.setStartKey(ObRowKey.getInstance(insUp.getRowKey()));
range.setEndKey(ObRowKey.getInstance(insUp.getRowKey()));
range.setStartKey(ObRowKey.getInstance(insUp.getRowKeyValues()));
range.setEndKey(ObRowKey.getInstance(insUp.getRowKeyValues()));
query.addScanRangeColumns(insUp.getRowKeyNames());
query.addScanRange(range);
query.setFilterString(checkAndInsUp.getFilter().toString());
String[] rowKeyNames = checkAndInsUp.getInsUp().getRowKeyNames().toArray(new String[0]);
Object[] rowKey = checkAndInsUp.getInsUp().getRowKey();
Object[] rowKeyValues = checkAndInsUp.getInsUp().getRowKeyValues().toArray(new Object[0]);
String[] propertiesNames = checkAndInsUp.getInsUp().getColumns();
Object[] propertiesValues = checkAndInsUp.getInsUp().getValues();
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKey,
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKeyValues,
propertiesNames, propertiesValues);
ObTableSingleOp singleOp = new ObTableSingleOp();
@ -202,7 +202,7 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
public void addOperation(Mutation mutation) throws Exception {
// entity
String[] rowKeyNames = null;
Object[] rowKey = null;
Object[] rowKeyValues = null;
String[] propertiesNames = null;
Object[] propertiesValues = null;
@ -213,53 +213,53 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
case INSERT:
((Insert) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Insert) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Insert) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Insert) mutation).getColumns();
propertiesValues = ((Insert) mutation).getValues();
break;
case DEL:
rowKeyNames = ((Delete) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Delete) mutation).getRowKeyValues().toArray(new Object[0]);
break;
case UPDATE:
((Update) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Update) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Update) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Update) mutation).getColumns();
propertiesValues = ((Update) mutation).getValues();
break;
case INSERT_OR_UPDATE:
((InsertOrUpdate) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((InsertOrUpdate) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((InsertOrUpdate) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((InsertOrUpdate) mutation).getColumns();
propertiesValues = ((InsertOrUpdate) mutation).getValues();
break;
case REPLACE:
((Replace) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Replace) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Replace) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Replace) mutation).getColumns();
propertiesValues = ((Replace) mutation).getValues();
break;
case INCREMENT:
((Increment) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Increment) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Increment) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Increment) mutation).getColumns();
propertiesValues = ((Increment) mutation).getValues();
break;
case APPEND:
((Append) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Append) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Append) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Append) mutation).getColumns();
propertiesValues = ((Append) mutation).getValues();
break;
case PUT:
((Put) mutation).removeRowkeyFromMutateColval();
rowKeyNames = ((Put) mutation).getRowKeyNames().toArray(new String[0]);
rowKey = mutation.getRowKey();
rowKeyValues = ((Put) mutation).getRowKeyValues().toArray(new Object[0]);
propertiesNames = ((Put) mutation).getColumns();
propertiesValues = ((Put) mutation).getValues();
break;
@ -267,7 +267,7 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
throw new ObTableException("unknown operation type " + type);
}
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKey,
ObTableSingleOpEntity entity = ObTableSingleOpEntity.getInstance(rowKeyNames, rowKeyValues,
propertiesNames, propertiesValues);
ObTableSingleOp singleOp = new ObTableSingleOp();
singleOp.setSingleOpType(type);
@ -341,8 +341,8 @@ public class ObTableClientLSBatchOpsImpl extends AbstractTableBatchOps {
for (int j = 0; j < rowKeySize; j++) {
rowKey[j] = rowkeyObjs.get(j).getValue();
}
ObPair<Long, ObTableParam> tableObPair= obTableClient.getTableBySingleRowKeyWithRoute(tableName, rowKey,
false, false, false, obTableClient.getRoute(false));
ObPair<Long, ObTableParam> tableObPair= obTableClient.getTable(tableName, rowKey,
false, false, obTableClient.getRoute(false));
long lsId = tableObPair.getRight().getLsId();
Map<Long, ObPair<ObTableParam, List<ObPair<Integer, ObTableSingleOp>>>> tabletOperations

View File

@ -274,8 +274,8 @@ public class ObTableClientQueryImpl extends AbstractTableQueryImpl {
ObBorderFlag borderFlag = rang.getBorderFlag();
// pairs -> List<Pair<logicId, param>>
List<ObPair<Long, ObTableParam>> pairs = this.obTableClient.getTables(indexTableName,
tableQuery, start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), false,
false);
tableQuery, start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(),
false, false);
if (this.tableQuery.getScanOrder() == ObScanOrder.Reverse) {
for (int i = pairs.size() - 1; i >= 0; i--) {
this.partitionObTables.put(pairs.get(i).getLeft(), pairs.get(i));

View File

@ -259,7 +259,7 @@ public class ObTableCheckAndInsUpTest {
Assert.assertTrue(false);
} finally {
Delete delete = client.delete(testTable);
delete.setRowKey(row(colVal("c1", 5L), colVal("c2", "c2_v0")));
delete.setRowKey(row(colVal("c2", 5L), colVal("c1", "c2_v0")));
MutationResult res = delete.execute();
Assert.assertEquals(1, res.getAffectedRows());
}

View File

@ -48,7 +48,7 @@ public class ObTableTest extends ObTableClientTestBase {
throw new ObTableException("ODP Mode does not support this test");
} else {
obTable = obTableClient
.getTableBySingleRowKey("test_varchar_table", new Object[] { "abc" }, true, true, false).getRight()
.getTable("test_varchar_table", new Object[] { "abc" }, true, true).getRight()
.getObTable();
client = obTable;
}

View File

@ -55,7 +55,7 @@ public class ObHTableTest {
throw new ObTableException("ODP Mode does not support this test");
} else {
client = obTableClient
.getTableBySingleRowKey("test_varchar_table", new Object[] { "abc" }, true, true, false).getRight()
.getTable("test_varchar_table", new Object[] { "abc" }, true, true).getRight()
.getObTable();
this.obTableClient = obTableClient;
}

View File

@ -23,11 +23,13 @@ import com.alipay.oceanbase.rpc.protocol.payload.impl.ObCollationType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObjType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.column.ObSimpleColumn;
import com.alipay.oceanbase.rpc.mutation.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -61,204 +63,586 @@ public class ObHashPartDescTest {
@Test
public void testGetPartId() {
// set values
Map<String, Object> values0 = new HashMap<String, Object>() {
{
put("K", 0);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values1 = new HashMap<String, Object>() {
{
put("K", 1);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values2 = new HashMap<String, Object>() {
{
put("K", 2);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values3 = new HashMap<String, Object>() {
{
put("K", 3);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values4 = new HashMap<String, Object>() {
{
put("K", 4);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values5 = new HashMap<String, Object>() {
{
put("K", 5);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values6 = new HashMap<String, Object>() {
{
put("K", 6);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values7 = new HashMap<String, Object>() {
{
put("K", 7);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values8 = new HashMap<String, Object>() {
{
put("K", 8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values9 = new HashMap<String, Object>() {
{
put("K", 9);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values10 = new HashMap<String, Object>() {
{
put("K", 10);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values11 = new HashMap<String, Object>() {
{
put("K", 11);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values12 = new HashMap<String, Object>() {
{
put("K", 12);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values13 = new HashMap<String, Object>() {
{
put("K", 13);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values14 = new HashMap<String, Object>() {
{
put("K", 14);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values15 = new HashMap<String, Object>() {
{
put("K", 15);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Assert.assertEquals(0,
(long) obHashPartDesc.getPartId(0, "column_1", System.currentTimeMillis()));
Assert.assertEquals(1,
(long) obHashPartDesc.getPartId(1, "column_1", System.currentTimeMillis()));
Assert.assertEquals(2,
(long) obHashPartDesc.getPartId(2, "column_1", System.currentTimeMillis()));
Assert.assertEquals(3,
(long) obHashPartDesc.getPartId(3, "column_1", System.currentTimeMillis()));
Assert.assertEquals(4,
(long) obHashPartDesc.getPartId(4, "column_1", System.currentTimeMillis()));
Assert.assertEquals(5,
(long) obHashPartDesc.getPartId(5, "column_1", System.currentTimeMillis()));
Assert.assertEquals(6,
(long) obHashPartDesc.getPartId(6, "column_1", System.currentTimeMillis()));
Assert.assertEquals(7,
(long) obHashPartDesc.getPartId(7, "column_1", System.currentTimeMillis()));
Assert.assertEquals(8,
(long) obHashPartDesc.getPartId(8, "column_1", System.currentTimeMillis()));
Assert.assertEquals(9,
(long) obHashPartDesc.getPartId(9, "column_1", System.currentTimeMillis()));
Assert.assertEquals(10,
(long) obHashPartDesc.getPartId(10, "column_1", System.currentTimeMillis()));
Assert.assertEquals(11,
(long) obHashPartDesc.getPartId(11, "column_1", System.currentTimeMillis()));
Assert.assertEquals(12,
(long) obHashPartDesc.getPartId(12, "column_1", System.currentTimeMillis()));
Assert.assertEquals(13,
(long) obHashPartDesc.getPartId(13, "column_1", System.currentTimeMillis()));
Assert.assertEquals(14,
(long) obHashPartDesc.getPartId(14, "column_1", System.currentTimeMillis()));
Assert.assertEquals(15,
(long) obHashPartDesc.getPartId(15, "column_1", System.currentTimeMillis()));
Map<String, Object> values_0 = new HashMap<String, Object>() {
{
put("K", -0);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_1 = new HashMap<String, Object>() {
{
put("K", -1);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_2 = new HashMap<String, Object>() {
{
put("K", -2);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_3 = new HashMap<String, Object>() {
{
put("K", -3);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_4 = new HashMap<String, Object>() {
{
put("K", -4);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_5 = new HashMap<String, Object>() {
{
put("K", -5);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_6 = new HashMap<String, Object>() {
{
put("K", -6);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_7 = new HashMap<String, Object>() {
{
put("K", -7);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_8 = new HashMap<String, Object>() {
{
put("K", -8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_9 = new HashMap<String, Object>() {
{
put("K", -9);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_10 = new HashMap<String, Object>() {
{
put("K", -10);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_11 = new HashMap<String, Object>() {
{
put("K", -11);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_12 = new HashMap<String, Object>() {
{
put("K", -12);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_13 = new HashMap<String, Object>() {
{
put("K", -13);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_14 = new HashMap<String, Object>() {
{
put("K", -14);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_15 = new HashMap<String, Object>() {
{
put("K", -15);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Assert.assertEquals(0,
(long) obHashPartDesc.getPartId(-0, "column_1", System.currentTimeMillis()));
Assert.assertEquals(1,
(long) obHashPartDesc.getPartId(-1, "column_1", System.currentTimeMillis()));
Assert.assertEquals(2,
(long) obHashPartDesc.getPartId(-2, "column_1", System.currentTimeMillis()));
Assert.assertEquals(3,
(long) obHashPartDesc.getPartId(-3, "column_1", System.currentTimeMillis()));
Assert.assertEquals(4,
(long) obHashPartDesc.getPartId(-4, "column_1", System.currentTimeMillis()));
Assert.assertEquals(5,
(long) obHashPartDesc.getPartId(-5, "column_1", System.currentTimeMillis()));
Assert.assertEquals(6,
(long) obHashPartDesc.getPartId(-6, "column_1", System.currentTimeMillis()));
Assert.assertEquals(7,
(long) obHashPartDesc.getPartId(-7, "column_1", System.currentTimeMillis()));
Assert.assertEquals(8,
(long) obHashPartDesc.getPartId(-8, "column_1", System.currentTimeMillis()));
Assert.assertEquals(9,
(long) obHashPartDesc.getPartId(-9, "column_1", System.currentTimeMillis()));
Assert.assertEquals(10,
(long) obHashPartDesc.getPartId(-10, "column_1", System.currentTimeMillis()));
Assert.assertEquals(11,
(long) obHashPartDesc.getPartId(-11, "column_1", System.currentTimeMillis()));
Assert.assertEquals(12,
(long) obHashPartDesc.getPartId(-12, "column_1", System.currentTimeMillis()));
Assert.assertEquals(13,
(long) obHashPartDesc.getPartId(-13, "column_1", System.currentTimeMillis()));
Assert.assertEquals(14,
(long) obHashPartDesc.getPartId(-14, "column_1", System.currentTimeMillis()));
Assert.assertEquals(15,
(long) obHashPartDesc.getPartId(-15, "column_1", System.currentTimeMillis()));
Map<String, Object> values0_e = new HashMap<String, Object>() {
{
put("K", 0);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values0_l = new HashMap<String, Object>() {
{
put("K", 0);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values1_e = new HashMap<String, Object>() {
{
put("K", 1);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values1_l = new HashMap<String, Object>() {
{
put("K", 1);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values2_e = new HashMap<String, Object>() {
{
put("K", 2);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values2_l = new HashMap<String, Object>() {
{
put("K", 2);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values3_e = new HashMap<String, Object>() {
{
put("K", 3);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values3_l = new HashMap<String, Object>() {
{
put("K", 3);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values4_e = new HashMap<String, Object>() {
{
put("K", 4);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values4_l = new HashMap<String, Object>() {
{
put("K", 4);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values5_e = new HashMap<String, Object>() {
{
put("K", 5);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values5_l = new HashMap<String, Object>() {
{
put("K", 5);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values6_e = new HashMap<String, Object>() {
{
put("K", 6);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values6_l = new HashMap<String, Object>() {
{
put("K", 6);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values7_e = new HashMap<String, Object>() {
{
put("K", 7);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values7_l = new HashMap<String, Object>() {
{
put("K", 7);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values8_e = new HashMap<String, Object>() {
{
put("K", 8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values8_l = new HashMap<String, Object>() {
{
put("K", 8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values9_e = new HashMap<String, Object>() {
{
put("K", 9);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values9_l = new HashMap<String, Object>() {
{
put("K", 9);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values10_e = new HashMap<String, Object>() {
{
put("K", 10);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values10_l = new HashMap<String, Object>() {
{
put("K", 10);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Assert.assertEquals(obHashPartDesc.getPartId(1, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("1", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(2, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("2", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(3, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("3", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(4, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("4", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(5, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("5", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(6, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("6", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(7, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("7", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(8, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("8", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(9, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("9", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(10, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("10", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(11, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("11", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(12, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("12", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(13, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("13", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(14, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("14", "column_1", System.currentTimeMillis()));
Assert.assertEquals(obHashPartDesc.getPartId(15, "column_1", System.currentTimeMillis()),
obHashPartDesc.getPartId("15", "column_1", System.currentTimeMillis()));
// test getPartId interface
Assert.assertEquals(0, (long) obHashPartDesc.getPartId(new Row(values0)));
Assert.assertEquals(1, (long) obHashPartDesc.getPartId(new Row(values1)));
Assert.assertEquals(2, (long) obHashPartDesc.getPartId(new Row(values2)));
Assert.assertEquals(3, (long) obHashPartDesc.getPartId(new Row(values3)));
Assert.assertEquals(4, (long) obHashPartDesc.getPartId(new Row(values4)));
Assert.assertEquals(5, (long) obHashPartDesc.getPartId(new Row(values5)));
Assert.assertEquals(6, (long) obHashPartDesc.getPartId(new Row(values6)));
Assert.assertEquals(7, (long) obHashPartDesc.getPartId(new Row(values7)));
Assert.assertEquals(8, (long) obHashPartDesc.getPartId(new Row(values8)));
Assert.assertEquals(9, (long) obHashPartDesc.getPartId(new Row(values9)));
Assert.assertEquals(10, (long) obHashPartDesc.getPartId(new Row(values10)));
Assert.assertEquals(11, (long) obHashPartDesc.getPartId(new Row(values11)));
Assert.assertEquals(12, (long) obHashPartDesc.getPartId(new Row(values12)));
Assert.assertEquals(13, (long) obHashPartDesc.getPartId(new Row(values13)));
Assert.assertEquals(14, (long) obHashPartDesc.getPartId(new Row(values14)));
Assert.assertEquals(15, (long) obHashPartDesc.getPartId(new Row(values15)));
Assert.assertEquals(0, (long) obHashPartDesc.getPartId(new Row(values_0)));
Assert.assertEquals(1, (long) obHashPartDesc.getPartId(new Row(values_1)));
Assert.assertEquals(2, (long) obHashPartDesc.getPartId(new Row(values_2)));
Assert.assertEquals(3, (long) obHashPartDesc.getPartId(new Row(values_3)));
Assert.assertEquals(4, (long) obHashPartDesc.getPartId(new Row(values_4)));
Assert.assertEquals(5, (long) obHashPartDesc.getPartId(new Row(values_5)));
Assert.assertEquals(6, (long) obHashPartDesc.getPartId(new Row(values_6)));
Assert.assertEquals(7, (long) obHashPartDesc.getPartId(new Row(values_7)));
Assert.assertEquals(8, (long) obHashPartDesc.getPartId(new Row(values_8)));
Assert.assertEquals(9, (long) obHashPartDesc.getPartId(new Row(values_9)));
Assert.assertEquals(10, (long) obHashPartDesc.getPartId(new Row(values_10)));
Assert.assertEquals(11, (long) obHashPartDesc.getPartId(new Row(values_11)));
Assert.assertEquals(12, (long) obHashPartDesc.getPartId(new Row(values_12)));
Assert.assertEquals(13, (long) obHashPartDesc.getPartId(new Row(values_13)));
Assert.assertEquals(14, (long) obHashPartDesc.getPartId(new Row(values_14)));
Assert.assertEquals(15, (long) obHashPartDesc.getPartId(new Row(values_15)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values0_e)),
obHashPartDesc.getPartId(new Row(values0_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values1_e)),
obHashPartDesc.getPartId(new Row(values1_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values2_e)),
obHashPartDesc.getPartId(new Row(values2_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values3_e)),
obHashPartDesc.getPartId(new Row(values3_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values4_e)),
obHashPartDesc.getPartId(new Row(values4_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values5_e)),
obHashPartDesc.getPartId(new Row(values5_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values6_e)),
obHashPartDesc.getPartId(new Row(values6_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values7_e)),
obHashPartDesc.getPartId(new Row(values7_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values8_e)),
obHashPartDesc.getPartId(new Row(values8_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values9_e)),
obHashPartDesc.getPartId(new Row(values9_l)));
Assert.assertEquals(obHashPartDesc.getPartId(new Row(values10_e)),
obHashPartDesc.getPartId(new Row(values10_l)));
}
@Test
public void testGetPartIds() {
Object[] rowKey_0 = new Object[] { 0, "column_1", System.currentTimeMillis() };
Object[] rowKey_8 = new Object[] { 8, "column_1", System.currentTimeMillis() };
Object[] rowKey_15 = new Object[] { 15, "column_1", System.currentTimeMillis() };
Object[] rowKey_16 = new Object[] { 16, "column_1", System.currentTimeMillis() };
Object[] rowKey_30 = new Object[] { 30, "column_1", System.currentTimeMillis() };
Object[] rowKey_8f = new Object[] { -8, "column_1", System.currentTimeMillis() };
Object[] rowKey_15f = new Object[] { -15, "column_1", System.currentTimeMillis() };
Object[] rowKey_30f = new Object[] { -30, "column_1", System.currentTimeMillis() };
Map<String, Object> values0 = new HashMap<String, Object>() {
{
put("K", 0);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values8 = new HashMap<String, Object>() {
{
put("K", 8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values15 = new HashMap<String, Object>() {
{
put("K", 15);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values16 = new HashMap<String, Object>() {
{
put("K", 16);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values30 = new HashMap<String, Object>() {
{
put("K", 30);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_8f = new HashMap<String, Object>() {
{
put("K", -8);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_15f = new HashMap<String, Object>() {
{
put("K", -15);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> values_30f = new HashMap<String, Object>() {
{
put("K", -30);
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Assert.assertEquals(buildPartIds(0, 0),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values0), true));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values0), false));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values0), true));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values0), false));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_8, true, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values8), true, new Row(values0), true));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_8, false, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values8), false, new Row(values0), true));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_8, true, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values8), true, new Row(values0), false));
Assert.assertEquals(buildEmptyPartIds(),
obHashPartDesc.getPartIds(rowKey_8, false, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values8), false, new Row(values0), false));
Assert.assertEquals(buildPartIds(0, 8),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_8, true));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values8), true));
Assert.assertEquals(buildPartIds(1, 8),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_8, true));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values8), true));
Assert.assertEquals(buildPartIds(0, 7),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_8, false));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values8), false));
Assert.assertEquals(buildPartIds(1, 7),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_8, false));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values8), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_15, true));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values15), true));
Assert.assertEquals(buildPartIds(0, 14),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_15, false));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values15), false));
Assert.assertEquals(buildPartIds(1, 15),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_15, true));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values15), true));
Assert.assertEquals(buildPartIds(1, 14),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_15, false));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values15), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_16, true));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values16), true));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_16, false));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values16), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_16, true));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values16), true));
Assert.assertEquals(buildPartIds(1, 15),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_16, false));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values16), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_30, true));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values30), true));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, true, rowKey_30, false));
obHashPartDesc.getPartIds(new Row(values0), true, new Row(values30), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_30, true));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values30), true));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_0, false, rowKey_30, false));
obHashPartDesc.getPartIds(new Row(values0), false, new Row(values30), false));
Assert.assertEquals(buildPartIds(-8, 0),
obHashPartDesc.getPartIds(rowKey_8f, true, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_8f), true, new Row(values0), true));
Assert.assertEquals(buildPartIds(-8, -1),
obHashPartDesc.getPartIds(rowKey_8f, true, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_8f), true, new Row(values0), false));
Assert.assertEquals(buildPartIds(-7, 0),
obHashPartDesc.getPartIds(rowKey_8f, false, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_8f), false, new Row(values0), true));
Assert.assertEquals(buildPartIds(-7, -1),
obHashPartDesc.getPartIds(rowKey_8f, false, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_8f), false, new Row(values0), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_15f, true, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_15f), true, new Row(values0), true));
Assert.assertEquals(buildPartIds(-15, -1),
obHashPartDesc.getPartIds(rowKey_15f, true, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_15f), true, new Row(values0), false));
Assert.assertEquals(buildPartIds(-14, 0),
obHashPartDesc.getPartIds(rowKey_15f, false, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_15f), false, new Row(values0), true));
Assert.assertEquals(buildPartIds(-14, -1),
obHashPartDesc.getPartIds(rowKey_15f, false, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_15f), false, new Row(values0), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_30f, true, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_30f), true, new Row(values0), true));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_30f, true, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_30f), true, new Row(values0), false));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_30f, false, rowKey_0, true));
obHashPartDesc.getPartIds(new Row(values_30f), false, new Row(values0), true));
Assert.assertEquals(buildPartIds(0, 15),
obHashPartDesc.getPartIds(rowKey_30f, false, rowKey_0, false));
obHashPartDesc.getPartIds(new Row(values_30f), false, new Row(values0), false));
}
private List<Long> buildPartIds(long start, long end) {

View File

@ -19,6 +19,7 @@ package com.alipay.oceanbase.rpc.location.model.partition;
import com.alipay.oceanbase.rpc.location.LocationUtil;
import com.alipay.oceanbase.rpc.location.model.TableEntry;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObCollationType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObjType;
@ -28,9 +29,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import static com.alipay.oceanbase.rpc.location.model.partition.ObPartFuncType.KEY_V3;
@ -100,7 +99,7 @@ public class ObKeyPartDescTest {
partColumns.add(column);
keyUtf8.setPartColumns(partColumns);
keyUtf8.setRowKeyElement(TableEntry.HBASE_ROW_KEY_ELEMENT);
keyUtf8.prepare();
// keyUtf8.prepare();
}
@Test
@ -164,32 +163,105 @@ public class ObKeyPartDescTest {
@Test
public void testGetPartIds() {
long timestamp = System.currentTimeMillis();
Object[] startKey1 = new Object[] { "partition_1", "column_1", timestamp };
Object[] endKey1 = new Object[] { "partition_2", "column_1", timestamp };
Map<String, Object> startKey1 = new HashMap<String, Object>() {
{
put("K", "partition_1");
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey1 = new HashMap<String, Object>() {
{
put("K", "partition_2");
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey2 = new Object[] { "partition_1".getBytes(), "column_1", timestamp };
Object[] endKey2 = new Object[] { "partition_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey2 = new HashMap<String, Object>() {
{
put("K", "partition_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey2 = new HashMap<String, Object>() {
{
put("K", "partition_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey3 = new Object[] { "test_1".getBytes(), "column_1", timestamp };
Object[] endKey3 = new Object[] { "test_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey3 = new HashMap<String, Object>() {
{
put("K", "test_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey3 = new HashMap<String, Object>() {
{
put("K", "test_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey4 = new Object[] { "PARTITION_1", "column_1", timestamp };
Object[] endKey4 = new Object[] { "PARTITION_2", "column_1", timestamp };
Map<String, Object> startKey4 = new HashMap<String, Object>() {
{
put("K", "PARTITION_1");
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey4 = new HashMap<String, Object>() {
{
put("K", "PARTITION_2");
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey5 = new Object[] { "PARTITION_1".getBytes(), "column_1", timestamp };
Object[] endKey5 = new Object[] { "PARTITION_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey5 = new HashMap<String, Object>() {
{
put("K", "PARTITION_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey5 = new HashMap<String, Object>() {
{
put("K", "PARTITION_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey6 = new Object[] { "TEST_1".getBytes(), "column_1", timestamp };
Object[] endKey6 = new Object[] { "TEST_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey6 = new HashMap<String, Object>() {
{
put("K", "TEST_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey6 = new HashMap<String, Object>() {
{
put("K", "TEST_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Assert.assertEquals(keyBinary.getPartIds(startKey1, true, endKey1, true),
keyBinary.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(keyBinary.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyBinary.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(keyBinary.getPartIds(startKey1, true, endKey2, true),
keyBinary.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(keyBinary.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
keyBinary.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(keyBinary.getPartIds(startKey1, false, endKey2, false),
keyBinary.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(
keyBinary.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
keyBinary.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
try {
List<Long> ans = keyBinary.getPartIds(startKey1, false, endKey3, false);
@ -215,59 +287,71 @@ public class ObKeyPartDescTest {
Assert.assertTrue(false);
}
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, true, endKey1, true),
keyUtf8_CI.getPartIds(startKey4, true, endKey4, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8_CI.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey2, true, endKey2, true),
keyUtf8_CI.getPartIds(startKey5, true, endKey5, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey2), true),
keyUtf8_CI.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey3, false, endKey3, false),
keyUtf8_CI.getPartIds(startKey6, false, endKey6, false));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey3), false, new Row(endKey3), false),
keyUtf8_CI.getPartIds(new Row(startKey6), false, new Row(endKey6), false));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, true, endKey1, true),
keyUtf8_CI.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, true, endKey2, true),
keyUtf8_CI.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
keyUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, false, endKey2, false),
keyUtf8_CI.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
keyUtf8_CI.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, true, endKey1, true),
keyUtf8_CI.getPartIds(startKey4, true, endKey4, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8_CI.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, true, endKey2, true),
keyUtf8_CI.getPartIds(startKey5, true, endKey5, true));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
keyUtf8_CI.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertEquals(keyUtf8_CI.getPartIds(startKey1, false, endKey2, false),
keyUtf8_CI.getPartIds(startKey5, false, endKey4, false));
Assert.assertEquals(
keyUtf8_CI.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
keyUtf8_CI.getPartIds(new Row(startKey5), false, new Row(endKey4), false));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, true, endKey1, true),
keyUtf8.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, true, endKey2, true),
keyUtf8.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
keyUtf8.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, false, endKey2, false),
keyUtf8.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
keyUtf8.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, true, endKey1, true),
keyUtf8.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, true, endKey2, true),
keyUtf8.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
keyUtf8.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(keyUtf8.getPartIds(startKey1, false, endKey2, false),
keyUtf8.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(keyUtf8.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
keyUtf8.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertNotEquals(keyUtf8.getPartIds(startKey1, true, endKey1, true),
keyUtf8.getPartIds(startKey4, true, endKey4, true));
Assert.assertNotEquals(
keyUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
keyUtf8.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertNotEquals(keyUtf8.getPartIds(startKey2, true, endKey2, true),
keyUtf8.getPartIds(startKey5, true, endKey5, true));
Assert.assertNotEquals(
keyUtf8.getPartIds(new Row(startKey2), true, new Row(endKey2), true),
keyUtf8.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertNotEquals(keyUtf8.getPartIds(startKey3, false, endKey3, false),
keyUtf8.getPartIds(startKey6, false, endKey6, false));
Assert.assertNotEquals(
keyUtf8.getPartIds(new Row(startKey3), false, new Row(endKey3), false),
keyUtf8.getPartIds(new Row(startKey6), false, new Row(endKey6), false));
}

View File

@ -22,6 +22,7 @@ import com.alipay.oceanbase.rpc.location.model.TableEntry;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObCollationType;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObjType;
import com.alipay.oceanbase.rpc.mutation.Row;
import com.alipay.oceanbase.rpc.protocol.payload.impl.column.ObSimpleColumn;
import org.junit.Assert;
import org.junit.Before;
@ -29,6 +30,8 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import static com.alipay.oceanbase.rpc.location.model.partition.ObPartFuncType.RANGE_COLUMNS;
@ -140,78 +143,160 @@ public class ObRangePartDescTest {
@Test
public void testGetPartId() {
long partId = rangeBinary.getPartId("partition_1", "column_1", System.currentTimeMillis());
Map<String, Object> partition_1 = new HashMap<String, Object>() {
{
put("K", "partition_1");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> partition_2 = new HashMap<String, Object>() {
{
put("K", "partition_2");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
long partId = rangeBinary.getPartId(new Row(partition_1));
Assert.assertEquals(1, partId);
partId = rangeBinary.getPartId("a", "column_1", System.currentTimeMillis());
Map<String, Object> test_a = new HashMap<String, Object>() {
{
put("K", "a");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
partId = rangeBinary.getPartId(new Row(test_a));
Assert.assertEquals(0, partId);
partId = rangeBinary.getPartId("x", "column_1", System.currentTimeMillis());
Map<String, Object> test_x = new HashMap<String, Object>() {
{
put("K", "x");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
partId = rangeBinary.getPartId(new Row(test_x));
Assert.assertEquals(2, partId);
Assert.assertEquals(
rangeBinary.getPartId("partition_1", "column_1", System.currentTimeMillis()),
rangeBinary.getPartId("partition_2", "column_1", System.currentTimeMillis()));
Assert.assertEquals(rangeBinary.getPartId(new Row(partition_1)),
rangeBinary.getPartId(new Row(partition_2)));
Assert.assertEquals(
rangeBinary.getPartId("test_1", "column_1", System.currentTimeMillis()),
rangeBinary.getPartId("test_2", "column_1", System.currentTimeMillis()));
Map<String, Object> test_1 = new HashMap<String, Object>() {
{
put("K", "test_1");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_1_bytes = new HashMap<String, Object>() {
{
put("K", "test_1".getBytes());
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_2 = new HashMap<String, Object>() {
{
put("K", "test_2");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_2_bytes = new HashMap<String, Object>() {
{
put("K", "test_2".getBytes());
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Assert.assertEquals(
rangeBinary.getPartId("test_1", "column_1", System.currentTimeMillis()),
rangeBinary.getPartId("test_2".getBytes(), "column_1", System.currentTimeMillis()));
Assert.assertEquals(rangeBinary.getPartId(new Row(test_1)),
rangeBinary.getPartId(new Row(test_2)));
Assert.assertEquals(
rangeBinary.getPartId("test_1".getBytes(), "column_1", System.currentTimeMillis()),
rangeBinary.getPartId("test_2".getBytes(), "column_1", System.currentTimeMillis()));
Assert.assertEquals(rangeBinary.getPartId(new Row(test_1)),
rangeBinary.getPartId(new Row(test_2_bytes)));
partId = rangeBinary.getPartId("A", "column_1", System.currentTimeMillis());
Assert.assertEquals(rangeBinary.getPartId(new Row(test_1_bytes)),
rangeBinary.getPartId(new Row(test_2_bytes)));
Map<String, Object> test_A = new HashMap<String, Object>() {
{
put("K", "A");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_P = new HashMap<String, Object>() {
{
put("K", "P");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_X = new HashMap<String, Object>() {
{
put("K", "X");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
Map<String, Object> test_p = new HashMap<String, Object>() {
{
put("K", "p");
put("Q", "column_1");
put("T", System.currentTimeMillis());
}
};
partId = rangeBinary.getPartId(new Row(test_A));
Assert.assertEquals(0, partId);
partId = rangeBinary.getPartId("P", "column_1", System.currentTimeMillis());
partId = rangeBinary.getPartId(new Row(test_P));
Assert.assertEquals(0, partId);
partId = rangeBinary.getPartId("X", "column_1", System.currentTimeMillis());
partId = rangeBinary.getPartId(new Row(test_X));
Assert.assertEquals(0, partId);
partId = rangeUtf8_CI.getPartId("a", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(test_a));
Assert.assertEquals(0, partId);
partId = rangeUtf8_CI.getPartId("partition_1", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(partition_1));
Assert.assertEquals(1, partId);
partId = rangeUtf8_CI.getPartId("x", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(test_x));
Assert.assertEquals(2, partId);
partId = rangeUtf8_CI.getPartId("A", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(test_A));
Assert.assertEquals(0, partId);
partId = rangeUtf8_CI.getPartId("P", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(test_P));
Assert.assertEquals(1, partId);
partId = rangeUtf8_CI.getPartId("X", "column_1", System.currentTimeMillis());
partId = rangeUtf8_CI.getPartId(new Row(test_X));
Assert.assertEquals(2, partId);
partId = rangeUtf8.getPartId("a", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_a));
Assert.assertEquals(0, partId);
partId = rangeUtf8.getPartId("p", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_p));
Assert.assertEquals(1, partId);
partId = rangeUtf8.getPartId("x", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_x));
Assert.assertEquals(2, partId);
partId = rangeUtf8.getPartId("A", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_A));
Assert.assertEquals(0, partId);
partId = rangeUtf8.getPartId("P", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_P));
Assert.assertEquals(0, partId);
partId = rangeUtf8.getPartId("X", "column_1", System.currentTimeMillis());
partId = rangeUtf8.getPartId(new Row(test_X));
Assert.assertEquals(0, partId);
ArrayList<Object[]> rowKeys = new ArrayList<Object[]>();
rowKeys.add(new Object[] { "P", "column_1", System.currentTimeMillis() });
ArrayList<Object> rowKeys = new ArrayList<Object>();
rowKeys.add(new Row(test_P));
partId = rangeUtf8.getPartId(rowKeys, true);
Assert.assertEquals(0, partId);
Assert.assertTrue(rangeUtf8.toString().contains("partExpr"));
@ -220,137 +305,245 @@ public class ObRangePartDescTest {
@Test
public void testGetPartIds() {
long timestamp = System.currentTimeMillis();
Object[] startKey1 = new Object[] { "partition_1", "column_1", timestamp };
Object[] endKey1 = new Object[] { "partition_2", "column_1", timestamp };
Map<String, Object> startKey1 = new HashMap<String, Object>() {
{
put("K", "partition_1");
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey1 = new HashMap<String, Object>() {
{
put("K", "partition_1");
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey2 = new Object[] { "partition_1".getBytes(), "column_1", timestamp };
Object[] endKey2 = new Object[] { "partition_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey2 = new HashMap<String, Object>() {
{
put("K", "partition_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey2 = new HashMap<String, Object>() {
{
put("K", "partition_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey3 = new Object[] { "yes_1".getBytes(), "column_1", timestamp };
Object[] endKey3 = new Object[] { "yes_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey3 = new HashMap<String, Object>() {
{
put("K", "yes_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey3 = new HashMap<String, Object>() {
{
put("K", "yes_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey4 = new Object[] { "PARTITION_1", "column_1", timestamp };
Object[] endKey4 = new Object[] { "PARTITION_2", "column_1", timestamp };
Map<String, Object> startKey4 = new HashMap<String, Object>() {
{
put("K", "PARTITION_1");
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey4 = new HashMap<String, Object>() {
{
put("K", "PARTITION_2");
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey5 = new Object[] { "PARTITION_1".getBytes(), "column_1", timestamp };
Object[] endKey5 = new Object[] { "PARTITION_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey5 = new HashMap<String, Object>() {
{
put("K", "PARTITION_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey5 = new HashMap<String, Object>() {
{
put("K", "PARTITION_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Object[] startKey6 = new Object[] { "YES_1".getBytes(), "column_1", timestamp };
Object[] endKey6 = new Object[] { "YES_2".getBytes(), "column_1", timestamp };
Map<String, Object> startKey6 = new HashMap<String, Object>() {
{
put("K", "YES_1".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Map<String, Object> endKey6 = new HashMap<String, Object>() {
{
put("K", "YES_2".getBytes());
put("Q", "column_1");
put("T", timestamp);
}
};
Assert.assertEquals(rangeBinary.getPartIds(startKey1, true, endKey1, true),
rangeBinary.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(
rangeBinary.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeBinary.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(rangeBinary.getPartIds(startKey1, true, endKey2, true),
rangeBinary.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(
rangeBinary.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeBinary.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(rangeBinary.getPartIds(startKey1, false, endKey2, false),
rangeBinary.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(
rangeBinary.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeBinary.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey1, true, endKey1, true),
rangeBinary.getPartIds(startKey4, true, endKey4, true));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeBinary.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey2, true, endKey2, true),
rangeBinary.getPartIds(startKey5, true, endKey5, true));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey2), true, new Row(endKey2), true),
rangeBinary.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey3, false, endKey3, false),
rangeBinary.getPartIds(startKey6, false, endKey6, false));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey3), false, new Row(endKey3), false),
rangeBinary.getPartIds(new Row(startKey6), false, new Row(endKey6), false));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey1, true, endKey1, true),
rangeBinary.getPartIds(startKey5, true, endKey5, true));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeBinary.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey1, true, endKey2, true),
rangeBinary.getPartIds(startKey5, true, endKey4, true));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeBinary.getPartIds(new Row(startKey5), true, new Row(endKey4), true));
Assert.assertNotEquals(rangeBinary.getPartIds(startKey1, false, endKey2, false),
rangeBinary.getPartIds(startKey5, false, endKey5, false));
Assert.assertNotEquals(
rangeBinary.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeBinary.getPartIds(new Row(startKey5), false, new Row(endKey5), false));
List<Long> partIds = new ArrayList<Long>();
partIds.add(1L);
partIds.add(2L);
Assert.assertEquals(partIds, rangeBinary.getPartIds(startKey1, false, endKey3, false));
Assert.assertEquals(partIds,
rangeBinary.getPartIds(new Row(startKey1), false, new Row(endKey3), false));
partIds = new ArrayList<Long>();
partIds.add(0L);
Assert.assertEquals(partIds, rangeBinary.getPartIds(startKey4, false, endKey4, false));
Assert.assertEquals(partIds,
rangeBinary.getPartIds(new Row(startKey4), false, new Row(endKey4), false));
Assert.assertEquals(partIds, rangeBinary.getPartIds(startKey6, false, endKey4, true));
Assert.assertEquals(partIds,
rangeBinary.getPartIds(new Row(startKey6), false, new Row(endKey4), true));
Assert.assertEquals(0, rangeBinary.getPartIds(startKey3, false, endKey1, true).size());
Assert.assertEquals(0,
rangeBinary.getPartIds(new Row(startKey3), false, new Row(endKey1), true).size());
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, true, endKey1, true),
rangeUtf8_CI.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, true, endKey2, true),
rangeUtf8_CI.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, false, endKey2, false),
rangeUtf8_CI.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeUtf8_CI.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, true, endKey1, true),
rangeUtf8_CI.getPartIds(startKey4, true, endKey4, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8_CI.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey2, true, endKey2, true),
rangeUtf8_CI.getPartIds(startKey5, true, endKey5, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey2), true, new Row(endKey2), true),
rangeUtf8_CI.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey3, false, endKey3, false),
rangeUtf8_CI.getPartIds(startKey6, false, endKey6, false));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey3), false, new Row(endKey3), false),
rangeUtf8_CI.getPartIds(new Row(startKey6), false, new Row(endKey6), false));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, true, endKey1, true),
rangeUtf8_CI.getPartIds(startKey5, true, endKey5, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8_CI.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, true, endKey2, true),
rangeUtf8_CI.getPartIds(startKey5, true, endKey4, true));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeUtf8_CI.getPartIds(new Row(startKey5), true, new Row(endKey4), true));
Assert.assertEquals(rangeUtf8_CI.getPartIds(startKey1, false, endKey2, false),
rangeUtf8_CI.getPartIds(startKey5, false, endKey4, false));
Assert.assertEquals(
rangeUtf8_CI.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeUtf8_CI.getPartIds(new Row(startKey5), false, new Row(endKey4), false));
partIds = new ArrayList<Long>();
partIds.add(1L);
partIds.add(2L);
Assert.assertEquals(partIds, rangeUtf8_CI.getPartIds(startKey1, false, endKey3, false));
Assert.assertEquals(partIds, rangeUtf8_CI.getPartIds(startKey4, false, endKey6, false));
Assert.assertEquals(0, rangeUtf8_CI.getPartIds(startKey3, false, endKey1, true).size());
Assert.assertEquals(partIds,
rangeUtf8_CI.getPartIds(new Row(startKey1), false, new Row(endKey3), false));
Assert.assertEquals(partIds,
rangeUtf8_CI.getPartIds(new Row(startKey4), false, new Row(endKey6), false));
Assert.assertEquals(0,
rangeUtf8_CI.getPartIds(new Row(startKey3), false, new Row(endKey1), true).size());
Assert.assertEquals(rangeUtf8.getPartIds(startKey1, true, endKey1, true),
rangeUtf8.getPartIds(startKey2, true, endKey2, true));
Assert.assertEquals(rangeUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8.getPartIds(new Row(startKey2), true, new Row(endKey2), true));
Assert.assertEquals(rangeUtf8.getPartIds(startKey1, true, endKey2, true),
rangeUtf8.getPartIds(startKey2, true, endKey1, true));
Assert.assertEquals(rangeUtf8.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeUtf8.getPartIds(new Row(startKey2), true, new Row(endKey1), true));
Assert.assertEquals(rangeUtf8.getPartIds(startKey1, false, endKey2, false),
rangeUtf8.getPartIds(startKey2, false, endKey1, false));
Assert.assertEquals(
rangeUtf8.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeUtf8.getPartIds(new Row(startKey2), false, new Row(endKey1), false));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey1, true, endKey1, true),
rangeUtf8.getPartIds(startKey4, true, endKey4, true));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8.getPartIds(new Row(startKey4), true, new Row(endKey4), true));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey2, true, endKey2, true),
rangeUtf8.getPartIds(startKey5, true, endKey5, true));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey2), true, new Row(endKey2), true),
rangeUtf8.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey3, false, endKey3, false),
rangeUtf8.getPartIds(startKey6, false, endKey6, false));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey3), false, new Row(endKey3), false),
rangeUtf8.getPartIds(new Row(startKey6), false, new Row(endKey6), false));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey1, true, endKey1, true),
rangeUtf8.getPartIds(startKey5, true, endKey5, true));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey1), true, new Row(endKey1), true),
rangeUtf8.getPartIds(new Row(startKey5), true, new Row(endKey5), true));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey1, true, endKey2, true),
rangeUtf8.getPartIds(startKey5, true, endKey4, true));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey1), true, new Row(endKey2), true),
rangeUtf8.getPartIds(new Row(startKey5), true, new Row(endKey4), true));
Assert.assertNotEquals(rangeUtf8.getPartIds(startKey1, false, endKey2, false),
rangeUtf8.getPartIds(startKey5, false, endKey5, false));
Assert.assertNotEquals(
rangeUtf8.getPartIds(new Row(startKey1), false, new Row(endKey2), false),
rangeUtf8.getPartIds(new Row(startKey5), false, new Row(endKey5), false));
partIds = new ArrayList<Long>();
partIds.add(1L);
partIds.add(2L);
Assert.assertEquals(partIds, rangeUtf8.getPartIds(startKey1, false, endKey3, false));
Assert.assertEquals(partIds,
rangeUtf8.getPartIds(new Row(startKey1), false, new Row(endKey3), false));
partIds = new ArrayList<Long>();
partIds.add(0L);
Assert.assertEquals(partIds, rangeUtf8.getPartIds(startKey4, false, endKey4, false));
Assert.assertEquals(partIds,
rangeUtf8.getPartIds(new Row(startKey4), false, new Row(endKey4), false));
Assert.assertEquals(partIds, rangeUtf8.getPartIds(startKey6, false, endKey4, true));
Assert.assertEquals(partIds,
rangeUtf8.getPartIds(new Row(startKey6), false, new Row(endKey4), true));
Assert.assertEquals(0, rangeUtf8.getPartIds(startKey3, false, endKey1, true).size());
Assert.assertEquals(0,
rangeUtf8.getPartIds(new Row(startKey3), false, new Row(endKey1), true).size());
}

View File

@ -76,8 +76,8 @@ public class ObTableConnectionTest extends ObTableClientTestBase {
assertEquals(TEST_CONNECTION_POOL_SIZE, obTableClient.getOdpTable()
.getObTableConnectionPoolSize());
} else {
ObPair<Long, ObTableParam> obPair = obTableClient.getTableBySingleRowKey("test_varchar_table",
new String[] { "abc" }, false, false, false);
ObPair<Long, ObTableParam> obPair = obTableClient.getTable("test_varchar_table",
new String[] { "abc" }, false, false);
int poolSize = obPair.getRight().getObTable().getObTableConnectionPoolSize();
assertEquals(TEST_CONNECTION_POOL_SIZE, poolSize);
}
@ -108,8 +108,8 @@ public class ObTableConnectionTest extends ObTableClientTestBase {
assertEquals(TEST_NETTY_WAIT_INTERVAL, obTableClient.getOdpTable()
.getNettyBlockingWaitInterval());
} else {
ObPair<Long, ObTableParam> obPair = obTableClient.getTableBySingleRowKey("test_varchar_table",
new String[] { "abc" }, false, false, false);
ObPair<Long, ObTableParam> obPair = obTableClient.getTable("test_varchar_table",
new String[] { "abc" }, false, false);
int lowWatermark = obPair.getRight().getObTable().getNettyBufferLowWatermark();
int highWatermark = obPair.getRight().getObTable().getNettyBufferHighWatermark();
int waitInterval = obPair.getRight().getObTable().getNettyBlockingWaitInterval();
@ -130,8 +130,8 @@ public class ObTableConnectionTest extends ObTableClientTestBase {
if (obTableClient.isOdpMode()) {
// do nothing
} else {
ObPair<Long, ObTableParam> obPair = obTableClient.getTableBySingleRowKey("test_varchar_table",
new String[] { "abc" }, false, false, false);
ObPair<Long, ObTableParam> obPair = obTableClient.getTable("test_varchar_table",
new String[] { "abc" }, false, false);
int lowWatermark = obPair.getRight().getObTable().getNettyBufferLowWatermark();
int highWatermark = obPair.getRight().getObTable().getNettyBufferHighWatermark();
int waitInterval = obPair.getRight().getObTable().getNettyBlockingWaitInterval();