on 03-29-2012 9:10 PM
Hi,
I'm getting SUPRESS; When i want to concat values from diffrent nodes.
example:
Node1: <11> <> <12> <> <> <13> <> <> <> <>
Node2: <21> <22> <23> <24> <25> <26> <27> <28> <29> <24>
should be Result: <1121> <1122><1223><1224><1225><1326><1327><1328><1329><1324>
<> is no value or no node occures.
help is appriciated.
thanks.
Prema Boodi
Hi Prema
You can write a UDF to do this.
Take two inputs A and B for Node1 and Node2
String s1=A[0]
for (int i=0;i<A.length();i++)
{ if (A[i]=="")
{ res=s1.concat(B[i];
else
{ res=A[i].concat(B[i]);
s1=A[i];
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sourabh Nirmal,
Let me make few small corrections to your code, as I'm afraid it won't work as required. First of all, string comparisons in Java usually do not work well when formulated like this: if (A[i]==""). Use equals() function instead. Moreover, I think I made the code more understandable. And finally, the important thing was to add result.addValue() statement.
String s1=A[0];
for (int i=0;i<A.length();i++)
{
if (!(A[i].equals(""))) s1 = A[i];
res = s1.concat(B[i];
result.addValue(res);
}
Prema Boodi, make sure your UDF's execution type is all values of queue, otherwise it might give surprising results.
Regards,
Greg
thank you both; but why do i get this error:
can u please be more specific on this...
field in subnode1 occurs only sometimes or subnode1 itself will occur sometimes..?
if subnode1 occurs only sometimes: u can't concatinate untill and unless u have an unique identifier between subnode1 and subnode2.
if field in subnode1 occurs only sometimes: use the below code in the udf. it will work.
String s1="";
String s2="";
for (int i=0;i<B.length;i++)
{
if (!(A[i].equals("")))
{
s1 = A[i];
s2 = s1.concat(B[i]);
result.addValue(s2);
}else{
s2 = s1.concat(B[i]);
result.addValue(s2);
}
}
hope this clarifies.
Hi Prema Boodi,
I guess there is no need for that. Only now did I realize that you do not have an EMPTY value when Node1 is missing, but you have SUPRESS instead (according to your initial post). So a slight change to the UDF should get the job done finally:
String s1 = "";
for (int i=0;i<A.length();i++) {
if (!(A[i].equalsIgnoreCase(ResultList.SUPRESS)))
s1 = A[i];
res.addValue(s1.concat(B[i]);
}
There is no need for further complications, ELSE conditions and so on. The only change is to compare the currently checked value with SUPRESS, not an empty string
Hope this helps,
Greg
i am also facing the same issue...
use the udf code that i have pasted 10 min back...
String s1="";
String s2="";
for (int i=0;i<B.length;i++)
{
if (!(A[i].equals("")))
{
s1 = A[i];
s2 = s1.concat(B[i]);
result.addValue(s2);
}else{
s2 = s1.concat(B[i]);
result.addValue(s2);
}
}
input values to the udf:
input1: field in subnode1->mapwithdefault->removecontexts
input2: field in subnode2->removecontexts
output value of the udf should be mapped to splitbyvalue(each value) function and then to the target field.
the below code worked like a charm; thanks so much everyone.
String s1="";
for (int i=0;i<A.length;i++)
{
if (!(A[i].equals("")))
s1 = A[i];
res.addValue(s1.concat(B[i]));
}
with Veerendra's logic:
input1: field in subnode1->mapwithdefault->removecontexts
input2: field in subnode2->removecontexts
output value of the udf should be mapped to splitbyvalue(each value) function and then to the target field.
Dear Baskar,
I believe else block is not necessary here. See that the only thing we do conditionally is we set the value of the temporary variable s1 (only under the condition that the value exists). Later, we always concatenate the current value of s1 with the second argument - either s1 is equal to current Node1 value, or any existing previous one (last value that did exist).
So I believe the only thing my code was missing is the information from the initial post - that "empty" is not "" (empty string), but SUPRESS.
Hope you got that clear now,
Greg
cross check the code
String s1="";
for (int i=0;i<A.length;i++)
{
if (!(A[i].equals("")))
s1 = A[i];
res.addValue(s1.concat(B[i]));
}
i hope it will not work it will not work for the muiltiple values. Do thorough testing(Ex: Field1: 1, field1:no value, field1: 2 and field2:3, field2:4, field2: 5... your output should be 13,14,25).. cross check...
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.