Skip to content

Example of a Process With Sub-process

This is an example of creating and running a parent process, which is consisting of two children sub-processes.

First, define the processes. Process parent1 will consist of two 'dependent' children sub-processes. The term dependent is used to highlight the fact that the children processes do not have their own input and output nodes - the children depend on the parent to provide them with input and print out their output.

$ cat child1.strm

// Name the process as child1
name child1

// Create an SQL node that reads from input queue and feeds into output1 queue
sql select * from input where lower(class1)="new york" into output1;
$ cat child2.strm

// Name the process as child2
name child2

// Create an SQL node that reads from input queue and feeds into output2 queue
sql select * from input where lower(class2)="los angeles" into output2;
$ cat parent1.strm

// Name the process as parent1
name parent1

// Read data from input.csv file
in input.csv -> input

// Define children subprocesses and their dependencies
subprocess child1(input)(output1)
subprocess child2(input)(output2)

// Write data to output csv files
out output1 -> output1.csv
out output2 -> output2.csv

The above processes require the following dictionary.csv and tables.csv files to be in the SRC directory.

name,type,descr,genFormat,arraylen
id,char
class1,char,,State
class2,char,,City
value,num
name,descr,type,inherit
input,Input table
id
class1
class2
value

output1,Output table1,,input

output2,Output table2,,input

Note, to declare a subprocess within a process, the subprocess must already exist. Therefore, to run process parent1, we must create the children processes first.

vor create process child1

vor create process child2

vor create process parent1

vor run parent1

An Inline form

Subprocesses can be defined inline in a single stream file. The above example could be written as the following:

// Name the process as parent1
name parent1

// Read data from input.csv file
in input.csv -> input

// Define children subprocesses and their dependencies
subprocess child1(input)(output1) {
    // Create an SQL node that reads from input queue and feeds into output1 queue
    sql select * from input where lower(class1)="new york" into output1;
}
subprocess child2(input)(output2) {
    // Create an SQL node that reads from input queue and feeds into output2 queue
    sql select * from input where lower(class2)="los angeles" into output2;
}

// Write data to output csv files
out output1 -> output1.csv
out output2 -> output2.csv

The declarations of the supprocesses could be further simplified by omiting the input and output declarations:

// Name the process as parent1
name parent1

// Read data from input.csv file
in input.csv -> input

// Define children subprocesses and their dependencies
subprocess child1 {
    // Create an SQL node that reads from input queue and feeds into output1 queue
    sql select * from input where lower(class1)="new york" into output1;
}
subprocess child2 {
    // Create an SQL node that reads from input queue and feeds into output2 queue
    sql select * from input where lower(class2)="los angeles" into output2;
}

// Write data to output csv files
out output1 -> output1.csv
out output2 -> output2.csv

Standalone SubProcesses

Another way to define or use sub-processes is to have 'independent' children. In contrast to our first example, independent children are standalone processes that read input and write output independent of their parent process. The parent process, parent2 in the following example, acts as an orchestrator for the children. In other words, the parent is only managing workflow - dictating which sub-processes to execute.

$ cat child1.strm

// Name process as child1
name child1

// Read from process.csv file
in input1.csv -> input1

// Create a node that read from input queue and feed into output1 queue
sql select * from input1 where lower(class1)="new york" into output1;

// Write out the results
out output1 -> output1.csv
$ cat child2.strm

// Name process as child2
name child2

// Read from process.csv file
in input2.csv -> input2

// Create a node that read from input queue and feed into output1 queue
sql select * from input2 where lower(class2)="los angeles" into output2;

// Write out the results
out output2 -> output2.csv
$ cat parent2.strm

//name process as parent2
name parent2

// Define children subprocesses to execute
subprocess child1(Null)(Null)
subprocess child2(Null)(Null)

Use the following dictionary.csv and tables.csv files for this example.

name,type,descr,genFormat,arraylen
id,char,,sequenceN
class1,char,,state
class2,char,,city
value,num,,uniform 0 1000 2
name,descr,type,inherit
input1,Input table1,,,
id
class1
class2,
value
input2,Input table2,,input1

output1,Output table1,,input1
output2,Output table2,,input2

Reminder: sub-processes must already exist in order to declare them in a parent process.

vor create process child1

vor create process child2

vor create process parent2

vor run parent2