Store Dataset In Memory

In this example you will learn how to store your dataset in memory using MemoryDataset.

This example be easily modified to show how to Store Dataset on Disk.

Input CSV file

868,Hewitt,Jennifer Love,0,17000.00,5/25/1985,B

Java code listing

package com.northconcepts.datapipeline.foundations.examples.pipeline;

import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.Record;
import com.northconcepts.datapipeline.csv.CSVReader;
import com.northconcepts.datapipeline.foundations.pipeline.Pipeline;
import com.northconcepts.datapipeline.foundations.pipeline.dataset.Dataset;
import com.northconcepts.datapipeline.foundations.pipeline.dataset.MemoryDataset;


public class StoreDatasetInMemory {

    public static void main(String[] args) {
        DataReader reader = new CSVReader(new File("example/data/input/credit-balance-01.csv"))

        Pipeline pipeline = new Pipeline().setInputAsDataReader(reader);

        Dataset dataset = new MemoryDataset(pipeline);


        for (Record record : dataset) {


Code walkthrough

  1. A CSVReader is created using the file path of the input file credit-balance-01.csv.
  2. The CSVReader.setFieldNamesInFirstRow(true) method is invoked to specify that the names specified in the first row should be used as field names.
  3. An instance of Pipeline is created which receives the reader as input (Pipeline().setInputAsDataReader(reader)).
  4. new MemoryDataset(pipeline) is used to create the dataset in memory, it accepts pipeline as a parameter which is the source of the dataset's data.
  5. dataset.load() starts the asynchronous loading of records from the pipeline into this dataset. This method returns immediately and does not wait for loading to complete.
  6. .waitForRecordsToLoad() is used to ensure that all the records have been loaded before proceeding forward.
  7. Since Dataset is Iterable , it is looped over and the records are printed from memory.
  8. dataset.close() terminates any asynchronous data loading and column stats calculation.

All Examples

Mobile Analytics