-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-13425][SQL] Documentation for CSV datasource options #12817
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4471e2a
Add CSV documentation
HyukjinKwon 52efce1
Fetch upstream
HyukjinKwon 34b52fa
Replace `` to "empty string".
HyukjinKwon b9aeac1
Add omitted opening tag ` and max length
HyukjinKwon 8201f23
Remove alias for delimiter and charset.
HyukjinKwon 54f58d3
Add starting tag for option, delimiter.
HyukjinKwon ab70b6d
Address comments
HyukjinKwon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,6 +282,45 @@ def csv(self, paths): | |
|
|
||
| :param paths: string, or list of strings, for input path(s). | ||
|
|
||
| You can set the following CSV-specific options to deal with CSV files: | ||
| * ``sep`` (default ``,``): sets the single character as a separator \ | ||
| for each field and value. | ||
| * ``charset`` (default ``UTF-8``): decodes the CSV files by the given \ | ||
| encoding type. | ||
| * ``quote`` (default ``"``): sets the single character used for escaping \ | ||
| quoted values where the separator can be part of the value. | ||
| * ``escape`` (default ``\``): sets the single character used for escaping quotes \ | ||
| inside an already quoted value. | ||
| * ``comment`` (default empty string): sets the single character used for skipping \ | ||
| lines beginning with this character. By default, it is disabled. | ||
| * ``header`` (default ``false``): uses the first line as names of columns. | ||
| * ``ignoreLeadingWhiteSpace`` (default ``false``): defines whether or not leading \ | ||
| whitespaces from values being read should be skipped. | ||
| * ``ignoreTrailingWhiteSpace`` (default ``false``): defines whether or not trailing \ | ||
| whitespaces from values being read should be skipped. | ||
| * ``nullValue`` (default empty string): sets the string representation of a null value. | ||
| * ``nanValue`` (default ``NaN``): sets the string representation of a non-number \ | ||
| value. | ||
| * ``positiveInf`` (default ``Inf``): sets the string representation of a positive \ | ||
| infinity value. | ||
| * ``negativeInf`` (default ``-Inf``): sets the string representation of a negative \ | ||
| infinity value. | ||
| * ``dateFormat`` (default ``None``): sets the string that indicates a date format. \ | ||
| Custom date formats follow the formats at ``java.text.SimpleDateFormat``. This \ | ||
| applies to both date type and timestamp type. By default, it is None which means \ | ||
| trying to parse times and date by ``java.sql.Timestamp.valueOf()`` and \ | ||
| ``java.sql.Date.valueOf()``. | ||
| * ``maxColumns`` (default ``20480``): defines a hard limit of how many columns \ | ||
| a record can have. | ||
| * ``maxCharsPerColumn`` (default ``1000000``): defines the maximum number of \ | ||
| characters allowed for any given value being read. | ||
| * ``mode`` (default ``PERMISSIVE``): allows a mode for dealing with corrupt records \ | ||
| during parsing. | ||
| * ``PERMISSIVE`` : sets other fields to ``null`` when it meets a corrupted record. \ | ||
| When a schema is set by user, it sets ``null`` for extra fields. | ||
| * ``DROPMALFORMED`` : ignores the whole corrupted records. | ||
| * ``FAILFAST`` : throws an exception when it meets corrupted records. | ||
|
|
||
| >>> df = sqlContext.read.csv('python/test_support/sql/ages.csv') | ||
| >>> df.dtypes | ||
| [('C0', 'string'), ('C1', 'string')] | ||
|
|
@@ -663,6 +702,19 @@ def csv(self, path, mode=None, compression=None): | |
| known case-insensitive shorten names (none, bzip2, gzip, lz4, | ||
| snappy and deflate). | ||
|
|
||
| You can set the following CSV-specific options to deal with CSV files: | ||
| * ``sep`` (default ``,``): sets the single character as a separator \ | ||
| for each field and value. | ||
| * ``quote`` (default ``"``): sets the single character used for escaping \ | ||
| quoted values where the separator can be part of the value. | ||
| * ``escape`` (default ``\``): sets the single character used for escaping quotes \ | ||
| inside an already quoted value. | ||
| * ``header`` (default ``false``): writes the names of columns as the first line. | ||
| * ``nullValue`` (default empty string): sets the string representation of a null value. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am less sure that |
||
| * ``compression``: compression codec to use when saving to file. This can be one of \ | ||
| the known case-insensitive shorten names (none, bzip2, gzip, lz4, snappy and \ | ||
| deflate). | ||
|
|
||
| >>> df.write.csv(os.path.join(tempfile.mkdtemp(), 'data')) | ||
| """ | ||
| self.mode(mode) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
encoding