Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 06-30-2016 06:15 AM
I have a list of hive tables and want to select the last table for performing some query. Here is what I use to get the list of similar hive tables.
show tables 'test_temp_table*';
It displays the below result
test_temp_table_1
test_temp_table_2
test_temp_table_3
test_temp_table_4
test_temp_table_5
test_temp_table_6
I need to run some query on test_temp_table_6. I can do this using shell script by writing the output to a temp file and reading the last value from it but is there a simple way using hive query to get the last table that has the maximum number at the end?
Created 06-30-2016 12:13 PM
Finally, I got the answer from Stackoverflow and wanted to propagate here. There isn't seems to be a straight way to get the last table name however the answer works just using a single line of shell script including the hive query. Here is it.
last_table=$(hive -e "show tables 'test_temp_table*';" | sort -r | head -n1)
Created 06-30-2016 12:13 PM
Finally, I got the answer from Stackoverflow and wanted to propagate here. There isn't seems to be a straight way to get the last table name however the answer works just using a single line of shell script including the hive query. Here is it.
last_table=$(hive -e "show tables 'test_temp_table*';" | sort -r | head -n1)
Created 06-30-2016 12:52 PM
@Alex Raj You can also create a script using 2 commands