Reputation: 2095
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?
Upvotes: 1
Views: 1407
Reputation: 38335
Using shell:
last_table=$(hive -e "show tables 'test_temp_table*';" | sort -r | head -n1)
Upvotes: 2
Reputation: 813
You can actually run a "select query" on the Hive metastore based on tablenames (and then use regular sql sorting using ORDER BY DESC and LIMIT 1) instead of using "SHOW TABLES", by following the approach mentioned here: Query Hive Metadata Store for table metadata
Upvotes: 0