Class ITER_CSV

  • All Implemented Interfaces:
    IteratorFunction

    public class ITER_CSV
    extends IteratorStreamFunctionBase
    Iterator function iter:CSV batch-processes CSV documents, potentially having some custom CSV dialect, and iteratively binds the content of a selection of cells to the list of provided variables.

    See Live example

    The list of parameters is interpreted as follows:
    • the URI of the CSV document (a URI), or the CSV document itself (a String);
    • Optional group of string parameters for custom CSV dialects.
      • (boolean: header) true if the CSV has a header row (default is true ).
      • (string: quoteChar) the quote character (default is '"' );
      • (string: delimiterChar) the delimiter character (default is ',' );
      • (string: endOfLineSymbols) the end of line symbol (default is '\n' );
    • (integer: batch) Optional number of rows per batch (by default, all the CSV document is processed as one batch);
    • (string parameters: names) Names of the columns to select (by default, all the columns are selected).

    Examples:

    • ITERATOR ite:CSV(<path/to/file>) AS ?PersonId ?Name fetches the document having URI <path/to/file> (using the provided jena stream manager); assumes that it has a header row, quote character '"', delimiter character ',', end of line symbol '\n'; processes it in one batch, and binds the cells of the two first column to ?PersonId and ?Name (except for the first column which is the header).
    • ITERATOR ite:CSV("""A1 B1
      A2 B2""", false, '"', '\t', '\n') AS ?A ?B
      uses the provided CSV document; assumes that it has no header now, uses the provided custom configuration; processes it in one batch, and binds the cells of the two first column to ?A and ?B.
    • ITERATOR ite:CSV(<path/to/file>, "PersonId", "Name") AS ?PersonId ?Name fetches the document having URI <path/to/file> (using the provided jena stream manager); uses the default configuration; processes it in one batch, and binds the cells of the rows named "PersonId" and "Name" to the corresponding variables.
    • ITERATOR ite:CSV(<path/to/file>, 1000, "PersonId", "Name") AS ?PersonId ?Name fetches the document having URI <path/to/file> (using the provided jena stream manager); uses the default configuration; processes it in batches of 1000 rows, and binds the cells of the rows named "PersonId" and "Name" to the corresponding variables.
    Since:
    2019-03-23
    Author:
    Maxime Lefrançois