1

I'm having trouble writing a statement to count the number of columns in Spark SQL. I tried using the information schema and using the table.columns, but both don't seem to work in Spark SQL. Does anyone have any suggestions?

1 Answer 1

1

Below is couple of lines you can add to count number of columns in Spark SQL,

Pyspark Solution:

df_cont = spark.creatDataframe() // use right funtion to create dataframe based on source 
print("Number of columns:"+str(len(df_cont.columns)))

Scala Solution:

val df_cont = spark.creatDataframe() // use right funtion to create dataframe based on source 
val length = df_cont.columns.length
println("Number of columns:"+length)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.