Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notes about file extensions and _corrupt_record to documentation #674

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ When reading files the API accepts several options:
* `FAILFAST` : throws an exception when it meets corrupted records.
* `inferSchema`: if `true`, attempts to infer an appropriate type for each resulting DataFrame column, like a boolean, numeric or date type. If `false`, all resulting columns are of string type. Default is `true`.
* `columnNameOfCorruptRecord`: The name of new field where malformed strings are stored. Default is `_corrupt_record`.

Note: you should explicitly add `_corrupt_record` field to dataframe schema, like this:
dolfinus marked this conversation as resolved.
Show resolved Hide resolved
```python
schema = StructType([StructField("my_field", TimestampType()), StructField("_corrupt_record", StringType())])
spark.read.format("xml").options(rowTag='item').schema(schema).load("file.xml")
```
Otherwise the corrupt record will lead to creating row with all `null` fields, and you cannot access the original xml string.
* `attributePrefix`: The prefix for attributes so that we can differentiate attributes and elements. This will be the prefix for field names. Default is `_`. Can be empty, but only for reading XML.
* `valueTag`: The tag used for the value when there are attributes in the element having no child. Default is `_VALUE`.
* `charset`: Defaults to 'UTF-8' but can be set to other valid charset names
Expand Down Expand Up @@ -94,6 +101,8 @@ Defaults to [ISO_DATE](https://docs.oracle.com/javase/8/docs/api/java/time/forma

Currently it supports the shortened name usage. You can use just `xml` instead of `com.databricks.spark.xml`.

NOTE: created files have no `.xml` extension.

### XSD Support

Per above, the XML for individual rows can be validated against an XSD using `rowValidationXSDPath`.
Expand Down