Select all except particular column in spark sql

Patel picture Patel · Apr 26, 2017 · Viewed 12.1k times · Source

I want to select all columns in a table except StudentAddress and hence I wrote following query:

select `(StudentAddress)?+.+` from student;

It gives following error in Squirrel Sql client. org.apache.spark.sql.AnalysisException: cannot resolve '(StudentAddress)?+.+' given input columns

Answer

Neeraj Malhotra picture Neeraj Malhotra · Nov 17, 2017

You can use drop() method in the DataFrame API to drop a particular column and then select all the columns.

For example:

val df = hiveContext.read.table("student")
val dfWithoutStudentAddress = df.drop("StudentAddress")