diff --git a/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java b/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java index 216603f0..8845d6ab 100644 --- a/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java +++ b/databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java @@ -10,6 +10,7 @@ import java.util.Properties; import static org.testng.AssertJUnit.assertEquals; + @Test(timeOut = 10000) public class TestBasicDriver { private Connection createConnection() @@ -68,7 +69,45 @@ public void testBasic() } @Test - public void testCreateUserFunction() throws SQLException { + public void TestInsertInto() throws SQLException { + try (Connection connection = createConnection()) { + DatabendStatement statement = (DatabendStatement) connection.createStatement(); + statement.execute("CREATE OR REPLACE TABLE test_basic_driver.target_table (\n" + + " ID INT,\n" + + " Name VARCHAR(50),\n" + + " Age INT,\n" + + " City VARCHAR(50)\n" + + ");"); + statement.execute("INSERT INTO test_basic_driver.target_table (ID, Name, Age, City)\n" + + "VALUES\n" + + " (1, 'Alice', 25, 'Toronto'),\n" + + " (2, 'Bob', 30, 'Vancouver'),\n" + + " (3, 'Carol', 28, 'Montreal');"); + statement.execute("CREATE OR REPLACE TABLE test_basic_driver.source_table (\n" + + " ID INT,\n" + + " Name VARCHAR(50),\n" + + " Age INT,\n" + + " City VARCHAR(50)\n" + + ");"); + statement.execute("INSERT INTO test_basic_driver.source_table (ID, Name, Age, City)\n" + + "VALUES\n" + + " (1, 'David', 27, 'Calgary'),\n" + + " (2, 'Emma', 29, 'Ottawa'),\n" + + " (4, 'Frank', 32, 'Edmonton');"); + statement.execute("INSERT INTO test_basic_driver.target_table (ID, Name, Age, City)\n" + + "SELECT * FROM test_basic_driver.source_table;"); + ResultSet r = statement.getResultSet(); + r.next(); + Assert.assertEquals(3, statement.getUpdateCount()); + System.out.println(statement.getUpdateCount()); + } catch (SQLException throwables) { + throwables.printStackTrace(); + throw throwables; + } + } + + @Test + public void testCreateUserFunction() throws SQLException { String s = "create or replace function add_plus(int,int)\n" + "returns int\n" + "language javascript\n" + @@ -93,6 +132,7 @@ public void testCreateUserFunction() throws SQLException { Assert.assertEquals(r.getInt(1), 3); } catch (SQLException throwables) { throwables.printStackTrace(); + throw throwables; } } @@ -100,7 +140,7 @@ public void testCreateUserFunction() throws SQLException { public void TestMergeinto() throws SQLException { try (Connection connection = createConnection()) { DatabendStatement statement = (DatabendStatement) connection.createStatement(); - statement.execute("CREATE TABLE IF NOT EXISTS test_basic_driver.target_table (\n" + + statement.execute("CREATE OR REPLACE TABLE test_basic_driver.target_table (\n" + " ID INT,\n" + " Name VARCHAR(50),\n" + " Age INT,\n" + @@ -111,7 +151,7 @@ public void TestMergeinto() throws SQLException { " (1, 'Alice', 25, 'Toronto'),\n" + " (2, 'Bob', 30, 'Vancouver'),\n" + " (3, 'Carol', 28, 'Montreal');"); - statement.execute("CREATE TABLE IF NOT EXISTS test_basic_driver.source_table (\n" + + statement.execute("CREATE OR REPLACE TABLE test_basic_driver.source_table (\n" + " ID INT,\n" + " Name VARCHAR(50),\n" + " Age INT,\n" + @@ -136,6 +176,7 @@ public void TestMergeinto() throws SQLException { System.out.println(statement.getUpdateCount()); } catch (SQLException throwables) { throwables.printStackTrace(); + throw throwables; } }