Skip to content

Latest commit

 

History

History
109 lines (84 loc) · 4.68 KB

File metadata and controls

109 lines (84 loc) · 4.68 KB

DB2 Batch Source

Description

Reads from a DB2 using a configurable SQL query. Outputs one record for each row returned by the query.

Use Case

The source is used whenever you need to read from a DB2. For example, you may want to create daily snapshots of a database table by using this source and writing to a TimePartitionedFileSet.

Properties

Reference Name: Name used to uniquely identify this source for lineage, annotating metadata, etc.

Driver Name: Name of the JDBC driver to use.

Host: Host that DB2 is running on.

Port: Port that DB2 is listening to.

Database: DB2 database name.

Import Query: The SELECT query to use to import data from the specified table. You can specify an arbitrary number of columns to import, or import all columns using *. The Query should contain the '$CONDITIONS' string. For example, 'SELECT * FROM table WHERE $CONDITIONS'. The '$CONDITIONS' string will be replaced by 'splitBy' field limits specified by the bounding query. The '$CONDITIONS' string is not required if numSplits is set to one.

Bounding Query: Bounding Query should return the min and max of the values of the 'splitBy' field. For example, 'SELECT MIN(id),MAX(id) FROM table'. Not required if numSplits is set to one.

Split-By Field Name: Field Name which will be used to generate splits. Not required if numSplits is set to one.

Number of Splits to Generate: Number of splits to generate.

Username: User identity for connecting to the specified database.

Password: Password to use to connect to the specified database.

Connection Arguments: A list of arbitrary string key/value pairs as connection arguments. These arguments will be passed to the JDBC driver as connection arguments for JDBC drivers that may need additional configurations.

Schema: The schema of records output by the source. This will be used in place of whatever schema comes back from the query. However, it must match the schema that comes back from the query, except it can mark fields as nullable and can contain a subset of the fields.

Fetch Size: The number of rows to fetch at a time per split. Larger fetch size can result in faster import, with the tradeoff of higher memory usage.

Example

Suppose you want to read data from DB2 database named "prod" that is running on "localhost", port 50000, as "sa" user with "Test11" password (Ensure that the driver for DB2 is installed. You can also provide driver name for some specific driver, otherwise "db211" will be used), then configure plugin with:

Reference Name: "src1"
Driver Name: "db211"
Host: "localhost"
Port: 50000
Database: "prod"
Import Query: "select id, name, email, phone from users;"
Number of Splits to Generate: 1
Username: "sa"
Password: "Test11"

For example, if the 'id' column is a primary key of type int and the other columns are non-nullable varchars, output records will have this schema:

field name type
id int
name string
email string
phone string

Data Types Mapping

DB2 Data Type CDAP Schema Data Type Comment
SMALLINT int
INTEGER int
BIGINT long
DECIMAL(p,s) or NUMERIC(p,s) decimal
DECFLOAT string
REAL float
DOUBLE double
CHAR string
VARCHAR string
CHAR(n) FOR BIT DATA bytes
VARCHAR(n) FOR BIT DATA bytes
BINARY bytes
VARBINARY bytes
GRAPHIC string
VARGRAPHIC string
CLOB string
BLOB bytes
DBCLOB string
DATE date
TIME time
TIMESTAMP timestamp