You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sd...@apache.org on 2022/03/05 12:47:19 UTC
[ignite-3] 02/02: IGNITE-15655 remove wrong changes
This is an automated email from the ASF dual-hosted git repository.
sdanilov pushed a commit to branch ignite-15655-new-network
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit c754fcd31edb5aa78e4e965887fce0c6416d900e
Author: Mirza Aliev <al...@gmail.com>
AuthorDate: Tue Feb 15 11:48:26 2022 +0300
IGNITE-15655 remove wrong changes
---
.../app/jdbc/ItJdbcUpdateStatementSelfTest.java | 110 +++++++++++++++++----
1 file changed, 90 insertions(+), 20 deletions(-)
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcUpdateStatementSelfTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcUpdateStatementSelfTest.java
index 1a5b08e..99e5d56 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcUpdateStatementSelfTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/jdbc/ItJdbcUpdateStatementSelfTest.java
@@ -18,52 +18,122 @@
package org.apache.ignite.internal.runner.app.jdbc;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.function.Consumer;
import org.apache.ignite.table.KeyValueView;
-import org.apache.ignite.table.Tuple;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Update statement self test.
*/
-
-public class ItJdbcUpdateStatementSelfTest extends ItJdbcAbstractStatementSelfTest {
+public class ItJdbcUpdateStatementSelfTest extends AbstractJdbcSelfTest {
/**
* Execute test.
*
* @throws SQLException If failed.
*/
@Test
- public void testExecute() throws SQLException {
- stmt.execute("update PUBLIC.PERSON set firstName = 'Jack' where substring(SID, 2, 1)::int % 2 = 0");
+ public void testExecuteUpdateMultipleColumnsUpdate() throws Exception {
+ final String q1 = "CREATE TABLE usertable (\n"
+ + " ycsb_key1 int NOT NULL,\n"
+ + " ycsb_key2 varchar(3) NOT NULL,\n"
+ + " field1 varchar(100),\n"
+ + " field2 varchar(100),\n"
+ + " field3 varchar(100),\n"
+ + " field4 varchar(100),\n"
+ + " field5 varchar(100),\n"
+ + " field6 varchar(100),\n"
+ + " field7 varchar(100),\n"
+ + " field8 varchar(100),\n"
+ + " field9 varchar(100),\n"
+ + " field10 varchar(100),\n"
+ + " PRIMARY KEY(ycsb_key1, ycsb_key2)\n"
+ + ");";
+
+ final String q2 = "INSERT INTO usertable values(1, 'key', 'a1','a2','a3','a4','a5','a6','a7','a8','a9','a10');";
+
+ final String q3 = "UPDATE usertable SET FIELD1='b1',FIELD2='b2',FIELD3='b3',FIELD4='b4',FIELD5='b5',"
+ + "FIELD6='b6',FIELD7='b7',FIELD8='b8',FIELD9='b9',FIELD10='b10' WHERE YCSB_KEY1=1";
+
+ final String q4 = "DROP TABLE usertable;";
+
+ assertEquals(0, stmt.executeUpdate(q1));
+ assertEquals(1, stmt.executeUpdate(q2));
+ assertEquals(1, stmt.executeUpdate(q3));
- KeyValueView<Tuple, Tuple> person = clusterNodes.get(0).tables()
- .table("PUBLIC.PERSON").keyValueView();
+ stmt.executeQuery("SELECT * FROM usertable WHERE YCSB_KEY1=1;");
- assertEquals("John", person.get(null, Tuple.create().set("ID", 1)).stringValue("FIRSTNAME"));
- assertEquals("Jack", person.get(null, Tuple.create().set("ID", 2)).stringValue("FIRSTNAME"));
- assertEquals("Mike", person.get(null, Tuple.create().set("ID", 3)).stringValue("FIRSTNAME"));
+ ResultSet resultSet = stmt.getResultSet();
+
+ assertTrue(resultSet.next());
+
+ for (int i = 1; i < 11; i++) {
+ assertEquals("b" + i, resultSet.getString(i + 2));
+ }
+
+ assertEquals(0, stmt.executeUpdate(q4));
}
/**
- * Execute update test.
+ * Execute test.
*
* @throws SQLException If failed.
*/
@Test
- public void testExecuteUpdate() throws SQLException {
- int i = stmt.executeUpdate(
- "update PUBLIC.PERSON set firstName = 'Jack' where substring(SID, 2, 1)::int % 2 = 0");
+ public void testExecuteAndExecuteUpdate() throws SQLException {
+ testExecute((String updateQuery) -> {
+ try {
+ stmt.executeUpdate(updateQuery);
+ } catch (SQLException e) {
+ fail(e);
+ }
+ });
- assertEquals(1, i);
+ testExecute((String updateQuery) -> {
+ try {
+ stmt.execute(updateQuery);
+ } catch (SQLException e) {
+ fail(e);
+ }
+ });
+ }
+
+ private void testExecute(Consumer<String> updateFunction) throws SQLException {
+ final String createSql = "CREATE TABLE public.person(id INTEGER PRIMARY KEY, sid VARCHAR,"
+ + " firstname VARCHAR NOT NULL, lastname VARCHAR NOT NULL, age INTEGER NOT NULL)";
+
+ final String insertSql = "INSERT INTO public.person(sid, id, firstname, lastname, age) VALUES "
+ + "('p1', 1, 'John', 'White', 25), "
+ + "('p2', 2, 'Joe', 'Black', 35), "
+ + "('p3', 3, 'Mike', 'Green', 40)";
+
+ final String updateSql = "update PUBLIC.PERSON set firstName = 'Jack' where substring(SID, 2, 1)::int % 2 = 0";
+
+ final String dropSql = "DROP TABLE PUBLIC.PERSON;";
- KeyValueView<Tuple, Tuple> person = clusterNodes.get(0).tables()
- .table("PUBLIC.PERSON").keyValueView();
+ updateFunction.accept(createSql);
+ updateFunction.accept(insertSql);
+ updateFunction.accept(updateSql);
+
+ KeyValueView<Integer, Person> person = clusterNodes.get(0).tables()
+ .table("PUBLIC.PERSON").keyValueView(Integer.class, Person.class);
+
+ assertEquals("John", person.get(null, 1).firstname);
+ assertEquals("Jack", person.get(null, 2).firstname);
+ assertEquals("Mike", person.get(null, 3).firstname);
+
+ updateFunction.accept(dropSql);
+ }
- assertEquals("John", person.get(null, Tuple.create().set("ID", 1)).stringValue("FIRSTNAME"));
- assertEquals("Jack", person.get(null, Tuple.create().set("ID", 2)).stringValue("FIRSTNAME"));
- assertEquals("Mike", person.get(null, Tuple.create().set("ID", 3)).stringValue("FIRSTNAME"));
+ private static class Person {
+ public int age;
+ public String sid;
+ public String firstname;
+ public String lastname;
}
}