|
5 | 5 | import com.alipay.oceanbase.rpc.mutation.result.BatchOperationResult; |
6 | 6 | import com.alipay.oceanbase.rpc.mutation.result.MutationResult; |
7 | 7 | import com.alipay.oceanbase.rpc.protocol.payload.ResultCodes; |
8 | | -import com.alipay.oceanbase.rpc.protocol.payload.impl.execute.query.ObTableQuery; |
9 | 8 | import com.alipay.oceanbase.rpc.stream.QueryResultSet; |
10 | | -import com.alipay.oceanbase.rpc.table.ObTable; |
11 | | -import com.alipay.oceanbase.rpc.table.api.TableBatchOps; |
12 | 9 | import com.alipay.oceanbase.rpc.table.api.TableQuery; |
13 | 10 | import com.alipay.oceanbase.rpc.util.ObTableClientTestUtil; |
14 | | -import com.google.protobuf.MapEntry; |
15 | 11 | import org.junit.After; |
16 | 12 | import org.junit.Assert; |
17 | 13 | import org.junit.Before; |
18 | 14 | import org.junit.Test; |
19 | 15 |
|
20 | | -import java.nio.ByteBuffer; |
21 | 16 | import java.sql.Connection; |
22 | 17 | import java.sql.SQLException; |
23 | 18 | import java.sql.Statement; |
24 | 19 | import java.sql.Timestamp; |
25 | | -import java.util.List; |
26 | 20 | import java.util.Locale; |
27 | 21 | import java.util.Map; |
28 | 22 |
|
@@ -596,211 +590,6 @@ public void testFTSQueryWithTTL() throws Exception { |
596 | 590 | } |
597 | 591 | } |
598 | 592 |
|
599 | | - @Test |
600 | | - public void testIncrment() throws Exception { |
601 | | - try { |
602 | | - // increment row not exist |
603 | | - int id = 9; |
604 | | - |
605 | | - MutationResult res = client.increment(partTableName).setRowKey(colVal(idCol, id)) |
606 | | - .addMutateRow(row(colVal(c2Col, 1))) |
607 | | - .execute(); |
608 | | - Assert.assertEquals(1, res.getAffectedRows()); |
609 | | - |
610 | | - Map<String, Object> getRes = client.get(partTableName, new Object[] { id }, null); |
611 | | - Assert.assertEquals(3, getRes.size()); |
612 | | - Assert.assertEquals(id, getRes.get(idCol)); |
613 | | - Assert.assertEquals(1, getRes.get(c2Col)); |
614 | | - Assert.assertEquals(null, getRes.get(txtCol)); |
615 | | - |
616 | | - res = client.increment(partTableName).setRowKey(colVal(idCol, id)) |
617 | | - .addMutateRow(row(colVal(c2Col, 1))) |
618 | | - .execute(); |
619 | | - Assert.assertEquals(1, res.getAffectedRows()); |
620 | | - |
621 | | - getRes = client.get(partTableName, new Object[] { id }, null); |
622 | | - Assert.assertEquals(3, getRes.size()); |
623 | | - Assert.assertEquals(id, getRes.get(idCol)); |
624 | | - Assert.assertEquals(2, getRes.get(c2Col)); |
625 | | - Assert.assertEquals(null, getRes.get(txtCol)); |
626 | | - } catch(Exception e) { |
627 | | - e.printStackTrace(); |
628 | | - Assert.fail(); |
629 | | - } finally { |
630 | | - executeSQL(truncatePartTableSQL); |
631 | | - } |
632 | | - } |
633 | | - |
634 | | - @Test |
635 | | - public void testAppend() throws Exception { |
636 | | - try { |
637 | | - // append row not exist |
638 | | - int id = 10; |
639 | | - String txt1 = "We enjoyed a peaceful walk."; |
640 | | - MutationResult res = client.append(partTableName).setRowKey(colVal(idCol, id)) |
641 | | - .addMutateRow(row(colVal(txtCol, txt1))) |
642 | | - .execute(); |
643 | | - Assert.assertEquals(1, res.getAffectedRows()); |
644 | | - |
645 | | - Map<String, Object> getRes = client.get(partTableName, new Object[] { id }, null); |
646 | | - Assert.assertEquals(3, getRes.size()); |
647 | | - Assert.assertEquals(id, getRes.get(idCol)); |
648 | | - Assert.assertEquals(null, getRes.get(c2Col)); |
649 | | - Assert.assertEquals(txt1, getRes.get(txtCol)); |
650 | | - |
651 | | - String txt2 = "Can you pass me the salt, please?"; |
652 | | - res = client.append(partTableName).setRowKey(colVal(idCol, id)) |
653 | | - .addMutateRow(row(colVal(txtCol, txt2))) |
654 | | - .execute(); |
655 | | - Assert.assertEquals(1, res.getAffectedRows()); |
656 | | - |
657 | | - getRes = client.get(partTableName, new Object[] { id }, null); |
658 | | - Assert.assertEquals(3, getRes.size()); |
659 | | - Assert.assertEquals(id, getRes.get(idCol)); |
660 | | - Assert.assertEquals(null, getRes.get(c2Col)); |
661 | | - Assert.assertEquals(txt1+txt2, getRes.get(txtCol)); |
662 | | - } catch(Exception e) { |
663 | | - e.printStackTrace(); |
664 | | - Assert.fail(); |
665 | | - } finally { |
666 | | - executeSQL(truncatePartTableSQL); |
667 | | - } |
668 | | - } |
669 | | - |
670 | | - private void loadData(String tableName) throws Exception { |
671 | | - // load data |
672 | | - client.insert(tableName).setRowKey(colVal(idCol, 1)) |
673 | | - .addMutateRow(row(colVal(c2Col, 1), colVal(txtCol, "hello world"))) |
674 | | - .execute(); |
675 | | - client.insert(tableName).setRowKey(colVal(idCol, 2)) |
676 | | - .addMutateRow(row(colVal(c2Col, 2), colVal(txtCol, "OceanBase Database is a native, enterprise-level distributed database developed independently by the OceanBase team"))) |
677 | | - .execute(); |
678 | | - client.insert(tableName).setRowKey(colVal(idCol, 3)) |
679 | | - .addMutateRow(row(colVal(c2Col, 3), colVal(txtCol, "Learn about SQL and database administration in oceanBase"))) |
680 | | - .execute(); |
681 | | - client.insert(tableName).setRowKey(colVal(idCol, 4)) |
682 | | - .addMutateRow(row(colVal(c2Col, 4), colVal(txtCol, "Master the art of full text searching"))) |
683 | | - .execute(); |
684 | | - } |
685 | | - |
686 | | - @Test |
687 | | - public void testFTSQuery() throws Exception { |
688 | | - try { |
689 | | - executeSQL(truncatePartTableSQL); |
690 | | - client.addRowKeyElement(partTableName, new String[] {"id"}); |
691 | | - //load data |
692 | | - loadData(partTableName); |
693 | | - //sync query |
694 | | - QueryResultSet resultSet = client.query(partTableName) |
695 | | - .setSearchText("oceanbase") |
696 | | - .indexName("full_idx1_tbl1") |
697 | | - .execute(); |
698 | | - int count = 0; |
699 | | - while(resultSet.next()) { |
700 | | - count++; |
701 | | - Map<String, Object> row = resultSet.getRow(); |
702 | | - Assert.assertEquals(3, row.size()); |
703 | | - int id = (int) row.get("id"); |
704 | | - Assert.assertEquals(id, row.get("c2")); |
705 | | - Assert.assertTrue(((String)row.get("txt")).toLowerCase(Locale.ROOT).contains("oceanbase")); |
706 | | - } |
707 | | - Assert.assertTrue(2 == count); |
708 | | - |
709 | | - // async query |
710 | | - QueryResultSet asyncResultSet = client.query(partTableName) |
711 | | - .indexName("full_idx1_tbl1") |
712 | | - .setSearchText("oceanbase") |
713 | | - .asyncExecute(); |
714 | | - count = 0; |
715 | | - while(asyncResultSet.next()) { |
716 | | - count++; |
717 | | - Map<String, Object> row = asyncResultSet.getRow(); |
718 | | - Assert.assertEquals(3, row.size()); |
719 | | - int id = (int) row.get("id"); |
720 | | - Assert.assertEquals(id, row.get("c2")); |
721 | | - Assert.assertTrue(((String)row.get("txt")).toLowerCase(Locale.ROOT).contains("oceanbase")); |
722 | | - } |
723 | | - Assert.assertTrue(2 == count); |
724 | | - } catch (Exception e) { |
725 | | - e.printStackTrace(); |
726 | | - Assert.fail(); |
727 | | - } finally { |
728 | | - executeSQL(truncatePartTableSQL); |
729 | | - } |
730 | | - } |
731 | | - |
732 | | - private void loadDataWithTTL() throws Exception { |
733 | | - // load data |
734 | | - Timestamp curTs = new Timestamp(System.currentTimeMillis()); |
735 | | - Timestamp expireTs = new Timestamp(System.currentTimeMillis() - 1000000); |
736 | | - client.insert(ttlTableName).setRowKey(colVal(idCol, 1)) |
737 | | - .addMutateRow(row(colVal(c2Col, 1), |
738 | | - colVal(expireTsCol, curTs), |
739 | | - colVal(txtCol, "Hello World"))) |
740 | | - .execute(); |
741 | | - client.insert(ttlTableName).setRowKey(colVal(idCol, 2)) |
742 | | - .addMutateRow(row(colVal(c2Col, 2), |
743 | | - colVal(expireTsCol, curTs), |
744 | | - colVal(txtCol, "OceanBase Database is a native, enterprise-level distributed database developed independently by the OceanBase team"))) |
745 | | - .execute(); |
746 | | - client.insert(ttlTableName).setRowKey(colVal(idCol, 3)) |
747 | | - .addMutateRow(row(colVal(c2Col, 3), |
748 | | - colVal(expireTsCol, expireTs), |
749 | | - colVal(txtCol, "Learn about SQL and database administration in oceanBase"))) |
750 | | - .execute(); |
751 | | - client.insert(ttlTableName).setRowKey(colVal(idCol, 4)) |
752 | | - .addMutateRow(row(colVal(c2Col, 4), |
753 | | - colVal(expireTsCol, expireTs), |
754 | | - colVal(txtCol, "Master the art of full text searching"))) |
755 | | - .execute(); |
756 | | - } |
757 | | - |
758 | | - @Test |
759 | | - public void testFTSQueryWithTTL() throws Exception { |
760 | | - try { |
761 | | - executeSQL(truncateTTLTableSQL); |
762 | | - client.addRowKeyElement(ttlTableName, new String[]{"id"}); |
763 | | - //load data |
764 | | - loadDataWithTTL(); |
765 | | - //sync query |
766 | | - QueryResultSet resultSet = client.query(ttlTableName) |
767 | | - .setSearchText("oceanbase") |
768 | | - .indexName("full_idx1_tbl1") |
769 | | - .execute(); |
770 | | - int count = 0; |
771 | | - while(resultSet.next()) { |
772 | | - count++; |
773 | | - Map<String, Object> row = resultSet.getRow(); |
774 | | - Assert.assertEquals(4, row.size()); |
775 | | - int id = (int) row.get("id"); |
776 | | - Assert.assertEquals(id, row.get("c2")); |
777 | | - Assert.assertTrue(((String)row.get("txt")).toLowerCase(Locale.ROOT).contains("oceanbase")); |
778 | | - } |
779 | | - Assert.assertTrue(1 == count); |
780 | | - |
781 | | - // async query |
782 | | - QueryResultSet asyncResultSet = client.query(ttlTableName) |
783 | | - .indexName("full_idx1_tbl1") |
784 | | - .setSearchText("oceanbase") |
785 | | - .asyncExecute(); |
786 | | - count = 0; |
787 | | - while(asyncResultSet.next()) { |
788 | | - count++; |
789 | | - Map<String, Object> row = asyncResultSet.getRow(); |
790 | | - Assert.assertEquals(4, row.size()); |
791 | | - int id = (int) row.get("id"); |
792 | | - Assert.assertEquals(id, row.get("c2")); |
793 | | - Assert.assertTrue(((String)row.get("txt")).toLowerCase(Locale.ROOT).contains("oceanbase")); |
794 | | - } |
795 | | - Assert.assertTrue(1 == count); |
796 | | - } catch (Exception e) { |
797 | | - e.printStackTrace(); |
798 | | - Assert.fail(); |
799 | | - } finally { |
800 | | - executeSQL(truncateTTLTableSQL); |
801 | | - } |
802 | | - } |
803 | | - |
804 | 593 | private void executeSQL(String createSQL) throws SQLException { |
805 | 594 | Connection connection = ObTableClientTestUtil.getConnection(); |
806 | 595 | Statement statement = connection.createStatement(); |
|
0 commit comments