Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add single insert into test #209

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions databend-jdbc/src/test/java/com/databend/jdbc/TestBasicDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Properties;

import static org.testng.AssertJUnit.assertEquals;

@Test(timeOut = 10000)
public class TestBasicDriver {
private Connection createConnection()
Expand Down Expand Up @@ -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" +
Expand All @@ -93,14 +132,15 @@ public void testCreateUserFunction() throws SQLException {
Assert.assertEquals(r.getInt(1), 3);
} catch (SQLException throwables) {
throwables.printStackTrace();
throw throwables;
}
}

@Test
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" +
Expand All @@ -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" +
Expand All @@ -136,6 +176,7 @@ public void TestMergeinto() throws SQLException {
System.out.println(statement.getUpdateCount());
} catch (SQLException throwables) {
throwables.printStackTrace();
throw throwables;
}
}

Expand Down
Loading