Starburst IBM DB2 connector#

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

Requirements#

To connect to IBM DB2, you need:

  • DB2 11.5 or higher for Linux, Unix, and Windows (LUW).

  • Network access from the coordinator and workers to the DB2 server. Port 51000 is the default port.

  • A valid Starburst Enterprise 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 SEP on every node.

General configuration properties#

The following table describes general catalog configuration properties for the connector:

Property name

Description

Default value

case-insensitive-name-matching

Support case insensitive schema and table names.

false

case-insensitive-name-matching.cache-ttl

1m

case-insensitive-name-matching.config-file

Path to a name mapping configuration file in JSON format that allows Trino to disambiguate between schemas and tables with similar names in different cases.

null

case-insensitive-name-matching.refresh-period

Frequency with which Trino checks the name matching configuration file for changes.

0 (refresh disabled)

metadata.cache-ttl

Duration for which metadata, including table and column statistics, is cached.

0 (caching disabled)

metadata.cache-missing

Cache the fact that metadata, including table and column statistics, is not available

false

metadata.cache-maximum-size

Maximum number of objects stored in the metadata cache

10000

write.batch-size

Maximum number of statements in a batched execution. Do not change this setting from the default. Non-default values may negatively impact performance.

1000

join-pushdown.enabled

Enable join pushdown. Equivalent catalog session property is join_pushdown_enabled. Enabling this may negatively impact performance for some queries.

false

Type mapping#

Because SEP and DB2 each support types that the other does not, this connector modifies some types when reading or writing data.

Type mapping for reading data#

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

DB2 to Trino type mapping#

DB2 type

Trino 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 Trino types and performs conversion to DB2 types with the detailed mappings.

Trino to DB2 type mapping#

Trino 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.

General configuration properties#

The following properties can be used to configure how data types from the connected data source are mapped to Trino data types and how the metadata is cached in Trino.

Property name

Description

Default value

unsupported-type-handling

Configure how unsupported column data types are handled:

  • IGNORE, column is not accessible.

  • CONVERT_TO_VARCHAR, column is converted to unbounded VARCHAR.

The respective catalog session property is unsupported_type_handling.

IGNORE

jdbc-types-mapped-to-varchar

Allow forced mapping of comma separated lists of data types to convert to unbounded VARCHAR

SQL support#

The connector provides read and write access to data and metadata in the DB2 database. In addition to the globally available and read operation statements, the connector supports the following features:

SQL DELETE#

If a WHERE clause is specified, the DELETE operation only works if the predicate in the clause can be fully pushed down to the data source.

ALTER TABLE#

The connector does not support renaming tables across multiple schemas. For example, the following statement is supported:

ALTER TABLE catalog.schema_one.table_one RENAME TO catalog.schema_one.table_two

The following statement attempts to rename a table across schemas, and therefore is not supported:

ALTER TABLE catalog.schema_one.table_one RENAME TO catalog.schema_two.table_two

Performance#

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

Table statistics#

The DB2 connector supports table and column statistics to improve query processing performance based on the actual data in the data source.

The statistics are collected by DB2 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');

Pushdown#

The connector supports pushdown for a number of operations:

Aggregate pushdown for the following functions:

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.

Starburst Cached Views#

The connectors supports table scan redirection to improve performance and reduce load on the data source.

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.

Password credential pass-through#

The connector supports password credential pass-through. To enable it, edit the catalog properties file to include the authentication type:

db2.authentication.type=PASSWORD_PASS_THROUGH

For more information about configurations and limitations, see Password credential pass-through.