diff --git a/src/integrationTest/java/integration/tests/PreparedStatementTest.java b/src/integrationTest/java/integration/tests/PreparedStatementTest.java index 84f44423d..bae01c915 100644 --- a/src/integrationTest/java/integration/tests/PreparedStatementTest.java +++ b/src/integrationTest/java/integration/tests/PreparedStatementTest.java @@ -14,6 +14,7 @@ import lombok.Value; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -395,6 +396,33 @@ void shouldInsertAndSelectDateTime() throws SQLException { } + @Test + @Tag("v2") + void shouldInsertAndSelectGeography() throws SQLException { + + executeStatementFromFile("/statements/prepared-statement/ddl_2_0.sql"); + try (Connection connection = createConnection()) { + + try (PreparedStatement statement = connection + .prepareStatement("INSERT INTO prepared_statement_2_0_test (make, location) VALUES (?,?)")) { + statement.setString(1, "Ford"); + statement.setString(2, "POINT(1 1)"); + statement.executeUpdate(); + } + + try (Statement statement = connection.createStatement(); + ResultSet rs = statement + .executeQuery("SELECT location FROM prepared_statement_2_0_test")) { + rs.next(); + assertEquals(FireboltDataType.GEOGRAPHY.name().toLowerCase(), + rs.getMetaData().getColumnTypeName(1).toLowerCase()); + assertEquals("0101000020E6100000FEFFFFFFFFFFEF3F000000000000F03F", rs.getString(1)); + } + } finally { + executeStatementFromFile("/statements/prepared-statement/cleanup_2_0.sql"); + } + } + private QueryResult createExpectedResult(List> expectedRows) { return QueryResult.builder().databaseName(ConnectionInfo.getInstance().getDatabase()) .tableName("prepared_statement_test") diff --git a/src/integrationTest/resources/statements/prepared-statement/cleanup_2_0.sql b/src/integrationTest/resources/statements/prepared-statement/cleanup_2_0.sql new file mode 100644 index 000000000..3696d518b --- /dev/null +++ b/src/integrationTest/resources/statements/prepared-statement/cleanup_2_0.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS prepared_statement_2_0_test; \ No newline at end of file diff --git a/src/integrationTest/resources/statements/prepared-statement/ddl_2_0.sql b/src/integrationTest/resources/statements/prepared-statement/ddl_2_0.sql new file mode 100644 index 000000000..a81dc33b5 --- /dev/null +++ b/src/integrationTest/resources/statements/prepared-statement/ddl_2_0.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS prepared_statement_2_0_test; +CREATE +FACT TABLE IF NOT EXISTS prepared_statement_2_0_test ( + make STRING not null, + location GEOGRAPHY null +) +PRIMARY INDEX make; \ No newline at end of file diff --git a/src/main/java/com/firebolt/jdbc/type/FireboltDataType.java b/src/main/java/com/firebolt/jdbc/type/FireboltDataType.java index e1a9b6307..acad47600 100644 --- a/src/main/java/com/firebolt/jdbc/type/FireboltDataType.java +++ b/src/main/java/com/firebolt/jdbc/type/FireboltDataType.java @@ -40,7 +40,9 @@ public enum FireboltDataType { NUMERIC(Types.NUMERIC, FireboltDataTypeDisplayNames.NUMERIC, BaseType.NUMERIC, true, false, 38, 0, 37, false, "Decimal", "DEC", "NUMERIC"), ARRAY(Types.ARRAY, FireboltDataTypeDisplayNames.ARRAY, BaseType.ARRAY, false, true, 0, 0, 0, false,"Array"), TUPLE(Types.OTHER, FireboltDataTypeDisplayNames.TUPLE, BaseType.OBJECT, false, true, 0, 0, 0, false,"Tuple"), - BYTEA(Types.BINARY, FireboltDataTypeDisplayNames.BYTEA, BaseType.BYTEA, false, true, 0, 0, 0, false,"ByteA"); + BYTEA(Types.BINARY, FireboltDataTypeDisplayNames.BYTEA, BaseType.BYTEA, false, true, 0, 0, 0, false, "ByteA"), + GEOGRAPHY(Types.VARCHAR, FireboltDataTypeDisplayNames.GEOGRAPHY, BaseType.TEXT, false, false, 0, 0, 0, false, + "Geography"); private static final Map typeNameOrAliasToType; diff --git a/src/main/java/com/firebolt/jdbc/type/FireboltDataTypeDisplayNames.java b/src/main/java/com/firebolt/jdbc/type/FireboltDataTypeDisplayNames.java index a404d02bd..23e01b680 100644 --- a/src/main/java/com/firebolt/jdbc/type/FireboltDataTypeDisplayNames.java +++ b/src/main/java/com/firebolt/jdbc/type/FireboltDataTypeDisplayNames.java @@ -21,4 +21,5 @@ public class FireboltDataTypeDisplayNames { static final String ARRAY = "array"; static final String TUPLE = "tuple"; static final String BYTEA = "bytea"; + static final String GEOGRAPHY = "geography"; } \ No newline at end of file diff --git a/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java b/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java index 5d3c7e3e2..407a4e45a 100644 --- a/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java +++ b/src/test/java/com/firebolt/jdbc/resultset/FireboltResultSetTest.java @@ -1464,6 +1464,20 @@ void shouldReturnUrl() throws SQLException, MalformedURLException { assertNull(resultSet.getURL("url")); } + @Test + void shouldReturnGeography() throws SQLException { + inputStream = getInputStreamWithCommonResponseExample(); + resultSet = createResultSet(inputStream); + resultSet.next(); + String expectedValue = "0101000020E6100000FEFFFFFFFFFFEF3F000000000000F03F"; + assertEquals(expectedValue, resultSet.getObject(9)); + assertEquals(expectedValue, resultSet.getObject("location")); + assertEquals(expectedValue, resultSet.getString(9)); + assertEquals(expectedValue, resultSet.getString("location")); + // Returns native JDBC type + assertEquals(Types.VARCHAR, resultSet.getMetaData().getColumnType(9)); + } + @Test void shouldBeCaseInsensitive() throws SQLException { inputStream = getInputStreamWithCommonResponseExample(); diff --git a/src/test/resources/responses/firebolt-response-example b/src/test/resources/responses/firebolt-response-example index 5ae23519d..ba7e13461 100644 --- a/src/test/resources/responses/firebolt-response-example +++ b/src/test/resources/responses/firebolt-response-example @@ -1,4 +1,4 @@ -id arr name a_date is_online a_double an_integer url -int32 Array(Array(Array(String))) Nullable(String) Date Boolean Float32 Int64 Nullable(String) -1 [[['1','2'],['3','4']]] Taylor\'s Prime Steak House 2022-05-10 1 14.6 5 http://firebolt.io -2 [[['1','2'],['3','4']],[['5','6'],['7','8',NULL]]] \N 2022-05-10 0 \N \N \N \ No newline at end of file +id arr name a_date is_online a_double an_integer url location +int32 Array(Array(Array(String))) Nullable(String) Date Boolean Float32 Int64 Nullable(String) Geography +1 [[['1','2'],['3','4']]] Taylor\'s Prime Steak House 2022-05-10 1 14.6 5 http://firebolt.io 0101000020E6100000FEFFFFFFFFFFEF3F000000000000F03F +2 [[['1','2'],['3','4']],[['5','6'],['7','8',NULL]]] \N 2022-05-10 0 \N \N \N \N \ No newline at end of file