I have used df.printSchema()
in pyspark and it gives me the schema with tree structure. Now i need to save it in a variable or a text file.
I have tried below methods of saving but they didn't work.
v = str(df.printSchema())
print(v)
#and
df.printSchema().saveAsTextFile(<path>)
I need the saved schema in below format
|-- COVERSHEET: struct (nullable = true)
| |-- ADDRESSES: struct (nullable = true)
| | |-- ADDRESS: struct (nullable = true)
| | | |-- _VALUE: string (nullable = true)
| | | |-- _city: string (nullable = true)
| | | |-- _primary: long (nullable = true)
| | | |-- _state: string (nullable = true)
| | | |-- _street: string (nullable = true)
| | | |-- _type: string (nullable = true)
| | | |-- _zip: long (nullable = true)
| |-- CONTACTS: struct (nullable = true)
| | |-- CONTACT: array (nullable = true)
| | | |-- element: struct (containsNull = true)
| | | | |-- _VALUE: string (nullable = true)
| | | | |-- _name: string (nullable = true)
| | | | |-- _type: string (nullable = true)