linuxhivebeeline

how to remove table names from column names in beeline query results


I am saving beeline query output to a csv file. However the column names in the csv files contain the table name too. For example if table name is sales and col name is Date then csv has sales.Date as the column name. I googled around and found a very good solution in Stack overflow Hive - How to display Hive query results in the Command Line along with column names

I tried doing below from hive terminal and it works.

set hive.resultset.use.unique.column.names=false;

However when I try saving the file to csv from command line it still puts the table name in column names.

Is there any way to avoid that?

Query used from CLI:-

bee_line --outputformat=csv2 --showHeader=true --silent=true -e "select * from salesdata.ales" >path-to-csv

where bee_line is an alias for full connection string stored in bash profile.


Solution

  • You can set hive properties as arguments to beeline using the --hiveconf option.

    Your command would look like,

    bee_line --hiveconf hive.resultset.use.unique.column.names=false -outputformat=csv2 --showHeader=true --silent=true -e "select * from salesdata.ales" >path-to-csv
    

    Note: Restricted properties cannot be passed to this option.