DBJoin
Short Description
DBJoin receives data through a single input port and joins it with data from a database table. These two data sources can potentially have different metadata structures.
DBJoin
x
x
1 (virtual)
1-2
✓
x
✓
✓
Ports
After the data from an input port and database table are joined, they are sent to the first output port. The second output port can optionally be used to capture unmatched master records.
Input
0
✓
Master input port
Any
1 (virtual)
✓
Slave input port
Any
Output
0
✓
Output port for the joined data
Any
1
x
The optional output port for master data records without slave matches. (Only if the Join type attribute is set to Inner join.) This applies only to LookupJoin and DBJoin.
Input 0
Metadata
DBJoin propagates metadata from the first input port to the second output port and vice versa. DBJoin has no metadata template. If mapping is not defined, DBJoin requires output metadata to match metadata of a query result. If mapping is defined, metadata of a query result must match metadata defined in the DBJoin attribute.
DBJoin Attributes
BASIC
Join key
yes
Key according to which the incoming data flows are joined. See Join Key below.
Left outer join
If set to true
, driver records without corresponding slave are parsed, as well. Otherwise, inner join
is performed.
false (default) | true
DB connection
yes
The ID of DB metadata to be used. If not set, metadata is extracted from a database using an SQL query.
Query URL
[1]
The name of an external file, including the path, defining an SQL query.
SQL query
[1]
The SQL query defined in a graph.
Transform
[2] [3]
Transformation in CTL or Java defined in the graph.
Transform URL
[2] [3]
An external file defining the transformation in CTL or Java.
Transform class
[2] [3]
An external transformation class.
Cache size
The maximum number of records with different key values that can be stored in memory.
100 (default)
ADVANCED
Transform source charset
Encoding of an external file defining the transformation. The default encoding depends on DEFAULT_SOURCE_CODE_CHARSET in defaultProperties.
E.g. UTF-8
DEPRECATED
Error actions
The definition of an action that should be performed when the specified transformation returns an Error code. See Return Values of Transformations.
Error log
A URL of the file to which error messages for specified Error actions should be written. If not set, they are written to Console.
Details
DBJoin receives data through a single input port and joins it with data from a database table. These two data sources can potentially have different metadata structure. It is a general purpose joiner usable in most common situations. It does not require the input to be sorted and is very fast as data is processed in memory.
The data attached to the first input port is called master, the second data source is called slave. Its data is considered as if it were incoming through the second (virtual) input port. Each master record is matched to the slave record on one or more fields known as a join key. The output is produced by applying a transformation that maps joined inputs to the output.
Join Key Join key is a sequence of field names from a master data source separated from each other by a semicolon, colon, or pipe. You can define the key in the Edit key wizard.
The order of these field names must correspond to the order of the key fields from the database table (and their data types). The slave part of Join key must be defined in the SQL query attribute.
One of the query attributes must contain the expression of the following form: ... where field_K=? and field_L=?
.
Example 41. Join Key for DBJoin
This is the master part of fields that should serve to join master records with slave records. The SQL query must contain an expression that can look like this:
Corresponding fields will be compared and matching values will serve to join master and slave records.
Transformation The transform in DBJoin lets you define a transformation that sends records to the first output port. The unjoined master records sent to the second output port cannot be modified within the DBJoin transformation.
CTL Scripting Specifics
Java Interfaces
Examples
Joining on Exact Key
Input records contain one field customerId
with values:
The customers
database table has the following structure and data:
Join incoming records with data from the database on customerId
.
Solution
Create input metadata with one field customerId (integer)
and output metadata with the customerId (integer)
, customerName (string), customerSurname (string)
fields.
Set the Join key and **SQL query **attributes of DBJoin.
Join key
customerId
DBConnection
Your DBConnection
SQL query
select * from "customers" where customer_id=?
Only records with customerId (integer)
found in the database are sent to output.
Matching Range Input records contain a product code and date of order.
Price of a particular product on particular date can be found in the database.
Match the price to particular product orders.
Solution Create input metadata (productCode, orderDate), output metadata (productCode, orderDate, price) and metadata for DBJoin ( productCode, price).
Set attributes:
Join key
product;orderDate;orderDate
Metadata
DBJoinMetadata
DBConnection
Your DBConnection
SQL query
select product_id,price_per_unit from "dbjoin_example_02" where product_id=? and valid_from<=? and ?<=valid_to
Transform
See the code below.
Best Practices
If the transformation is specified in an external file (with Transform URL), we recommend users to explicitly specify Transform source charset.