Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: awilliams1024Hi,
For a particular field, all its records (cells) must have the same data type - unlike with, say, Microsoft Excel.
In the case of your code, the data type of the transactionID field is being determined when the node logic is compiled (i.e. before the first record is processed), and as the final assignment for the transactionID is to a string variable, the output field is given a string data type.
The simplest way to set the data type for a field is to use the Data Analyzer node (which can be found in the publishing and patterns category of the library) to scan the data and automatically convert the field to the most appropriate data type.
However, this node will attempt to convert all fields in the data set. If you do not want to modify all the fields in the data set then it would be necessary to split out the field(s) to be processed by the Data Analyzer node from the other fields and join them together when the data type analysis and conversion has been completed. The attached data flow shows how this can be achieved. When the original data set has been split an additional record ID field is inserted so that the data sets can be reliably merged together after the conversion has been performed.
In the example the first test data set has all numeric values in the 'nr' field. In the second (lower) test data set there is a non-numeric value in the third record. To show that all records are being converted by the Data Analyzer node, the 'rand' field has all numeric values but uses a string data type field.
Regards,
Adrian
Attachments:
Convert_to_string_or_integer.brg