Class CsvHelpers

java.lang.Object
com.illumon.iris.db.tables.utils.CsvHelpers

public class CsvHelpers
extends Object
Utilities for reading and writing CSV files to and from Tables
  • Field Details

  • Constructor Details

  • Method Details

    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, String destPath, boolean compressed, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      destPath - path to the CSV file to be written
      compressed - whether to zip the file being written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, String destPath, boolean compressed, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      destPath - path to the CSV file to be written
      compressed - whether to zip the file being written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, String destPath, boolean compressed, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, char separator, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      destPath - path to the CSV file to be written
      compressed - whether to zip the file being written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      separator - the delimiter for the CSV
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, String destPath, boolean compressed, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, char separator, List<String> columnNames, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      destPath - path to the CSV file to be written
      compressed - whether to zip the file being written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      separator - the delimiter for the CSV
      columnNames - a list of column names to use for the header in lieu of the actual names of the columns
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - BufferedWriter used to write the CSV
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, char separator, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - BufferedWriter used to write the CSV
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      separator - the delimiter for the CSV
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsv

      @ScriptApi public static void writeCsv​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, char separator, List<String> columnNames, String... columns) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - BufferedWriter used to write the CSV
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      separator - the delimiter for the CSV
      columnNames - a list of column names to use for the header in lieu of the actual names of the columns
      columns - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsvHeader

      @ScriptApi public static void writeCsvHeader​(BufferedWriter out, String... columns) throws IOException
      Writes the column name header row to a CSV file.
      Parameters:
      out - the BufferedWriter to which the header should be written
      columns - a list of column names to be written
      Throws:
      IOException - if the BufferedWriter cannot be written to
    • writeCsvHeader

      @ScriptApi public static void writeCsvHeader​(BufferedWriter out, char separator, String... columns) throws IOException
      Writes the column name header row to a CSV file.
      Parameters:
      out - the BufferedWriter to which the header should be written
      separator - a char to use as the delimiter value when writing out the header
      columns - a list of column names to be written
      Throws:
      IOException - if the BufferedWriter cannot be written to
    • writeCsvPaginate

      @ScriptApi public static void writeCsvPaginate​(Table source, String destPath, String filename) throws IOException
      Writes a Deephaven table to one or more files, splitting it based on the MAX_CSV_LINE_COUNT setting.
      Parameters:
      source - a Deephaven table to be exported
      destPath - the path in which the CSV file(s) should be written
      filename - the base file name to use for the files. A dash and starting line number will be concatenated to each file.
      Throws:
      IOException - if the destination files cannot be written
    • writeCsvPaginate

      @ScriptApi public static void writeCsvPaginate​(Table source, String destPath, String filename, boolean nullsAsEmpty) throws IOException
      Writes a Deephaven table to one or more files, splitting it based on the MAX_CSV_LINE_COUNT setting.
      Parameters:
      source - a Deephaven table to be exported
      destPath - the path in which the CSV file(s) should be written
      filename - the base file name to use for the files. A dash and starting line number will be concatenated to each file.
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      Throws:
      IOException - if the destination files cannot be written
    • writeToMultipleFiles

      @ScriptApi public static void writeToMultipleFiles​(Table table, String path, String filename, long startLine) throws IOException
      Writes a subset of rows from a Deephaven table to a CSV file.
      Parameters:
      table - a Deephaven table from which rows should be exported
      path - the destination path in which the output CSV file should be created
      filename - the base file name to which a dash and starting line number will be concatenated for the file
      startLine - the starting line number from the table to export; the ending line number will be startLine + MAX_CSV_LINE_COUNT-1, or the end of the table
      Throws:
      IOException - if the destination file cannot be written
    • writeToMultipleFiles

      @ScriptApi public static void writeToMultipleFiles​(Table table, String path, String filename, long startLine, boolean nullsAsEmpty) throws IOException
      Writes a subset of rows from a Deephaven table to a CSV file.
      Parameters:
      table - a Deephaven table from which rows should be exported
      path - the destination path in which the output CSV file should be created
      filename - the base file name to which a dash and starting line number will be concatenated for the file
      startLine - the starting line number from the table to export; the ending line number will be startLine + MAX_CSV_LINE_COUNT-1, or the end of the table
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      Throws:
      IOException - if the destination file cannot be written
    • writeCsvContents

      @ScriptApi public static void writeCsvContents​(Table source, BufferedWriter out, DBTimeZone timeZone, String... colNames) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - a BufferedWriter to which the header should be written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      colNames - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsvContents

      @ScriptApi public static void writeCsvContents​(Table source, BufferedWriter out, DBTimeZone timeZone, boolean nullsAsEmpty, String... colNames) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - a BufferedWriter to which the header should be written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      colNames - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsvContents

      @ScriptApi public static void writeCsvContents​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, String... colNames) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - a BufferedWriter to which the header should be written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      colNames - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsvContents

      @ScriptApi public static void writeCsvContents​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, String... colNames) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - a BufferedWriter to which the header should be written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      colNames - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • writeCsvContents

      @ScriptApi public static void writeCsvContents​(Table source, BufferedWriter out, DBTimeZone timeZone, @Nullable com.fishlib.base.Procedure.Binary<Long,​Long> progress, boolean nullsAsEmpty, char separator, String... colNames) throws IOException
      Writes a DB table out as a CSV file.
      Parameters:
      source - a Deephaven table object to be exported
      out - a BufferedWriter to which the header should be written
      timeZone - a DBTimeZone constant relative to which DBDateTime data should be adjusted
      progress - a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progress
      nullsAsEmpty - if nulls should be written as blank instead of '(null)'
      separator - the delimiter for the CSV
      colNames - a list of columns to include in the export
      Throws:
      IOException - if the target file cannot be written
    • separatorCsvEscape

      protected static String separatorCsvEscape​(String str, String separator)
      Returns a String value for a CSV column's value. This String will be enclosed in double quotes if the value includes a double quote, a newline, or the separator.
      Parameters:
      str - the String to be escaped
      separator - the delimiter for the CSV
      Returns:
      the input String, enclosed in double quotes if the value contains a comma, newline or double quote
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is, String format) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      format - an Apache Commons CSV format name to be used to parse the CSV, or a single non-newline character to use as a delimiter.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is, String format, StatusCallback progress) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      format - an Apache Commons CSV format name to be used to parse the CSV, or a single non-newline character to use as a delimiter.
      progress - a StatusCallback object that can be used to log progress details or update a progress bar. If passed explicitly as null, a StatusCallback instance will be created to log progress to the current logger.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is, char separator) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      separator - a char to use as the delimiter value when parsing the file.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is, char separator, StatusCallback progress) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      separator - a char to use as the delimiter value when parsing the file.
      progress - a StatusCallback object that can be used to log progress details or update a progress bar. If passed explicitly as null, a StatusCallback instance will be created to log progress to the current logger.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv2

      @ScriptApi public static QueryTable readCsv2​(InputStream is, char separator) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      separator - a char to use as the delimiter value when parsing the file.
      Returns:
      an Iris QueryTable object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv

      @ScriptApi public static Table readCsv​(InputStream is, StatusCallback progress) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      progress - a StatusCallback object that can be used to log progress details or update a progress bar. If passed explicitly as null, a StatusCallback instance will be created to log progress to the current logger.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - if the InputStream cannot be read
    • readCsv2

      public static QueryTable readCsv2​(InputStream is) throws IOException
      Returns a memory table created by importing CSV data. The first row must be column names. Column data types are inferred from the data.
      Parameters:
      is - an InputStream providing access to the CSV data.
      Returns:
      an Iris QueryTable object
      Throws:
      IOException - if the InputStream cannot be read