zoukankan      html  css  js  c++  java
  • Pyspark:AssertionError: dataType should be DataType

    1. schema参数,AssertionError: dataType should be DataType

    # AssertionError: dataType should be DataType
    schema = StructType([
            # true代表不为空
            StructField("col_1", StringType, True),
            StructField("col_2", StringType, True),
            StructField("col_3", StringType, True),
          ]
    )
    #原因:StringType等后面没有加括号“()”
    #修改为:
    schema = StructType([
            # true代表不为空
            StructField("col_1", StringType(), True),
            StructField("col_2", StringType(), True),
            StructField("col_3", StringType(), True),
          ]
    )

    2. pyspark目前的数据类型有:

    NullType、StringType、BinaryType、BooleanType、DateType、TimestampType、DecimalType、DoubleType、FloatType、ByteType、IntegerType、LongType、ShortType、ArrayType、MapType、StructType(StructField)等,要根据情况使用,注意可能的溢出问题。

    其中大佬总结的对应python数据类型如下:

    NullType None
    StringType basestring
    BinaryType bytearray
    BooleanType bool
    DateType datetime.date
    TimestampType datetime.datetime
    DecimalType decimal.Decimal
    DoubleType float(double precision floats)
    FloatType float(single precision floats)
    ByteType int(a signed integer)
    IntegerType int(a signed 32-bit integer)
    LongType long(a signed 64-bit integer)
    ShortType int(a signed 16-bit integer)

    参考:https://www.cnblogs.com/yurunmiao/p/4923694.html

  • 相关阅读:
    js FormData 的使用
    js代码 注释 test
    JavaScript创建对象的几种 方式
    js prototype 原型
    C# 遍历对象下的 属性
    C#模拟按键
    C#获取硬盘序列号
    C#结束Explorer进程
    Java书籍推荐
    编程资料合集
  • 原文地址:https://www.cnblogs.com/qi-yuan-008/p/11770339.html
Copyright © 2011-2022 走看看