7
 So let's assume the query is nested like Query +- DEPT DEPTNO DNAME LOC +- EMP EMPNO ENAME SAL DEPTNO . For each schema you have to ask yourself "How many elements do I want to have?" and dept has the dept columns plus the emp schema, emp has the emp columns. This query has as inputs three sources, the EMP, DEPT table plus a Row_Generation transform generating one row. How many repeats of the XML root nodes do you want to have? One obviously, an XML has to have one and only one root node. So we make the Query the current and modify the FROM clause so that only the Row_gen is listed. How many times do we want to see the DEPT tag? Once per DEPT row. So we make the DEPT schema the current and modify the FROM clause to be DEPT only. Now all columns within the DEPT schema can be set to values coming fro m the DEPT input table (plus the parent Row_Gen table but we don 't need that). Same thing for the EMP schema. How many EMP tags do we want to see inside each DEPT? As many EMPs as the department has. Hence we make that schema the current, the FROM clause is set to EMP only and we need a where clause for this schema: EMP.DEPTNO = DEPT.DEPTNO.

XML Schema Doc

Embed Size (px)

DESCRIPTION

learning purpose

Citation preview

So let's assume the query is nested like

Query +- DEPT DEPTNO DNAME LOC +- EMP EMPNO ENAME SAL DEPTNO.

For each schema you have to ask yourself "How many elements do I want to have?"

and dept has the dept columns plus the emp schema, emp has the emp columns.This query has as inputs three sources, the EMP, DEPT table plus a Row_Generation transform generating one row.How many repeats of the XML root nodes do you want to have? One obviously, an XML has to have one and only one root node. So we make the Query the current and modify the FROM clause so that only the Row_gen is listed.How many times do we want to see the DEPT tag? Once per DEPT row. So we make the DEPT schema the current and modify the FROM clause to be DEPT only. Now all columns within the DEPT schema can be set to values coming from the DEPT input table (plus the parent Row_Gen table but we don't need that).Same thing for the EMP schema. How many EMP tags do we want to see inside each DEPT? As many EMPs as the department has. Hence we make that schema the current, the FROM clause is set to EMP only and we need a where clause for this schema: EMP.DEPTNO = DEPT.DEPTNO.

For QT_GET , from clause we have to select Row_Generation only . Because we need QT_GET only once it is just output schema.

For DEPT schema( right click make as current) we need to select DEPT table only . We need all the departments should be occur .

In the EMP schema ( right click make as current) from clause should be from EMP only as we are taking fields from EMP table.

Below screenshot for nesting as my target schema.

Output is like this .

Because of Row_generation it occurred only once not many as no of departments.

Departments occurred based of no of departments only not join with EMP as we selected only DEPT in the from clause.

If we click on the EMP schema of department 10 we can see the above result. This is because of join condition between DEPT & EMP and from clause only EMP . If we select DEPT also it causes Cartesian product and we will not get desired result.I hope you understand the nesting from flat structures to nested structures.previous post explained about nesting as i told told it is some how expensive. Now loading data from xml to flat structures like tables/files.I am taking the output of the previous example as source here .

See the input data of the xml .

Here we can approach two ways to do un-nesting . one is xml pipe line is straight forward and second one using query transform .1. XML pipeline .

Drag the required columns to the output schema from input schema. It is very striaght forward.2. Query transform .

Drag the root schema(QT_GET_nt_1) as shown in the above picture to the output schema.Then right click on the root schema(QT_GET_nt_1) and select the option Unnest with sub-schemas. Then you will see arrow symbol on that schema and child schema also as shown in the screenshot.

You can see schema is un-nested , we can directly drag the required fields.Here if we want to load different tables then use different query transforms like DEPT & EMP as shown in the 1st screenshot and drag the required fields for the table.Here DEPT table is master table while dragging fields we have to use distinct as it was combination of EMP & DEPT data .