Copying the input field to a string in build-op

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
dsusr
Premium Member
Premium Member
Posts: 104
Joined: Sat Sep 03, 2005 11:30 pm

Copying the input field to a string in build-op

Post by dsusr »

Hi,

I am trying to create a build-op stage that takes the input column and do all the processing on that field and pass it to output.

Input column is coming as Varchar field. Can anyone please tell me how to copy this VarChar column to a string and also how to find the total length of this varchar field.

I have also tried the search option on the forum but didnt get anything specific to this problem :(

Thanks
dsusr
thompsonp
Premium Member
Premium Member
Posts: 205
Joined: Tue Mar 01, 2005 8:41 am

Post by thompsonp »

The datatype of your input column is an APT_String.

The methods available for this class are defined in string.h and basicstring.h which you can find in $APT_ORCHHOME/include/apt_util.

You may not need to convert to a normal C string depending on what you need to do as there are lots of methods available for an APT_String.

If you do need to convert look at basicstring.terminatedContent().

I imagine your output datatype will also need to be an APT_String so if you do convert the input you'll have to convert it back again.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

As thompsonp mentioned, the input column will actually be treated as APT_String within the buildop. A char(6) will be mapped to string[6] and a varchar(6) will be mapped to string[max=6].

APT_String is a C++ class, as is its parent APT_BasicString, and together they many methods for manipulating themselves. (note: all of the methods for APT_BasicString work against anything defined as APT_String). The header files are your best reference for those methods.

In regards to you length question, there is a length method:

Code: Select all

// If you have a target field myStringLength of type APT_Int32 
// for containing the length
out.myStringLength = in.myString.length();

// If you want to capture the length in a local variable (either
// a PX class object or a normal C-type variable)
APT_Int32 myStringLength;
int length;
myStringLength = in.myString.length();
length = in.myString.length()

// If you want to use the length in a calculation
if (in.myString.length() > 0) {
    out.myStringCopy = in.myString;
} else {
    out.myStringCopy_setnull();
}

Hope this helps,

Brad.
dsusr
Premium Member
Premium Member
Posts: 104
Joined: Sat Sep 03, 2005 11:30 pm

Post by dsusr »

Hi,

Thanks Brad and Thomsonp for ur suggestions. I was able to partially solve the problem. The problem why I was not using the APT_String was that it consists of const char* type record.

But we were applying the complete logic in C++ by passing the character string to a function. So if I change this to APT_String some new errors comes in that function. And if try to use without changing to APT_String, I got SIGSEGV at runtime.

Still trying some way to solve the problem :(

Thanks
dsusr
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

If you a willing to post the function, maybe another pair of eyes can help.

If memory serves me correctly, SIGSEGV abends often occur when a C-type string (a.k.a a character array) is overrun. That is, you have a 6-character string that you are trying to load into a 6-byte character array, forgetting that the 7th byte is also required to hold the null-terminator. or you are trying to access an element of the array that is out-of-bounds (trying to access byte 8 on a 7-byte character array).

Brad.
Post Reply