@@ -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