Copyright | (c) Nikos Karagiannidis 2018 |
---|---|
License | BSD3 |
Maintainer | nkarag@gmail.com |
Stability | stable |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module implements the RTabular
instance of the CSV
data type, i.e., implements the interface by which a CSV file can be transformed to/from an RTable
.
It is required when we want to do ETL/ELT over CSV files with the DBFunctor package (i.e., with the Julius EDSL for ETL/ELT found in the Etl.Julius module).
The minimum requirement for implementing an RTabular
instance for a data type is to implement the toRTable
and fromRTable
functions. Apart from these two functions, this
module also exports functions for reading and writing CSV
data from/to CSV files. Also it supports all types of delimiters (not only commas) and CSVs with or without headers.
(see CSVOptions
)
For the CSV
data type this module uses the Cassava library (Data.Csv)
Synopsis
- newtype CSV = CSV {}
- type Row = Vector Column
- type Column = Field
- data CSVOptions = CSVOptions {}
- data YesNo
- readCSV :: FilePath -> IO CSV
- readCSVwithOptions :: CSVOptions -> FilePath -> IO CSV
- readCSVFile :: FilePath -> IO ByteString
- writeCSV :: FilePath -> CSV -> IO ()
- writeCSVFile :: FilePath -> ByteString -> IO ()
- toRTable :: RTabular a => RTableMData -> a -> RTable
- fromRTable :: RTabular a => RTableMData -> RTable -> a
- printCSV :: CSV -> IO ()
- printCSVFile :: ByteString -> IO ()
- copyCSV :: FilePath -> FilePath -> IO ()
- selectNrows :: Int -> CSV -> CSV
- projectByIndex :: [Int] -> CSV -> CSV
- headCSV :: CSV -> Row
- tailCSV :: CSV -> CSV
- csvHeaderFromRtable :: RTable -> Header
- data CsvFileDecodingError = CsvFileDecodingError FilePath Text
- data CSVColumnToRDataTypeError = CSVColumnToRDataTypeError ColumnName Text
The CSV data type
Definition of a CSV file. Treating CSV data as opaque byte strings
Instances
RTabular CSV Source # | CSV data are "Tabular" data thus implement the |
Defined in RTable.Data.CSV toRTable :: RTableMData -> CSV -> RTable Source # fromRTable :: RTableMData -> RTable -> CSV Source # |
type Row = Vector Column Source #
Definition of a CSV Row. Essentially a Row is just a Vector of ByteString
data CSVOptions Source #
Options for a CSV file (e.g., delimiter specification, header specification etc.)
Read/Write CSV
reads a CSV file and returns a CSV
data type (Treating CSV data as opaque byte strings)
:: CSVOptions | |
-> FilePath | the CSV file |
-> IO CSV | the output CSV type |
reads a CSV file based on input options (delimiter and header option) and returns a CSV
data type (Treating CSV data as opaque byte strings)
:: FilePath | the CSV file |
-> IO ByteString | the output CSV |
reads a CSV file and returns a lazy bytestring
write a CSV
to a newly created csv file
:: FilePath | the csv file to be created |
-> ByteString | input CSV |
-> IO () |
write a CSV (bytestring) to a newly created csv file
CSV as Tabular data
fromRTable :: RTabular a => RTableMData -> RTable -> a Source #
CSV I/O
:: ByteString | input CSV to be printed on screen |
-> IO () |
print input CSV on screen
Basic CSV processing
copy input csv file to specified output csv file
selectNrows: Returns the first N rows from a CSV file
Column projection on an input CSV file where desired columns are defined by position (index) in the CSV.
tailCSV :: CSV -> CSV Source #
O(1) Yield all but the first row without copying. The CSV may not be empty.
Misc
csvHeaderFromRtable :: RTable -> Header Source #
Exceptions
data CsvFileDecodingError Source #
Exception to signify an error in decoding a CSV file into a CSV
data type
Instances
Eq CsvFileDecodingError Source # | |
Defined in RTable.Data.CSV (==) :: CsvFileDecodingError -> CsvFileDecodingError -> Bool # (/=) :: CsvFileDecodingError -> CsvFileDecodingError -> Bool # | |
Show CsvFileDecodingError Source # | |
Defined in RTable.Data.CSV showsPrec :: Int -> CsvFileDecodingError -> ShowS # show :: CsvFileDecodingError -> String # showList :: [CsvFileDecodingError] -> ShowS # | |
Exception CsvFileDecodingError Source # | |
Defined in RTable.Data.CSV |
data CSVColumnToRDataTypeError Source #
Instances
Eq CSVColumnToRDataTypeError Source # | |
Defined in RTable.Data.CSV | |
Show CSVColumnToRDataTypeError Source # | |
Defined in RTable.Data.CSV showsPrec :: Int -> CSVColumnToRDataTypeError -> ShowS # show :: CSVColumnToRDataTypeError -> String # showList :: [CSVColumnToRDataTypeError] -> ShowS # | |
Exception CSVColumnToRDataTypeError Source # | |