No Results
Example: Changing a Column Type

For this example, we will be converting the values to exponential notation. We are going to use the following data:

Value|NUMBER
656
3
10601
55031
3090
352514
3941
4
506
6040
53
909278
168
6872
27684
866
195
94
9
77

JavaScript Transform

Instructions:

  1. Download the values.csv file.
  2. Create a Server Filesystem Connection.
  3. Create a CSV Feed off of the previously created connection.
    a) In File Name, upload the values.csv file and select it from the dropdown.
  4. Create a JavaScript Transform off of the CSV Feed, configured as follows:
    a) Provide a Transform Name (for example, Exponential_Values).
    b) In Script References > Referenced Datasets, make sure Values is selected.
    c) In Script, paste the following:
function getAttributes(sourceAttrs, nodeVars, secVars, sourceRecords) {
    var attributes = [];
    sourceAttrs.forEach(function(attrList) {
        attrList.forEach(function(attr) {
            if (attr.name === "Value") {
                // change the type from 'number' to 'string'
                attr.type = 'string';
                attributes.push(attr);
            }
        });
    });
    return jsAttributesSuccess(attributes);
}
 
function getRecords(sourceRecords, nodeVars, secVars, attributes) {
    var records = [];
    sourceRecords.forEach(function(recordList) {
        recordList.forEach(function(record) {
            // convert the value to exponential notation and store the record
            record.Value = record.Value.toExponential();
            records.push(record);
        });
    });
    return jsRecordsSuccess(records);
}

     d) Go to Data Preview to view the end result where the values are converted to exponential notation.


Terms | Privacy