Page 1 of 1

Possible truncation of variable length string

Posted: Mon Apr 11, 2011 8:13 am
by karthi_gana
All,

I have a simple job which will generate the header and current date.
The job design is:

Row Generator --> Tranformer --> Export Column --> SeqFile

Header1 varchar(20)
Header2 varchar(20)

'UHDR' = Header1
DateToString(currentdate(),"%yyyy%ddd") = Header2

export_header:

exported_col varchar(255)

header1 & header2 will be stored in 'exported_col' as below


UHDR|2011101


when i run the job, i am getting the below error message.

export_header: When checking operator: When binding output interface field "exported_col" to field "exported_col": Implicit conversion from source type "string" to result type "string[max=255]": Possible truncation of variable length string.

why? I don't understand this error message.

Posted: Mon Apr 11, 2011 8:35 am
by jwiles
In your job, the column export stage is outputting an unbounded varchar() column (no defined max length). By placing a length of 255 on the output link metadata for the column, you have told the parallel engine to limit the length to 255 bytes (bounded varchar() ). This is done immediately after the operator when the job runs (look in the generated OSH for a modify statement attached to the output of the export operator). The warning is there because of the change from unbounded to bounded varchar().

Regards,

Posted: Tue Apr 12, 2011 3:27 am
by karthi_gana
How to avoid this warning message? if i specify char(255), will it resolve the warning message?

Posted: Tue Apr 12, 2011 5:01 am
by ray.wurlod
Always specify a maximum string length (VarChar(255) for example) or always specify unbounded VarChar.

There are pros and cons to both approaches, discussed elsewhere.

Posted: Tue Apr 12, 2011 5:14 am
by karthi_gana
you mean

Header1 varchar(255)
Header2 varchar(255)

something like this..

Posted: Tue Apr 12, 2011 5:15 am
by karthi_gana
ray.wurlod wrote:Always specify a maximum string length (VarChar(255) for example) or always specify unbounded VarChar.

There are pros and cons to both approaches, discussed elsewhere.
It is already specifiad as varchar(255) only. :roll:

Posted: Tue Apr 12, 2011 5:16 am
by karthi_gana
unbounded VarChar
how should i specifiy it?

Posted: Tue Apr 12, 2011 6:24 am
by rohithmuthyala
Do not specify any limit define it as varchar()..!

Posted: Wed Apr 13, 2011 3:50 am
by karthi_gana
rohithmuthyala wrote:Do not specify any limit define it as varchar()..!
Yes. It works fine now.