数据类型

Spark SQLDataFrames 支持下面的数据类型 :  

// Spark SQL的所有数据类型都放在 org.apache.spark.sql.types 这个包下。你可以这样获取它们 : 
import org.apache.spark.sql.types._

完整示例代码参见 Spark 仓库中的 "examples/src/main/scala/org/apache/spark/examples/sql/SparkSQLExample.scala”。

数据类型 Scala 中值的类型
用于获取或创建数据类型的 API
ByteType Byte ByteType
ShortType Short ShortType
IntegerType Int IntegerType
LongType Long LongType
FloatType Float FloatType
DoubleType Double DoubleType
DecimalType java.math.BigDecimal DecimalType
StringType String StringType
BinaryType Array[Byte] BinaryType
BooleanType Boolean BooleanType
TimestampType java.sql.Timestamp TimestampType
DateType java.sql.Date DateType
ArrayType

scala.collection.Seq

ArrayType(elementType, [containsNull])

注意 : containsNull 的默认值是 true

MapType scala.collection.Map

MapType(keyType, valueType, [valueContainsNull])

注意 : valueContainsNull 的默认值是 true

StructType org.apache.spark.sql.Row

StructType(fields)

注意 : fields 是一个 StructField 序列,另外不允许出现名称重复的字段。

StructField Scala 中该字段的数据类型对应的值类型(例如,如果 StructField 的数据类型为 IntegerType,则 Scala 中其值类型为 Int list(name=name, type=dataType, nullable=nullable)