Skip to content

Commit

Permalink
#320: hardcoded the size of MySQL data type TEXT (#323)
Browse files Browse the repository at this point in the history
* #320: hardcoded the size of MySQL data type TEXT because the driver can return an incorrect value.
* #320: fixed review findings and adjusted documentation for MySQL dialect
  • Loading branch information
AnastasiiaSergienko authored Mar 30, 2020
1 parent c704406 commit 62f1ff2
Show file tree
Hide file tree
Showing 20 changed files with 120 additions and 28 deletions.
2 changes: 1 addition & 1 deletion doc/dialects/athena.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/AthenaJDBC42-<JDBC driver version>.jar;
/
;
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/aurora.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/postgresql-<JDBC driver version>.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/bigquery.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ List all the JAR files from Magnitude Simba JDBC driver.
```sql
CREATE JAVA ADAPTER SCRIPT SCHEMA_FOR_VS_SCRIPT.ADAPTER_SCRIPT_BIGQUERY AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/GoogleBigQueryJDBC42.jar;
...
...
Expand Down
4 changes: 2 additions & 2 deletions doc/dialects/db2.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/db2jcc4.jar;
%jar /buckets/<BFS service>/<bucket>/db2jcc_license_cu.jar;
/
Expand All @@ -68,7 +68,7 @@ CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/db2jcc4.jar;
%jar /buckets/<BFS service>/<bucket>/db2jcc_license_cu.jar;
%jar /buckets/<BFS service>/<bucket>/db2jcc_license_cisuz.jar;
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/exasol.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
/
```

Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/hive.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/jars/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/jars/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/jars/HiveJDBC41.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/impala.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/ImpalaJDBC41.jar;
/
;
Expand Down
62 changes: 52 additions & 10 deletions doc/dialects/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ Upload the latest available release of [Virtual Schema JDBC Adapter](https://git
Then create a schema to hold the adapter script.

```sql
CREATE SCHEMA ADAPTER;
CREATE SCHEMA SCHEMA_FOR_VS_SCRIPT;
```

The SQL statement below creates the adapter script, defines the Java class that serves as entry point and tells the UDF framework where to find the libraries (JAR files) for Virtual Schema and database driver.

```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
CREATE OR REPLACE JAVA ADAPTER SCRIPT SCHEMA_FOR_VS_SCRIPT.ADAPTER_SCRIPT_MYSQL AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/mysql-connector-java-<version>.jar;
/
;
Expand All @@ -62,7 +62,7 @@ CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
Define the connection to MySQL as shown below.

```sql
CREATE OR REPLACE CONNECTION MYSQL_CONNECTION
CREATE OR REPLACE CONNECTION MYSQL_JDBC_CONNECTION
TO 'jdbc:mysql://<host>:<port>/'
USER '<user>'
IDENTIFIED BY '<password>';
Expand All @@ -74,14 +74,56 @@ Below you see how a MySQL Virtual Schema is created. Use CATALOG_NAME property t

```sql
CREATE VIRTUAL SCHEMA <virtual schema name>
USING ADAPTER.JDBC_ADAPTER
USING SCHEMA_FOR_VS_SCRIPT.ADAPTER_SCRIPT_MYSQL
WITH
SQL_DIALECT = 'MYSQL'
CONNECTION_NAME = 'MYSQL_CONNECTION'
CONNECTION_NAME = 'MYSQL_JDBC_CONNECTION'
CATALOG_NAME = '<database name>';
```

## Data Types Mapping and Limitations

- `TIME` is casted to `TIMESTAMP` with a format `1970-01-01 hh:mm:ss`.
- Unsupported data types: `BINARY`, `VARBINARY`, `BLOB`, `TINYBLOB`, `MEDIUMBLOB`, `LONGBLOB`.
## Data Types Conversion

MySQL Data Type | Supported | Converted Exasol Data Type| Known limitations
-------------------|-----------|---------------------------|-------------------
BOOLEAN | ✓ | BOOLEAN |
BIGINT | ✓ | DECIMAL |
BINARY | × | |
BIT | ✓ | BOOLEAN |
BLOB | × | |
CHAR | ✓ | CHAR |
DATE | ✓ | DATE |
DATETIME | ✓ | TIMESTAMP |
DECIMAL | ✓ | DECIMAL |
DOUBLE | ✓ | DOUBLE PRECISION |
ENUM | ✓ | CHAR |
FLOAT | ✓ | DOUBLE PRECISION |
INT | ✓ | DECIMAL |
LONGBLOB | × | |
LONGTEXT | ✓ | VARCHAR(2000000) |
MEDIUMBLOB | × | |
MEDIUMINT | ✓ | DECIMAL |
MEDIUMTEXT | ✓ | VARCHAR(2000000) |
SET | ✓ | CHAR |
SMALLINT | ✓ | DECIMAL |
TEXT | ✓ | VARCHAR(65535) | The size of the column is always 65535.*
TINYBLOB | × | |
TINYINT | ✓ | DECIMAL |
TINYTEXT | ✓ | VARCHAR |
TIME | ✓ | TIMESTAMP | Casted to `TIMESTAMP` with a format `1970-01-01 hh:mm:ss`.
TIMESTAMP | ✓ | TIMESTAMP |
VARBINARY | × | |
VARCHAR | ✓ | VARCHAR |
YEAR | ✓ | DATE |

* The tested versions of MySQL Connector JDBC Driver return the column's size depending on the charset and its collation.
As the real data in a MySQL table can sometimes exceed the size that we get from the JDBC driver, we set the size for all TEXT columns to 65535 characters.

If you need to use currently unsupported data types or find a way around known limitations, please, create a github issue in the [VS repository](https://github.com/exasol/virtual-schemas/issues).

## Testing information

In the following matrix you find combinations of JDBC driver and dialect version that we tested.

Virtual Schema Version| Big Query Version | Driver Name | Driver Version
----------------------|---------------------|--------------------------|------------------------
3.1.1 | MySQL 8.0.19 | MySQL Connector | 8.0.17
2 changes: 1 addition & 1 deletion doc/dialects/oracle.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/ojdbc<JDBC driver version>.jar;
/
;
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/postgresql-<version>.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/redshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/RedshiftJDBC42-<JDBC driver version>.jar;
/
;
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/saphana.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/ngdbc-<JDBC driver version>.jar;
/
;
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/sql_server.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/jtds.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/sybase.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/jtds-<version>.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion doc/dialects/teradata.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE OR REPLACE JAVA ADAPTER SCRIPT ADAPTER.JDBC_ADAPTER AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/<BFS service>/<bucket>/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/<BFS service>/<bucket>/terajdbc4.jar;
%jar /buckets/<BFS service>/<bucket>/tdgssconfig.jar;
/
Expand Down
2 changes: 1 addition & 1 deletion doc/user-guide/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ The SQL statement below creates the adapter script, defines the Java class that
```sql
CREATE JAVA ADAPTER SCRIPT SCHEMA_FOR_VS_SCRIPT.JDBC_ADAPTER_SCRIPT AS
%scriptclass com.exasol.adapter.RequestDispatcher;
%jar /buckets/your-bucket-fs/your-bucket/virtualschema-jdbc-adapter-dist-3.1.1.jar;
%jar /buckets/your-bucket-fs/your-bucket/virtualschema-jdbc-adapter-dist-3.1.2.jar;
%jar /buckets/your-bucket-fs/your-bucket/<JDBC driver>.jar;
/
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>${product.version}</version>
<name>Virtual Schema JDBC Adapter</name>
<properties>
<product.version>3.1.1</product.version>
<product.version>3.1.2</product.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* This class implements MySQL-specific reading of column metadata.
*/
public class MySqlColumnMetadataReader extends BaseColumnMetadataReader {
private static final String TEXT_DATA_TYPE_NAME = "TEXT";
protected static final int TEXT_DATA_TYPE_SIZE = 65535;

/**
* Create a new instance of the {@link MySqlColumnMetadataReader}.
*
Expand All @@ -32,8 +35,40 @@ public DataType mapJdbcType(final JdbcTypeDescription jdbcTypeDescription) {
return DataType.createTimestamp(false);
case Types.BINARY:
return DataType.createUnsupported();
case Types.LONGVARCHAR:
return convertVarChar(jdbcTypeDescription);
default:
return super.mapJdbcType(jdbcTypeDescription);
}
}

private DataType convertVarChar(final JdbcTypeDescription jdbcTypeDescription) {
final int size = getVarcharSize(jdbcTypeDescription);
final int octetLength = jdbcTypeDescription.getByteSize();
final DataType.ExaCharset charset = (octetLength == size) ? DataType.ExaCharset.ASCII
: DataType.ExaCharset.UTF8;
if (size <= DataType.MAX_EXASOL_VARCHAR_SIZE) {
final int precision = getVarcharPrecision(size);
return DataType.createVarChar(precision, charset);
} else {
return DataType.createVarChar(DataType.MAX_EXASOL_VARCHAR_SIZE, charset);
}
}

private int getVarcharPrecision(int size) {
if (size == 0) {
return DataType.MAX_EXASOL_VARCHAR_SIZE;
} else {
return size;
}
}

private int getVarcharSize(final JdbcTypeDescription jdbcTypeDescription) {
final String typeName = jdbcTypeDescription.getTypeName();
if (typeName.equals(TEXT_DATA_TYPE_NAME)) {
return TEXT_DATA_TYPE_SIZE;
} else {
return jdbcTypeDescription.getPrecisionOrSize();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public final class IntegrationTestConstants {
public static final String INTEGRATION_TEST_CONFIGURATION_FILE_PROPERTY = "integrationtest.configfile";
public static final String VIRTUAL_SCHEMAS_JAR_NAME_AND_VERSION = "virtualschema-jdbc-adapter-dist-3.1.1.jar";
public static final String VIRTUAL_SCHEMAS_JAR_NAME_AND_VERSION = "virtualschema-jdbc-adapter-dist-3.1.2.jar";
public static final Path PATH_TO_VIRTUAL_SCHEMAS_JAR = Path.of("target", VIRTUAL_SCHEMAS_JAR_NAME_AND_VERSION);
public static final String SCHEMA_EXASOL = "SCHEMA_EXASOL";
public static final String ADAPTER_SCRIPT_EXASOL = "ADAPTER_SCRIPT_EXASOL";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.exasol.adapter.dialects.mysql;

import static com.exasol.adapter.dialects.mysql.MySqlColumnMetadataReader.TEXT_DATA_TYPE_SIZE;
import static com.exasol.adapter.metadata.DataType.MAX_EXASOL_VARCHAR_SIZE;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

Expand Down Expand Up @@ -33,4 +35,17 @@ void mapBinary() {
final JdbcTypeDescription typeDescription = new JdbcTypeDescription(Types.BINARY, 0, 0, 10, "BINARY");
assertThat(columnMetadataReader.mapJdbcType(typeDescription), equalTo(DataType.createUnsupported()));
}

@Test
void mapText() {
final JdbcTypeDescription typeDescription = new JdbcTypeDescription(Types.LONGVARCHAR, 0, 16383, 10, "TEXT");
assertThat(columnMetadataReader.mapJdbcType(typeDescription).getSize(), equalTo(TEXT_DATA_TYPE_SIZE));
}

@Test
void mapMediumText() {
final JdbcTypeDescription typeDescription = new JdbcTypeDescription(Types.LONGVARCHAR, 0, 4194303, 10,
"MEDIUMTEXT");
assertThat(columnMetadataReader.mapJdbcType(typeDescription).getSize(), equalTo(MAX_EXASOL_VARCHAR_SIZE));
}
}

0 comments on commit 62f1ff2

Please sign in to comment.