Starburst IBM DB2 connector#

The IBM DB2 connector allows querying and creating tables in an external DB2 database.

The connector supports DB2 11.5 for Linux, Unix, and Windows (LUW).

Note

The Starburst IBM DB2 connector requires a valid Starburst Enterprise Presto license.

Installation and configuration#

Any of the below installation and configuration methods require the following artifacts:

  • DB2 JDBC driver file db2jcc-db2jcc4.jar obtained from IBM

  • JDBC connection details to connect to DB2 in a catalog properties file (e.g. db2.properties for a catalog named db2). File should contain the following contents, replacing the connection properties as appropriate for your setup:

connector.name=db2
connection-url=jdbc:db2://HOST:PORT/DATABASE
connection-user=USERNAME
connection-password=PASSWORD

The DB2 JDBC driver documentation contains information about format and parameters of the JDBC URL.

To install the DB2 Database connector, use the following steps:

  1. Add the DB2 JDBC driver JAR files to the plugin/db2 directory.

  2. Add a catalog properties file (e.g. db2.properties for a catalog named db2).

  3. Perform the above steps on every node.

  4. Restart Presto on every node.

Querying DB2 databases#

The DB2 connector provides a schema for each DB2 database. Assuming the catalog name is db2, you can see the available schemas by running SHOW SCHEMAS:

SHOW SCHEMAS FROM db2;

If you have an DB2 database named web, you can view the tables they own by running SHOW TABLES:

SHOW TABLES FROM db2.web;

You can see a list of the columns in the clicks table in web’s schema using either of the following:

DESCRIBE db2.web.clicks;
SHOW COLUMNS FROM db2.web.clicks;

Finally, you can access the clicks table in web’s schema:

SELECT * FROM db2.web.clicks;

Your privileges in these schemas are those of the user configured in the connection properties file. If the user does not have access to these tables, you are not able to access them.

Type mapping for reading data#

The connector supports reading the following DB2 types and performs conversion to Presto types with the detailed mappings.

DB2 to Presto type mapping#

DB2 type

Presto type

Notes

NUMERIC

DECIMAL(p, s)

DECIMAL(p, s)

DECIMAL(p, s)

DECFLOAT(p)

DECIMAL(p, s)

FLOAT[(p)]

DOUBLE

REAL

REAL

DOUBLE

DOUBLE

DOUBLE PRECISION

DOUBLE

TINYINT

SMALLINT

SMALLINT

SMALLINT

INT

INT

BIGINT

BIGINT

DOUBLE PRECISION

DOUBLE

VARCHAR(n)

VARCHAR(n)

CHAR VARYING(n)

VARCHAR(n)

BINARY(n)

VARBINARY

BINARY VARYING

VARBINARY

VARBINARY(n)

VARBINARY

CHAR(n)

CHAR(n)

CLOB

VARCHAR

BLOB

VARBINARY

ROWID

VARCHAR

DATE

DATE

See Mapping datetime types

TIMESTAMP(p)

TIMESTAMP(3)

See Mapping datetime types

TIME

TIME

See Mapping datetime types

Type mapping for writing data#

The connector supports writing the following Presto types and performs conversion to DB2 types with the detailed mappings.

Presto to DB2 type mapping#

Presto type

DB2 type

Notes

BOOLEAN

BOOLEAN

TINYINT

SMALLINT

SMALLINT

SMALLINT

INTEGER

INTEGER

BIGINT

BIGINT

REAL

FLOAT(23)

DOUBLE

FLOAT(53)

DECIMAL(p, s)

DECIMAL(p, s)

VARCHAR(n)

VARCHAR(n)

For n up to 32704.

VARCHAR(n)

CLOB

For n above 32704.

VARCHAR

CLOB

When no bound is given.

CHAR(n)

CHAR(n)

For n up to 255. n above 255 is not supported.

VARBINARY

BLOB

TIMESTAMP

TIMESTAMP

See Mapping datetime types

TIME

TIME

See Mapping datetime types

DATE

DATE

See Mapping datetime types

Mapping datetime types#

The DB2 connector does not currently support variable-precision timestamps.

Selecting a DB2 timestamp value with fractional second precision greater than 3 truncates (not rounds) the fractional seconds to three digits.

Inserting a TIME value with fractional seconds into DB2 truncates (not rounds) the time to second precision, as DB2 does not support fractional seconds in TIME values.

Warning

Because of differences in date and time representation in DB2 and JDBC, attempting to insert or select a datetime value earlier than 1582-10-15 results in an incorrect date being stored/retrieved.

User impersonation#

DB2 connector supports user impersonation.

User impersonation can be enabled in your catalog file:

db2.impersonation-enabled=true

User impersonation is based on SET SESSION_USER detailed in the IBM documentation.

Note

Running SET SESSION_USER in DB2 requires the user to have a SETSESSIONUSER privilege.

Table statistics#

DB2 connector supports table and column statistics. The statistics are collected by the DB2 database and retrieved by the connector. To collect statistics for a table, execute the following statements in DB2.

CALL SYSPROC.ADMIN_CMD('RUNSTATS ON TABLE table_name');

The table statistics can be viewed in Presto using SHOW STATS and are used for Cost based optimizations.

Table statistics configuration properties#

Property name

Description

Default

statistics.enabled

Enables table and column statistics

true

statistics.cache-ttl

Duration for which table and column statistics are cached

0s

statistics.cache-missing

Cache the fact that table statistics are not available

false

Limitations#

The following SQL statements are not yet supported: