Samples used for illustration

The WordCount sample is used to illustrate the debugger features.

The WordCount sample application counts the number of lines, words, and characters in an input file. The sample can be found at:

$STREAMS_INSTALL/sample/spl/application/WordCount

For most of the illustrations, this sample is used as a stand-alone application and thus all the operators in it are available within a single debug session.

Here is the source for the WordCount sample:

namespace sample;

composite WordCount
{
param
  expression<rstring> $file : getSubmissionTimeValue(”file”);

type
  WordCharStat = int32 words , int32 chars;
  LineStat = int32 lines , WordCharStat wcs;

graph

  stream<rstring line> Data = FileSource ()
  {
    param file : $file ;
          format : line ;
  }
  stream<LineStat> CountOneLine = Functor (Data)
  { 
    logic
      state :
      { 
        mutable list <rstring> tokens;
      }
      onTuple Data :
      { 
        tokens = tokenize (line , " \t" , false);
      } 
    output
      CountOneLine : lines = 1 , wcs = {words = size (tokens) , 
                     chars = length (line) + 1 };
  }
  stream<LineStat> CountAllLines = Custom(CountOneLine)
  { 
    logic
      state :
      { 
        mutable LineStat aggregate = { lines =0, wcs = {words=0, char s=0} };
      }
      onTuple CountOneLine :
      {
        aggregate.lines += CountOneLine.lines ;
        aggregate.wcs.words += CountOneLine.wcs.words;
        aggregate.wcs.chars += CountOneLine.wcs.chars;
      }
      onPunct CountOneLine :
      { 
        if (currentPunct()==Sys.FinalMarker)
           submit(aggregate, CountAllLines);
      }
  }

  () as Writer = Custom(CountAllLines)
  { 
    logic
      onTuple CountAllLines :
      { 
        println (CountAllLines);
      }
  }
}