Search code examples
linuxshellhivebeeline

Beeline usage instead of hive in shell script


In my shell script I am using this query to get the last_value of the column id.

last_val=`beeline -e "select nvl(max(id),0) from testing.1_test"`

The result is

+----------+--+
|   _c0    |
+----------+--+
| 3380901  |
+----------+--+

Now I want to pass this value as variable ${last_val}

when I do echo ${last_val} I want to have 3380901 but I am receiving

+----------+--+
|   _c0    |
+----------+--+
| 3380901  |
+----------+--+

How can I echo 3380901.

When I used hive option like below I got what I want

last_val=`hive -e "select nvl(max(id),0) from testing.1_test"`

echo ${last_val} gave me 3380901

Please let me know how can I do this?


Solution

  • last_val=`beeline --showHeader=false --outputformat=tsv2 -e "select nvl(max(id),0) from testing.1_test"`