How to get column names and their parquet data types using pyspark?

I have a parquet file on my hadoop cluster, I want to capture the column names and their data types and write them to a text file. How to get column names and their parquet data types using pyspark.

+4
source share
2 answers

You can simply read the file and use it schemato access individual fields:

sqlContext.read.parquet(path_to_parquet_file).schema.fields
+8
source

Use dataframe.printSchema () - Prints a diagram in tree format.

  

df.printSchema () root | - Humor | - Name: string (nullable = true)

  

You can redirect the output of your program and fix it in a text file.

+2

Source: https://habr.com/ru/post/1623568/


All Articles