Skip to content

Commit 7b97f73

Browse files
authored
remove rowKeyElement dependencies test for code review (#159)
* merged all commits into one * correct reverse test * format code * check whether startRow and endRow contain the refColumn in Hash and Key part * keep the same format with ObHashPartDesc
1 parent 402b604 commit 7b97f73

23 files changed

+1490
-920
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,4 @@
365365
</build>
366366
</profile>
367367
</profiles>
368-
</project>
368+
</project>

src/main/java/com/alipay/oceanbase/rpc/ObTableClient.java

Lines changed: 183 additions & 102 deletions
Large diffs are not rendered by default.

src/main/java/com/alipay/oceanbase/rpc/checkandmutate/CheckAndInsUp.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.alipay.oceanbase.rpc.exception.ObTableException;
2222
import com.alipay.oceanbase.rpc.filter.ObTableFilter;
2323
import com.alipay.oceanbase.rpc.mutation.InsertOrUpdate;
24+
import com.alipay.oceanbase.rpc.mutation.Row;
2425
import com.alipay.oceanbase.rpc.mutation.result.MutationResult;
2526
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObRowKey;
2627
import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.ObTableOperation;
@@ -58,7 +59,7 @@ public CheckAndInsUp(Table client, String tableName, ObTableFilter filter,
5859
this.checkExists = check_exists;
5960
}
6061

61-
public Object[] getRowKey() {
62+
public Row getRowKey() {
6263
return insUp.getRowKey();
6364
}
6465

@@ -85,15 +86,15 @@ public MutationResult execute() throws Exception {
8586

8687
TableQuery query = client.query(tableName);
8788
query.setFilter(filter);
88-
Object[] rowKey = getRowKey();
89+
Row rowKey = getRowKey();
8990
List<ObNewRange> ranges = new ArrayList<>();
9091
ObNewRange range = new ObNewRange();
91-
range.setStartKey(ObRowKey.getInstance(insUp.getRowKey()));
92-
range.setEndKey(ObRowKey.getInstance(insUp.getRowKey()));
92+
range.setStartKey(ObRowKey.getInstance(insUp.getRowKey().getValues()));
93+
range.setEndKey(ObRowKey.getInstance(insUp.getRowKey().getValues()));
9394
ranges.add(range);
9495
query.getObTableQuery().setKeyRanges(ranges);
9596
ObTableOperation operation = ObTableOperation.getInstance(ObTableOperationType.INSERT_OR_UPDATE,
96-
insUp.getRowKey(), insUp.getColumns(), insUp.getValues());
97+
insUp.getRowKey().getValues(), insUp.getColumns(), insUp.getValues());
9798

9899
return new MutationResult(((ObTableClient)client).mutationWithFilter(query, rowKey, ranges, operation, false, true, checkExists));
99100
}

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.alibaba.fastjson.JSONException;
2222
import com.alibaba.fastjson.JSONObject;
2323
import com.alibaba.fastjson.parser.ParserConfig;
24+
import com.alipay.oceanbase.rpc.ObClusterTableBatchOps;
2425
import com.alipay.oceanbase.rpc.ObGlobal;
2526
import com.alipay.oceanbase.rpc.constant.Constants;
2627
import com.alipay.oceanbase.rpc.exception.*;
@@ -1312,8 +1313,29 @@ private static ObPartitionInfo parsePartitionInfo(ResultSet rs)
13121313
}
13131314

13141315
// set the property of first part and sub part
1315-
setPartDescProperty(info.getFirstPartDesc(), info.getPartColumns(), orderedPartedColumns1);
1316-
setPartDescProperty(info.getSubPartDesc(), info.getPartColumns(), orderedPartedColumns2);
1316+
List<ObColumn> firstPartColumns = new ArrayList<ObColumn>(), subPartColumns = new ArrayList<ObColumn>();
1317+
if (null != info.getFirstPartDesc()) {
1318+
for (String partColumnNames : info.getFirstPartDesc().getOrderedPartColumnNames()) {
1319+
for (ObColumn curColumn : info.getPartColumns()) {
1320+
if (curColumn.getColumnName().equalsIgnoreCase(partColumnNames)) {
1321+
firstPartColumns.add(curColumn);
1322+
break;
1323+
}
1324+
}
1325+
}
1326+
}
1327+
if (null != info.getSubPartDesc()) {
1328+
for (String partColumnNames : info.getSubPartDesc().getOrderedPartColumnNames()) {
1329+
for (ObColumn curColumn : info.getPartColumns()) {
1330+
if (curColumn.getColumnName().equalsIgnoreCase(partColumnNames)) {
1331+
subPartColumns.add(curColumn);
1332+
break;
1333+
}
1334+
}
1335+
}
1336+
}
1337+
setPartDescProperty(info.getFirstPartDesc(), firstPartColumns, orderedPartedColumns1);
1338+
setPartDescProperty(info.getSubPartDesc(), subPartColumns, orderedPartedColumns2);
13171339

13181340
return info;
13191341
}

src/main/java/com/alipay/oceanbase/rpc/location/model/partition/ObHashPartDesc.java

Lines changed: 48 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717

1818
package com.alipay.oceanbase.rpc.location.model.partition;
1919

20+
import com.alipay.oceanbase.rpc.exception.ObTableException;
2021
import com.alipay.oceanbase.rpc.exception.ObTablePartitionConsistentException;
2122
import com.alipay.oceanbase.rpc.mutation.Row;
2223
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObColumn;
2324
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObj;
2425
import com.alipay.oceanbase.rpc.protocol.payload.impl.ObObjType;
2526
import com.alipay.oceanbase.rpc.util.RandomUtil;
2627
import com.alipay.oceanbase.rpc.util.TableClientLoggerFactory;
28+
import com.alipay.oceanbase.rpc.mutation.Row;
2729
import org.apache.commons.lang.builder.ToStringBuilder;
2830
import org.slf4j.Logger;
2931

3032
import java.util.ArrayList;
33+
import java.util.Arrays;
3134
import java.util.Collections;
3235
import java.util.List;
3336

@@ -98,105 +101,49 @@ public void prepare() {
98101
* Get part ids.
99102
*/
100103
@Override
101-
public List<Long> getPartIds(Object[] start, boolean startInclusive, Object[] end,
104+
public List<Long> getPartIds(Object startRowObj, boolean startInclusive, Object endRowObj,
102105
boolean endInclusive) {
103106
// close set
104107
try {
108+
// verify the type of parameters and convert to Row
109+
if (!(startRowObj instanceof Row) || !(endRowObj instanceof Row)) {
110+
throw new ObTableException("invalid format of rowObj: " + startRowObj + ", "
111+
+ endRowObj);
112+
}
113+
Row startRow = (Row) startRowObj, endRow = (Row) endRowObj;
105114
// pre-check start and end
106115
// should remove after remove addRowkeyElement
107-
if (start.length != end.length) {
116+
if (startRow.size() != endRow.size()) {
108117
throw new IllegalArgumentException("length of start key and end key is not equal");
109118
}
110119

120+
if (startRow.size() == 1 && startRow.getValues()[0] instanceof ObObj && ((ObObj) startRow.getValues()[0]).isMinObj() &&
121+
endRow.size() == 1 && endRow.getValues()[0] instanceof ObObj && ((ObObj) endRow.getValues()[0]).isMaxObj()) {
122+
return completeWorks;
123+
}
124+
111125
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
112-
for (ObPair<ObColumn, List<Integer>> pair : orderedPartRefColumnRowKeyRelations) {
113-
for (int refIdx : pair.getRight()) {
114-
if (start.length <= refIdx) {
115-
throw new IllegalArgumentException("rowkey length is " + start.length
126+
for (ObColumn curObcolumn : partColumns) {
127+
for (int refIdx = 0; refIdx < curObcolumn.getRefColumnNames().size(); ++refIdx) {
128+
String curObRefColumnName = curObcolumn.getRefColumnNames().get(refIdx);
129+
if (startRow.size() <= refIdx) {
130+
throw new IllegalArgumentException("rowkey length is " + startRow.size()
116131
+ ", which is shortest than " + refIdx);
117132
}
118-
if (start[refIdx] instanceof ObObj
119-
&& (((ObObj) start[refIdx]).isMinObj() || ((ObObj) start[refIdx])
120-
.isMaxObj())) {
121-
return completeWorks;
133+
Object startValue = startRow.get(curObRefColumnName);
134+
if (startValue == null) {
135+
throw new IllegalArgumentException("Please include all partition key in start range. Currently missing key: { " + curObRefColumnName + " }");
122136
}
123-
if (end[refIdx] instanceof ObObj
124-
&& (((ObObj) end[refIdx]).isMinObj() || ((ObObj) end[refIdx]).isMaxObj())) {
137+
if (startValue instanceof ObObj
138+
&& (((ObObj) startValue).isMinObj() || ((ObObj) startValue).isMaxObj())) {
125139
return completeWorks;
126140
}
127-
}
128-
}
129-
130-
// eval partition key
131-
List<Object> startValues = evalRowKeyValues(start);
132-
Object startValue = startValues.get(0);
133-
List<Object> endValues = evalRowKeyValues(end);
134-
Object endValue = endValues.get(0);
135-
136-
Long startLongValue = ObObjType.parseToLongOrNull(startValue);
137-
Long endLongValue = ObObjType.parseToLongOrNull(endValue);
138-
139-
if (startLongValue == null || endLongValue == null) {
140-
throw new NumberFormatException("can not parseToComparable start value ["
141-
+ startValue + "] or end value [" + endValue
142-
+ "] to long");
143-
}
144-
long startHashValue = startLongValue - (startInclusive ? 0 : -1);
145-
long endHashValue = endLongValue - (endInclusive ? 0 : 1);
146-
147-
if (endHashValue - startHashValue + 1 >= partNum) {
148-
return completeWorks;
149-
} else {
150-
List<Long> partIds = new ArrayList<Long>();
151-
for (long i = startHashValue; i <= endHashValue; i++) {
152-
partIds.add(innerHash(i));
153-
}
154-
return partIds;
155-
}
156-
} catch (IllegalArgumentException e) {
157-
logger.error(LCD.convert("01-00002"), e);
158-
throw new IllegalArgumentException(
159-
"ObHashPartDesc get part id come across illegal params", e);
160-
}
161-
}
162-
163-
@Override
164-
public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, boolean startInclusive,
165-
Object[] end, boolean endInclusive) throws IllegalArgumentException {
166-
try {
167-
if (start.length != end.length) {
168-
throw new IllegalArgumentException("length of start key and end key in range is not equal, " +
169-
"the start key: " + start + ", the end key: " + end);
170-
}
171-
172-
if (start.length == 1 && start[0] instanceof ObObj && ((ObObj) start[0]).isMinObj() &&
173-
end.length == 1 && end[0] instanceof ObObj && ((ObObj) end[0]).isMaxObj()) {
174-
return completeWorks;
175-
}
176-
177-
if (scanRangeColumns.size() != start.length) {
178-
throw new IllegalArgumentException("length of start key in range and scan range columns is not equal," +
179-
"the start key: " + start + ", the scan range columns: " + scanRangeColumns);
180-
}
181-
182-
Row startRow = new Row();
183-
Row endRow = new Row();
184-
for (int i = 0; i < scanRangeColumns.size(); i++) {
185-
startRow.add(scanRangeColumns.get(i), start[i]);
186-
endRow.add(scanRangeColumns.get(i), end[i]);
187-
}
188-
189-
// check whether partition key is Min or Max, should refactor after remove addRowkeyElement
190-
for (ObColumn partColumn : partColumns) {
191-
List<String> refColumns = partColumn.getRefColumnNames();
192-
for (String column : refColumns) {
193-
if (startRow.get(column) instanceof ObObj
194-
&& (((ObObj) startRow.get(column)).isMinObj() || ((ObObj) startRow.get(column))
195-
.isMaxObj())) {
196-
return completeWorks;
141+
Object endValue = endRow.get(curObRefColumnName);
142+
if (endValue == null) {
143+
throw new IllegalArgumentException("Please include all partition key in end range. Currently missing key: { " + curObRefColumnName + " }");
197144
}
198-
if (endRow.get(column) instanceof ObObj
199-
&& (((ObObj) endRow.get(column)).isMinObj() || ((ObObj) endRow.get(column)).isMaxObj())) {
145+
if (endValue instanceof ObObj
146+
&& (((ObObj) endValue).isMinObj() || ((ObObj) endValue).isMaxObj())) {
200147
return completeWorks;
201148
}
202149
}
@@ -213,8 +160,8 @@ public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, bool
213160

214161
if (startLongValue == null || endLongValue == null) {
215162
throw new NumberFormatException("can not parseToComparable start value ["
216-
+ startValue + "] or end value [" + endValue
217-
+ "] to long");
163+
+ startValue + "] or end value [" + endValue
164+
+ "] to long");
218165
}
219166
long startHashValue = startLongValue - (startInclusive ? 0 : -1);
220167
long endHashValue = endLongValue - (endInclusive ? 0 : 1);
@@ -231,7 +178,7 @@ public List<Long> getPartIds(List<String> scanRangeColumns, Object[] start, bool
231178
} catch (IllegalArgumentException e) {
232179
logger.error(LCD.convert("01-00002"), e);
233180
throw new IllegalArgumentException(
234-
"ObHashPartDesc get part id come across illegal params", e);
181+
"ObHashPartDesc get part id come across illegal params", e);
235182
}
236183
}
237184

@@ -247,26 +194,30 @@ public Long getRandomPartId() {
247194
* Get part id.
248195
*/
249196
@Override
250-
public Long getPartId(Object... rowKey) {
251-
List<Object[]> rowKeys = new ArrayList<Object[]>();
252-
rowKeys.add(rowKey);
253-
return this.getPartId(rowKeys, false);
197+
public Long getPartId(Object... row) {
198+
List<Object> rows = new ArrayList<Object>();
199+
rows.addAll(Arrays.asList(row));
200+
return this.getPartId(rows, false);
254201
}
255202

256203
/*
257204
* Get part id.
258205
*/
259206
@Override
260-
public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
207+
public Long getPartId(List<Object> rows, boolean consistency) {
261208

262-
if (rowKeys == null || rowKeys.size() == 0) {
263-
throw new IllegalArgumentException("invalid row keys :" + rowKeys);
209+
if (rows == null || rows.size() == 0) {
210+
throw new IllegalArgumentException("invalid row keys :" + rows);
264211
}
265212

266213
Long partId = null;
267214
try {
268-
for (Object[] rowKey : rowKeys) {
269-
List<Object> evalValues = evalRowKeyValues(rowKey);
215+
for (Object rowObj : rows) {
216+
if (!(rowObj instanceof Row)) {
217+
throw new ObTableException("invalid format of rowObj: " + rowObj);
218+
}
219+
Row row = (Row) rowObj;
220+
List<Object> evalValues = evalRowKeyValues(row);
270221
Object value = evalValues.get(0);// the partition type of hash has one param at most
271222
Long longValue = ObObjType.parseToLongOrNull(value);
272223

@@ -285,7 +236,7 @@ public Long getPartId(List<Object[]> rowKeys, boolean consistency) {
285236

286237
if (!partId.equals(currentPartId)) {
287238
throw new ObTablePartitionConsistentException(
288-
"across partition operation may cause consistent problem " + rowKeys);
239+
"across partition operation may cause consistent problem " + rows);
289240
}
290241
}
291242
} catch (IllegalArgumentException e) {

0 commit comments

Comments
 (0)