Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyspark error passing StructType to Schema

Getting Error : TypeError: 'StructType' object is not callable, while passing StructType to the schema method. Below is the code:

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

Data is string type as below:

id
AO_01
AO_02
AO_03
like image 487
isha Avatar asked Oct 17 '25 14:10

isha


1 Answers

Changed the call to sc.read.schema(final_schema).text('/path') because text(...) will return a dataframe instance and need to set schema before that.

like image 139
isha Avatar answered Oct 22 '25 06:10

isha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!