Support Questions

Find answers, ask questions, and share your expertise

how to create hive table with timestamp as name?

avatar
Rising Star

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?

1 ACCEPTED SOLUTION

avatar
Super Guru

@Ravikiran Dasari,

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

View solution in original post

4 REPLIES 4

avatar
Super Guru

@Ravikiran Dasari,

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

avatar
Rising Star

Thank You @Aditya Sirna.. what is the use os -S in that script. And Can I add two hive table id schema is same?

avatar
Super Guru

@Ravikiran Dasari,

-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

avatar
Super Collaborator

@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`