Skip to content

Commit ef65f99

Browse files
committed
remove getPartition with only row key values
1 parent 3cfeaae commit ef65f99

File tree

3 files changed

+69
-36
lines changed

3 files changed

+69
-36
lines changed

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

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,33 +2903,6 @@ public BatchOperation batchOperation(String tableName) {
29032903
return new BatchOperation(this, tableName);
29042904
}
29052905

2906-
/**
2907-
* get partition information and host information by row key in object list
2908-
* @param tableName table name
2909-
* @param rowKey row key values which want to query
2910-
* @return Partition information
2911-
* @throws Exception Exception
2912-
*/
2913-
public Partition getPartition(String tableName, Object[] rowKey) throws Exception {
2914-
if (rowKey == null) {
2915-
throw new Exception("The input row key value can not be empty");
2916-
}
2917-
Map<String, Integer> rowKeyElements = getRowKeyElement(tableName);
2918-
if (rowKeyElements == null) {
2919-
throw new Exception(
2920-
"Please use addRowKeyElement before just use row key values for table" + tableName);
2921-
}
2922-
if (rowKeyElements.size() < rowKey.length) {
2923-
throw new Exception("The table row keys should not be less than input row keys");
2924-
}
2925-
Row row = new Row();
2926-
String[] rowKeyNames = rowKeyElements.keySet().toArray(new String[0]);
2927-
for (int i = 0; i < rowKey.length; ++i) {
2928-
row.add(rowKeyNames[i], rowKey[i]);
2929-
}
2930-
return getSinglePartitionInternal(tableName, row);
2931-
}
2932-
29332906
/**
29342907
* get partition information and host information by row key in Row
29352908
* @param tableName table name

src/test/java/com/alipay/oceanbase/rpc/ODPGetPartitionMetaTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ PRIMARY KEY (`c0`, `c1`, `c2`, `c3`, `c4`, `c5`)
382382
public void testTwoLevelKeyPartition() throws Exception {
383383
client.setRunningMode(ObTableClient.RunningMode.NORMAL);
384384
String testTable = "testPartitionKeyComplex";
385-
client.addRowKeyElement(testTable, new String[] { "c0", "c1", "c2", "c3", "c4", "c5" });
386385
try {
387386
cleanTable(testTable);
388387
Connection connection = ObTableClientTestUtil.getConnection();
@@ -399,8 +398,8 @@ public void testTwoLevelKeyPartition() throws Exception {
399398
statement.execute("insert into " + testTable
400399
+ "(c0, c1, c2, c3, c4, c5, c6) values (" + c0 + "," + c1 + ","
401400
+ c2 + ",'" + c3 + "','" + c4 + "','" + c5 + "'," + "'value')");
402-
Partition partition = client.getPartition(testTable, new Object[] { c0, c1, c2, c3,
403-
c4, c5 });
401+
Partition partition = client.getPartition(testTable, row(colVal("c0", c0), colVal("c1", c1), colVal("c2", c2),
402+
colVal("c3", c3), colVal("c4", c4), colVal("c5", c5)));
404403
Assert.assertNotNull(partition);
405404
System.out.println(partition.toString());
406405
// test scan range with partition
@@ -466,7 +465,8 @@ public void testTwoLevelRangePartition() throws Exception {
466465
statement.execute("insert into " + testTable + "(c1, c2, c3, c4, c5) values (" + c1
467466
+ "," + c2 + ",'" + c3 + "','" + c4 + "'," + "'value')");
468467
Partition partition = client.getPartition(testTable,
469-
new Object[] { c1, c2, c3, c4 });
468+
row(colVal("c1", c1), colVal("c2", c2),
469+
colVal("c3", c3), colVal("c4", c4)));
470470
Assert.assertNotNull(partition);
471471
System.out.println(partition.toString());
472472
// test scan range with partition

src/test/java/com/alipay/oceanbase/rpc/ObGetPartitionTest.java

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ public void testGetPartitionInBatchOperation() throws Exception {
278278

279279
@Test
280280
public void testGetPartitionWithRowKeyValues() throws Exception {
281-
client.addRowKeyElement(TABLE_NAME, new String[] { "c1", "c2" });
282281
Object values[][] = { { 1L, "c2_val", "c3_val", 100L }, { 400L, "c2_val", "c3_val", 100L },
283282
{ 1001L, "c2_val", "c3_val", 100L } };
284283
int rowCnt = values.length;
@@ -298,10 +297,10 @@ public void testGetPartitionWithRowKeyValues() throws Exception {
298297
System.out.println(partition.toString());
299298
}
300299

301-
Partition partition = client.getPartition(TABLE_NAME, new Object[] { 1L, "c2_val" });
300+
Partition partition = client.getPartition(TABLE_NAME, row(colVal("c1", 1L), colVal("c2", "c2_val")));
302301
Assert.assertNotNull(partition.getPartitionId());
303302
// test get partition with partition key
304-
Partition partition_prefix = client.getPartition(TABLE_NAME, new Object[] { 1L });
303+
Partition partition_prefix = client.getPartition(TABLE_NAME, row(colVal("c1", 1L)));
305304
Assert.assertEquals(partition.getPartitionId(), partition_prefix.getPartitionId());
306305

307306
} catch (Exception e) {
@@ -493,8 +492,8 @@ public void testWithTwoLevelPartitionWithScan() throws Exception {
493492
statement.execute("insert into " + testTable
494493
+ "(c0, c1, c2, c3, c4, c5, c6) values (" + c0 + "," + c1 + ","
495494
+ c2 + ",'" + c3 + "','" + c4 + "','" + c5 + "'," + "'value')");
496-
Partition partition = client.getPartition(testTable, new Object[] { c0, c1, c2, c3,
497-
c4, c5 });
495+
Partition partition = client.getPartition(testTable, row(colVal("c0", c0), colVal("c1", c1), colVal("c2", c2),
496+
colVal("c3", c3), colVal("c4", c4), colVal("c5", c5)));
498497
System.out.println(partition.toString());
499498
QueryResultSet result = client.query(testTable)
500499
.addScanRange(partition.start(), partition.end()).execute();
@@ -620,4 +619,65 @@ public void testConcurrentGetPartition() throws Exception {
620619
}
621620
}
622621
}
622+
623+
/*
624+
* CREATE TABLE IF NOT EXISTS `testSubStrKey` (
625+
`K` varbinary(1024),
626+
`Q` varbinary(256),
627+
`T` bigint,
628+
`V` varbinary(1024),
629+
K_PREFIX varbinary(1024) generated always as (substring(`K`, 1, 4)),
630+
PRIMARY KEY(`K`, `Q`, `T`)
631+
) partition by key(K_PREFIX) partitions 15;
632+
* */
633+
@Test
634+
public void testSubstrInOldBatch() throws Exception {
635+
String table_name = "testSubStrKey";
636+
BatchOperation batchOperation = client.batchOperation(table_name);
637+
client.addRowKeyElement("testSubStrKey", new String[] { "K", "Q", "T" });
638+
long timeStamp = System.currentTimeMillis();
639+
Object values[][] = { { "K_val1", "Q_val1", timeStamp, "V_val1" },
640+
{ "K_val2", "Q_val2", timeStamp, "V_val2" },
641+
{ "K_val3", "Q_val3", timeStamp, "V_val3" },
642+
{ "K_val4", "Q_val4", timeStamp, "V_val4" },
643+
{ "K_val5", "Q_val5", timeStamp, "V_val5" },
644+
{ "K_val6", "Q_val6", timeStamp, "V_val6" },
645+
{ "K_val1", "Q_val2", timeStamp, "V_val1" } };
646+
int rowCnt = values.length;
647+
try {
648+
// batch insert
649+
for (int i = 0; i < rowCnt; i++) {
650+
Object[] curRow = values[i];
651+
InsertOrUpdate insertOrUpdate = new InsertOrUpdate();
652+
insertOrUpdate.setRowKey(row(colVal("K", curRow[0]), colVal("Q", curRow[1]),
653+
colVal("T", curRow[2])));
654+
insertOrUpdate.addMutateRow(row(colVal("V", curRow[3])));
655+
batchOperation.addOperation(insertOrUpdate);
656+
}
657+
client.insert(table_name, new Object[] { "K_val1", "Q_val1", timeStamp }, new String[] { "V" }, new Object[] { "V_val1".getBytes() });
658+
client.insert(table_name, new Object[] { "K_val2", "Q_val2", timeStamp }, new String[] { "V" }, new Object[] { "V_val2".getBytes() });
659+
660+
TableBatchOps tableBatchOps = client.batch(table_name);
661+
tableBatchOps
662+
.delete(new Object[] { "K_val1", "Q_val1", timeStamp });
663+
tableBatchOps.insert(
664+
new Object[] { "K_val3", "Q_val3", timeStamp },
665+
new String[] { "V" }, new Object[] { "V_val3".getBytes() });
666+
tableBatchOps.replace(
667+
new Object[] { "K_val2", "Q_val2", timeStamp },
668+
new String[] { "V" }, new Object[] { "V_value2".getBytes() });
669+
List<Object> batchResult = tableBatchOps.execute();
670+
Assert.assertEquals(3, batchResult.size());
671+
Assert.assertEquals(1L, batchResult.get(0));
672+
Assert.assertEquals(1L, batchResult.get(1));
673+
Assert.assertEquals(2L, batchResult.get(2));
674+
675+
676+
} catch (Exception e) {
677+
e.printStackTrace();
678+
Assert.assertTrue(false);
679+
} finally {
680+
cleanTable(table_name);
681+
}
682+
}
623683
}

0 commit comments

Comments
 (0)