Spark DataSet Options

本文详细介绍了Spark 2.1.0及以后版本中,针对CSV和JDBC数据集的读取选项。在CSV部分,重点讲解了如何通过设置`header`和`encoding`等参数来高效读取CSV文件,同时提到了自动表结构推测的功能。在JDBC部分,虽然未展开详细内容,但暗示了存在类似的配置选项。
摘要由CSDN通过智能技术生成

目录

 

分:

1.CSV

2.JDBC


在 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)或者\

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值