IBM InfoSphere Streams Version 4.1.0

Operator Format

Primitive operator image not displayed. Problem loading file: ../../image/tk$spl/op$spl.utility$Format.svg

The Format operator is similar to the FileSink, TCPSink, and UDPSink operators, in that it converts SPL tuples into formatted data. The Format operator writes data in many formats (such as line or bin), therefore the output of the operator is generated as a blob attribute.

Checkpointed data

When the Format operator is checkpointed, logic state variables (if present) are saved in checkpoint.

Behavior in a consistent region

The Format operator can be an operator within the reachability graph of a consistent region. It cannot be the start of a consistent region. In a consistent region, a Functor operator stores its state when a checkpoint is taken. When the region is reset, the operator restores the state from the checkpoint.

Checkpointing behavior in an autonomous region

When the Format operator is in an autonomous region and configured with config checkpoint : periodic(T) clause, a background thread in SPL Runtime checkpoints the operator every T seconds, and such periodic checkpointing activity is asynchronous to tuple processing. Upon restart, the operator restores its state from the last checkpoint.

When the Format operator is in an autonomous region and configured with config checkpoint : operatorDriven clause, no checkpoint is taken at runtime. Upon restart, the operator restores to its initial state.

Such checkpointing behavior is subject to change in the future.

Examples

This example uses the Format operator.

composite Main {
  graph
    stream<rstring s, float64 d, rstring q> A = Beacon() {
      param iterations : 100u;
      output A         : s = "hi", q = "ho", d = 6.7;
    }
/*
 * format the input tuple (except for attribute s, which is passed separately)
*/
   stream<blob b, rstring inputData> B = Format (A) {
      param suppress : s;
      // 'b' will contain '6.7,"ho"\n"'
      // inputData is set from attribute s
      output B       : b = Output(), inputData = s;
    }
    // Strip down to just the blob and print some of the input tuple.
    stream <blob b> JustBlob = Functor (B) {
      logic onTuple B : { println (inputData); }
      JustBlob        : b = b;
    }
    // Write out the formatted data to a file
    () as Nul = FileSink (JustBlob) {
      param file   : "out";
            format : block;
    }
}

Summary

Ports
This operator has 1 input port and 1 output port.
Windowing
This operator does not accept any windowing configurations.
Parameters
This operator supports 7 parameters.

Optional: format, eolMarker, writePunctuations, hasDelayField, separator, quoteStrings, suppress

Metrics
This operator does not report any metrics.

Properties

Implementation
C++
Threading
Always - Operator always provides a single threaded execution context.

Input Ports

Ports (0)

The Format operator is configurable with a single input port, which ingests tuples to be formatted. The input stream to the Format operator must meet all the requirements of the input stream of the FileSink operator, with respect to the format parameter. For example, if the format is line, the input stream must have one attribute of type rstring that is sent to the output.

Properties

Output Ports

Assignments
This operator allows any SPL expression of the correct type to be assigned to output attributes. Attributes not assigned in the output clause will be automatically assigned from the attributes of the input ports that have the same name and type. If there is no such input attribute, an error is reported at compile-time.
Output Functions
OutputFunctions
blob Output()

The output attribute is set to the value of formatting the input tuple as specified by the format parameter.

<any T> T AsIs(T v)

Returns the input argument.

Ports (0)

The Format operator is configurable with a single output port, which produces formatted tuples.

If the writePunctuations parameter value is true, punctuation is encoded in the output blob in the same manner as FileSink. The assignments in the output clause must not reference any input attributes because there is no input tuple present when a punctuation arrives.

If the writePunctuations parameter is not specified or its value is false, punctuation is preserved in the output stream.

Properties

Parameters

This operator supports 7 parameters.
format

Specifies the format of the data. For more information, see the format parameter in the spl.adapter::FileSource operator.

Properties

eolMarker

Specifies the end of line marker. For more information, see the eolMarker parameter in the spl.adapter::FileSource operator.

Properties

writePunctuations

Specifies whether to write punctuations to output. For more information, see the writePunctuations parameter in the spl.adapter::FileSink operator.

Properties

hasDelayField

Specifies whether the format contains inter-arrival delays as the first field. For more information, see the hasDelayField parameter in the spl.adapter::FileSource operator.

Properties

separator

Specifies the separator character for the csv format. For more information, see the separator parameter in the spl.adapter::FileSource operator.

Properties

quoteStrings

Specifies whether to generate quoted strings for csv format. For more information, see the quoteStrings parameter in the spl.adapter::FileSink operator.

Properties

suppress

Specifies the input attributes to be omitted from formatted output. For more information, see the suppress parameter in the spl.adapter::FileSink operator.

Properties

Code Templates

Format
(stream<${schema}> ${outputStream} = Format(${inputStream})   {
            param
                format : "${format}";
            output
                ${outputStream} : ${outputAttribute} = ${value};
        }
      

Libraries

spl-std-tk-lib
Library Name: streams-stdtk-runtime
Include Path: ../../../impl/include