1

I am trying to write a file to s3 the name of which should contain current year day and month. To do this I want to define variables to get year, month and day

set year=year(from_unixtime(unix_timestamp()));
set month=month(from_unixtime(unix_timestamp()));
set day=day(from_unixtime(unix_timestamp()));

CREATE EXTERNAL TABLE abc (col1 int, col2 varchar(100), col3 INT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION "s3://location_${hiveconf:year}${hiveconf:month}${hiveconf:day}/"
TBLPROPERTIES ("skip.header.line.count"="1");

If I run the script - 'select "${hiveconf:year}";' I get 'year(from_unixtime(unix_timestamp()))' as output.

Is there any other way to include day, month and year in the filename?

1 Answers1

0

As far as I know, the set command will never evaluate a function, thats why it's returning the string the way it is.

see this for more info: How to store the output of a query in a variable in HIVE

One recommendation is to use shell to capture the date and then pass that through as a parameter to your sql script.

AndyK
  • 9
  • 4