cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

how to read columns dynamically using pyspark

Enthusiastic_Da
New Contributor II

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