目录
总
在 Spark-2.1.0 以后支持的 Options 如下:
--------- JDBC’s options ---------
user
password
url
dbtable
driver
partitionColumn
lowerBound
upperBound
numPartitions
fetchsize
truncate
createTableOptions
batchsize
isolationLevel
--------- CSV’s options ---------
path
sep
delimiter
mode
encoding
charset
quote
escape
comment
header
inferSchema
ignoreLeadingWhiteSpace
ignoreTrailingWhiteSpace
nullValue
nanValue
positiveInf
negativeInf
compression
codec
dateFormat
timestampFormat
maxColumns
maxCharsPerColumn
escapeQuotes
quoteAll
--------- JSON’s options ---------
path
samplingRatio
primitivesAsString
prefersDecimal
allowComments
allowUnquotedFieldNames
allowSingleQuotes
allowNumericLeadingZeros
allowNonNumericNumbers
allowBackslashEscapingAnyCharacter
compression
mode
columnNameOfCorruptRecord
dateFormat
timestampFormat
--------- Parquet’s options ---------
path
compression
mergeSchema.
--------- ORC’s options ---------
path
compression
orc.compress.
--------- FileStream’s options ---------
path
maxFilesPerTrigger
maxFileAge
latestFirst.
--------- Text’s options ---------
path
compression
--------- LibSVM’s options -------
path
vectorType
numFeatures
分:
1.CSV
Spark读取CSV文件详解
如题,有一个spark读取csv的需求,这会涉及到很多参数。通过对源码(spark version 2.4.5(DataFrameReader.scala:535 line))的阅读,现在我总结在这里:
spark读取csv的代码如下
val dataFrame: DataFrame = spark.read.format("csv")
.option("header", "true")
.option("encoding", "gbk2312")
.load(path)
这个option
里面的参数,进行介绍:
spark
读取csv
的时候,如果inferSchema
开启,spark
只会输入一行数据,推测它的表结构类型,避免遍历一次所有的数,禁用inferSchema
参数的时候,或者直接指定schema
。
参数 |
解释 |
sep |
默认是, 指定单个字符分割字段和值 |
encoding |
默认是uft-8通过给定的编码类型进行解码 |
quote |
默认是“,其中分隔符可以是值的一部分,设置用于转义带引号的值的单个字符。如果您想关闭引号,则需要设置一个空字符串,而不是null。 |
escape |
默认(\)设置单个字符用于在引号里面转义引号 |
charToEscapeQuoteEscaping |
默认是转义字符(上面的escape)或者\ |