Multi Source Nodes
Multi Source nodes represent Coalesce's implementation of SQL UNIONs.
Nodes can have multiple sources, using JOINs or UNIONs (or both) to ultimately create a new table/view.
Multi Source Strategy
There are three options for how a multi source node will load source tables into the target table.
INSERT (default option)
This will break down the operation into multiple INSERTs. This allows individual parts to fail before moving on to others, which can improve performance. This operation will retain duplicates.
UNION
This will make a UNION of sources and get rid of duplicates.
UNION ALL
This will make a UNION ALL of sources and keep duplicates.
Multi Source Node Load Order
Multi source nodes will load in the order they appear on the Multi Source node screen, top to bottom.
Example UNION with Three Tables
Let's walk through a simple example using a multi source node to form a UNION of 3 tables. We're looking to consolidate all the crew members of the Nostromo onto one table, but they're currently scattered across three similar, but not identical tables.
Sample Nostromo Data
CREATE OR REPLACE TABLE NOSTROMO_SRC1 (
N_CREWKEY NUMBER(38,0),
N_FIRSTNAME VARCHAR(50),
N_LASTNAME VARCHAR(50),
N_COMMENT VARCHAR(152)
);
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC1
(N_CREWKEY, N_FIRSTNAME, N_LASTNAME, N_COMMENT)
VALUES(1, 'Ellen', 'Ripley', 'Warrant Officer');
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC1
(N_CREWKEY, N_FIRSTNAME, N_LASTNAME, N_COMMENT)
VALUES(2, 'Arthur', 'Dallas', 'Captain');
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC1
(N_CREWKEY, N_FIRSTNAME, N_LASTNAME, N_COMMENT)
VALUES(3, 'Thomas', 'Kane', 'Executive Officer');
CREATE OR REPLACE TABLE NOSTROMO_SRC2 (
N_CREWKEY NUMBER(38,0),
N_FIRSTNAME VARCHAR(50),
N_MIDDLEINITIAL VARCHAR(1),
N_LASTNAME VARCHAR(50),
N_COMMENT VARCHAR(152)
);
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC2
(N_CREWKEY, N_FIRSTNAME, N_MIDDLEINITIAL, N_LASTNAME, N_COMMENT)
VALUES(4, 'Ash', NULL, NULL, 'Science Officer');
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC2
(N_CREWKEY, N_FIRSTNAME, N_MIDDLEINITIAL, N_LASTNAME, N_COMMENT)
VALUES(5, 'Joan', 'M', 'Lambert', 'Navigation Officer');
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC2
(N_CREWKEY, N_FIRSTNAME, N_MIDDLEINITIAL, N_LASTNAME, N_COMMENT)
VALUES(6, 'Dennis', 'M', 'Parker', 'Chief Engineer');
CREATE OR REPLACE TABLE NOSTROMO_SRC3 (
N_CREWKEY NUMBER(38,0),
N_FIRSTNAME VARCHAR(50),
N_LASTNAME VARCHAR(50),
N_COMMENT VARCHAR(152)
);
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC3
(N_CREWKEY, N_FIRSTNAME, N_LASTNAME, N_COMMENT)
VALUES(7, 'Samuel', 'Brett', 'Engineers Mate');
INSERT INTO <YOUR_DATABASE>.<YOUR_SCHEMA>.NOSTROMO_SRC3
(N_CREWKEY, N_FIRSTNAME, N_LASTNAME, N_COMMENT)
VALUES(8, 'Jones', NULL, 'Ship''s Cat');
-
Add the 3 tables using the above commands.
-
Add the 3 tables as sources in Coalesce.
-
Add a Stage Node from
NOSTROMO_SRC1
and rename itSTG_NOSTROMO_COMBINED
-
From within
STG_NOSTROMO_COMBINED
select Options and toggle Multi Source to on. -
With multi source enabled, now inside of
STG_NOSTROMO_COMBINED
you'll see a column on the left listing all the sources for the multi source node. Inside ofSTG_NOSTROMO_COMBINED
, you can edit their names by clicking on them and editing the relevant text field. Rename the one source node to justSRC1
.There are two different zones for drag and drop, and they work differently. The top drop zone (blue in the image below) will attempt to map columns from the new source into those of the existing source, like in a UNION. The bottom drop zone (orange in the image below) is available in all nodes, and will add the columns as separate columns, like in a JOIN.
-
Add a new source to
STG_NOSTROMO_COMBINED
by clicking on the + symbol beneathSRC1
. -
Select and rename it
SRC2
. -
Now we will add
NOSTROMO_SRC2
by dragging it from the Nodes list on the left into the blue drop zone. -
Notice it didn't copy one of the columns,
N_MIDDLEINITIAL
, as this doesn't correspond to any fromSRC1
. Select that column specifically and drag it into the orange drop zone. -
Move the new
N_MIDDLEINITIAL
column to order it afterN_FIRSTNAME
. -
Open the Join tab for SRC2 >Generate Join>Copy to Editor.
-
Return to the Mapping area for
STG_NOSTROMO_COMBINED
. -
Add another source, renaming it
SRC3
. -
Drag
NOSTROMO_SRC3
into the blue area. -
Open the Join tab for
SRC3
> Generate Join> Copy to Editor. -
Return to the mapping area for
STG_NOSTROMO_COMBINED
. -
Create and Run the
STG_NOSTROMO_COMBINED
node and you'll see all the data combined.