cancel
Showing results for 
Search instead for 
Did you mean: 

Need UDF to delete duplicates from same context

Former Member
0 Kudos

Hi friends,

I was trying to write an udf to delete the duplicate values from same context but couldn't get any success.

Source Data

V1
V1
V2
V2
V3
Context Change
V1
V1
V6
V9

I want Result As:

V1
V2
V3
Context Change
V1
V6
V9

I Cannot use CollapseContext because I need to maintain the ContextChange as it is.

Thanks in advance.

Regards,

Sarvesh

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

Try this

boolean flag = false;

int k=0;

 String[] output = new String [input1.length] ; 

if (input1.length != 0) {

output[k] = input[0];

k++;

for (int i = 1;i<input1.length;i++) {

for (int j = 0; j<output1.length; j++) {

if (input1<i> == output[j]) {

flag=true;

break;

}

else {

flag=false;

}

}

if (!flag) {

output[k] = input<i>;

k++;

}

flag = false;

}

for (int l=0; l<output.length;l++) result.addValue(output[l];

}

input1 is the input and output is the actual output

Regards

Suraj

Edited by: S.R.Suraj on Sep 4, 2009 6:20 AM

Former Member
0 Kudos

Hi Suraj,

There were some little issues in udf which I fixed, but it gives me result as it is without any change. No duplicates were removed.

boolean flag = false;

int k=0;

 String[] output = new String [input1.length]; 

if (input1.length != 0) {
output[k] = input1[0];
k++;
for (int i = 1;i<input1.length;i++) {
for (int j = 0; j<output.length; j++) { 
if (input1<i> == output[j]) {
flag=true;
break;
}
else {
flag=false; 
}
}

if (!flag) {
output[k] = input1<i>;
k++; 
} 
flag = false;
}

for (int l=0; l<output.length;l++)
result.addValue( output[l] );
}

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

Check whether you have written an advanced udf with Context values

Regards

Suraj

Former Member
0 Kudos

Yes it is advance udf with Cache set as Context.

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

I checked the UDF and it is working

Make sure that each context in input has multiple values as per your first post. Something like this

V1

V1

V2

V2

V3

CONTEXT CHANGE

V2

V3

And it is working

Regards

Suraj

Former Member
0 Kudos

Hi Suraj,

In you code you have used input instead on input1 and without using array that I have replaced with input1 using array i.

Please test code which I have sent and see if it works in your system.

Regards,

Sarvesh

former_member187339
Active Contributor
0 Kudos

Hio Sarvesh,

The signature of my code which I tested was

public void Test (String[] input, ResultList result, Container container) throws StreamTransformationException{

}

Try making your signature like this and give your input as per your first post and it will work

Regards

suraj

Former Member
0 Kudos

> The signature of my code which I tested was

> public void Test (String[] input, ResultList result, Container container) throws StreamTransformationException{

> }

But when I created udf, my signature looks like as shown below and still I am not getting the results.

>public void Test(String[] input,ResultList result,Container container){

What I did,

1. Created udf of type Cache: Context

2. Given Argument as input

Now when I paste your code, it gives error about input1 & output1, so I changed it to input & output. But still no luck.

I am working on XI3.0 SP 22.

Secondly not necessary that every context will have duplicates. So it could be like this also..

V1

ContextChange

V2

V2

V3

ContextChange

V4

ContextChange

V5

V5

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

Can you paste here the actual input going into the udf and provide the graphical mapping steps that you have used

Regards

Suraj

Former Member
former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

Just now saw, your signature

>>public void Test(String[] input,ResultList result,Container container){

Says input1 to be input. Also check in your udf thorougly for input and input1 mismatch

Regards

Suraj

Former Member
0 Kudos

Suraj,

I made the input argument as input1. and now it is throwing error. Can not resolve input & output1.

So because of this error, last time I changed input1 to input & output1 to output.

In your code somewhere you have used input and somewhere input1 and also somewhere output & output1.

Can you please review your code again and send the udf again to avoide the confusion.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

Check this code and let me know

public void Samp(String[] a, ResultList result, Container container) throws StreamTransformationException

{

int k=0;

String b[]= new String[100];

for (int i=0;i<a.length;i++)

{

char flag=0;

if(a<i>.equals(ResultList.CC))

{

result.addValue(ResultList.CC);

flag=1;

}

else

{

for(int j=i1;j<a.length;j+)

{

if(a<i>.equals(a[j]))

{

flag= 1;

}

}

}

if (flag==0)

{

b[k]=a<i>;

result.addValue(b[k]);

k++;

}

}

Regards

Ramesh

Edited by: Venkataramesh Boppana on Sep 4, 2009 10:32 PM

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

Use this code (this is tested in the MEssage Mappiing)

public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{

boolean flag = false;

int k=0;

String[] output = new String [input.length];

if (input.length != 0) {

output[k] = input[0];

k++;

for (int i = 1;i<input.length;i++) {

for (int j = 0; j<output.length; j++) {

if (input<i> == output[j]) {

flag=true;

break;

}

else {

flag=false;

}

}

if (!flag) {

output[k] = input<i>;

k++;

}

flag = false;

}

for (int l=0; l<output.length;l++)

result.addValue( output[l] );

}

}

Regards

Suraj

Former Member
0 Kudos

Hi Suraj & Ramesh,

Thanks for your help, but still result in not populating..

I think the udf, which you people have provided is not working because in my system when I create the udf it create a different signature then your's. May be because I am on XI3.0 SP22 and you are on PI.

Your's Signature:

public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{

My Signature:

public void calculate(String[] var1, ResultList result, Container container){

So whenever I use your codes it throws below error.

'class' or 'interface' expected.

Any way I created below UDF and it is working fine, but the problem is here I need to assign the array memory to v_current in advance which is not good.

And when I try to give

String[] v_current = new String [var1.lenght];

then in case of single value in context throws the error "ArrayIndexOutOfBound".

Can you suggest some better solution.

My code is:

String[] v_current = new String [100];

int k = 0;

v_current[k] = "";

for(int i = 0; i<var1.length; i++)
{
  if( var1.length == 1 )
	{
		result.addValue( var1<i> );
	}
  else  if( var1<i>.compareTo(v_current[k]) != 0)
	{
		result.addValue( var1<i> );
	        k++;
	}
  v_current[k] = var1<i>;
}

Regards,

Sarvesh.

former_member187339
Active Contributor
0 Kudos

Hi,

Try to modify your code like this

 String[] v_current = new String [var1.length];
for(int i = 0; i<var1.length-1; i++)
{
  if( (var1.length -1) == 1 )
	{
		result.addValue( var1<i> );
	}
  else  if( var1<i>.compareTo(v_current[k]) != 0)
	{
		result.addValue( var1<i> );
	        k++;
	}
  v_current[k] = var1<i>;
}

PS: When there is one value the actual array length is '2' because of the presence of "context"

Regards

Suraj

Former Member
0 Kudos

> PS: When there is one value the actual array length is '2' because of the presence of "context"

No, it always takes the actual length. It will not count context, so if there is a single value in one context then the length will be '1'.

So this will not work.

former_member187339
Active Contributor
0 Kudos

Hi Sarvesh,

I tried both these code and they were working. In the second code you are definitely missing some parenthesis. Give a complete check:


public void sdn(String[] var1, ResultList result, Container container) throws StreamTransformationException{

int len =var1.length;
String[] v_current = new String [len];

int k = 0;
 
v_current[k] = "";
 
for(int i = 0; i<var1.length; i++)
{
  if( var1.length == 1 )
	{
		result.addValue( var1<i> );
	}
  else  if( var1<i>.compareTo(v_current[k]) != 0)
	{
		result.addValue( var1<i> );
	        k++;
	}
  v_current[k] = var1<i>;
}
}

AND


public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{
boolean flag = false;
int k=0;
int len = input.length;

String[] output = new String [100]; 
 
if (input.length != 0) {
	output[k] = input[0];
	k++;
	for (int i = 1;i<input.length;i++) {
		for (int j = 0; j<output.length; j++) { 
			if (input<i> == output[j]) {
				flag=true;
				break;
			}	
			else {
				flag=false; 
			}
		}
		
		if (!flag) {
			output[k] = input<i>;
			k++; 
		} 
		
		flag = false;
	}
 
	for (int l=0; l<output.length;l++)
			result.addValue( output[l] );

}
}

Regards

Suraj

Edited by: S.R.Suraj on Sep 7, 2009 6:12 AM

Former Member
0 Kudos

Hello friends,

Thanks for you help and time.

Finally it has been solved based on your inputs.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Suraj,

below is the code which is working perfectly in system..

Hint: No need to increment v_current.

String[] v_current = new String [var1.length];
v_current[0] = "";

for(int i = 0; i<var1.length ; i++)
{
	 if( var1.length == 1 )
	{
		result.addValue( var1<i> );
	}
                      else  if( var1<i>.compareTo(v_current[0]) != 0)
	{
		result.addValue( var1<i> );
		 v_current[0] = var1<i>;
	}

}

Regards,

Sarvesh