Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the table name from a Spark Dataframe

If I have a dataframe created as follows:

df = spark.table("tblName")

Is there anyway that I can get back tblName from df?

like image 986
Subramaniam Ramasubramanian Avatar asked Sep 27 '18 13:09

Subramaniam Ramasubramanian


People also ask

How do I get a PySpark DataFrame name?

You can find all column names & data types (DataType) of PySpark DataFrame by using df. dtypes and df. schema and you can also retrieve the data type of a specific column name using df. schema["name"].

How can I see the table in Spark?

Spark show() – Display DataFrame Contents in Table. Spark DataFrame show() is used to display the contents of the DataFrame in a Table Row & Column Format. By default, it shows only 20 Rows and the column values are truncated at 20 characters.

How do I get data from Spark DataFrame?

PySpark Collect() – Retrieve data from DataFrame. Collect() is the function, operation for RDD or Dataframe that is used to retrieve the data from the Dataframe. It is used useful in retrieving all the elements of the row from each partition in an RDD and brings that over the driver node/program.


Video Answer


1 Answers

You can extract it from the plan:

df.logicalPlan().argString().replace("`","")
like image 129
Alex Stanovsky Avatar answered Oct 13 '22 12:10

Alex Stanovsky