Skip to content

Commit

Permalink
Add complex struct test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin committed Dec 11, 2024
1 parent b0f1178 commit 8cb6f62
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,44 @@ void shouldInsertAndSelectStruct() throws SQLException {
}
}

@Test
@Tag("v2")
void shouldInsertAndSelectComplexStruct() throws SQLException {
Car car1 = Car.builder().ts(new Timestamp(2)).d(new Date(3)).tags(new String[] { "fast", "sleek" }).build();

executeStatementFromFile("/statements/prepared-statement-struct/ddl.sql");
try (Connection connection = createConnection()) {

try (PreparedStatement statement = connection
.prepareStatement("INSERT INTO test_struct_helper(a, b) VALUES (?,?)")) {
statement.setArray(1, connection.createArrayOf("VARCHAR", car1.getTags()));
statement.setTimestamp(2, car1.getTs());
statement.executeUpdate();
}

setParam(connection, "advanced_mode", "true");
setParam(connection, "enable_row_selection", "true");
try (Statement statement = connection.createStatement()) {
statement.execute(
"INSERT INTO test_struct(id, s) SELECT 1, test_struct_helper FROM test_struct_helper");
}
try (Statement statement = connection.createStatement();
ResultSet rs = statement
.executeQuery("SELECT test_struct FROM test_struct")) {
rs.next();
assertEquals(FireboltDataType.STRUCT.name().toLowerCase()
+ "(id int, s struct(a array(text null), b timestamp null))",
rs.getMetaData().getColumnTypeName(1).toLowerCase());
String expectedJson = String.format(
"{\"id\":%d,\"s\":{\"a\":[\"%s\",\"%s\"],\"b\":\"%s\"}}", 1, car1.getTags()[0],
car1.getTags()[1], car1.getTs().toString());
assertEquals(expectedJson, rs.getString(1));
}
} finally {
executeStatementFromFile("/statements/prepared-statement-struct/cleanup.sql");
}
}

private QueryResult createExpectedResult(List<List<?>> expectedRows) {
return QueryResult.builder().databaseName(ConnectionInfo.getInstance().getDatabase())
.tableName("prepared_statement_test")
Expand Down Expand Up @@ -527,6 +565,7 @@ private static class Car {
Timestamp ts;
Date d;
URL url;
String[] tags;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS test_struct;
DROP TABLE IF EXISTS test_struct_helper;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SET advanced_mode=1;
SET enable_struct=1;
SET enable_create_table_v2=true;
SET enable_row_selection=true;
SET prevent_create_on_information_schema=true;
SET enable_create_table_with_struct_type=true;
DROP TABLE IF EXISTS test_struct;
DROP TABLE IF EXISTS test_struct_helper;
CREATE TABLE IF NOT EXISTS test_struct(id int not null, s struct(a array(text) not null, b datetime null) not null);
CREATE TABLE IF NOT EXISTS test_struct_helper(a array(text) not null, b datetime null);

0 comments on commit 8cb6f62

Please sign in to comment.