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 connector requires a valid Starburst Enterprise Presto license.

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.

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.

Performance#

The connector includes a number of performance improvements, detailed in the following sections.

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

Pushdown#

The connector supports pushdown for the following aggregate functions:

The connector supports pushdown for LIMIT clauses of a SELECT statement.

Dynamic filtering#

Dynamic filtering is enabled by default. It causes the connector to wait for dynamic filtering to complete before starting a JDBC query.

You can disable dynamic filtering by setting the property dynamic-filtering.enabled in your catalog properties file to false.

JDBC connection pooling#

You can improve performance by enabling JDBC connection pooling, which is disabled by default.

Security#

The connector includes a number of security-related features, detailed in the following sections.

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.

Limitations#

The following SQL statements are not yet supported: