You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by Santlal J Gupta <Sa...@bitwiseglobal.com> on 2015/07/27 08:17:49 UTC

Issue while working with Date

Hi,

I am beginner with working in hive.
I have one issue.
I have seen the source code of hive_master. In that source code there is one class named Date_Writable. In this class there is get and set method. One of set method tatking int  as argument.


  public DateWritable(int d) {
    set(d);
  }

  /**
   * Set the DateWritable based on the days since epoch date.
   * @param d integer value representing days since epoch date
   */
  public void set(int d) {
    daysSinceEpoch = d;
  }

  /**
   * Set the DateWritable based on the year/month/day of the date in the local timezone.
   * @param d Date value
   */
  public void set(Date d) {
    if (d == null) {
      daysSinceEpoch = 0;
      return;
    }

    set(dateToDays(d));
  }

  public void set(DateWritable d) {
    set(d.daysSinceEpoch);
  }

And there is one of method named get which will return the daysSinceEpoch

public int getDays() {
    return daysSinceEpoch;
  }

So my query is that if I pass the daysSinceEpoch as value to date column so it should take it.
For this I have written following query.

Query :

hive (primitive_type)> create table dateDemo(data Date) ;
OK
Time taken: 0.296 seconds

hive (primitive_type)> insert into dateDemo values(50);
OK
Time taken: 24.529 seconds

hive (primitive_type)> select * from dateDemo;
OK
NULL
Time taken: 0.168 seconds, Fetched: 1 row(s)

So can I insert epochDays in the date type column. So that when I read the column I will get actual date.
Please guide me for this issue.

Thanks,
Santlal J. Gupta




**************************************Disclaimer****************************************** This e-mail message and any attachments may contain confidential information and is for the sole use of the intended recipient(s) only. Any views or opinions presented or implied are solely those of the author and do not necessarily represent the views of BitWise. If you are not the intended recipient(s), you are hereby notified that disclosure, printing, copying, forwarding, distribution, or the taking of any action whatsoever in reliance on the contents of this electronic information is strictly prohibited. If you have received this e-mail message in error, please immediately notify the sender and delete the electronic message and any attachments.BitWise does not accept liability for any virus introduced by this e-mail or any attachments. ********************************************************************************************

Re: Issue while working with Date

Posted by Jason Dere <jd...@hortonworks.com>.
Hi Santlal,

While DateWritable uses daysSinceEpoch for its internal representation, I don't think there is a way to set a Date value in SQL using the days value. A more typical way to set a value would be something like

  insert into data values (date '2015-07-27')

I suppose you could create a UDF to generate a date value based on an int parameter representing daysSinceEpoch, but I wouldn't have expected that to have been a common use case.


Jason

________________________________________
From: Santlal J Gupta <Sa...@bitwiseglobal.com>
Sent: Sunday, July 26, 2015 11:17 PM
To: dev@hive.apache.org
Subject: Issue while working with Date

Hi,

I am beginner with working in hive.
I have one issue.
I have seen the source code of hive_master. In that source code there is one class named Date_Writable. In this class there is get and set method. One of set method tatking int  as argument.


  public DateWritable(int d) {
    set(d);
  }

  /**
   * Set the DateWritable based on the days since epoch date.
   * @param d integer value representing days since epoch date
   */
  public void set(int d) {
    daysSinceEpoch = d;
  }

  /**
   * Set the DateWritable based on the year/month/day of the date in the local timezone.
   * @param d Date value
   */
  public void set(Date d) {
    if (d == null) {
      daysSinceEpoch = 0;
      return;
    }

    set(dateToDays(d));
  }

  public void set(DateWritable d) {
    set(d.daysSinceEpoch);
  }

And there is one of method named get which will return the daysSinceEpoch

public int getDays() {
    return daysSinceEpoch;
  }

So my query is that if I pass the daysSinceEpoch as value to date column so it should take it.
For this I have written following query.

Query :

hive (primitive_type)> create table dateDemo(data Date) ;
OK
Time taken: 0.296 seconds

hive (primitive_type)> insert into dateDemo values(50);
OK
Time taken: 24.529 seconds

hive (primitive_type)> select * from dateDemo;
OK
NULL
Time taken: 0.168 seconds, Fetched: 1 row(s)

So can I insert epochDays in the date type column. So that when I read the column I will get actual date.
Please guide me for this issue.

Thanks,
Santlal J. Gupta




**************************************Disclaimer****************************************** This e-mail message and any attachments may contain confidential information and is for the sole use of the intended recipient(s) only. Any views or opinions presented or implied are solely those of the author and do not necessarily represent the views of BitWise. If you are not the intended recipient(s), you are hereby notified that disclosure, printing, copying, forwarding, distribution, or the taking of any action whatsoever in reliance on the contents of this electronic information is strictly prohibited. If you have received this e-mail message in error, please immediately notify the sender and delete the electronic message and any attachments.BitWise does not accept liability for any virus introduced by this e-mail or any attachments. ********************************************************************************************