Building DataFlow Applications Using RushScript : Executing a Graph : Implicit Execution
 
Share this page                  
Implicit Execution
It is not required to explicitly invoke the dr.execute() method within RushScript code. If the code is composing a single application, then calling dr.execute() directly is optional.
After evaluating all RushScript source files within the environment the current graph will be executed if it has any composition elements. For example, the following RushScript code composes a DataFlow application but does not execute it. Running this script within the RushScript environment will cause the composed application to be executed automatically.
RushScript without an explicit call to dr.execute()
// Define ratings schema
var ratingschema = dr.schema()
    .nullable(true)
    .trimmed(true)
    .INT("userID")
    .INT("movieID")
    .DOUBLE("rating")
    .INT("timestamp");

// Read the ratings
var ratings = dr.readDelimitedText({source:'ratings.txt', schema:ratingschema, fieldSeparator:"::", header:true});

// Count and average the ratings per user
var aggs = [
    Aggregation.count("rating").as("count"), 
    Aggregation.min("rating").as("min"),
    Aggregation.max("rating").as("max"),
    Aggregation.avg("rating").as("avg"),
    Aggregation.stddev("rating").as("stddev")
];
var results = dr.group(ratings, {keys:'userID', aggregations:aggs});

// Write the results to a delimited text file.
dr.writeDelimitedText(results, {target:'ratings-group.txt', mode:WriteMode.OVERWRITE, header:true, fieldDelimiter:"", writeSingleSink:true});