how to read schema from text file stored in cloud storage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 11:48 PM
I have file a.csv or a.parquet while creating data frame reading we can explictly define schema with struct type. instead of write the schema in the notebook want to create schema lets say for all my csv i have one schema like csv_schema and stored in cloud storage. if any addition or deletion i will do that in csv_schema file separately.
In notebook when creating data frame during reading file want to pass this schema which stored in separate file .Please suggest if we can write any function in python or other idea to automate schema creation and addition in data frame for different file systemSo its like, i have schema file a.schema where i have the schema definition for all the parquet file/any file its generic. kind of like
a.schema text file contains below details
schema1=StructType([StructField("x1", StringType(), True),StructField("Name", StringType(), True),StructField("PRICE", DoubleType(), True)])
read the a.schema from storage in notebook create the required schema which need to pass to dataframe.
df=spark.read.schema(generic schema).parquet ..