concept pipeline in category javascript

appears as: pipeline, The pipeline, pipelines, A pipeline
Data Wrangling with JavaScript

This is an excerpt from Manning's book Data Wrangling with JavaScript.

In this chapter, we’ll use the CDR to bridge the gap between our import and export code. This allows us to piece together data conversion pipelines from reusable code modules. We can mix and match import and export code to build a pipeline that converts data from any one format to any other.

In this chapter, we extend the conceptual model of our data pipeline to include multiple transformation stages to clean up, prepare, and transform our data. Figure 6.2 shows how arbitrary cleanup and preparation stages fit into the pipeline. It demonstrates how we can include any number of data transformation stages between import and export. We can use this model to build a data pipeline that can import from any one format, transform the data through multiple stages, and then export to any other format.

Listing 6.12 A more complex data pipeline constructed with Data-Forge (extract from listing-6.12.js)
dataForge.readFile(inputFileName)    #1  
 .parseCSV()    #2  
    .then(dataFrame => {
 return dataFrame.dropSeries([    #3  
 "exp_id",    #3  
 "dive_observations",    #3  
 "obs_topography"    #3  
 ])    #3  
 .parseDates([    #4  
 "start_datetime",    #4  
 "end_datetime"    #4  
 ],    #4  
 importDateFormat    #4  
 )    #4  
 .where(row =>    #5  
 moment(row.start_datetime).year() === 2014    #5  
 )    #5  
 .parseFloats("dive_temperature")    #6  
 .where(row => row.dive_temperature !== 0)    #7  
 .groupBy(row => row.country)    #8  
 .select(group => ({    #9  
 country: group.first().country,    #9  
 dive_temperature: group    #9  
 .select(row => row.dive_temperature)    #9  
 .average()    #9  
 }))    #9  
 .inflate()    #10  
 .asCSV()    #11  
 .writeFile(outputFileName);    #12  
    });

#1   At the start of the pipeline, we load survey.csv into memory.
#2   Parses CSV data from the data file
#3   Drops columns in which we aren’t interested. This makes the data a bit more compact.
#4   Parses the columns that contain dates
#5   Applies a filter because we’re only interested in rows of data from 2014
#6   Parses the column we’re interested in as floats
#7   Removes broken rows because these will skew our analysis
#8   Groups rows by country
#9   Transforms each group and creates new rows with the average temperature per country
#10   Inflates to a DataFrame, the output of groupBy is Series, but we want to return it to a DataFrame for output to a CSV file.
#11   Outputs the data in the CSV format
#12   Writes the CSV data to a file at the end of the pipeline

Figure 13.4 D3 creates a pipeline that converts our data set to a visualization.

c13_04.eps
Functional Programming in JavaScript

This is an excerpt from Manning's book Functional Programming in JavaScript.

4.1.2. Arranging functions in a pipeline

Functional programming removes the limitations present in method chaining and provides the flexibility to combine any set of functions, no matter where they come from. A pipeline is a directional sequence of functions loosely arranged so that the output of one is input into the next. Figure 4.4 illustrates this abstractly by connecting functions that work with different types of objects.

Figure 5.11. Same two functions as in figure 5.10; but this time the null value travels in a monad (Either or Maybe), which causes the rest of the functions in the pipeline to gracefully fail.