You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by "PICQUENOT Samuel (i-BP - CGI)" <Sa...@i-bp.fr> on 2016/01/19 11:31:47 UTC

Group by and FROM_UNIXTIME function

Hello,

Firstly, the FROM_UNIXTIME function's date pattern is case sensitive :

*         FROM_UNIXTIME(1451308548, 'yyyy-MM') --> 2015-12

*         FROM_UNIXTIME(1451308548, 'YYYY-MM') --> 2016-12 (because YYYY is not a valid date pattern and 2016 is the current year)

Consider the following query (dual is the oracle 1 row table) :
SELECT
  FROM_UNIXTIME(ts, 'yyyy-MM'),
  FROM_UNIXTIME(ts, 'YYYY-MM')
FROM (
  SELECT 1451308548 AS ts FROM dual -- Timestamp for the 2015-12-28 date
  UNION
  SELECT 1482930948 AS ts FROM dual -- Timestamp for the 2016-12-25 date
) dual
GROUP BY FROM_UNIXTIME(ts, 'YYYY-MM')

The query should throw an error because there is a field in the SELECT clause which is not present in the GROUP BY clause (without an aggregate function).
In deed the previous query returns only one row (from the 2016-12 value from the GROUP BY) but there is 2 distinct values (2015-12 and 2016-12) for the 1st field in the SELECT CLAUSE.

Is this an intended behavior ?

Best regards,
Samuel Picquenot



__________  L'int�grit� de ce message n'�tant pas assur�e sur Internet, la soci�t� i-BP ne peut �tre tenue responsable de son contenu. Si vous n'�tes pas destinataire de ce message, merci de le d�truire et d'avertir l'exp�diteur.  The integrity of this message cannot be guaranteed on the Internet. The i-BP company cannot therefore be considered responsible for the contents. If you are not the intended recipient of this message, then please delete it and notify the sender.  __________