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

#56: Improved BaseColumnMetadataReader JDBC types mapping. #57

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Changes

* [5.0.4](changes-5.0.4.md)
* [5.0.3](changes-5.0.3.md)
* [5.0.2](changes-5.0.2.md)
5 changes: 5 additions & 0 deletions doc/changes/changes-5.0.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Virtual Schema Common JDBC 5.0.4, released 2020-08-13

## Refactoring

* #56: Improved BaseColumnMetadataReader JDBC types mapping.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.exasol</groupId>
<artifactId>virtual-schema-common-jdbc</artifactId>
<version>5.0.3</version>
<version>5.0.4</version>
<name>Virtual Schema Common JDBC</name>
<description>Common module for JDBC-based data access from Virtual Schemas.</description>
<url>https://github.com/exasol/virtual-schema-common-jdbc</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.exasol.adapter.jdbc;

import static com.exasol.adapter.jdbc.RemoteMetadataReaderConstants.*;
import static com.exasol.adapter.metadata.DataType.ExaCharset.UTF8;
AnastasiiaSergienko marked this conversation as resolved.
Show resolved Hide resolved

import java.sql.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -229,25 +230,10 @@ public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
case Types.BOOLEAN:
return DataType.createBool();
case Types.TIME:
return DataType.createVarChar(100, DataType.ExaCharset.UTF8);
case Types.TIMESTAMP_WITH_TIMEZONE:
return DataType.createVarChar(100, UTF8);
case Types.NUMERIC:
return fallBackToMaximumSizeVarChar();
case Types.BINARY:
case Types.CLOB:
case Types.OTHER:
case Types.BLOB:
case Types.NCLOB:
case Types.LONGVARBINARY:
case Types.VARBINARY:
case Types.JAVA_OBJECT:
case Types.DISTINCT:
case Types.STRUCT:
case Types.ARRAY:
case Types.REF:
case Types.DATALINK:
case Types.SQLXML:
case Types.NULL:
case Types.REF_CURSOR:
default:
LOGGER.finer("Found unsupported type: " + jdbcTypeDescription.getJdbcType());
return DataType.createUnsupported();
Expand Down Expand Up @@ -294,13 +280,12 @@ protected DataType convertDecimal(final int jdbcPrecision, final int scale) {
}

private static DataType fallBackToMaximumSizeVarChar() {
return DataType.createMaximumSizeVarChar(DataType.ExaCharset.UTF8);
return DataType.createMaximumSizeVarChar(UTF8);
}

private static DataType convertVarChar(final int size, final int octetLength) {
final DataType colType;
final DataType.ExaCharset charset = (octetLength == size) ? DataType.ExaCharset.ASCII
: DataType.ExaCharset.UTF8;
final DataType.ExaCharset charset = (octetLength == size) ? DataType.ExaCharset.ASCII : UTF8;
if (size <= DataType.MAX_EXASOL_VARCHAR_SIZE) {
final int precision = size == 0 ? DataType.MAX_EXASOL_VARCHAR_SIZE : size;
colType = DataType.createVarChar(precision, charset);
Expand All @@ -312,8 +297,7 @@ private static DataType convertVarChar(final int size, final int octetLength) {

private static DataType convertChar(final int size, final int octetLength) {
final DataType colType;
final DataType.ExaCharset charset = (octetLength == size) ? DataType.ExaCharset.ASCII
: DataType.ExaCharset.UTF8;
final DataType.ExaCharset charset = (octetLength == size) ? DataType.ExaCharset.ASCII : UTF8;
if (size <= DataType.MAX_EXASOL_CHAR_SIZE) {
colType = DataType.createChar(size, charset);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ void testMappingUnsupportedTypesReturnsUnsupportedType(final int jdbcType) {
assertThat(this.reader.mapJdbcType(jdbcTypeDescription).getExaDataType(), equalTo(ExaDataType.UNSUPPORTED));
}

@ValueSource(ints = { Types.NUMERIC })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a parametrized test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Forgot to refactor it after removing types

@ParameterizedTest
void testMappingToMaxSizeVarchar(final int jdbcType) {
final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(jdbcType, 0, 0, 0, null);
assertThat(this.reader.mapJdbcType(jdbcTypeDescription),
equalTo(DataType.createMaximumSizeVarChar(DataType.ExaCharset.UTF8)));
}

@ValueSource(ints = { Types.TIME, Types.TIMESTAMP_WITH_TIMEZONE })
@ParameterizedTest
void testMappingDateTimeToVarchar(final int jdbcType) {
final JdbcTypeDescription jdbcTypeDescription = new JdbcTypeDescription(jdbcType, 0, 0, 0, null);
assertThat(this.reader.mapJdbcType(jdbcTypeDescription), equalTo(DataType.createVarChar(100, ExaCharset.UTF8)));
}

@Test
void testGetColumnsFromResultSetSkipsUnsupportedColumns() throws SQLException {
final ResultSet remoteColumnsMock = mock(ResultSet.class);
Expand Down