1 / 21

The Join and Union steps

The Join and Union steps. We will create a simple job demonstrating the Join and Union steps. We will assume that you are familiar with the Hello World program. Start by setting up your Global Workspace and Global Connection as you did for Hello World. Create Netezza tables.

biana
Download Presentation

The Join and Union steps

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Join and Union steps • We will create a simple job demonstrating the Join and Union steps. • We will assume that you are familiar with the Hello World program. • Start by setting up your Global Workspace and Global Connection as you did for Hello World.

  2. Create Netezza tables Create and populate two tables as follows: create table member_names (member_idint, member_namevarchar(30)); insert into member_namesvalues (1001, 'albert'); insert into member_namesvalues (1002, 'barbara'); insert into member_names values (1003, 'calvin'); insert into member_names values (1004, 'donna'); insert into member_names values (1005, 'earl'); create table member_scores (member_idint, pluses int, minuses int); insert into member_scores values (1002, 4, 5); insert into member_scores values (1003, 6, 6); insert into member_scores values (1006, 4, 3); insert into member_scores values (1007, 8, 2);

  3. Create a job named join_jb

  4. Create two table steps Place two table step icons on the job canvas, and connect them to the two tables you created.

  5. Create a join step Place a join step on the canvas, and connect the two tables steps to is, as shown above.

  6. Edit the join step Select MEMBER_ID from each column, then click on INSERT to set the join condition, as shown above. Then click OK/Save.

  7. Create output table step Place another table step on the palette, and connect the join step to it, as shown above. Note that the transformer connecting the JOIN step to the new TABLE step is black (meaning “not yet validated”).

  8. Edit output table step This time, use the “Create Table” option. Use a table name that doesn’t yet exist in the database.

  9. Now the transformer is red. Click on the arrow head of the (red) transformer to edit it.

  10. Editing the transformer When we open up the transformer, we see the mapping shown above. The is the mapping we want, so just click “OK”.

  11. Now the transformer is blue. …meaning that it is validated. We’re ready to run the job.

  12. Create and run batch • Save your job. • Create a batch job to run it. • Run the job. • Check the database verify that the correct table was created, and contains the correct output.

  13. Edit the join step Next, Edit the job, and change the Join Type to Left Outer. Click OK/Save.

  14. Edit the output table step Change the options to Existing Table, Truncate, and choose the output table that you created with the Join step.Click OK. The transformer will turn red again; open it up and click OK. Then run the job.

  15. Verify your output HELLO_DB(USER1)=> select * from join_out; MEMBER_ID | MEMBER_NAME | PLUSES | MINUSES -----------+-------------+--------+--------- 1002 | barbara | 4 | 5 1003 | calvin | 6 | 6 1004 | donna | | 1001 | albert | | 1005 | earl | | (5 rows) Is this what you got? Is this what you expected?

  16. Add union step Create another table step, also connected to MEMBER_NAMES. Disconnect the old MEMBER_NAMES step from the Join. Drag a Union step onto the palete, and connect both MEMBER_NAMES steps to it.

  17. Edit union step Edit the Union step and choose UNION ALL, as shown.

  18. Connect Union to Join Connect Union to Join as shown. There’s no need to re-edit the Join step, since the input metadata hasn’t changed. Save and run.

  19. Verify your output HELLO_DB(USER1)=> select * from join_out; MEMBER_ID | MEMBER_NAME | PLUSES | MINUSES -----------+-------------+--------+--------- 1001 | albert | | 1001 | albert | | 1002 | barbara | 4 | 5 1002 | barbara | 4 | 5 1004 | donna | | 1004 | donna | | 1005 | earl | | 1005 | earl | | 1003 | calvin | 6 | 6 1003 | calvin | 6 | 6 (10 rows) It should look something like this.

  20. Add a de-duplication step The De-Duplicate step removes duplicate records where every field value is the same. Add a De-Duplicate step between the join and the output table. Again, since there are no metadata changes, there is no need to refresh any transformers. Rerun, and check your output.

  21. Exercises • What would happen if you chose UNION instead of UNION ALL inside the Union step? • Create a new table with the same column definitions as MEMBER_NAMES, but different data. Connect the second MEMBER_NAMES table to this new table, and rerun the job, with various options for the Join and Union stages. • Create yet another MEMBER_NAMES table with data that overlaps with, but isn’t the same as the original MEMBER_NAMES table. Replace the Union step with the Minus step.

More Related