cancel
Showing results for 
Search instead for 
Did you mean: 

how to read columns dynamically using pyspark

Enthusiastic_Da
New Contributor

I have a table called MetaData and what columns are needed in the select are stored in MetaData.columns

I would like to read columns dynamically from MetaData.columns and create a view based on that.

csv_values = "col1, col2, col3, col4"

df = spark.createDataFrame([(csv_values,)], ["csv_column"])

df = df.select(split(df["csv_column"], ",").alias("array_column"))

df1 = spark.read.format("parquet").load("FilePath").select(df["*"])

This code is throwing error like below

Unexpected exception formatting exception. Falling back to standard exception

0 REPLIES 0
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.