-
Notifications
You must be signed in to change notification settings - Fork 52
fix: Fix Column Type Name for PostgreSQL ARRAY types #2409
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
|
|
||
| package com.google.cloud.spanner.jdbc; | ||
|
|
||
| import com.google.cloud.spanner.Dialect; | ||
| import com.google.cloud.spanner.ResultSet; | ||
| import com.google.cloud.spanner.Type; | ||
| import com.google.cloud.spanner.connection.ConnectionProperties; | ||
| import com.google.common.base.Preconditions; | ||
| import java.sql.Connection; | ||
|
|
@@ -192,7 +194,14 @@ public int getColumnType(int column) { | |
|
|
||
| @Override | ||
| public String getColumnTypeName(int column) { | ||
| return spannerResultSet.getColumnType(column - 1).getCode().name(); | ||
| Type columnType = spannerResultSet.getColumnType(column - 1); | ||
| if (columnType.getCode() == Type.Code.ARRAY && statement instanceof JdbcStatement) { | ||
| Dialect dialect = ((JdbcStatement) statement).getConnection().getDialect(); | ||
| if (dialect == Dialect.POSTGRESQL) { | ||
| return "_" + columnType.getArrayElementType().getSpannerTypeName(dialect); | ||
| } | ||
| } | ||
| return columnType.getCode().name(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we fix this for more than only PostgreSQL arrays? The current implementation will (I think)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes
Sorry? What do you mean by this?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I mean is that it is a bit weird that:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. we can change it. I don't think there will be a problem if we change it. So far ARRAY is the only thing which was concerning for me so I changed it.. Right now, there's a complex handling of types in PG. If you feel, we should do it, I can incorporate the change. |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import static org.mockito.Mockito.when; | ||
|
|
||
| import com.google.cloud.ByteArray; | ||
| import com.google.cloud.spanner.Dialect; | ||
| import com.google.cloud.spanner.ResultSet; | ||
| import com.google.cloud.spanner.ResultSets; | ||
| import com.google.cloud.spanner.Struct; | ||
|
|
@@ -540,6 +541,30 @@ public void getColumnTypeName() { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void getColumnTypeNameForPostgreSQL() throws SQLException { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a test that verifies a type name in 'plain text'. That is: I suspect that the current implementation will return something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now it will return |
||
| JdbcConnection connection = mock(JdbcConnection.class); | ||
| JdbcStatement statement = mock(JdbcStatement.class); | ||
| JdbcResultSet resultSet = getFooTestResultSet(statement); | ||
| when(connection.getSchema()).thenReturn(""); | ||
| when(connection.getCatalog()).thenReturn("test-database"); | ||
| when(statement.getConnection()).then(new Returns(connection)); | ||
| when(connection.getDialect()).thenReturn(Dialect.POSTGRESQL); | ||
|
|
||
| JdbcResultSetMetaData sub = resultSet.getMetaData(); | ||
|
|
||
| int index = 1; | ||
| for (TestColumn col : TEST_COLUMNS) { | ||
| if (col.type.getCode() == Type.Code.ARRAY | ||
| && col.type.getSpannerTypeName(Dialect.POSTGRESQL).contains("bool")) { | ||
| assertEquals("_boolean", sub.getColumnTypeName(index)); | ||
| } else if (col.type.getCode() != Type.Code.ARRAY) { | ||
| assertEquals(col.type.getCode().name(), sub.getColumnTypeName(index)); | ||
| } | ||
| index++; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsReadOnly() { | ||
| for (int i = 0; i < TEST_COLUMNS.size(); i++) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.