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

test: Struct with spaces #484

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void shouldInsertAndSelectComplexStruct() throws SQLException {
try (Connection connection = createConnection()) {

try (PreparedStatement statement = connection
.prepareStatement("INSERT INTO test_struct_helper(a, b) VALUES (?,?)")) {
.prepareStatement("INSERT INTO test_struct_helper(a, \"b column\") VALUES (?,?)")) {
statement.setArray(1, connection.createArrayOf("VARCHAR", car1.getTags()));
statement.setTimestamp(2, car1.getTs());
statement.executeUpdate();
Expand All @@ -483,11 +483,11 @@ void shouldInsertAndSelectComplexStruct() throws SQLException {
.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))",
+ "(id int, s struct(a array(text null), `b column` 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());
"{\"id\":%d,\"s\":{\"a\":[\"%s\",\"%s\"],\"b column\":\"%s\"}}", 1, car1.getTags()[0],
car1.getTags()[1], car1.getTs().toString());
assertEquals(expectedJson, rs.getString(1));
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ 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);
CREATE TABLE IF NOT EXISTS test_struct(id int not null, s struct(a array(text) not null, "b column" datetime null) not null);
CREATE TABLE IF NOT EXISTS test_struct_helper(a array(text) not null, "b column" datetime null);
Original file line number Diff line number Diff line change
Expand Up @@ -1490,8 +1490,8 @@ void shouldReturnStruct() throws SQLException {
assertEquals("{\"a\":\"1\"}", resultSet.getObject("a_struct"));
assertEquals("{\"a\":[1,2,3]}", resultSet.getObject(5));
assertEquals("{\"a\":[1,2,3]}", resultSet.getObject("array_struct"));
assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\",\"c\":\"3\"}}", resultSet.getObject(6));
assertEquals("{\"x\":\"2\",\"a\":{\"b\":\"1\",\"c\":\"3\"}}", resultSet.getObject("nested_struct"));
assertEquals("{\"x\":\"2\",\"a\":{\"b col\":\"1\",\"c\":\"3\"}}", resultSet.getObject(6));
assertEquals("{\"x\":\"2\",\"a\":{\"b col\":\"1\",\"c\":\"3\"}}", resultSet.getObject("nested_struct"));
// Returns native JDBC type
for (int i = 2; i <= 6; i++) {
assertEquals(Types.VARCHAR, resultSet.getMetaData().getColumnType(i));
Expand All @@ -1501,7 +1501,7 @@ void shouldReturnStruct() throws SQLException {
assertEquals("STRUCT(A INT)", resultSet.getMetaData().getColumnTypeName(3));
assertEquals("STRUCT(A INT)", resultSet.getMetaData().getColumnTypeName(4));
assertEquals("STRUCT(A ARRAY(INT))", resultSet.getMetaData().getColumnTypeName(5));
assertEquals("STRUCT(X INT, A STRUCT(B INT, C INT))", resultSet.getMetaData().getColumnTypeName(6));
assertEquals("STRUCT(X INT, A STRUCT(`B COL` INT, C INT))", resultSet.getMetaData().getColumnTypeName(6));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id null_struct an_empty_struct a_struct array_struct nested_struct
Int64 struct(a int null) struct(a int) struct(a int) struct(a array(int)) struct(x int, a struct(b int, c int))
1 {"a":null} {"a":"1"} {"a":[1,2,3]} {"x":"2","a":{"b":"1","c":"3"}}
2 {"a":null} {"a":"2"} {"a":[1,2,3]} {"x":"2","a":{"b":"1","c":"3"}}
Int64 struct(a int null) struct(a int) struct(a int) struct(a array(int)) struct(x int, a struct(`b col` int, c int))
1 {"a":null} {"a":"1"} {"a":[1,2,3]} {"x":"2","a":{"b col":"1","c":"3"}}
2 {"a":null} {"a":"2"} {"a":[1,2,3]} {"x":"2","a":{"b col":"1","c":"3"}}
Loading