cdm_data_loaders.readers.jsonschema_xsv.xsv_validator.qsv ¶
Core qsv-interacting code for the xsv validator.
qsv_check ¶
Check whether the qsv binary is available and whether it is functioning as expected.
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/qsv.py
clean_validate_file ¶
Clean and validate an xSV file.
Files undergo the following steps:
- headers are added if missing_header=True
- preliminary validation removes ragged rows
- files are normalised using xsv input
- nulls are replaced if null_regex != None
- second validation occurs with stricter criteria to ensure fields match
Files are validated in two stages: the first pass schema is used for very rough validation and basically ensures that there are the correct number of columns in each row.
The second validation occurs after the files are tidied up, nulls removed, and so on.
Note: there is currently no way to set custom escape characters or quotes in qsv validate, so lines with
a delimiter character as part of the field may fail the first pass validation for having too many cols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
CleanerValidatorArgs
|
object with all the useful params required for running the clean/validate workflow |
required |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/qsv.py
run_qsv_input ¶
Run qsv input to normalise the file input_file_name.
See https://github.com/dathere/qsv/blob/master/docs/help/input.md for more information.
Does not currently take account of quote or escape characters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
CleanerValidatorArgs
|
args for the cleaner validator |
required |
input_file_name
|
str
|
name of the input file |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
name of the output file if all went ok; otherwise None |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/qsv.py
run_qsv_null_replacement ¶
Run qsv replace to replace any exact matches of args.null_regex in input_file_name with "".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
CleanerValidatorArgs
|
args for the cleaner validator |
required |
input_file_name
|
str
|
name of the input file |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
name of the output file if all went ok; otherwise None |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/qsv.py
run_qsv_validate ¶
run_qsv_validate(
args: CleanerValidatorArgs,
input_file_name: str,
schema: ValidatedXsvSchema,
first_pass: bool = True,
) -> str | None
Run the validator over the file input_file_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
CleanerValidatorArgs
|
args for the cleaner validator |
required |
input_file_name
|
str
|
name of the input file |
required |
schema
|
ValidatedXsvSchema
|
ValidatedXsvSchema object to use for validation |
required |
first_pass
|
bool
|
if True, this runs the first pass validator, which does not check format |
True
|
Returns:
| Type | Description |
|---|---|
str | None
|
name of the output file if all went ok; otherwise None |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/qsv.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |