# Denormalizer example

**URL:** <https://forum.cloverdx.com/t/denormalizer-example/1049>\
**Category:** CloverDX Platform\
**Created:** [April 10, 2012, 12:00am UTC](https://forum.cloverdx.com/t/denormalizer-example/1049 "2012-04-10T00:00:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pro7](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@pro7](https://forum.cloverdx.com/u/pro7)\
**Post date:** [April 10, 2012, 12:00am UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/1 "2012-04-10T00:00:00Z")

</div>

Hi all,  
I am looking for a simple Denormalizer example using CTL. Please don’t point me to the Users guide or Wiki. I have already been to both places. What I am trying to do is fairly simple but I keep getting:

Message: Denormalization failed! caused by: java.lang.ArrayIndexOutOfBoundsException: 0

Thanks  
pro7

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [April 11, 2012, 10:55am UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/2 "2012-04-11T10:55:41Z")

</div>

Hi pro7,

It looks like bug in Clover, but you didn’t provide me enough information to advise you. Please send me:

\* version of clover  
\* your graph (possibly simplified, privacy detail removed, …)  
\* sample of data

Then I can reproduce and solve your problem.

---

<div class="post-metadata">

**Author:** ![pro7](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@pro7](https://forum.cloverdx.com/u/pro7)\
**Post date:** [April 17, 2012, 5:52pm UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/3 "2012-04-17T17:52:19Z")

</div>

Thanks.  
We are running 3.0. Probably not a bug. Most likely my misunderstanding. A simple example below.

Restaurant Rated  
Name Category Score

Daniel Cost A  
Daniel Service B  
Daniel Food A+

Blue Hill Cost B-  
Blue Hill Service A  
Blue Hill Food B  
Blue Hill Parking C

Antonio’s Cost A  
Antonio’s Service B  
Antonio’s Food A-

Now let’s say we are looking for a result like :

Daniel | A | B | A+

Blue Hill | B- | A | B | C

Antonio’s | A | B | A-

Is Normalizer a correct choice for this type of transformation?

If I understand correctly, we need to implement, at a minimum, a count() function, and a transform() function. What might they look like for the above example?

Thank You

pro7

---

<div class="post-metadata">

**Author:** ![pro7](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@pro7](https://forum.cloverdx.com/u/pro7)\
**Post date:** [April 17, 2012, 5:55pm UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/4 "2012-04-17T17:55:23Z")

</div>

Sorry…I meant to say “Is Denormalizer a correct choice for this type of transformation?”

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [April 18, 2012, 8:29am UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/5 "2012-04-18T08:29:05Z")

</div>

Hi pro7,

yes, denormalizer is good component for this. See attached sample I created.

It produces:

```auto

INFO [TRASH0_0] - +-------+------------+-------+----------+-------+----------+
INFO [TRASH0_0] - |Record |name |Cost |Service |Food |Parking |
INFO [TRASH0_0] - +-------+------------+-------+----------+-------+----------+
INFO [TRASH0_0] - |# 1 |Antonio's |A |B |A- | |
INFO [TRASH0_0] - |# 2 |Blue Hill |B- |A |B |C |
INFO [TRASH0_0] - |# 3 |Daniel |A |B |A+ | |
INFO [TRASH0_0] - +-------+------------+-------+----------+-------+----------+

```

- [test\_denormalizer.zip](https://cdn.cloverdx.com/forum/15157%5F93449390954032160a0e552919ff8e2d/test%5Fdenormalizer.zip)

---

<div class="post-metadata">

**Author:** ![pro7](https://avatars.discourse-cdn.com/v4/letter/p/13edae/32.png) [@pro7](https://forum.cloverdx.com/u/pro7)\
**Post date:** [April 18, 2012, 6:10pm UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/6 "2012-04-18T18:10:33Z")

</div>

Thank you. I’ll study in detail but I’m wondering if the sample is using some feature not supported in my release (3.0)?

I say this because when I open the graph I see errors.

Unable to resolve input metadata ‘in’  
Unable to resolve input metadata ‘out’

The sample has a Metadata named Result, and another named to\_normalize\_txt. I can change $in to $to\_normalize\_txt but I still get an error on the line  
of code in transform:

$out.0.\* = res.\*;

I tried a number of things here but can’t get rid of the error. Anyway, thanks again, this might be enough to get me going in the right direction.

pro7

---

<div class="post-metadata">

**Author:** ![David\_Hlidek](https://avatars.discourse-cdn.com/v4/letter/d/58f4c7/32.png) [@David\_Hlidek](https://forum.cloverdx.com/u/David_Hlidek)\
**Post date:** [April 19, 2012, 1:04pm UTC](https://forum.cloverdx.com/t/denormalizer-example/1049/7 "2012-04-19T13:04:16Z")

</div>

For 3.0 you need to change CTL2 transformation to:

```auto

//#CTL2

Result res;

function integer append() {
	//set name

	res.name = $0.Name;
	
	if ($0.Type=="Cost") {
		res.Cost = $0.Rate;
	} else if ($0.Type=="Service") {
		res.Service = $0.Rate;
	} else if ($0.Type=="Food") {
		res.Food = $0.Rate;
	} else if ($0.Type=="Parking") {
		res.Parking = $0.Rate;
	} else {
		raiseError("Unknown type '"+$0.Type+"'");
	}
	
	return OK;
}

function integer transform() {
	//send prepared record to output
	$0.* = res.*;
  	return OK;
}

function void clean() {
	res.name = "";
	res.Cost = "";
	res.Service = "";
	res.Food = "";
	res.Parking = "";
}

```
