Created 01-08-2018 08:45 AM
I want to create one table with name_timestamp,when ever I run the create script i need to get table name with timestamp.Can we able to do this?
Created 01-08-2018 10:50 AM
If you are using shell script, then you use the below script to create hive table with timestamp
# curr_timestamp=`date +%s` # hive -S -e "create table test_$curr_timestamp(name string)" # hive -S -e "show tables" > test_1515408162 // output of show tables
Thanks,
Aditya
Created 01-08-2018 10:50 AM
If you are using shell script, then you use the below script to create hive table with timestamp
# curr_timestamp=`date +%s` # hive -S -e "create table test_$curr_timestamp(name string)" # hive -S -e "show tables" > test_1515408162 // output of show tables
Thanks,
Aditya
Created 01-09-2018 08:36 AM
Thank You @Aditya Sirna.. what is the use os -S in that script. And Can I add two hive table id schema is same?
Created 01-09-2018 08:48 AM
-S is for running hive shell in silent mode. Yes you can create 2 tables with same schema. Make sure that table names are different
Created 01-09-2018 08:58 AM
@Ravikiran Dasari: You can see all parameters from hive with "hive -H".
hive -H usage: hive -d,--define <key=value> Variable substitution to apply to Hive commands. e.g. -d A=B or --define A=B -e <quoted-query-string> SQL from command line -f <filename> SQL from files -H,--help Print help information -h <hostname> Connecting to Hive Server on remote host --hiveconf <property=value> Use value for given property --hivevar <key=value> Variable substitution to apply to hive commands. e.g. --hivevar A=B -i <filename> Initialization SQL file -p <port> Connecting to Hive Server on port number -S,--silent Silent mode in interactive shell -v,--verbose Verbose mode (echo executed SQL to the console)
You can add two or more tables into the same schema if they have different names (which will be the case if you use the timestamp). If you are running your create script in parallel, you could always just get a new timestamp in case the tablename with the timestamp you have already exists. If needed you can add the date stamp as well by
curr_timestamp=`date +%Y%m%d_%s`