Pyspark 将 StructType 传递给 Schema 时出错

ish*_*sha 4 apache-spark-sql pyspark

传递给架构方法时出现错误:类型错误:“StructType”对象不可调用。StructType下面是代码:

final_schema = StructType([StructField("id", StringType(), True)])
dataframe = sc.read.text('/path').schema(final_schema)
Run Code Online (Sandbox Code Playgroud)

数据为字符串类型,如下:

id
AO_01
AO_02
AO_03
Run Code Online (Sandbox Code Playgroud)

ish*_*sha 5

更改了调用,sc.read.schema(final_schema).text('/path')因为text(...)将返回一个数据帧实例并且需要在此之前设置架构。