Class CsvTools

java.lang.Object
com.illumon.iris.db.tables.utils.csv.CsvTools

public class CsvTools extends Object
Util class that supports and handles the changes needed to migrate to new dhc-fast-csv parser.
  • Constructor Details

    • CsvTools

      public CsvTools()
  • Method Details

    • getColumnHeaders

      @NotNull public static List<String> getColumnHeaders(@NotNull InputStream stream, @NotNull io.deephaven.csv.CsvSpecs specs) throws IOException
      Return the column headers as list using the values from the first row. To avoid reading the entire file the CsvSpecs should restrict the num of rows to be read to 1, this check is enforced.
      Parameters:
      stream - An InputStream providing access to the CSV data.
      specs - The CsvSpecs
      Returns:
      Return the column headers using the values from the first row.
      Throws:
      IOException - throws IOException if a Reader Exception occurs
    • readCsv

      public static Table readCsv(@NotNull InputStream stream, @Nullable String format, boolean v2, @Nullable StatusCallback progress, boolean noHeader, @Nullable Collection<String> header) throws IOException
      Creates an in-memory table from stream by importing CSV data according to the specs. The stream will be closed upon return.
      Parameters:
      stream - an InputStream providing access to the CSV data.
      format - can be null a delimiter or one of DEFAULT, TDF, EXCEL, MYSQL, RFC4180 and TRIM
      v2 - whether the process imports using the older QueryTable processing (v2 = true) or the newer InMemoryTable processing (v2 = false).
      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.
      noHeader - boolean indicates if data contains header
      header - Column names to use as, or instead of, the header row for the CSV.
      Returns:
      a Deephaven Table object
      Throws:
      IOException - throws IOException if a Reader Exception occurs
    • getCsvSpecsBuilder

      @NotNull public static io.deephaven.csv.CsvSpecs.Builder getCsvSpecsBuilder(@Nullable String format, boolean hasHeader, @Nullable Collection<String> headers, @Nullable List<String> nullLiterals, boolean validateHeaders) throws CsvFormatException
      Returns the CsvSpecs.Builder created with appropriate properties. Allows user to make the choices for header validation to conform to deephaven column header rules. Users have flexibility to include a null literal value list
      Parameters:
      format - can be null a delimiter or one of DEFAULT, TDF, EXCEL, MYSQL, RFC4180 and TRIM
      hasHeader - true or false to indicate if data includes header row
      headers - Column names to use as, or instead of, the header row for the CSV.
      nullLiterals - The list of null value literals that should be considered as null by the parser, if null is passed then default list consisting of 1. Empty String 2. The string value null 3. The string value of null in parentheses will be used
      validateHeaders - true indicates headers will be validated with deephaven based column header rules
      Returns:
      CsvSpecs.Builder
      Throws:
      CsvFormatException - thrown for an unsupported format
    • getImportCsvSpecsBuilder

      @NotNull public static io.deephaven.csv.CsvSpecs.Builder getImportCsvSpecsBuilder(@Nullable String format, boolean hasHeader, @Nullable Collection<String> headers) throws CsvFormatException
      Returns the CsvSpecs.Builder that doesn't include source file header validation and legalization to conform to deephaven column header rules. This method should therefore not be used where deephaven column header rules are expected to be applied. The typical use case for this is in Csv imports where the schema drive the eventual column names. In addition to not validating the headers a default list for Null Literals is used for more information see getDefaultFormatBuilder(CsvSpecs.Builder, List). The method is public to allow Csv Import related classes to access it.
      Parameters:
      format - can be null a delimiter or one of DEFAULT, TDF, EXCEL, MYSQL, RFC4180 and TRIM
      hasHeader - true or false to indicate if data includes header row
      headers - Column names to use as, or instead of, the header row for the CSV.
      Returns:
      CsvSpecs.Builder
      Throws:
      CsvFormatException - thrown for an unsupported format