diff --git a/pom.xml b/pom.xml index e4094828..119dfef7 100644 --- a/pom.xml +++ b/pom.xml @@ -365,4 +365,4 @@ - + \ No newline at end of file diff --git a/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java b/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java index f3a5d021..f29020e9 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java +++ b/src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java @@ -53,8 +53,7 @@ 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; @@ -502,7 +501,7 @@ void checkObTableQueryAndMutateResult(String ip, int port, ObPayload result) { * Get row key. */ public Object[] getRowKey() { - return rowKey; + return this.rowKey; } } @@ -539,8 +538,8 @@ private T execute(String tableName, TableExecuteCallback callback, ObServ if (odpMode) { obPair = new ObPair(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); @@ -609,10 +608,10 @@ private T execute(String tableName, TableExecuteCallback callback, ObServ } private abstract class MutationExecuteCallback { - private final Object[] rowKey; + private final Row rowKey; private final List keyRanges; - MutationExecuteCallback(Object[] rowKey, List keyRanges) { + MutationExecuteCallback(Row rowKey, List keyRanges) { this.rowKey = rowKey; this.keyRanges = keyRanges; } @@ -650,7 +649,7 @@ void checkResult(String ip, int port, ObPayload request, ObPayload result) { /* * Get row key. */ - public Object[] getRowKey() { + public Row getRowKey() { return rowKey; } @@ -702,11 +701,12 @@ private T executeMutation(String tableName, MutationExecuteCallback callb } 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"); } @@ -747,6 +747,10 @@ private T executeMutation(String tableName, MutationExecuteCallback callb } } 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 @@ -798,7 +802,6 @@ public void calculateContinuousFailure(String tableName, String errorMsg) throws } } - /** * Reset execute continuous failure count. * @param tableName table name @@ -1166,6 +1169,10 @@ public TableEntry getOrRefreshTableEntry(final String tableName, final boolean r 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"), @@ -1240,6 +1247,7 @@ private TableEntry refreshTableEntry(TableEntry tableEntry, String tableName, bo if (tableEntry.isPartitionTable()) { switch (runningMode) { case HBASE: + tableRowKeyElement.put(tableName, HBASE_ROW_KEY_ELEMENT); tableEntry.setRowKeyElement(HBASE_ROW_KEY_ELEMENT); break; case NORMAL: @@ -1247,11 +1255,12 @@ private TableEntry refreshTableEntry(TableEntry tableEntry, String tableName, bo 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(); @@ -1335,31 +1344,29 @@ private String refreshTableNameByTableGroup(String physicalTableName, String tab /** * 根据 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 getPartitionsForLevelTwo(TableEntry tableEntry, - List scanRangeColumns, Object[] start, - boolean startIncluded, Object[] end, + private List 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"); @@ -1367,9 +1374,9 @@ private List getPartitionsForLevelTwo(TableEntry tableEntry, } List partIds1 = tableEntry.getPartitionInfo().getFirstPartDesc() - .getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded); + .getPartIds(startRow, startIncluded, endRow, endIncluded); List partIds2 = tableEntry.getPartitionInfo().getSubPartDesc() - .getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded); + .getPartIds(startRow, startIncluded, endRow, endIncluded); List partIds = new ArrayList(); if (partIds1.isEmpty()) { @@ -1439,15 +1446,13 @@ private ReplicaLocation getPartitionLocation(TableEntry tableEntry, long partId, * @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 getTableBySingleRowKey(String tableName, Object[] rowKey, - boolean refresh, boolean waitForRefresh, boolean needFetchAll) - throws Exception { + public ObPair 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); } /** @@ -1460,16 +1465,33 @@ public ObPair getTableBySingleRowKey(String tableName, Objec * @return ObPair of partId and table * @throws Exception exception */ - public ObPair getTableBySingleRowKeyWithRoute(String tableName, - Object[] rowKey, - boolean refresh, - boolean waitForRefresh, - boolean needFetchAll, - ObServerRoute route) - throws Exception { - TableEntry tableEntry = getOrRefreshTableEntry(tableName, refresh, waitForRefresh, needFetchAll); + public ObPair 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 curTableRowKeyNames = new ArrayList(); + Map tableRowKeyEle = getRowKeyElement(tableName); + if (tableRowKeyEle != null) { + curTableRowKeyNames = new ArrayList(tableRowKeyEle.keySet()); + } + if (curTableRowKeyNames.isEmpty()) { + throw new IllegalArgumentException("Please make sure add row key elements"); + } + + // 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, rowKey); // partition id in 3.x, origin partId in 4.x, logicId + long partId = getPartition(tableEntry, row); // partition id in 3.x, origin partId in 4.x, logicId return getTableInternal(tableName, tableEntry, partId, waitForRefresh, route); } @@ -1478,11 +1500,15 @@ public ObPair getTableBySingleRowKeyWithRoute(String tableNa * 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 getTableByRowKeyRange(String tableName, ObTableQuery query, List keyRanges) - throws Exception { + public ObPair getTable(String tableName, ObTableQuery query, List keyRanges, boolean refresh, + boolean waitForRefresh, ObServerRoute route) + throws Exception { Map partIdMapObTable = new HashMap(); for (ObNewRange rang : keyRanges) { ObRowKey startKey = rang.getStartKey(); @@ -1521,6 +1547,40 @@ public ObPair getTableByRowKeyRange(String tableName, ObTabl 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 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 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 @@ -1532,9 +1592,11 @@ public ObPair getTableByRowKeyRange(String tableName, ObTabl * @throws Exception exception */ public ObPair 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); } @@ -1598,19 +1660,18 @@ public ObPair getTableInternal(String tableName, TableEntry /** * 根据 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> getPartitionReplica(TableEntry tableEntry, - List scanRangeColumns, - Object[] start, + Row startRow, boolean startIncluded, - Object[] end, + Row endRow, boolean endIncluded, ObServerRoute route) throws Exception { @@ -1623,14 +1684,14 @@ private List> getPartitionReplica(TableEntry table return replicas; } else if (tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_ONE) { List partIds = tableEntry.getPartitionInfo().getFirstPartDesc() - .getPartIds(scanRangeColumns, start, startIncluded, end, endIncluded); + .getPartIds(startRow, startIncluded, endRow, endIncluded); for (Long partId : partIds) { replicas.add(new ObPair(partId, getPartitionLocation( tableEntry, partId, route))); } } else if (tableEntry.getPartitionInfo().getLevel() == ObPartitionLevel.LEVEL_TWO) { - List partIds = getPartitionsForLevelTwo(tableEntry, scanRangeColumns, start, startIncluded, end, - endIncluded); + List partIds = getPartitionsForLevelTwo(tableEntry, startRow, startIncluded, + endRow, endIncluded); for (Long partId : partIds) { replicas.add(new ObPair(partId, getPartitionLocation( tableEntry, partId, route))); @@ -1677,27 +1738,46 @@ public List> getTables(String tableName, ObTableQuery * @return list of ObPair of partId(logicId) and tableParam * @throws Exception exception */ - public List> getTables(String tableName, ObTableQuery query, Object[] start, - boolean startInclusive, Object[] end, - boolean endInclusive, boolean refresh, - boolean waitForRefresh, ObServerRoute route) - throws Exception { + public List> 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 scanRangeColumns = query.getScanRangeColumns(); - if (scanRangeColumns == null || scanRangeColumns.size() == 0) { - Map tableRowKeyElement = tableEntry.getRowKeyElement(); - if (tableRowKeyElement != null) { - scanRangeColumns = new ArrayList<>(tableRowKeyElement.keySet()); + if (scanRangeColumns == null || scanRangeColumns.isEmpty()) { + Map tableEntryRowKeyElement = getRowKeyElement(tableName); + if (tableEntryRowKeyElement != null) { + scanRangeColumns = new ArrayList(tableEntryRowKeyElement.keySet()); } } - // 2. get replica location // partIdWithReplicaList -> List> + 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]); + } + } + List> partIdWithReplicaList = getPartitionReplica(tableEntry, - scanRangeColumns, start, startInclusive, end, endInclusive, route); + startRow, startInclusive, endRow, endInclusive, route); // obTableParams -> List> List> obTableParams = new ArrayList>(); @@ -1932,7 +2012,7 @@ public Long execute(ObPair obPair) throws Exception { * @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 keyRanges, final String[] columns, final Object[] values) throws Exception { final long start = System.currentTimeMillis(); @@ -1947,15 +2027,15 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 = obTable.execute(request); 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; @@ -2013,7 +2093,7 @@ public Long execute(ObPair obPair) throws Exception { * @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 keyRanges) throws Exception { final long start = System.currentTimeMillis(); return executeMutation(tableName, @@ -2028,14 +2108,15 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 = obTable.execute(request); 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; @@ -2095,7 +2176,7 @@ public Long execute(ObPair obPair) throws Exception { * @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 keyRanges, final String[] columns, final Object[] values) throws Exception { final long start = System.currentTimeMillis(); @@ -2110,15 +2191,15 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 = obTable.execute(request); 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; @@ -2136,7 +2217,7 @@ public ObPayload execute(ObPair obPair) throws Exception { * @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 keyRanges, final String[] columns, final Object[] values) throws Exception { final long start = System.currentTimeMillis(); @@ -2151,15 +2232,15 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 = obTable.execute(request); 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; @@ -2219,7 +2300,7 @@ public Long execute(ObPair obPair) throws Exception { * @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 keyRanges, final String[] columns, final Object[] values) throws Exception { final long start = System.currentTimeMillis(); @@ -2234,15 +2315,15 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 = obTable.execute(request); 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; @@ -2303,7 +2384,7 @@ public Long execute(ObPair obPair) throws Exception { * @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 keyRanges, final String[] columns, final Object[] values, boolean usePut) throws Exception { @@ -2319,7 +2400,7 @@ public ObPayload execute(ObPair obPair) throws Exception { 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 @@ -2330,7 +2411,7 @@ public ObPayload execute(ObPair obPair) throws Exception { ObPayload result = obTable.execute(request); 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; @@ -2409,7 +2490,7 @@ public Map execute(ObPair obPair) throws Exc * @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 keyRanges, final String[] columns, final Object[] values, final boolean withResult) throws Exception { @@ -2428,7 +2509,7 @@ public ObPayload execute(ObPair obPair) throws Exception { 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()); @@ -2436,8 +2517,8 @@ public ObPayload execute(ObPair obPair) throws Exception { request.setPartitionId(tableParam.getPartitionId()); ObPayload result = obTable.execute(request); 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; @@ -2494,7 +2575,7 @@ public Map execute(ObPair obPair) throws Exc * @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 keyRanges, final String[] columns, final Object[] values, final boolean withResult) throws Exception { @@ -2507,7 +2588,7 @@ public ObPayload execute(ObPair obPair) throws Exception { 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()); @@ -2515,8 +2596,8 @@ public ObPayload execute(ObPair obPair) throws Exception { request.setPartitionId(tableParam.getPartitionId()); ObPayload result = obTable.execute(request); 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; @@ -2541,7 +2622,7 @@ public BatchOperation batchOperation(String tableName) { * @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 keyRanges, final ObTableOperation operation, final boolean withResult) throws Exception { @@ -2561,7 +2642,7 @@ public ObPayload mutationWithFilter(final TableQuery tableQuery, final Object[] * @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 keyRanges, final ObTableOperation operation, final boolean withResult, final boolean checkAndExecute, final boolean checkExists) @@ -2787,9 +2868,9 @@ public ObPayload execute(final ObTableAbstractOperationRequest request) throws E end[i] = endKey.getObj(i).getValue(); } ObBorderFlag borderFlag = rang.getBorderFlag(); - List> pairList = getTables(request.getTableName(), tableQuery, - start, borderFlag.isInclusiveStart(), end, borderFlag.isInclusiveEnd(), - false, false); + List> pairList = getTables(request.getTableName(), + tableQuery, start, borderFlag.isInclusiveStart(), end, + borderFlag.isInclusiveEnd(), false, false); for (ObPair pair : pairList) { partIdMapObTable.put(pair.getLeft(), pair.getRight()); } @@ -3163,7 +3244,7 @@ public void addRowKeyElement(String tableName, String[] columns) { if (tableName == null || tableName.length() == 0) { throw new IllegalArgumentException("table name is null"); } - Map rowKeyElement = new LinkedHashMap<>(); + Map rowKeyElement = new LinkedHashMap(); for (int i = 0; i < columns.length; i++) { rowKeyElement.put(columns[i], i); } diff --git a/src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableRemoting.java b/src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableRemoting.java index ff4bcbaf..ebd9d1a3 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableRemoting.java +++ b/src/main/java/com/alipay/oceanbase/rpc/bolt/transport/ObTableRemoting.java @@ -186,7 +186,6 @@ protected InvokeFuture createInvokeFuture(Connection conn, RemotingCommand reque InvokeCallback invokeCallback) { return new ObClientFuture(request.getId()); } - // schema changed private boolean needFetchAll(int errorCode, int pcode) { diff --git a/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java b/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java index 3568a462..e588100c 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java +++ b/src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java @@ -21,6 +21,7 @@ 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 CheckAndInsUp(Table client, String tableName, ObTableFilter filter, this.checkExists = check_exists; } - public Object[] getRowKey() { + public Row getRowKey() { return insUp.getRowKey(); } @@ -85,15 +86,15 @@ public MutationResult execute() throws Exception { TableQuery query = client.query(tableName); query.setFilter(filter); - Object[] rowKey = getRowKey(); + Row rowKey = getRowKey(); List 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)); } diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java b/src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java index 9e894348..20d657e0 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java @@ -21,6 +21,7 @@ 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 @@ private static ObPartitionInfo parsePartitionInfo(ResultSet rs) } // set the property of first part and sub part - setPartDescProperty(info.getFirstPartDesc(), info.getPartColumns(), orderedPartedColumns1); - setPartDescProperty(info.getSubPartDesc(), info.getPartColumns(), orderedPartedColumns2); + List firstPartColumns = new ArrayList(), subPartColumns = new ArrayList(); + 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; } diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java index 316cb77e..969f81c0 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java @@ -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.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,105 +101,49 @@ public void prepare() { * Get part ids. */ @Override - public List getPartIds(Object[] start, boolean startInclusive, Object[] end, + public List 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> 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())) { - return completeWorks; + Object startValue = startRow.get(curObRefColumnName); + if (startValue == null) { + throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }"); } - if (end[refIdx] instanceof ObObj - && (((ObObj) end[refIdx]).isMinObj() || ((ObObj) end[refIdx]).isMaxObj())) { + if (startValue instanceof ObObj + && (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) { return completeWorks; } - } - } - - // eval partition key - List startValues = evalRowKeyValues(start); - Object startValue = startValues.get(0); - List endValues = evalRowKeyValues(end); - 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 partIds = new ArrayList(); - 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); - } - } - - @Override - public List getPartIds(List 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 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; + Object endValue = endRow.get(curObRefColumnName); + if (endValue == null) { + throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }"); } - if (endRow.get(column) instanceof ObObj - && (((ObObj) endRow.get(column)).isMinObj() || ((ObObj) endRow.get(column)).isMaxObj())) { + if (endValue instanceof ObObj + && (((ObObj) endValue).isMinObj() || ((ObObj) endValue).isMaxObj())) { return completeWorks; } } @@ -213,8 +160,8 @@ public List getPartIds(List scanRangeColumns, Object[] start, bool if (startLongValue == null || endLongValue == null) { throw new NumberFormatException("can not parseToComparable start value [" - + startValue + "] or end value [" + endValue - + "] to long"); + + startValue + "] or end value [" + endValue + + "] to long"); } long startHashValue = startLongValue - (startInclusive ? 0 : -1); long endHashValue = endLongValue - (endInclusive ? 0 : 1); @@ -231,7 +178,7 @@ public List getPartIds(List scanRangeColumns, Object[] start, bool } catch (IllegalArgumentException e) { logger.error(LCD.convert("01-00002"), e); throw new IllegalArgumentException( - "ObHashPartDesc get part id come across illegal params", e); + "ObHashPartDesc get part id come across illegal params", e); } } @@ -247,26 +194,30 @@ public Long getRandomPartId() { * Get part id. */ @Override - public Long getPartId(Object... rowKey) { - List rowKeys = new ArrayList(); - rowKeys.add(rowKey); - return this.getPartId(rowKeys, false); + public Long getPartId(Object... row) { + List rows = new ArrayList(); + rows.addAll(Arrays.asList(row)); + return this.getPartId(rows, false); } /* * Get part id. */ @Override - public Long getPartId(List rowKeys, boolean consistency) { + public Long getPartId(List 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 evalValues = evalRowKeyValues(rowKey); + for (Object rowObj : rows) { + if (!(rowObj instanceof Row)) { + throw new ObTableException("invalid format of rowObj: " + rowObj); + } + Row row = (Row) rowObj; + List 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 Long getPartId(List rowKeys, boolean consistency) { 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) { diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDesc.java index 2a379cc7..b90553d9 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDesc.java @@ -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,95 +88,48 @@ public void setPartNum(int partNum) { * Get part ids. */ @Override - public List getPartIds(Object[] start, boolean startInclusive, Object[] end, + public List 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> 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())) { - return completeWorks; + Object startValue = startRow.get(curObRefColumnName); + if (startValue == null) { + throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }"); } - if (end[refIdx] instanceof ObObj - && (((ObObj) end[refIdx]).isMinObj() || ((ObObj) end[refIdx]).isMaxObj())) { + if (startValue instanceof ObObj + && (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) { return completeWorks; } - } - } - - // eval partition key - List startValues = evalRowKeyValues(start); - List endValues = evalRowKeyValues(end); - - 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 partIds = new ArrayList(); - 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 partition ids for query - public List getPartIds(List 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 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; + Object endValue = endRow.get(curObRefColumnName); + if (endValue == null) { + throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }"); } - if (endRow.get(column) instanceof ObObj - && (((ObObj) endRow.get(column)).isMinObj() || ((ObObj) endRow.get(column)).isMaxObj())) { + if (endValue instanceof ObObj + && (((ObObj) endValue).isMinObj() || ((ObObj) endValue).isMaxObj())) { return completeWorks; } } @@ -187,8 +141,8 @@ public List getPartIds(List scanRangeColumns, Object[] start, bool if (startValues == null || endValues == null) { throw new NumberFormatException("can not parseToComparable start value [" - + startValues + "] or end value [" + endValues - + "] to long"); + + startValues + "] or end value [" + endValues + + "] to long"); } if (startValues.equals(endValues)) { @@ -202,7 +156,7 @@ public List getPartIds(List scanRangeColumns, Object[] start, bool } catch (IllegalArgumentException e) { logger.error(LCD.convert("01-00002"), e); throw new IllegalArgumentException( - "ObKeyPartDesc get part id come across illegal params", e); + "ObKeyPartDesc get part id come across illegal params", e); } } @@ -218,28 +172,32 @@ public Long getRandomPartId() { * Get part id. */ @Override - public Long getPartId(Object... rowKey) throws IllegalArgumentException { - List rowKeys = new ArrayList(); - rowKeys.add(rowKey); - return getPartId(rowKeys, false); + public Long getPartId(Object... row) throws IllegalArgumentException { + List rows = new ArrayList(); + rows.addAll(Arrays.asList(row)); + return getPartId(rows, false); } /* * Get part id. */ @Override - public Long getPartId(List rowKeys, boolean consistency) { + public Long getPartId(List 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 evalValues = null; - for (Object[] rowKey : rowKeys) { - List currentRowKeyEvalValues = evalRowKeyValues(rowKey); + for (Object rowObj : rows) { + if (!(rowObj instanceof Row)) { + throw new ObTableException("invalid format of rowObj: " + rowObj); + } + Row row = (Row) rowObj; + List currentRowKeyEvalValues = evalRowKeyValues(row); if (evalValues == null) { evalValues = currentRowKeyEvalValues; } @@ -253,11 +211,10 @@ public Long getPartId(List rowKeys, boolean consistency) { } 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 Long getPartId(List rowKeys, boolean consistency) { // calc partition id from eval values private Long calcPartId(List 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) diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObListPartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObListPartDesc.java index 08ca0071..3c3983f2 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObListPartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObListPartDesc.java @@ -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.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 void prepare() throws IllegalArgumentException { * Get part ids. */ @Override - public List getPartIds(Object[] start, boolean startInclusive, Object[] end, + public List getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj, boolean endInclusive) { - List rowKeys = new ArrayList(); - rowKeys.add(start); - rowKeys.add(end); - Long partId = getPartId(rowKeys, true); - List partIds = new ArrayList(); - partIds.add(partId); - return partIds; - } - - @Override - public List getPartIds(List 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 rowKeys = new ArrayList(); - rowKeys.add(rowKey); - return getPartId(rowKeys, false); + public Long getPartId(Object... row) { + List rows = new ArrayList(); + rows.addAll(Arrays.asList(row)); + return getPartId(rows, false); } /* * Get part id. */ @Override - public Long getPartId(List rowKeys, boolean consistency) { - if (rowKeys == null || rowKeys.size() == 0) { - throw new IllegalArgumentException("invalid row keys :" + rowKeys); + public Long getPartId(List 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 currentRowKeyEvalValues = evalRowKeyValues(rowKey); + for (Object rowObj : rows) { + if (!(rowObj instanceof Row)) { + throw new ObTableException("invalid format of rowObj: " + rowObj); + } + Row row = (Row) rowObj; + List currentRowKeyEvalValues = evalRowKeyValues(row); List values = super.initComparableElementByTypes( currentRowKeyEvalValues, this.orderCompareColumns); @@ -158,7 +152,7 @@ public Long getPartId(List rowKeys, boolean consistency) { if (partId != currentPartId) { throw new ObTablePartitionConsistentException( - "across partition operation may cause consistent problem " + rowKeys); + "across partition operation may cause consistent problem " + rows); } } diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObPartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObPartDesc.java index 609fdb8e..6be189ea 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObPartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObPartDesc.java @@ -23,6 +23,7 @@ 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 void setPartExpr(String partExpr) { */ public int getPartNum() { return -1; - }; + } /* * Get ordered part column names. @@ -169,129 +170,51 @@ protected List initComparableElementByTypes(List objects, //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>> orderPartRefColumnRowKeyRelations = new ArrayList>>( - orderedPartColumnNames.size()); - for (String partOrderColumnName : orderedPartColumnNames) { - for (ObColumn column : partColumns) { - if (column.getColumnName().equalsIgnoreCase(partOrderColumnName)) { - List partRefColumnRowKeyIndexes = new ArrayList(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>( - column, partRefColumnRowKeyIndexes)); - } - } - } - this.orderedPartRefColumnRowKeyRelations = orderPartRefColumnRowKeyRelations; - } + public void prepare() throws IllegalArgumentException { /* do nothing now */ } /* * Eval row key values. */ - public List evalRowKeyValues(Object... rowKey) throws IllegalArgumentException { - int partRefColumnSize = orderedPartRefColumnRowKeyRelations.size(); - List evalValues = new ArrayList(partRefColumnSize); - // column or generate column - for (int i = 0; i < partRefColumnSize; i++) { - ObPair> 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 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; - } - } - evalParams[j] = partKey[refIndex.get(j)]; - } - if (needEval) { - evalValues.add(orderedPartRefColumnRowKeyRelation.getLeft().evalValue(evalParams)); - } + public List evalRowKeyValues(Row row) throws IllegalArgumentException { + int partColumnSize = partColumns.size(); + List evalValues = new ArrayList(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)); } - return evalValues; - } - - public List evalRowKeyValues(Row rowKey) throws IllegalArgumentException { - // column or generate column - String[] rowkeyNames = rowKey.getColumns(); - List evalValues = new ArrayList(orderedPartRefColumnRowKeyRelations.size()); - for (int i = 0; i < orderedPartRefColumnRowKeyRelations.size(); i++) { - ObColumn partCol = orderedPartRefColumnRowKeyRelations.get(i).getLeft(); - List 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); - } + boolean needEval = true; - if (refCols.size() == 1 && refObj instanceof ObObj) { - ObObj obj = (ObObj) refObj; - if (obj.isMaxObj() || obj.isMinObj()) { - evalValues.add(obj); - needEval = false; - break; + // column or generate column + for (int i = 0; i < partColumns.size(); ++i) { + ObColumn curObColumn = partColumns.get(i); + List 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] = refObj; + if (needEval) { + evalValues.add(curObColumn.evalValue(evalParams)); + } } - if (needEval) { - evalValues.add(partCol.evalValue(evalParams)); - } - } return evalValues; } @@ -302,16 +225,15 @@ public List evalRowKeyValues(Row rowKey) throws IllegalArgumentException * @param end the end row key * @param endInclusive the end row key inclusive */ - public abstract List getPartIds(Object[] start, boolean startInclusive, Object[] end, - boolean endInclusive) throws IllegalArgumentException; - public abstract List getPartIds(List scanRangeColumns, Object[] start, boolean startInclusive, - Object[] end, boolean endInclusive) throws IllegalArgumentException; + public abstract List 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 rowKeys, boolean consistency) - throws IllegalArgumentException, - ObTablePartitionConsistentException; + public abstract Long getPartId(List row, boolean consistency) + throws IllegalArgumentException, + ObTablePartitionConsistentException; public abstract Long getRandomPartId(); diff --git a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java index c6e2777a..b41871e9 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java +++ b/src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDesc.java @@ -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 void setPartNum(int partNum) { * Get part ids. */ @Override - public List getPartIds(Object[] start, boolean startInclusive, Object[] end, + public List 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 partIds = new ArrayList(); - 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 getPartIds(List 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 partIds = new ArrayList(); @@ -264,9 +245,11 @@ public List getPartIds(List scanRangeColumns, Object[] start, bool * Get part id. */ @Override - public Long getPartId(Object... rowKey) { + public Long getPartId(Object... row) { try { - return this.bounds.get(getBoundsIdx(false, rowKey)).value; + List rows = new ArrayList(); + 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 Long getPartId(Object... rowKey) { } - 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 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 evalParams = evalRowKeyValues(rowKey); + List evalParams = evalRowKeyValues(row); List comparableElement = super.initComparableElementByTypes(evalParams, this.orderedCompareColumns); ObPartitionKey searchKey = ObPartitionKey.getInstance(orderedCompareColumns, @@ -340,14 +327,18 @@ public int getBoundsIdx(boolean isScan, Row rowKey) { * Get part id. */ @Override - public Long getPartId(List rowKeys, boolean consistency) { - if (rowKeys == null || rowKeys.size() == 0) { - throw new IllegalArgumentException("invalid row keys :" + rowKeys); + public Long getPartId(List 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 Long getPartId(List rowKeys, boolean consistency) { if (!partId.equals(currentPartId)) { throw new ObTablePartitionConsistentException( - "across partition operation may cause consistent problem " + rowKeys); + "across partition operation may cause consistent problem " + rows); } } diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java index 24bf99ea..6caf1887 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/BatchOperation.java @@ -195,42 +195,42 @@ private BatchOperationResult executeWithNormalBatchOp() throws Exception { + 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: @@ -309,12 +309,12 @@ private BatchOperationResult executeWithLSBatchOp() throws Exception { } 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); } } } diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java index b9afb8db..903539bb 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Insert.java @@ -159,7 +159,7 @@ public MutationResult execute() throws Exception { 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)); diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java index 8049f41e..e099a6ab 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Mutation.java @@ -32,6 +32,7 @@ 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.row; public class Mutation { - private String tableName; - private Table client; - protected Object[] rowKey; - private TableQuery query; - private boolean hasSetRowKey = false; - protected List rowKeyNames = null; - protected List columns; - protected List values; + private String tableName; + private Table client; + protected Row rowKey; + private TableQuery query; + private boolean hasSetRowKey = false; + protected List rowKeyNames = null; + protected List rowKeyValues = null; + protected List columns; + protected List values; /* * default constructor @@ -58,6 +60,7 @@ public Mutation() { rowKey = null; query = null; rowKeyNames = null; + rowKeyValues = null; columns = null; values = null; } @@ -76,6 +79,7 @@ public Mutation(Table client, String tableName) { this.rowKey = null; this.query = null; this.rowKeyNames = null; + this.rowKeyValues = null; this.columns = null; this.values = null; } @@ -104,7 +108,7 @@ protected TableQuery getQuery() { /* * get row key */ - public Object[] getRowKey() { + public Row getRowKey() { return rowKey; } @@ -132,6 +136,11 @@ public List getRowKeyNames() { return rowKeyNames; } + /* + * get rowkey values + */ + public List getRowKeyValues() { return rowKeyValues; } + /* * check mutation filter */ @@ -184,25 +193,22 @@ public T setRowKey(Row rowKey) { 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 columnNames = new ArrayList(); - List Keys = new ArrayList(); - for (Map.Entry 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 @@ protected T setRowKeyOnly(Row rowKey) { 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 columnNames = new ArrayList(); - List Keys = new ArrayList(); - for (Map.Entry 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 T setRowKey(ColumnValue... rowKey) { 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 columnNames = new ArrayList(); - List Keys = new ArrayList(); - 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 T setRowKeyOnly(ColumnValue... rowKey) { 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 columnNames = new ArrayList(); - List Keys = new ArrayList(); - 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 T setFilter(ObTableFilter filter) throws Exception { 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 diff --git a/src/main/java/com/alipay/oceanbase/rpc/mutation/Put.java b/src/main/java/com/alipay/oceanbase/rpc/mutation/Put.java index 70da952d..580cde63 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/mutation/Put.java +++ b/src/main/java/com/alipay/oceanbase/rpc/mutation/Put.java @@ -158,7 +158,7 @@ public MutationResult execute() throws Exception { 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 { diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java index 5437a5a1..f56e7b38 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientBatchOpsImpl.java @@ -243,8 +243,8 @@ public Map>>> for (int j = 0; j < rowKeySize; j++) { rowKey[j] = rowKeyObject.getObj(j).getValue(); } - ObPair tableObPair = obTableClient.getTableBySingleRowKeyWithRoute( - tableName, rowKey, false, false, false, + ObPair tableObPair = obTableClient.getTable( + tableName, rowKey, false, false, obTableClient.getRoute(batchOperation.isReadOnly())); ObPair>> obTableOperations = partitionOperationsMap .get(tableObPair.getLeft()); diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java index db7b152f..7c38d8d3 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientLSBatchOpsImpl.java @@ -156,17 +156,17 @@ public void addOperation(CheckAndInsUp checkAndInsUp) { 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(); @@ -200,7 +200,7 @@ public void addOperation(TableQuery query) throws Exception { public void addOperation(Mutation mutation) throws Exception { // entity String[] rowKeyNames = null; - Object[] rowKey = null; + Object[] rowKeyValues = null; String[] propertiesNames = null; Object[] propertiesValues = null; @@ -211,53 +211,53 @@ public void addOperation(Mutation mutation) throws Exception { 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; @@ -265,7 +265,7 @@ public void addOperation(Mutation mutation) throws Exception { 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); @@ -339,8 +339,8 @@ public Map tableObPair= obTableClient.getTableBySingleRowKeyWithRoute(tableName, rowKey, - false, false, false, obTableClient.getRoute(false)); + ObPair tableObPair= obTableClient.getTable(tableName, rowKey, + false, false, obTableClient.getRoute(false)); long lsId = tableObPair.getRight().getLsId(); Map>>> tabletOperations diff --git a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java index 03c83619..ecf435d0 100644 --- a/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java +++ b/src/main/java/com/alipay/oceanbase/rpc/table/ObTableClientQueryImpl.java @@ -274,8 +274,8 @@ public void initPartitions() throws Exception { ObBorderFlag borderFlag = rang.getBorderFlag(); // pairs -> List> List> 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)); diff --git a/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java b/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java index 9226b03e..dcc5ab21 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/ObTableCheckAndInsUpTest.java @@ -259,7 +259,7 @@ public void testBatchWithReverseRowKwyColumn() throws Exception { 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()); } diff --git a/src/test/java/com/alipay/oceanbase/rpc/bolt/ObTableTest.java b/src/test/java/com/alipay/oceanbase/rpc/bolt/ObTableTest.java index 4c14cb51..1526b6e9 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/bolt/ObTableTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/bolt/ObTableTest.java @@ -48,7 +48,7 @@ public void setup() throws Exception { 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; } diff --git a/src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java b/src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java index 85b549a2..f0faed35 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/hbase/ObHTableTest.java @@ -55,7 +55,7 @@ public void setup() throws Exception { 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; } diff --git a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDescTest.java b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDescTest.java index 58541158..424d5130 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDescTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDescTest.java @@ -23,11 +23,13 @@ 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 void setUp() { @Test public void testGetPartId() { - - 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())); - - 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())); - - 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())); - + // set values + Map values0 = new HashMap() { + { + put("K", 0); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values1 = new HashMap() { + { + put("K", 1); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values2 = new HashMap() { + { + put("K", 2); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values3 = new HashMap() { + { + put("K", 3); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values4 = new HashMap() { + { + put("K", 4); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values5 = new HashMap() { + { + put("K", 5); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values6 = new HashMap() { + { + put("K", 6); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values7 = new HashMap() { + { + put("K", 7); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values8 = new HashMap() { + { + put("K", 8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values9 = new HashMap() { + { + put("K", 9); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values10 = new HashMap() { + { + put("K", 10); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values11 = new HashMap() { + { + put("K", 11); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values12 = new HashMap() { + { + put("K", 12); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values13 = new HashMap() { + { + put("K", 13); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values14 = new HashMap() { + { + put("K", 14); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values15 = new HashMap() { + { + put("K", 15); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + + Map values_0 = new HashMap() { + { + put("K", -0); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_1 = new HashMap() { + { + put("K", -1); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_2 = new HashMap() { + { + put("K", -2); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_3 = new HashMap() { + { + put("K", -3); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_4 = new HashMap() { + { + put("K", -4); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_5 = new HashMap() { + { + put("K", -5); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_6 = new HashMap() { + { + put("K", -6); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_7 = new HashMap() { + { + put("K", -7); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_8 = new HashMap() { + { + put("K", -8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_9 = new HashMap() { + { + put("K", -9); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_10 = new HashMap() { + { + put("K", -10); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_11 = new HashMap() { + { + put("K", -11); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_12 = new HashMap() { + { + put("K", -12); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_13 = new HashMap() { + { + put("K", -13); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_14 = new HashMap() { + { + put("K", -14); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_15 = new HashMap() { + { + put("K", -15); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + + Map values0_e = new HashMap() { + { + put("K", 0); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values0_l = new HashMap() { + { + put("K", 0); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values1_e = new HashMap() { + { + put("K", 1); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values1_l = new HashMap() { + { + put("K", 1); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values2_e = new HashMap() { + { + put("K", 2); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values2_l = new HashMap() { + { + put("K", 2); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values3_e = new HashMap() { + { + put("K", 3); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values3_l = new HashMap() { + { + put("K", 3); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values4_e = new HashMap() { + { + put("K", 4); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values4_l = new HashMap() { + { + put("K", 4); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values5_e = new HashMap() { + { + put("K", 5); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values5_l = new HashMap() { + { + put("K", 5); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values6_e = new HashMap() { + { + put("K", 6); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values6_l = new HashMap() { + { + put("K", 6); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values7_e = new HashMap() { + { + put("K", 7); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values7_l = new HashMap() { + { + put("K", 7); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values8_e = new HashMap() { + { + put("K", 8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values8_l = new HashMap() { + { + put("K", 8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values9_e = new HashMap() { + { + put("K", 9); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values9_l = new HashMap() { + { + put("K", 9); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values10_e = new HashMap() { + { + put("K", 10); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values10_l = new HashMap() { + { + put("K", 10); + put("Q", "column_1"); + put("T", 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 values0 = new HashMap() { + { + put("K", 0); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values8 = new HashMap() { + { + put("K", 8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values15 = new HashMap() { + { + put("K", 15); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values16 = new HashMap() { + { + put("K", 16); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values30 = new HashMap() { + { + put("K", 30); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_8f = new HashMap() { + { + put("K", -8); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_15f = new HashMap() { + { + put("K", -15); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map values_30f = new HashMap() { + { + 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 buildPartIds(long start, long end) { diff --git a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDescTest.java b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDescTest.java index bcb6c5b8..15803924 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDescTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObKeyPartDescTest.java @@ -19,6 +19,7 @@ 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.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 void setUp() { partColumns.add(column); keyUtf8.setPartColumns(partColumns); keyUtf8.setRowKeyElement(TableEntry.HBASE_ROW_KEY_ELEMENT); - keyUtf8.prepare(); + // keyUtf8.prepare(); } @Test @@ -164,32 +163,105 @@ public void testGetPartId() { @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 startKey1 = new HashMap() { + { + put("K", "partition_1"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey1 = new HashMap() { + { + put("K", "partition_2"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey2 = new HashMap() { + { + put("K", "partition_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey2 = new HashMap() { + { + put("K", "partition_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey3 = new HashMap() { + { + put("K", "test_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey3 = new HashMap() { + { + put("K", "test_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey4 = new HashMap() { + { + put("K", "PARTITION_1"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey4 = new HashMap() { + { + put("K", "PARTITION_2"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey5 = new HashMap() { + { + put("K", "PARTITION_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey5 = new HashMap() { + { + put("K", "PARTITION_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey6 = new HashMap() { + { + put("K", "TEST_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey6 = new HashMap() { + { + put("K", "TEST_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + 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(new Row(startKey1), true, new Row(endKey2), true), + keyBinary.getPartIds(new Row(startKey2), true, new Row(endKey1), true)); - Object[] startKey2 = new Object[] { "partition_1".getBytes(), "column_1", timestamp }; - Object[] endKey2 = new Object[] { "partition_2".getBytes(), "column_1", timestamp }; - - Object[] startKey3 = new Object[] { "test_1".getBytes(), "column_1", timestamp }; - Object[] endKey3 = new Object[] { "test_2".getBytes(), "column_1", timestamp }; - - Object[] startKey4 = new Object[] { "PARTITION_1", "column_1", timestamp }; - Object[] endKey4 = new Object[] { "PARTITION_2", "column_1", timestamp }; - - Object[] startKey5 = new Object[] { "PARTITION_1".getBytes(), "column_1", timestamp }; - Object[] endKey5 = new Object[] { "PARTITION_2".getBytes(), "column_1", timestamp }; - - Object[] startKey6 = new Object[] { "TEST_1".getBytes(), "column_1", timestamp }; - Object[] endKey6 = new Object[] { "TEST_2".getBytes(), "column_1", timestamp }; - - Assert.assertEquals(keyBinary.getPartIds(startKey1, true, endKey1, true), - keyBinary.getPartIds(startKey2, true, endKey2, true)); - - Assert.assertEquals(keyBinary.getPartIds(startKey1, true, endKey2, true), - keyBinary.getPartIds(startKey2, true, 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 ans = keyBinary.getPartIds(startKey1, false, endKey3, false); @@ -215,59 +287,71 @@ public void testGetPartIds() { 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)); } diff --git a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDescTest.java b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDescTest.java index 35637a24..9f2cf6f7 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDescTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/location/model/partition/ObRangePartDescTest.java @@ -22,6 +22,7 @@ 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 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 void setUp() { @Test public void testGetPartId() { - long partId = rangeBinary.getPartId("partition_1", "column_1", System.currentTimeMillis()); + Map partition_1 = new HashMap() { + { + put("K", "partition_1"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map partition_2 = new HashMap() { + { + 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 test_a = new HashMap() { + { + 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 test_x = new HashMap() { + { + 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("test_1", "column_1", System.currentTimeMillis()), - rangeBinary.getPartId("test_2", "column_1", 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("test_1".getBytes(), "column_1", System.currentTimeMillis()), - rangeBinary.getPartId("test_2".getBytes(), "column_1", System.currentTimeMillis())); - - partId = rangeBinary.getPartId("A", "column_1", System.currentTimeMillis()); + Assert.assertEquals(rangeBinary.getPartId(new Row(partition_1)), + rangeBinary.getPartId(new Row(partition_2))); + + Map test_1 = new HashMap() { + { + put("K", "test_1"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_1_bytes = new HashMap() { + { + put("K", "test_1".getBytes()); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_2 = new HashMap() { + { + put("K", "test_2"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_2_bytes = new HashMap() { + { + put("K", "test_2".getBytes()); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + + Assert.assertEquals(rangeBinary.getPartId(new Row(test_1)), + rangeBinary.getPartId(new Row(test_2))); + + Assert.assertEquals(rangeBinary.getPartId(new Row(test_1)), + rangeBinary.getPartId(new Row(test_2_bytes))); + + Assert.assertEquals(rangeBinary.getPartId(new Row(test_1_bytes)), + rangeBinary.getPartId(new Row(test_2_bytes))); + + Map test_A = new HashMap() { + { + put("K", "A"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_P = new HashMap() { + { + put("K", "P"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_X = new HashMap() { + { + put("K", "X"); + put("Q", "column_1"); + put("T", System.currentTimeMillis()); + } + }; + Map test_p = new HashMap() { + { + 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 rowKeys = new ArrayList(); - rowKeys.add(new Object[] { "P", "column_1", System.currentTimeMillis() }); + ArrayList rowKeys = new ArrayList(); + 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 void testGetPartId() { @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 }; - - Object[] startKey2 = new Object[] { "partition_1".getBytes(), "column_1", timestamp }; - Object[] endKey2 = new Object[] { "partition_2".getBytes(), "column_1", timestamp }; - - Object[] startKey3 = new Object[] { "yes_1".getBytes(), "column_1", timestamp }; - Object[] endKey3 = new Object[] { "yes_2".getBytes(), "column_1", timestamp }; - - Object[] startKey4 = new Object[] { "PARTITION_1", "column_1", timestamp }; - Object[] endKey4 = new Object[] { "PARTITION_2", "column_1", timestamp }; - - Object[] startKey5 = new Object[] { "PARTITION_1".getBytes(), "column_1", timestamp }; - Object[] endKey5 = new Object[] { "PARTITION_2".getBytes(), "column_1", timestamp }; - - Object[] startKey6 = new Object[] { "YES_1".getBytes(), "column_1", timestamp }; - Object[] endKey6 = new Object[] { "YES_2".getBytes(), "column_1", timestamp }; + Map startKey1 = new HashMap() { + { + put("K", "partition_1"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey1 = new HashMap() { + { + put("K", "partition_1"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey2 = new HashMap() { + { + put("K", "partition_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey2 = new HashMap() { + { + put("K", "partition_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey3 = new HashMap() { + { + put("K", "yes_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey3 = new HashMap() { + { + put("K", "yes_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey4 = new HashMap() { + { + put("K", "PARTITION_1"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey4 = new HashMap() { + { + put("K", "PARTITION_2"); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey5 = new HashMap() { + { + put("K", "PARTITION_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey5 = new HashMap() { + { + put("K", "PARTITION_2".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + + Map startKey6 = new HashMap() { + { + put("K", "YES_1".getBytes()); + put("Q", "column_1"); + put("T", timestamp); + } + }; + Map endKey6 = new HashMap() { + { + 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 partIds = new ArrayList(); 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(); 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(); 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(); 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(); 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()); } diff --git a/src/test/java/com/alipay/oceanbase/rpc/table/ObTableConnectionTest.java b/src/test/java/com/alipay/oceanbase/rpc/table/ObTableConnectionTest.java index 451c9d69..c508c483 100644 --- a/src/test/java/com/alipay/oceanbase/rpc/table/ObTableConnectionTest.java +++ b/src/test/java/com/alipay/oceanbase/rpc/table/ObTableConnectionTest.java @@ -76,8 +76,8 @@ public void testConnectionPoolSize() throws Exception { assertEquals(TEST_CONNECTION_POOL_SIZE, obTableClient.getOdpTable() .getObTableConnectionPoolSize()); } else { - ObPair obPair = obTableClient.getTableBySingleRowKey("test_varchar_table", - new String[] { "abc" }, false, false, false); + ObPair 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 void testWatermarkSetting() throws Exception { assertEquals(TEST_NETTY_WAIT_INTERVAL, obTableClient.getOdpTable() .getNettyBlockingWaitInterval()); } else { - ObPair obPair = obTableClient.getTableBySingleRowKey("test_varchar_table", - new String[] { "abc" }, false, false, false); + ObPair 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 void testDefaultWatermark() throws Exception { if (obTableClient.isOdpMode()) { // do nothing } else { - ObPair obPair = obTableClient.getTableBySingleRowKey("test_varchar_table", - new String[] { "abc" }, false, false, false); + ObPair 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();