-
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
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 |
|---|---|---|
|
|
@@ -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.BOOL) { | ||
| assertEquals("boolean", sub.getColumnTypeName(index)); | ||
| } | ||
| index++; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsReadOnly() { | ||
| for (int i = 0; i < TEST_COLUMNS.size(); i++) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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)
ARRAYfor all GoogleSQL arraysSTRINGfor PostgreSQLvarcharcolumns (and so forth for each non-array type)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
Sorry? What do you mean by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean is that it is a bit weird that:
ARRAY<STRING>returnsARRAY, while PostgreSQLARRAY<STRING>returns_varcharSTRINGreturnsSTRING(instead ofvarchar), while PostgreSQLARRAY<STRING>returns_varcharThere was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
text == varchar == charater varying. We need to maintain one type which will be easy.If you feel, we should do it, I can incorporate the change.