Hey Elango!

Variables are not evaluated at assignment time - instead they are evaluated at 
the time of usage.

If you want to save the current time somehow I think you could:
* put the current_timestamp into a temporary table:
  create temporary table start_time as select current_timestamp() as t;
* not sure about your use case; but if you need the start date of the session 
you could set it as an external variable when you start the session:
  beeline -hivevar start_time=`date "+%Y-%m-%d %H:%M:%S"
  select current_timestamp() - cast('${hivevar:start_time}' as timestamp);
* consider using hplsql I think with that it might be possible to store it in a 
variable; however hplsql approaches things a bit differently...
  I can't give you an example how to do this right the top of my head


cheers,
Zoltan

On 11/30/21 7:03 AM, elango vaidyanathan wrote:


Hi All, any updates on this?

Thanks,
Elango

On Fri, Nov 26, 2021, 11:09 AM elango vaidyanathan <elango...@gmail.com 
<mailto:elango...@gmail.com>> wrote:


    Hi all,

    I am trying to create a hive variable and store the current time stamp. 
Then run some complex select queries and then create another variable to store 
current timestamp
    and then find the runtime.
    The problem I am facing is every time I use the variable it gives me the 
current time instead of the assigned value. It just runs the current timestamp 
function every
    time. Below is the code snippet.

    Code

    set hivevar:start_tm=current_timestamp();____

    select ${hivevar:start_tm};____

    select query;__

    select ${hivevar:start_tm};


    Here the start_tm variable calculates every time the current time and 
returns always the current time. How can I just store the value once and use 
that value for this
    variable. Please clarify.


    Thanks,
    Elango

Reply via email to