Skip to content

Commit

Permalink
feat(FIR-38074): add Geography type support (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptiurin authored Dec 3, 2024
1 parent 04a821d commit 96c6b3c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<List<?>> expectedRows) {
return QueryResult.builder().databaseName(ConnectionInfo.getInstance().getDatabase())
.tableName("prepared_statement_test")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS prepared_statement_2_0_test;
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion src/main/java/com/firebolt/jdbc/type/FireboltDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, FireboltDataType> typeNameOrAliasToType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/test/resources/responses/firebolt-response-example
Original file line number Diff line number Diff line change
@@ -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
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

0 comments on commit 96c6b3c

Please sign in to comment.