所有 Spark SQL DataType 的 Scala 类型映射是什么

What is the Scala type mapping for all Spark SQL DataType

可在 here 中找到可用于 Spark SQL 的不同 DataType。谁能告诉我每个 Spark SQL 的 DataType 对应的 Java/Scala 数据类型是什么?

直接来自 Spark SQL and DataFrame Guide:

Data type       |    Value type in Scala
------------------------------------------------
ByteType        |    Byte   
ShortType       |    Short  
IntegerType     |    Int    
LongType        |    Long   
FloatType       |    Float  
DoubleType      |    Double     
DecimalType     |    java.math.BigDecimal
StringType      |    String
BinaryType      |    Array[Byte]
BooleanType     |    Boolean 
TimestampType   |    java.sql.Timestamp
DateType        |    java.sql.Date
ArrayType       |    scala.collection.Seq   
MapType         |    scala.collection.Map   
StructType      |    org.apache.spark.sql.Row

对于那些试图找到 Java 类型的人,它们现在也托管在 的 link。要在此处记录当前修订:

Data type     |    Value type in Java              |    API to access or create a data type
-------------------------------------------------------------------------------------------
ByteType      |    byte or Byte                    |    DataTypes.ByteType
ShortType     |    short or Short                  |    DataTypes.ShortType
IntegerType   |    int or Integer                  |    DataTypes.IntegerType
LongType      |    long or Long                    |    DataTypes.LongType
FloatType     |    float or Float                  |    DataTypes.FloatType
DoubleType    |    double or Double                |    DataTypes.DoubleType
DecimalType   |    java.math.BigDecimal            |    DataTypes.createDecimalType() or DataTypes.createDecimalType(precision, scale).
StringType    |    String                          |    DataTypes.StringType
BinaryType    |    byte[]                          |    DataTypes.BinaryType
BooleanType   |    boolean or Boolean              |    DataTypes.BooleanType
TimestampType |    java.sql.Timestamp              |    DataTypes.TimestampType
DateType      |    java.sql.Date                   |    DataTypes.DateType
ArrayType     |    java.util.List                  |    DataTypes.createArrayType(elementType) or DataTypes.createArrayType(elementType, containsNull).
MapType       |    java.util.Map                   |    DataTypes.createMapType(keyType, valueType) or DataTypes.createMapType(keyType, valueType, valueContainsNull)
StructType    |    org.apache.spark.sql.Row        |    DataTypes.createStructType(fields)
StructField   |    The value type in Java of the   |    DataTypes.createStructField(name, dataType, nullable)
              |    data type of this field (For    |
              |    example, int for a StructField  |
              |    with the data type IntegerType) |

特别是在使用 StructTypes 时需要注意一件事 - 看起来,如果您希望在另一个中声明一个空的 StructType 作为占位符值,您必须使用 new StructType() 而不是建议的 DataTypes.createStructType((StructField)null) 来防止空指针。请记住在使用前使用 StructFields 实例化嵌套的 StructType。