Readers
CSV¶
Bases: BaseFileReader
A base reader for CSV files.
Init function for the base CSV reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- `delimiter`
|
the delimiter for the CSV file. This separates the fields.
Default: |
required | |
- `escape_char`
|
the character used to 'escape' the delimiter in unquoted
fields. Implementations may also use this character to escape the quote
character within quoted fields. Default: |
required | |
- `quote_char`
|
the character used to quote fields. Default: |
required | |
- `header`
|
a boolean value indicating whether to treat the first row of
the file as a header. Default: |
required | |
- `trim_cells`
|
a boolean value indicating whether to strip whitespace
from fields. Default: |
required | |
- `null_values`
|
a container of values to replace with null if encountered
in a cell. Default: |
required | |
- `encoding`
|
encoding of the CSV file. Default: |
required | |
- `**extra_args`
|
extra, implementation specific parser arguments. |
required |
Source code in src/dve/core_engine/backends/readers/csv.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
Bases: BaseFileReader
A reader for CSV files including the ability to compare the passed model to the file header, if it exists.
field_check: flag to compare submitted file header to the accompanying pydantic model field_check_error_code: The error code to provide if the file header doesn't contain the expected fields field_check_error_message: The error message to provide if the file header doesn't contain the expected fields
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/csv.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__init__(*, header=True, delim=',', quotechar='"', connection=None, field_check=False, field_check_error_code='ExpectedVsActualFieldMismatch', field_check_error_message='The submitted header is missing fields', null_empty_strings=False, **_)
¶
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/csv.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
Bases: DuckDBCSVReader
Utilises the polars lazy csv reader which is then converted into a DuckDBPyRelation object.
The primary reason this reader exists is due to the limitation within duckdb csv reader and it not being able to read partial content from a csv (i.e. select a, b NOT y).
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/csv.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
Bases: PolarsToDuckDBCSVReader
A Reader for files with a .csv extension and where there are repeating "header" values
within the file. Header in this case is not the column names at the top of a csv, rather a
collection of unique records that would usually be structured in another entity. However, due
to the fact that csv is a semi-structured data format, you cannot define complex entities,
hence the values are then repeated on all rows.
Example of a repeating header data may look like this...
| headerCol1 | headerCol2 | headerCol3 | nonHeaderCol1 | nonHeaderCol2 |
|---|---|---|---|---|
| shop 1 | clothes | 2025-01-01 | jeans | 20.39 |
| shop 1 | clothes | 2025-01-01 | shirt | 14.99 |
This reader will just pull out the distinct values from the header column. Where there are
more/less than one distinct value per column, the reader will produce a
NonDistinctHeaderError.
So using the example above, the expected entity would look like this...
| headerCol1 | headerCol2 | headerCol3 |
|---|---|---|
| shop1 | clothes | 2025-01-01 |
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/csv.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
__init__(*args, non_unique_header_error_code='NonUniqueHeader', non_unique_header_error_message=None, **kwargs)
¶
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/csv.py
211 212 213 214 215 216 217 218 219 220 | |
Bases: BaseFileReader
A Spark reader for CSV files.
Source code in src/dve/core_engine/backends/implementations/spark/readers/csv.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
__init__(*, delimiter=',', escape_char='\\', quote_char='"', header=True, multi_line=False, encoding='utf-8-sig', null_empty_strings=False, spark_session=None, **_)
¶
Source code in src/dve/core_engine/backends/implementations/spark/readers/csv.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
JSON¶
Bases: BaseFileReader
A reader for JSON files
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/json.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
__init__(*, json_format='array', **_)
¶
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/json.py
25 26 27 28 29 30 31 32 33 | |
Bases: BaseFileReader
A Spark reader for JSON files.
Source code in src/dve/core_engine/backends/implementations/spark/readers/json.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
__init__(*, encoding='utf-8', multi_line=True, spark_session=None, **_)
¶
Source code in src/dve/core_engine/backends/implementations/spark/readers/json.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
XML¶
Bases: BaseFileReader
A reader for XML files built atop LXML.
Init function for the base XML reader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- `record_tag`
|
a required string indicating the tag of each 'record' in the XML document. |
required | |
- `root_tag`
|
a string indicating the tag to find the records in within
the XML document. If |
required | |
- `trim_cells`
|
a boolean value indicating whether to strip whitespace
from elements in the XML document. Default: |
required | |
- `null_values`
|
a container of values to replace with null if encountered
in an element. Default: |
required | |
- `sanitise_multiline`
|
whether to sanitise (remove newlines and multiple spaces) from multiline fields. |
required | |
- `encoding`
|
encoding of the XML file. Default: |
required | |
- `n_records_to_read`
|
the maximum number of records to read from a document. |
required |
Source code in src/dve/core_engine/backends/readers/xml.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
Bases: XMLStreamReader
A reader for XML files
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/xml.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__init__(*, ddb_connection=None, **kwargs)
¶
Source code in src/dve/core_engine/backends/implementations/duckdb/readers/xml.py
27 28 29 | |
Bases: XMLStreamReader
An XML stream reader that adds a method to read to a dataframe
Source code in src/dve/core_engine/backends/implementations/spark/readers/xml.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
Bases: BasicXMLFileReader
A reader for XML files built atop Spark-XML.
Source code in src/dve/core_engine/backends/implementations/spark/readers/xml.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
__init__(*, record_tag, root_tag=None, spark_session=None, sampling_ratio=1, exclude_attribute=True, mode='PERMISSIVE', infer_schema=False, ignore_namespace=True, null_values=frozenset(('NULL', 'null', '')), sanitise_multiline=True, namespace=None, trim_cells=True, xsd_location=None, xsd_error_code=None, xsd_error_message=None, rules_location=None, **_)
¶
Source code in src/dve/core_engine/backends/implementations/spark/readers/xml.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |