Examples of partial update operations using tMDMOutput - 6.3

Talend Open Studio for Big Data Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Open Studio for Big Data
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

The section will demonstrate how to set the parameters in the component tMDMOutput to perform the partial update operations with several examples.

Partial update with Overwrite enabled or disabled

The following two examples explain how to add some elements to an existing item (entity) with multi-occurrence elements (attributes) and then update the newly added elements based on the content of a source XML stream.

Given an existing item as follows:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	<Houses>
		<House>[1]</House>
		<House>[2]</House>
		<House>[3]</House>
	</Houses>
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
	</Children>
<Person>

Example 1: If you want to add two Child items to the existing item, then the Xpath you enter in the Pivot field must read as follows: /Person/Children/Child where the Overwrite check box is cleared, and the Key field is set to /Name. Note that the Child element is of complex type, and needs to be identified with the Key field. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Children>
		<Child>
			<Name>k2</Name>
		</Child>
		<Child>
			<Name>k3</Name>
		</Child>
	</Children>
</Person>

In this case, the two child items Child [k2] and Child [k3] will be added, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	<Houses>
		<House>[1]</House>
		<House>[2]</House>
		<House>[3]</House>
	</Houses>
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
		<Child>
			<Name>k2</Name>
		</Child>
		<Child>
			<Name>k3</Name>
		</Child>
	</Children>
</Person>

Example 2: If you want to change the names of the two child items Child [k2] and Child [k3], then the Xpath you enter in the Pivot field must read as follows: /Person/Children/Child where the Overwrite check box is selected, and the Key field is set to /Name. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Children>
		<Child>
			<Name>Tina</Name>
		</Child>
		<Child>
			<Name>Tommy</Name>
		</Child>
	</Children>
</Person>

In this case, the names of the two child items Child [k2] and Child [k3] will be updated, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	<Houses>
		<House>[1]</House>
		<House>[2]</House>
		<House>[3]</House>
	</Houses>
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
		<Child>
			<Name>Tina</Name>
		</Child>
		<Child>
			<Name>Tommy</Name>
		</Child>
	</Children>
</Person>

Partial update with Delete enabled

The following examples show how to remove some elements from an existing item (entity) with multi-occurrence elements (attributes) based on the content of a source XML stream.

Given an existing item as follows:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	<Houses>
		<House>[1]</House>
		<House>[2]</House>
		<House>[3]</House>
	</Houses>
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
		<Child>
			<Name>k2</Name>
			<Age>2</Age>
		</Child>
		<Child>
			<Name>k3</Name>
			<Age>3</Age>
		</Child>
	</Children>
	<Habits>
		<Habit>Basketball</Habit>
		<Habit>Football</Habit>
		<Habit>Tennis</Habit>
		<Habit>Boxing</Habit>
	</Habits>
	<Pets>
		<Pet>Cat</Pet>
	</Pets>
	<Pets>
		<Pet>Dog</Pet>
	</Pets>
	<Pets>
		<Pet>Pig</Pet>
	</Pets>
	<Pets>
		<Pet>Cow</Pet>
	</Pets>
</Person>

Example 1: If you want to remove two child items from the existing item, then the Xpath you enter in the Pivot field must read as follows: /Person/Children/Child where the Delete check box is selected, and the Key field is set to /Name. Note that the Child element is of a complex type, and needs to be identified with the Key field. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Children>
		<Child>
			<Name>k2</Name>
		</Child>
		<Child>
			<Name>k3</Name>
		</Child>
	</Children>
</Person>

In this case, the two items Child [k2] and Child [k3] will be removed, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	...
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
	</Children>
	...
</Person>

Example 2: If you want to remove some habits for the Person element, then the Xpath you enter in the Pivot field must read as follows: /Person/Habits/Habit where the Delete check box is selected, and the Key field is set to . or empty. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Habits>
		<Habit>Basketball</Habit>
		<Habit>Football</Habit>
		<Habit>Boxing</Habit>
	</Habits>
</Person>

In this case, the three habit items Habit [Basketball], Habit [Football] and Habit [Boxing] will be removed, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	...
	<Habits>
		<Habit>Tennis</Habit>
	</Habits>
	...
</Person>

Example 3: If you want to remove some habits for the Child [k1] element, then the Xpath you enter in the Pivot field must read as follows: /Person/Children/Child[1]/Habits/Habit where the Delete check box is selected, and the Key field is set to . or empty. Note that Child[1] is used in the Pivot field to identify the habits of which child will be removed. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Children>
		<Child>
			<Habits>
				<Habit>Basketball</Habit>
				<Habit>Football</Habit>
			</Habits>
		</Child>
	</Children>
</Person>	

In this case, the two items Habit [Basketball] and Habit [Football] will be removed, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	...
	<Children>
		<Child>
			<Name>k1</Name>
			<Age>1</Age>
			<Habits>
				<Habit>Tennis</Habit>
				<Habit>Boxing</Habit>
			</Habits>
		</Child>
		<Child>
			<Name>k2</Name>
			<Age>2</Age>
		</Child>
		<Child>
			<Name>k3</Name>
			<Age>3</Age>
		</Child>
	</Children>
	...
</Person>

Example 4: If you want to remove some pets for the Person element, then the Xpath you enter in the Pivot field must read as follows: /Person/Pets where the Delete check box is selected, and the Key field is set to /Pet. Moreover, you need to provide the source XML stream as follows:

<Person>
	<Id>1</Id>
	<Pets>
		<Pet>Cat</Pet>
	</Pets>
	<Pets>
		<Pet>Pig</Pet>
	</Pets>
</Person>

In this case, the two items Pet [Cat] and Pet [Pig] will be removed, and you will get the following result:

<Person>
	<Id>1</Id>
	<Name>p1</Name>
	...
	<Pets>
		<Pet>Dog</Pet>
	</Pets>
	<Pets>
		<Pet>Cow</Pet>
	</Pets>
</Person>