Package com.illumon.iris.db.tables.utils
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
Table
s-
Field Summary
Fields Modifier and Type Field Description static int
MAX_CSV_LINE_COUNT
static boolean
useLegacyCsv
-
Constructor Summary
Constructors Constructor Description CsvHelpers()
-
Method Summary
Modifier and Type Method Description static Table
readCsv(InputStream is)
Returns a memory table created by importing CSV data.static Table
readCsv(InputStream is, char separator)
Returns a memory table created by importing CSV data.static Table
readCsv(InputStream is, char separator, StatusCallback progress)
Returns a memory table created by importing CSV data.static Table
readCsv(InputStream is, StatusCallback progress)
Returns a memory table created by importing CSV data.static Table
readCsv(InputStream is, String format)
Returns a memory table created by importing CSV data.static Table
readCsv(InputStream is, String format, StatusCallback progress)
Returns a memory table created by importing CSV data.static QueryTable
readCsv2(InputStream is)
Returns a memory table created by importing CSV data.static QueryTable
readCsv2(InputStream is, char separator)
Returns a memory table created by importing CSV data.protected static String
separatorCsvEscape(String str, String separator)
Returns a String value for a CSV column's value.static void
writeCsv(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, char separator, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, char separator, List<String> columnNames, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, String destPath, boolean compressed, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, char separator, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, String destPath, boolean compressed, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, char separator, List<String> columnNames, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, String destPath, boolean compressed, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, String... columns)
Writes a DB table out as a CSV file.static void
writeCsv(Table source, String destPath, boolean compressed, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, String... columns)
Writes a DB table out as a CSV file.static void
writeCsvContents(Table source, BufferedWriter out, DBTimeZone timeZone, boolean nullsAsEmpty, String... colNames)
Writes a DB table out as a CSV file.static void
writeCsvContents(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, char separator, String... colNames)
Writes a DB table out as a CSV file.static void
writeCsvContents(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, boolean nullsAsEmpty, String... colNames)
Writes a DB table out as a CSV file.static void
writeCsvContents(Table source, BufferedWriter out, DBTimeZone timeZone, com.fishlib.base.Procedure.Binary<Long,Long> progress, String... colNames)
Writes a DB table out as a CSV file.static void
writeCsvContents(Table source, BufferedWriter out, DBTimeZone timeZone, String... colNames)
Writes a DB table out as a CSV file.static void
writeCsvHeader(BufferedWriter out, char separator, String... columns)
Writes the column name header row to a CSV file.static void
writeCsvHeader(BufferedWriter out, String... columns)
Writes the column name header row to a CSV file.static void
writeCsvPaginate(Table source, String destPath, String filename)
Writes a Deephaven table to one or more files, splitting it based on the MAX_CSV_LINE_COUNT setting.static void
writeCsvPaginate(Table source, String destPath, String filename, boolean nullsAsEmpty)
Writes a Deephaven table to one or more files, splitting it based on the MAX_CSV_LINE_COUNT setting.static void
writeToMultipleFiles(Table table, String path, String filename, long startLine)
Writes a subset of rows from a Deephaven table to a CSV file.static void
writeToMultipleFiles(Table table, String path, String filename, long startLine, boolean nullsAsEmpty)
Writes a subset of rows from a Deephaven table to a CSV file.
-
Field Details
-
useLegacyCsv
public static boolean useLegacyCsv -
MAX_CSV_LINE_COUNT
public static final int MAX_CSV_LINE_COUNT- See Also:
- Constant Field Values
-
-
Constructor Details
-
CsvHelpers
public CsvHelpers()
-
-
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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exporteddestPath
- path to the CSV file to be writtencompressed
- whether to zip the file being writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progresscolumns
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exporteddestPath
- path to the CSV file to be writtencompressed
- whether to zip the file being writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exporteddestPath
- path to the CSV file to be writtencompressed
- whether to zip the file being writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- if nulls should be written as blank instead of '(null)'separator
- the delimiter for the CSVcolumns
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exporteddestPath
- path to the CSV file to be writtencompressed
- whether to zip the file being writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- if nulls should be written as blank instead of '(null)'separator
- the delimiter for the CSVcolumnNames
- a list of column names to use for the header in lieu of the actual names of the columnscolumns
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- BufferedWriter used to write the CSVtimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- BufferedWriter used to write the CSVtimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- if nulls should be written as blank instead of '(null)'separator
- the delimiter for the CSVcolumns
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- BufferedWriter used to write the CSVtimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- if nulls should be written as blank instead of '(null)'separator
- the delimiter for the CSVcolumnNames
- a list of column names to use for the header in lieu of the actual names of the columnscolumns
- 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 IOExceptionWrites the column name header row to a CSV file.- Parameters:
out
- the BufferedWriter to which the header should be writtencolumns
- 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 IOExceptionWrites the column name header row to a CSV file.- Parameters:
out
- the BufferedWriter to which the header should be writtenseparator
- a char to use as the delimiter value when writing out the headercolumns
- 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 IOExceptionWrites 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 exporteddestPath
- the path in which the CSV file(s) should be writtenfilename
- 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 IOExceptionWrites 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 exporteddestPath
- the path in which the CSV file(s) should be writtenfilename
- 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 IOExceptionWrites a subset of rows from a Deephaven table to a CSV file.- Parameters:
table
- a Deephaven table from which rows should be exportedpath
- the destination path in which the output CSV file should be createdfilename
- the base file name to which a dash and starting line number will be concatenated for the filestartLine
- 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 IOExceptionWrites a subset of rows from a Deephaven table to a CSV file.- Parameters:
table
- a Deephaven table from which rows should be exportedpath
- the destination path in which the output CSV file should be createdfilename
- the base file name to which a dash and starting line number will be concatenated for the filestartLine
- 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 tablenullsAsEmpty
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- a BufferedWriter to which the header should be writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedcolNames
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- a BufferedWriter to which the header should be writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustednullsAsEmpty
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- a BufferedWriter to which the header should be writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progresscolNames
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- a BufferedWriter to which the header should be writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- 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 IOExceptionWrites a DB table out as a CSV file.- Parameters:
source
- a Deephaven table object to be exportedout
- a BufferedWriter to which the header should be writtentimeZone
- a DBTimeZone constant relative to which DBDateTime data should be adjustedprogress
- a procedure that implements Procedure.Binary, and takes a progress Integer and a total size Integer to update progressnullsAsEmpty
- if nulls should be written as blank instead of '(null)'separator
- the delimiter for the CSVcolNames
- a list of columns to include in the export- Throws:
IOException
- if the target file cannot be written
-
separatorCsvEscape
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 escapedseparator
- the delimiter for the CSV- Returns:
- the input String, enclosed in double quotes if the value contains a comma, newline or double quote
-
readCsv
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 IOExceptionReturns 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
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 IOExceptionReturns 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
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
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
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
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
-