I have around 300 variables and I am trying to pass customschema via csv. Below is the sample code which I am using. However on uploading the schema via csv files...The output doesnt contain columns list:
Output : StructType(List(StructField(StructType([,StringType,true)))
Code in CSV:
schema = StructType([ \
StructField("COl1",StringType(),True), \
StructField("COL2",DecimalType(20,10),True), \
StructField("COL3",DecimalType(20,10),True)
])
# reading schema
sch_df = spark.read.option("header", "true").csv("schema.csv").schema
# Passing schema
df = spark.read.schema(sch_df).option("header", "true").csv("/sample.csv")
Can you please provide the right away to upload the schema via csv file?