You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jr...@apache.org on 2018/01/10 18:48:05 UTC

[3/4] impala git commit: IMPALA-5317: [DOCS] Doc for DATE_TRUNC() function

IMPALA-5317: [DOCS] Doc for DATE_TRUNC() function

Change-Id: Ifcf38903bb10db12cbb8d73a2dc875aef29cd359
Reviewed-on: http://gerrit.cloudera.org:8080/8768
Reviewed-by: Tim Armstrong <ta...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/1f4d687a
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/1f4d687a
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/1f4d687a

Branch: refs/heads/master
Commit: 1f4d687a9bd51a5c869dd806fb31449cdfb34180
Parents: c86b0a9
Author: John Russell <jr...@cloudera.com>
Authored: Tue Dec 5 14:19:22 2017 -0800
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Wed Jan 10 18:41:31 2018 +0000

----------------------------------------------------------------------
 docs/impala_keydefs.ditamap               |  4 ++
 docs/shared/impala_common.xml             |  5 +-
 docs/topics/impala_datetime_functions.xml | 96 ++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/impala/blob/1f4d687a/docs/impala_keydefs.ditamap
----------------------------------------------------------------------
diff --git a/docs/impala_keydefs.ditamap b/docs/impala_keydefs.ditamap
index 56de937..02cff8a 100644
--- a/docs/impala_keydefs.ditamap
+++ b/docs/impala_keydefs.ditamap
@@ -10516,6 +10516,7 @@ under the License.
   <keydef href="https://issues.apache.org/jira/browse/IMPALA-9999" scope="external" format="html" keys="IMPALA-9999"/>
 
 <!-- Short form of mapping from Impala release to vendor-specific releases, for use in headings. -->
+  <keydef keys="impala211"><topicmeta><keywords><keyword>Impala 2.11</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala210"><topicmeta><keywords><keyword>Impala 2.10</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala29"><topicmeta><keywords><keyword>Impala 2.9</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala28"><topicmeta><keywords><keyword>Impala 2.8</keyword></keywords></topicmeta></keydef>
@@ -10531,6 +10532,9 @@ under the License.
   <keydef keys="impala13"><topicmeta><keywords><keyword>Impala 1.3</keyword></keywords></topicmeta></keydef>
 
 <!-- 3-part forms of version numbers, for use in release notes. -->
+<!-- For the 2.11.0 entry, have to space out the digits with underscores to avoid a conflict with the
+     keydef for Impala 2.1.10. -->
+  <keydef keys="impala2_11_0"><topicmeta><keywords><keyword>Impala 2.11.0</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala2100"><topicmeta><keywords><keyword>Impala 2.10.0</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala290"><topicmeta><keywords><keyword>Impala 2.9.0</keyword></keywords></topicmeta></keydef>
   <keydef keys="impala280"><topicmeta><keywords><keyword>Impala 2.8.0</keyword></keywords></topicmeta></keydef>

http://git-wip-us.apache.org/repos/asf/impala/blob/1f4d687a/docs/shared/impala_common.xml
----------------------------------------------------------------------
diff --git a/docs/shared/impala_common.xml b/docs/shared/impala_common.xml
index c272893..dc8cdb5 100644
--- a/docs/shared/impala_common.xml
+++ b/docs/shared/impala_common.xml
@@ -2787,7 +2787,10 @@ flight_num:           INT32 SNAPPY DO:83456393 FPO:83488603 SZ:10216514/11474301
         each value.
       </p>
 
-      <p rev="2.9.0" id="added_in_2100">
+      <p rev="2.11.0" id="added_in_2110">
+        <b>Added in:</b> <keyword keyref="impala2_11_0"/>
+      </p>
+      <p rev="2.10.0" id="added_in_2100">
         <b>Added in:</b> <keyword keyref="impala2100"/>
       </p>
       <p rev="2.9.0" id="added_in_290">

http://git-wip-us.apache.org/repos/asf/impala/blob/1f4d687a/docs/topics/impala_datetime_functions.xml
----------------------------------------------------------------------
diff --git a/docs/topics/impala_datetime_functions.xml b/docs/topics/impala_datetime_functions.xml
index de8291b..f4d062a 100644
--- a/docs/topics/impala_datetime_functions.xml
+++ b/docs/topics/impala_datetime_functions.xml
@@ -389,6 +389,102 @@ select date_sub(cast('2016-05-31' as timestamp), interval 1 months) as 'april_31
 
       </dlentry>
 
+      <dlentry rev="2.11.0 IMPALA-5317" id="date_trunc">
+
+        <dt>
+          <codeph>date_trunc(string unit, timestamp)</codeph>
+        </dt>
+
+        <dd>
+          <indexterm audience="hidden">date_trunc() function</indexterm>
+          <b>Purpose:</b> Truncates a <codeph>TIMESTAMP</codeph> value to the specified precision.
+          <p>
+            <b>Unit argument:</b> The <codeph>unit</codeph> argument value for truncating
+            <codeph>TIMESTAMP</codeph> values is not case-sensitive. This argument string
+            can be one of:
+          </p>
+          <ul>
+            <li>microseconds</li>
+            <li>milliseconds</li>
+            <li>second</li>
+            <li>minute</li>
+            <li>hour</li>
+            <li>day</li>
+            <li>week</li>
+            <li>month</li>
+            <li>year</li>
+            <li>decade</li>
+            <li>century</li>
+            <li>millennium</li>
+          </ul>
+          <p>
+            For example, calling <codeph>date_trunc('hour',ts)</codeph> truncates
+            <codeph>ts</codeph> to the beginning of the corresponding hour, with
+            all minutes, seconds, milliseconds, and so on set to zero. Calling
+            <codeph>date_trunc('milliseconds',ts)</codeph> truncates
+            <codeph>ts</codeph> to the beginning of the corresponding millisecond,
+            with all microseconds and nanoseconds set to zero.
+          </p>
+          <note>
+            The sub-second units are specified in plural form. All units representing
+            one second or more are specified in singular form.
+          </note>
+          <p conref="../shared/impala_common.xml#common/added_in_2110"/>
+          <p conref="../shared/impala_common.xml#common/usage_notes_blurb"/>
+          <p>
+            Although this function is similar to calling <codeph>TRUNC()</codeph>
+            with a <codeph>TIMESTAMP</codeph> argument, the order of arguments
+            and the recognized units are different between <codeph>TRUNC()</codeph>
+            and <codeph>DATE_TRUNC()</codeph>. Therefore, these functions are not
+            interchangeable.
+          </p>
+          <p>
+            This function is typically used in <codeph>GROUP BY</codeph>
+            queries to aggregate results from the same hour, day, week, month, quarter, and so on.
+            You can also use this function in an <codeph>INSERT ... SELECT</codeph> into a
+            partitioned table to divide <codeph>TIMESTAMP</codeph> values into the correct partition.
+          </p>
+          <p>
+            Because the return value is a <codeph>TIMESTAMP</codeph>, if you cast the result of
+            <codeph>DATE_TRUNC()</codeph> to <codeph>STRING</codeph>, you will often see zeroed-out portions such as
+            <codeph>00:00:00</codeph> in the time field. If you only need the individual units such as hour, day,
+            month, or year, use the <codeph>EXTRACT()</codeph> function instead. If you need the individual units
+            from a truncated <codeph>TIMESTAMP</codeph> value, run the <codeph>TRUNCATE()</codeph> function on the
+            original value, then run <codeph>EXTRACT()</codeph> on the result.
+          </p>
+          <p>
+            <b>Return type:</b> <codeph>timestamp</codeph>
+          </p>
+          <p conref="../shared/impala_common.xml#common/example_blurb"/>
+          <p>
+            The following examples show how to call <codeph>DATE_TRUNC()</codeph> with different unit values:
+          </p>
+<codeblock>
+select now(), date_trunc('second', now());
++-------------------------------+-----------------------------------+
+| now()                         | date_trunc('second', now())       |
++-------------------------------+-----------------------------------+
+| 2017-12-05 13:58:04.565403000 | 2017-12-05 13:58:04               |
++-------------------------------+-----------------------------------+
+
+select now(), date_trunc('hour', now());
++-------------------------------+---------------------------+
+| now()                         | date_trunc('hour', now()) |
++-------------------------------+---------------------------+
+| 2017-12-05 13:59:01.884459000 | 2017-12-05 13:00:00       |
++-------------------------------+---------------------------+
+
+select now(), date_trunc('millennium', now());
++-------------------------------+---------------------------------+
+| now()                         | date_trunc('millennium', now()) |
++-------------------------------+---------------------------------+
+| 2017-12-05 14:00:30.296812000 | 2000-01-01 00:00:00             |
++-------------------------------+---------------------------------+
+</codeblock>
+        </dd>
+
+      </dlentry>
+
       <dlentry id="datediff">
 
         <dt>