Skip to content

Commit c946600

Browse files
committed
bugfix hbase mode using odp mode does not add row key; format code
1 parent babeabd commit c946600

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,25 @@ private TableEntry getOrFetchODPPartitionMeta(String tableName, boolean needRene
30403040
TableEntryKey key = new TableEntryKey(clusterName, tenantName, database,
30413041
tableName);
30423042
odpTableEntry.setTableEntryKey(key);
3043+
if (odpTableEntry.isPartitionTable()) {
3044+
switch (runningMode) {
3045+
case HBASE:
3046+
tableRowKeyElement.put(tableName, HBASE_ROW_KEY_ELEMENT);
3047+
odpTableEntry.setRowKeyElement(HBASE_ROW_KEY_ELEMENT);
3048+
break;
3049+
case NORMAL:
3050+
Map<String, Integer> rowKeyElement = tableRowKeyElement.get(tableName);
3051+
if (rowKeyElement != null) {
3052+
odpTableEntry.setRowKeyElement(rowKeyElement);
3053+
} else {
3054+
RUNTIME.error("partition table must has row key element key ="
3055+
+ key);
3056+
throw new ObTableEntryRefreshException(
3057+
"partition table must has row key element key ="
3058+
+ key);
3059+
}
3060+
}
3061+
}
30433062
ODPTableLocations.put(tableName, odpTableEntry);
30443063
done = true;
30453064
} catch (Exception ex) {

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

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,10 @@ public void testTwoLevelKeyPartition() throws Exception {
398398
statement.execute("insert into " + testTable
399399
+ "(c0, c1, c2, c3, c4, c5, c6) values (" + c0 + "," + c1 + ","
400400
+ c2 + ",'" + c3 + "','" + c4 + "','" + c5 + "'," + "'value')");
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)));
401+
Partition partition = client.getPartition(
402+
testTable,
403+
row(colVal("c0", c0), colVal("c1", c1), colVal("c2", c2), colVal("c3", c3),
404+
colVal("c4", c4), colVal("c5", c5)));
403405
Assert.assertNotNull(partition);
404406
System.out.println(partition.toString());
405407
// test scan range with partition
@@ -465,8 +467,7 @@ public void testTwoLevelRangePartition() throws Exception {
465467
statement.execute("insert into " + testTable + "(c1, c2, c3, c4, c5) values (" + c1
466468
+ "," + c2 + ",'" + c3 + "','" + c4 + "'," + "'value')");
467469
Partition partition = client.getPartition(testTable,
468-
row(colVal("c1", c1), colVal("c2", c2),
469-
colVal("c3", c3), colVal("c4", c4)));
470+
row(colVal("c1", c1), colVal("c2", c2), colVal("c3", c3), colVal("c4", c4)));
470471
Assert.assertNotNull(partition);
471472
System.out.println(partition.toString());
472473
// test scan range with partition
@@ -622,16 +623,17 @@ public void testODPRangeQuery() throws Exception {
622623
try {
623624
Connection connection = ObTableClientTestUtil.getConnection();
624625
Statement statement = connection.createStatement();
625-
statement.execute("CREATE TABLE IF NOT EXISTS `test_auto_increment_rowkey` ("
626-
+ "`c1` int auto_increment,"
627-
+ "`c2` int NOT NULL,"
628-
+ "`c3` int DEFAULT NULL,"
629-
+ "`c4` varchar(255) DEFAULT NULL,"
630-
+ "PRIMARY KEY(`c1`, `c2`)) partition by range columns(`c2`)"
631-
+ "(PARTITION p0 VALUES LESS THAN (100), PARTITION p1 VALUES LESS THAN (1000));");
626+
statement
627+
.execute("CREATE TABLE IF NOT EXISTS `test_auto_increment_rowkey` ("
628+
+ "`c1` int auto_increment,"
629+
+ "`c2` int NOT NULL,"
630+
+ "`c3` int DEFAULT NULL,"
631+
+ "`c4` varchar(255) DEFAULT NULL,"
632+
+ "PRIMARY KEY(`c1`, `c2`)) partition by range columns(`c2`)"
633+
+ "(PARTITION p0 VALUES LESS THAN (100), PARTITION p1 VALUES LESS THAN (1000));");
632634

633635
client.insert(TABLE_NAME, new Object[] { 0, 1 }, new String[] { "c3" },
634-
new Object[] { 1 });
636+
new Object[] { 1 });
635637

636638
TableQuery tableQuery = client.query(TABLE_NAME);
637639
tableQuery.select("c1", "c2", "c3");
@@ -646,7 +648,7 @@ public void testODPRangeQuery() throws Exception {
646648

647649
// test insert use user value
648650
client.insert(TABLE_NAME, new Object[] { 100, 1 }, new String[] { "c3" },
649-
new Object[] { 1 });
651+
new Object[] { 1 });
650652

651653
tableQuery.select("c1", "c2", "c3");
652654
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 100);
@@ -659,7 +661,7 @@ public void testODPRangeQuery() throws Exception {
659661

660662
// test insert sync global auto inc val
661663
client.insert(TABLE_NAME, new Object[] { 0, 1 }, new String[] { "c3" },
662-
new Object[] { 1 });
664+
new Object[] { 1 });
663665

664666
tableQuery.select("c1", "c2", "c3");
665667
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 101);
@@ -684,8 +686,8 @@ public void testODPRangeQuery() throws Exception {
684686
ObTableValueFilter filter_3 = compareVal(ObCompareOp.EQ, "c3", 1);
685687

686688
MutationResult updateResult = client.update(TABLE_NAME)
687-
.setRowKey(colVal("c1", 1), colVal("c2", 1)).setFilter(filter_3)
688-
.addMutateRow(row(colVal("c3", 5))).execute();
689+
.setRowKey(colVal("c1", 1), colVal("c2", 1)).setFilter(filter_3)
690+
.addMutateRow(row(colVal("c3", 5))).execute();
689691

690692
tableQuery.select("c1", "c2", "c3");
691693
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 1);
@@ -698,8 +700,8 @@ public void testODPRangeQuery() throws Exception {
698700

699701
// test replace not exist, insert
700702
MutationResult theResult = client.replace(TABLE_NAME)
701-
.setRowKey(colVal("c1", 0), colVal("c2", 1)).addMutateRow(row(colVal("c3", 2)))
702-
.execute();
703+
.setRowKey(colVal("c1", 0), colVal("c2", 1)).addMutateRow(row(colVal("c3", 2)))
704+
.execute();
703705

704706
tableQuery.select("c1", "c2", "c3");
705707
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 102);
@@ -712,7 +714,7 @@ public void testODPRangeQuery() throws Exception {
712714

713715
// test replace exist, replace
714716
theResult = client.replace(TABLE_NAME).setRowKey(colVal("c1", 101), colVal("c2", 1))
715-
.addMutateRow(row(colVal("c3", 20))).execute();
717+
.addMutateRow(row(colVal("c3", 20))).execute();
716718

717719
tableQuery.select("c1", "c2", "c3");
718720
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 101);
@@ -725,8 +727,8 @@ public void testODPRangeQuery() throws Exception {
725727

726728
// test insertup not exist, insert
727729
theResult = client.insertOrUpdate(TABLE_NAME)
728-
.setRowKey(colVal("c1", 0), colVal("c2", 1)).addMutateRow(row(colVal("c3", 5)))
729-
.execute();
730+
.setRowKey(colVal("c1", 0), colVal("c2", 1)).addMutateRow(row(colVal("c3", 5)))
731+
.execute();
730732

731733
tableQuery.select("c1", "c2", "c3");
732734
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 103);
@@ -739,8 +741,8 @@ public void testODPRangeQuery() throws Exception {
739741

740742
// test insertup exist, update
741743
theResult = client.insertOrUpdate(TABLE_NAME)
742-
.setRowKey(colVal("c1", 103), colVal("c2", 1)).addMutateRow(row(colVal("c3", 50)))
743-
.execute();
744+
.setRowKey(colVal("c1", 103), colVal("c2", 1)).addMutateRow(row(colVal("c3", 50)))
745+
.execute();
744746

745747
tableQuery.select("c1", "c2", "c3");
746748
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 103);
@@ -753,8 +755,8 @@ public void testODPRangeQuery() throws Exception {
753755

754756
// test insertup exist, update again
755757
theResult = client.insertOrUpdate(TABLE_NAME)
756-
.setRowKey(colVal("c1", 103), colVal("c2", 1)).addMutateRow(row(colVal("c3", 50)))
757-
.execute();
758+
.setRowKey(colVal("c1", 103), colVal("c2", 1)).addMutateRow(row(colVal("c3", 50)))
759+
.execute();
758760

759761
tableQuery.select("c1", "c2", "c3");
760762
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 103);
@@ -767,7 +769,7 @@ public void testODPRangeQuery() throws Exception {
767769

768770
// test increment not exist, insert
769771
value = client.increment(TABLE_NAME, new Object[] { 0, 1 }, new String[] { "c3" },
770-
new Object[] { 6 }, true);
772+
new Object[] { 6 }, true);
771773

772774
tableQuery.select("c1", "c2", "c3");
773775
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 104);
@@ -780,7 +782,7 @@ public void testODPRangeQuery() throws Exception {
780782

781783
// test increment exist, increment
782784
value = client.increment(TABLE_NAME, new Object[] { 104, 1 }, new String[] { "c3" },
783-
new Object[] { 6 }, true);
785+
new Object[] { 6 }, true);
784786

785787
tableQuery.select("c1", "c2", "c3");
786788
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 104);
@@ -794,15 +796,15 @@ public void testODPRangeQuery() throws Exception {
794796
// test illegal increment on auto increment column
795797
try {
796798
value = client.increment(TABLE_NAME, new Object[] { 104, 1 },
797-
new String[] { "c1" }, new Object[] { 1 }, true);
799+
new String[] { "c1" }, new Object[] { 1 }, true);
798800
} catch (ObTableException e) {
799801
assertNotNull(e);
800802
assertEquals(ResultCodes.OB_NOT_SUPPORTED.errorCode, e.getErrorCode());
801803
}
802804

803805
// test append not exist, insert
804806
Map<String, Object> res = client.append(TABLE_NAME, new Object[] { 0, 1 },
805-
new String[] { "c4" }, new Object[] { "a" }, true);
807+
new String[] { "c4" }, new Object[] { "a" }, true);
806808

807809
tableQuery.select("c1", "c2", "c3", "c4");
808810
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 105);
@@ -815,7 +817,7 @@ public void testODPRangeQuery() throws Exception {
815817

816818
// test append exist, append
817819
res = client.append(TABLE_NAME, new Object[] { 105, 1 }, new String[] { "c4" },
818-
new Object[] { "b" }, true);
820+
new Object[] { "b" }, true);
819821

820822
tableQuery.select("c1", "c2", "c3", "c4");
821823
filter = new ObTableValueFilter(ObCompareOp.EQ, "c1", 105);

0 commit comments

Comments
 (0)