Qore CsvUtil Module Reference 1.10.1
Loading...
Searching...
No Matches
CsvReadDataProvider.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
2// Qore CsvReadDataProvider class definition
3
4/* CsvReadDataProvider.qc Copyright 2012 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
26namespace CsvUtil {
28
31
32public:
34 const ProviderInfo = <DataProviderInfo>{
35 "type": "CsvReadDataProvider",
36 "supports_read": True,
37 "has_record": True,
38 "supports_search_expressions": True,
39 "constructor_options": ConstructorOptions,
40 "search_options": GenericRecordSearchOptions,
41 "expressions": AbstractDataProvider::GenericExpressions,
42 };
43
46 "path": <DataProviderOptionInfo>{
47 "type": AbstractDataProviderType::get(StringType),
48 "desc": "the location of the CSV data; mutually exclusive with \"stream\"; resolved with a call to "
49 "FileLocationHandler::getBinaryStreamFromLocation()",
50 },
51 "stream": <DataProviderOptionInfo>{
52 "type": AbstractDataProviderType::get(new Type("InputStream")),
53 "desc": "an input stream for CSV data; mutually exclusive with \"path\"",
54 },
55 "date_format": <DataProviderOptionInfo>{
56 "type": AbstractDataProviderType::get(StringType),
57 "desc": "the default date format for `date` fields (ex: `DD/MM/YYYY HH:mm:SS`)",
58 },
59 "encoding": <DataProviderOptionInfo>{
60 "type": AbstractDataProviderType::get(StringType),
61 "desc": "character encoding for the file (and output data)",
62 },
63 "eol": <DataProviderOptionInfo>{
64 "type": AbstractDataProviderType::get(StringType),
65 "desc": "the end of line character(s); if not specified, then the end-of-line characters will be "
66 "auto detected",
67 },
68 "fields": <DataProviderOptionInfo>{
69 "type": AbstractDataProviderType::get(AutoHashType),
70 "desc": "the keys are field names as given by the `header_names` or `headers` options (in case "
71 "neither of these options are used, then field names are numbers starting with `0`) and the "
72 "values are either strings (one of `bool`, `int`, `float`, `number`, `string`, `date`, "
73 "optionally prefixed by `*` if the value is optional) or a hash describing the field; also sets "
74 "`headers` if not set automatically with `header_names`; if no field type is given, the default "
75 "is `*string`; note that invalid field names given in this option are ignored",
76 },
77 "header_lines": <DataProviderOptionInfo>{
78 "type": AbstractDataProviderType::get(SoftIntType),
79 "desc": "the number of headers lines in the file",
80 },
81 "header_names": <DataProviderOptionInfo>{
82 "type": AbstractDataProviderType::get(SoftBoolType),
83 "desc": "if `true` then the object will parse the header names from the first header row, in this "
84 "case if `header_lines` is not set explicitly, it will be assumed to be `1`",
85 },
86 "header_reorder": <DataProviderOptionInfo>{
87 "type": AbstractDataProviderType::get(SoftBoolType),
88 "desc": "if `true` (the default) then if `headers` are provided, then data fields are reordered to "
89 "follow headers",
90 },
91 "headers": <DataProviderOptionInfo>{
92 "type": AbstractDataProviderType::get(new Type("softlist<string>")),
93 "desc": "list of header / column names for the data iterated; if this is present, then "
94 "`header_names` must be `false`",
95 },
96 "ignore_empty": <DataProviderOptionInfo>{
97 "type": AbstractDataProviderType::get(SoftBoolType),
98 "desc": "if `true`, empty lines will be ignored",
99 },
100 "ignore_whitespace": <DataProviderOptionInfo>{
101 "type": AbstractDataProviderType::get(SoftBoolType),
102 "desc": "if `true`, leading and trailing whitespace will be stripped from non-quoted fields",
103 },
104 "number_format": <DataProviderOptionInfo>{
105 "type": AbstractDataProviderType::get(StringType),
106 "desc": "the default format for `int`, `float`, and `number` fields as a string giving the thousands "
107 "separator character followed by the decimal separator character (ex: `.,` for "
108 "continental-European-style numbers)",
109 },
110 "quote": <DataProviderOptionInfo>{
111 "type": AbstractDataProviderType::get(StringType),
112 "desc": "the field quote character (default: `\"`)",
113 },
114 "separator": <DataProviderOptionInfo>{
115 "type": AbstractDataProviderType::get(StringType),
116 "desc": "the string separating the fields in the file (default: `,`)",
117 },
118 "timezone": <DataProviderOptionInfo>{
119 "type": AbstractDataProviderType::get(StringType),
120 "desc": "the timezone region to use when parsing dates (ex: `Europe/Prague`)",
121 },
122 "tolwr": <DataProviderOptionInfo>{
123 "type": AbstractDataProviderType::get(SoftBoolType),
124 "desc": "if `true` (default `false`), all header names will be converted to lower case letters",
125 },
126 "verify_columns": <DataProviderOptionInfo>{
127 "type": AbstractDataProviderType::get(SoftBoolType),
128 "desc": "if `true` (default `false`), if a line is parsed with a different column or field count "
129 "than other lines, a `CSVFILEITERATOR-DATA-ERROR` exception is raised",
130 },
131 };
132
134 const CsvIterationOptionList = keys (ConstructorOptions - ("path", "stream"));
135
136protected:
139
140public:
141
143
149 constructor(string path, *hash<auto> opts);
150
151
153
159 constructor(InputStream stream, *hash<auto> opts);
160
161
163 string getName();
164
165
167 constructor(*hash<auto> options);
168
169
171
174protected:
175 AbstractDataProviderRecordIterator searchRecordsImpl(*hash<auto> where_cond, *hash<auto> search_options);
176public:
177
178
180
183protected:
184 AbstractDataProviderRecordIterator searchRecordsImpl(*hash<DataProviderExpression> where_cond, *hash<auto> search_options);
185public:
186
187
189protected:
190 *hash<string, AbstractDataField> getRecordTypeImpl(*hash<auto> search_options);
191public:
192
193
195protected:
196 hash<DataProviderInfo> getStaticInfoImpl();
197public:
198
199};
200}; // CsvUtil namespace
the AbstractCsvIterator class is an abstract base class that allows abstract CSV data to be iterated
Definition: AbstractCsvIterator.qc.dox.h:285
Provides a data provider for reading CSV files.
Definition: CsvReadDataProvider.qc.dox.h:30
const ProviderInfo
Provider info.
Definition: CsvReadDataProvider.qc.dox.h:34
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
constructor(string path, *hash< auto > opts)
Creates the CsvReadDataProvider with the input data path and optionally an option hash.
AbstractDataProviderRecordIterator searchRecordsImpl(*hash< auto > where_cond, *hash< auto > search_options)
Returns an iterator for zero or more records matching the search options.
*hash< string, AbstractDataField > getRecordTypeImpl(*hash< auto > search_options)
Returns the description of the record type, if any.
const ConstructorOptions
Constructor options.
Definition: CsvReadDataProvider.qc.dox.h:45
AbstractDataProviderRecordIterator searchRecordsImpl(*hash< DataProviderExpression > where_cond, *hash< auto > search_options)
Returns an iterator for zero or more records matching the search options.
string getName()
Returns the object name.
constructor(InputStream stream, *hash< auto > opts)
Creates the CsvReadDataProvider with the input data stream and optionally an option hash.
constructor(*hash< auto > options)
Creates the object from constructor options.
const CsvIterationOptionList
CSV iteration option list.
Definition: CsvReadDataProvider.qc.dox.h:134
AbstractCsvIterator i
the iterator object
Definition: CsvReadDataProvider.qc.dox.h:138
the CsvUtil namespace. All classes used in the CsvUtil module should be inside this namespace
Definition: AbstractCsvIterator.qc.dox.h:28