CSV File Writer Output Adapter Sample

About This Sample

This sample demonstrates the use of the Spotfire Streaming CSV File Writer output adapter.

Importing This Sample into StreamBase Studio

In StreamBase Studio, import this sample with the following steps:

  • From the top-level menu, click File>Import Samples and Community Content.

  • Enter csv writer to narrow the list of options.

  • Select CSV file writer output Adapter from the StreamBase Standard Adapters category.

  • Click Import Now.

StreamBase Studio creates a project for the sample.

Running This Sample in StreamBase Studio

  1. In the Project Explorer view, open the sample you just loaded.

    If you see red marks on a project folder, wait a moment for the project to load its features.

    If the red marks do not resolve themselves after a minute, select the project, right-click, and select Maven>Update Project from the context menu.

  2. Open the src/main/configurations folder and double-click to open sbengine.conf.

  3. Use a dataAreaPath property to specify the full, absolute path to a folder that is to contain the file to be written by this adapter. You can uncomment the dataAreaPath line appropriate for your operating system and edit the sbuser placeholder name for your system login name. For example, take the following starting point:

    streamBase = {
      // dataAreaPath = "C:/Users/sbuser/Documents"
      // dataAreaPath = "/Users/sbuser/Documents"
      // dataAreaPath = "/home/sbuser/Documents"
      // dataAreaPath = "/Users/sbuser/tmp"
      }
    

    Uncomment the first dataAreaPath line and replace sbuser:

    streamBase = {
      dataAreaPath = "C:/Users/your-login-name/Documents"
      // dataAreaPath = "/Users/sbuser/Documents"
      // dataAreaPath = "/home/sbuser/Documents"
      // dataAreaPath = "/Users/sbuser/tmp"
      }
    
  4. Open the src/main/eventflow/packageName folder.

  5. Open the CSVWriterTest.sbapp file and click the Run button. This opens the SB Test/Debug perspective and starts the module.

  6. Select the Manual Input tab.

  7. In the Stream drop-down control, select the Write stream.

  8. Enter any integer value such as 10 in the num field and click Send Data.

  9. Enter several more integers, clicking Send Data after each one.

  10. Use your operating system's file browser to navigate to the folder you specified in step 3. A file named sample.csv (or named as specified in the File Name field of the adapter's Properties view, File Creation tab) should now contain tuples formatted as shown in this example:

    num,square,Timestamp
    10,100,2018-04-27 12:40:42.912-0400
    200,40000,2018-04-27 12:40:50.958-0400
    42,1764,2018-04-27 12:40:56.958-0400
    

    The sample is configured to append to the specified file, so you may also see lines from previous runs of this sample.

  11. In the Manual Input tab, select the Stream drop-down control, and select the zStartControl stream. Enter the name of an alternate file for this adapter to write to. For example, enter NewFileName.csv.

  12. In the Stream control, re-select the Write stream and enqueue a few more integers in the num field.

  13. Use your operating system's file browser to locate and open the NewFileName.csv file in the same directory you specified in step 3. Open the file to see the most recent set of tuples entered.

  14. When done, press F9 or click the Terminate EventFlow Fragment button.

Notes on the Default Write Location

If you do not edit the sbengine.conf file to specify a write location, the adapter writes its output file to a default location in the module's node directory. Navigate down the following folder sequence to find the default location:

  1. Studio workspace folder

  2. .nodes (This is a hidden folder on macOS.)

  3. nodename (see the Clusters view to identify the node name for this sample's most recent launch)

  4. fragments

  5. enginename (see the Clusters view)

  6. engine-data-area

You can identify the default write location using the Engine Data Area line of the engine properties for the current node in the Clusters view. This property shows the full path to the parent folder of the engine-data-area folder.

Remember that the node directory is normally removed on successful stopping and removal of a node. The node directories for all nodes that Studio starts are removed when Studio exits, if the nodes completed successfully. The node directories for nodes that ended with an error condition are preserved.

Sample Location

When you load the sample into StreamBase® Studio, Studio copies the sample project's files to your Studio workspace, which is normally part of your home directory, with full access rights.

Important

Load this sample in StreamBase® Studio, and thereafter use the Studio workspace copy of the sample to run and test it, even when running from the command prompt.

Using the workspace copy of the sample avoids permission problems. The default workspace location for this sample is:

studio-workspace/sample_adapter_embedded_csvwriter

See Default Installation Directories for the default location of studio-workspace on your system.