apache-sparkapache-spark-sqlhivespark-hive

Select all except particular column in spark sql


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


Solution

  • 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")