<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Gap filling and interpolation (GFI)</title>
    <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/</link>
    <description>Recent content in Gap filling and interpolation (GFI) on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Constant interpolation</title>
      <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/constant-interpolation/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/constant-interpolation/</guid>
      <description>
        
        
        &lt;p&gt;Given known input timestamps at 03:00:00 and 03:00:05 in the &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/&#34;&gt;sample TickStore schema&lt;/a&gt;, how might you determine the bid price at 03:00:03?&lt;/p&gt;
&lt;p&gt;A common interpolation scheme used on financial data is to set the bid price to &lt;em&gt;the last seen value so far&lt;/em&gt;. This scheme is referred to as &lt;strong&gt;constant interpolation&lt;/strong&gt;, in which the database computes a new value based on the previous input records.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Constant is OpenText™ Analytics Database&#39;s default interpolation scheme. Another interpolation scheme, &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/linear-interpolation/&#34;&gt;linear&lt;/a&gt;, is discussed in an upcoming topic.

&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Returning to the problem query, here is the table output, which shows a 5-second lag between bids at 03:00:00 and 03:00:05:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM TickStore;
         ts          | symbol | bid
---------------------+--------+------
 2009-01-01 03:00:00 | XYZ    |   10
 2009-01-01 03:00:05 | XYZ    | 10.5
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using constant interpolation, the interpolated bid price of &lt;code&gt;XYZ&lt;/code&gt; remains at $10.0 at 3:00:03, which falls between the two known data inputs (3:00:00 PM and 3:00:05). At 3:00:05, the value changes to $10.5. The known data points are represented by a red dot, and the interpolated value at 3:00:03 is represented by the blue star.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../../images/gfi1kp-1.png&#34; alt=&#34;TickStore table with 3-second time slice&#34;&gt;&lt;/p&gt;
&lt;p&gt;In order to write a query that makes the input rows more uniform, you first need to understand the &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/timeseries-clause-and-aggregates/&#34;&gt;TIMESERIES clause and time series aggregate functions&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: TIMESERIES clause and aggregates</title>
      <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/timeseries-clause-and-aggregates/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/timeseries-clause-and-aggregates/</guid>
      <description>
        
        
        &lt;p&gt;The SELECT..TIMESERIES clause and time series aggregates help solve the problem of gaps in input records by normalizing the data into 3-second time slices and interpolating the bid price when it finds gaps.&lt;/p&gt;
&lt;h2 id=&#34;timeseries-clause&#34;&gt;TIMESERIES clause&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/#&#34;&gt;TIMESERIES clause&lt;/a&gt; is an important component of time series analytics computation. It performs gap filling and interpolation (GFI) to generate time slices missing from the input records. The clause applies to the timestamp columns/expressions in the data, and takes the following form:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;TIMESERIES &lt;span class=&#34;code-variable&#34;&gt;slice_time&lt;/span&gt; AS &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;length_and_time_unit_expression&#39;&lt;/span&gt;
OVER ( ... [ &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-partition-clause/#&#34;&gt;window-partition-clause&lt;/a&gt;&lt;/span&gt;[ &lt;span class=&#34;code-variable&#34;&gt;, ...&lt;/span&gt; ] ] &lt;span class=&#34;code-variable&#34;&gt;&lt;/span&gt;
... ORDER BY &lt;span class=&#34;code-variable&#34;&gt;time_expression&lt;/span&gt; )
... [ ORDER BY &lt;span class=&#34;code-variable&#34;&gt;table_column&lt;/span&gt; [ , ... ] ]
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The TIMESERIES clause requires an ORDER BY operation on the timestamp column.

&lt;/div&gt;
&lt;h2 id=&#34;time-series-aggregate-functions&#34;&gt;Time series aggregate functions&lt;/h2&gt;
&lt;p&gt;The Timeseries Aggregate (TSA) functions &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-first-value/#&#34;&gt;TS_FIRST_VALUE&lt;/a&gt; and &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-last-value/#&#34;&gt;TS_LAST_VALUE&lt;/a&gt; evaluate the values of a given set of variables over time and group those values into a window for analysis and aggregation.&lt;/p&gt;
&lt;p&gt;TSA functions process the data that belongs to each time slice. One output row is produced per time slice or per partition per time slice if a partition expression is present.&lt;/p&gt;
&lt;p&gt;The following table shows 3-second time slices where:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The first two rows fall within the first time slice, which runs from 3:00:00 to 3:00:02. These are the input rows for the TSA function&#39;s output for the time slice starting at 3:00:00.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The second two rows fall within the second time slice, which runs from 3:00:03 to 3:00:05. These are the input rows for the TSA function&#39;s output for the time slice starting at 3:00:03.&lt;/p&gt;
&lt;p&gt;The result is the start of each time slice.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../../images/tsa.png&#34; alt=&#34;time series aggregate output&#34;&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following examples compare the values returned with and without the TS_FIRST_VALUE TSA function.&lt;/p&gt;
&lt;p&gt;This example shows the TIMESERIES clause without the TS_FIRST_VALUE TSA function.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, bid FROM TickStore TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39; OVER(PARTITION by TickStore.bid ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This example shows both the TIMESERIES clause and the TS_FIRST_VALUE TSA function. The query returns the values of the &lt;code&gt;bid&lt;/code&gt; column, as determined by the specified constant interpolation scheme.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, TS_FIRST_VALUE(bid, &amp;#39;CONST&amp;#39;) bid FROM TickStore
   TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39; OVER(PARTITION by symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database interpolates the last known value and fills in the missing datapoint, returning 10 at 3:00:03:

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;td &gt;


First query&lt;/td&gt; 

&lt;td &gt;
&lt;/td&gt; 

&lt;td &gt;


Interpolated value&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;









&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | bid
---------------------+-----
 2009-01-01 03:00:00 |  10
 2009-01-01 03:00:03 | 10.5
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt; 

&lt;td &gt;


&lt;strong&gt;&lt;code&gt;==&amp;gt;&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt; 

&lt;td &gt;









&lt;pre class=&#34;table-pre&#34;&gt;     slice_time      | bid
---------------------+-----
 2009-01-01 03:00:00 |  10
 2009-01-01 03:00:03 |  &lt;span class=&#34;code-input&#34;&gt;10&lt;/span&gt;
(2 rows)
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Time series rounding</title>
      <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/time-series-rounding/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/time-series-rounding/</guid>
      <description>
        
        
        &lt;p&gt;OpenText™ Analytics Database calculates all time series as equal intervals relative to the timestamp &lt;code&gt;2000-01-01 00:00:00&lt;/code&gt;. The database rounds time series timestamps as needed, to conform with this baseline. Start times are also rounded down to the nearest whole unit for the specified interval.&lt;/p&gt;
&lt;p&gt;Given this logic, the &lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/&#34;&gt;TIMESERIES&lt;/a&gt; clause generates series of timestamps as described in the following sections.&lt;/p&gt;
&lt;h2 id=&#34;minutes&#34;&gt;Minutes&lt;/h2&gt;
&lt;p&gt;Time series of minutes are rounded down to full minutes. For example, the following statement specifies a time span of &lt;code&gt;00:00:03&lt;/code&gt; - &lt;code&gt;00:05:50&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
    SELECT &amp;#39;2015-01-04 00:00:03&amp;#39;::TIMESTAMP AS tm
      UNION
    SELECT &amp;#39;2015-01-04 00:05:50&amp;#39;::TIMESTAMP AS tm
   ) t
   TIMESERIES ts AS &amp;#39;1 minute&amp;#39; OVER (ORDER BY tm);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database rounds down the time series start and end times to full minutes, &lt;code&gt;00:00:00&lt;/code&gt; and &lt;code&gt;00:05:00&lt;/code&gt;, respectively:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
         ts
---------------------
 2015-01-04 00:00:00
 2015-01-04 00:01:00
 2015-01-04 00:02:00
 2015-01-04 00:03:00
 2015-01-04 00:04:00
 2015-01-04 00:05:00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;weeks&#34;&gt;Weeks&lt;/h2&gt;
&lt;p&gt;Because the baseline timestamp &lt;code&gt;2000-01-01 00:00:00&lt;/code&gt; is a Saturday, all time series of weeks start on Saturday. The database rounds down the series start and end timestamps accordingly. For example, the following statement specifies a time span of 12/10/99 - 01/10/00:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
     SELECT &amp;#39;1999-12-10 00:00:00&amp;#39;::TIMESTAMP AS tm
       UNION
     SELECT &amp;#39;2000-01-10 23:59:59&amp;#39;::TIMESTAMP AS tm
     ) t
     TIMESERIES ts AS &amp;#39;1 week&amp;#39; OVER (ORDER BY tm);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The specified time span starts on Friday (12/10/99), so the database starts the time series on the preceding Saturday, 12/04/99. The time series ends on the last Saturday within the time span, 01/08/00:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;         ts
---------------------
 1999-12-04 00:00:00
 1999-12-11 00:00:00
 1999-12-18 00:00:00
 1999-12-25 00:00:00
 2000-01-01 00:00:00
 2000-01-08 00:00:00
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;months&#34;&gt;Months&lt;/h2&gt;
&lt;p&gt;Time series of months are divided into equal 30-day intervals, relative to the baseline timestamp &lt;code&gt;2000-01-01 00:00:00&lt;/code&gt;. For example, the following statement specifies a time span of 09/01/99 - 12/31/00:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
     SELECT &amp;#39;1999-09-01 00:00:00&amp;#39;::TIMESTAMP AS tm
       UNION
     SELECT &amp;#39;2000-12-31 23:59:59&amp;#39;::TIMESTAMP AS tm
   ) t
   TIMESERIES ts AS &amp;#39;1 month&amp;#39; OVER (ORDER BY tm);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database generates a series of 30-day intervals, where each timestamp is rounded up or down, relative to the baseline timestamp:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;         ts
---------------------
 1999-08-04 00:00:00
 1999-09-03 00:00:00
 1999-10-03 00:00:00
 1999-11-02 00:00:00
 1999-12-02 00:00:00
 2000-01-01 00:00:00
 2000-01-31 00:00:00
 2000-03-01 00:00:00
 2000-03-31 00:00:00
 2000-04-30 00:00:00
 2000-05-30 00:00:00
 2000-06-29 00:00:00
 2000-07-29 00:00:00
 2000-08-28 00:00:00
 2000-09-27 00:00:00
 2000-10-27 00:00:00
 2000-11-26 00:00:00
 2000-12-26 00:00:00
(18 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;years&#34;&gt;Years&lt;/h2&gt;
&lt;p&gt;Time series of years are divided into equal 365-day intervals. If a time span overlaps leap years since or before the baseline timestamp &lt;code&gt;2000-01-01 00:00:00&lt;/code&gt;, the database rounds the series timestamps accordingly.&lt;/p&gt;
&lt;p&gt;For example, the following statement specifies a time span of 01/01/95 - 05/08/09, which overlaps four leap years, including the baseline timestamp:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
      SELECT &amp;#39;1995-01-01 00:00:00&amp;#39;::TIMESTAMP AS tm
        UNION
      SELECT &amp;#39;2009-05-08&amp;#39;::TIMESTAMP AS tm
    ) t timeseries ts AS &amp;#39;1 year&amp;#39; over (ORDER BY tm);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database generates a series of timestamps that are rounded up or down, relative to the baseline timestamp:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;         ts
---------------------
 1994-01-02 00:00:00
 1995-01-02 00:00:00
 1996-01-02 00:00:00
 1997-01-01 00:00:00
 1998-01-01 00:00:00
 1999-01-01 00:00:00
 2000-01-01 00:00:00
 2000-12-31 00:00:00
 2001-12-31 00:00:00
 2002-12-31 00:00:00
 2003-12-31 00:00:00
 2004-12-30 00:00:00
 2005-12-30 00:00:00
 2006-12-30 00:00:00
 2007-12-30 00:00:00
 2008-12-29 00:00:00
(16 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Linear interpolation</title>
      <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/linear-interpolation/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/linear-interpolation/</guid>
      <description>
        
        
        &lt;p&gt;Instead of interpolating data points based on the last seen value (&lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/constant-interpolation/#&#34;&gt;Constant interpolation&lt;/a&gt;), linear interpolation is where OpenText™ Analytics Database interpolates values in a linear slope based on the specified time slice.&lt;/p&gt;
&lt;p&gt;The query that follows uses linear interpolation to place the input records in 2-second time slices and return the first bid value for each symbol/time slice combination (the value at the start of the time slice):&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, TS_FIRST_VALUE(bid, &amp;#39;LINEAR&amp;#39;) bid FROM Tickstore
   TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39; OVER(PARTITION BY symbol ORDER BY ts);
     slice_time      | bid
---------------------+------
 2009-01-01 03:00:00 |   10
 2009-01-01 03:00:02 | 10.2
 2009-01-01 03:00:04 | 10.4
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following figure illustrates the previous query results, showing the 2-second time gaps (3:00:02 and 3:00:04) in which no input record occurs. Note that the interpolated bid price of &lt;code&gt;XYZ&lt;/code&gt; changes to 10.2 at 3:00:02 and 10.3 at 3:00:03 and 10.4 at 3:00:04, all of which fall between the two known data inputs (3:00:00 and 3:00:05). At 3:00:05, the value would change to 10.5.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../../images/gfi3kp2.png&#34; alt=&#34;linear interpolation with ts_first_value&#34;&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The known data points above are represented by a red dot, and the interpolated values are represented by blue stars.

&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;The following is a side-by-side comparison of constant and linear interpolation schemes.

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;td &gt;


&lt;strong&gt;CONST interpolation&lt;/strong&gt;&lt;/td&gt; 

&lt;td &gt;


&lt;strong&gt;LINEAR interpolation&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;


&lt;img src=&#34;../../../../images/gfi1-1.png&#34; alt=&#34;constant interpolation&#34;&gt;&lt;/td&gt; 

&lt;td &gt;


&lt;img src=&#34;../../../../images/gfi3-1.png&#34; alt=&#34;linear interpolation&#34;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: GFI examples</title>
      <link>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/gfi-examples/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/gfi-examples/</guid>
      <description>
        
        
        &lt;p&gt;This topic illustrates some of the queries you can write using the constant and linear interpolation schemes.&lt;/p&gt;
&lt;h2 id=&#34;constant-interpolation&#34;&gt;Constant interpolation&lt;/h2&gt;
&lt;p&gt;The first query uses &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-first-value/&#34;&gt;TS_FIRST_VALUE()&lt;/a&gt; and the &lt;a href=&#34;../../../../en/sql-reference/statements/select/timeseries-clause/#&#34;&gt;TIMESERIES clause&lt;/a&gt; to place the input records in 3-second time slices and return the first bid value for each symbol/time slice combination (the value at the start of the time slice).

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The TIMESERIES clause requires an ORDER BY operation on the TIMESTAMP column.

&lt;/div&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol, TS_FIRST_VALUE(bid) AS first_bid FROM TickStore
   TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Because the bid price of stock &lt;code&gt;XYZ&lt;/code&gt; is 10.0 at 3:00:03, the &lt;code&gt;first_bid&lt;/code&gt; value of the second time slice, which starts at 3:00:03 is till 10.0 (instead of 10.5) because the input value of 10.5 does not occur until 3:00:05. In this case, the interpolated value is inferred from the last value seen on stock &lt;code&gt;XYZ&lt;/code&gt; for time 3:00:03:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | symbol | first_bid
---------------------+--------+-----------
 2009-01-01 03:00:00 | XYZ    |        10
 2009-01-01 03:00:03 | XYZ    |        10
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next example places the input records in 2-second time slices to return the first bid value for each symbol/time slice combination:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol, TS_FIRST_VALUE(bid) AS first_bid FROM TickStore
   TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The result now contains three records in 2-second increments, all of which occur between the first input row at 03:00:00 and the second input row at 3:00:05. Note that the second and third output record correspond to a time slice where there is no input record:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | symbol | first_bid
---------------------+--------+-----------
 2009-01-01 03:00:00 | XYZ    |        10
2009-01-01 03:00:02 | XYZ    |        10
2009-01-01 03:00:04 | XYZ    |        10
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the same table schema, the next query uses &lt;a href=&#34;../../../../en/sql-reference/functions/aggregate-functions/ts-last-value/&#34;&gt;TS_LAST_VALUE()&lt;/a&gt;, with the TIMESERIES clause to return the last values of each time slice (the values at the end of the time slices).

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Time series aggregate functions process the data that belongs to each time slice. One output row is produced per time slice or per partition per time slice if a partition expression is present.

&lt;/div&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol, TS_LAST_VALUE(bid) AS last_bid FROM TickStore
   TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Notice that the last value output row is 10.5 because the value 10.5 at time 3:00:05 was the last point inside the 2-second time slice that started at 3:00:04:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | symbol | last_bid
---------------------+--------+----------
 2009-01-01 03:00:00 | XYZ    |       10
 2009-01-01 03:00:02 | XYZ    |       10
 2009-01-01 03:00:04 | XYZ    |     10.5
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Remember that because constant interpolation is the default, the same results are returned if you write the query using the CONST parameter as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol, TS_LAST_VALUE(bid, &amp;#39;CONST&amp;#39;) AS last_bid FROM TickStore
   TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;linear-interpolation&#34;&gt;Linear interpolation&lt;/h2&gt;
&lt;p&gt;Based on the same input records described in the constant interpolation examples, which specify 2-second time slices, the result of TS_LAST_VALUE with linear interpolation is as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol, TS_LAST_VALUE(bid, &amp;#39;linear&amp;#39;) AS last_bid   FROM TickStore
   TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the results, no last_bid value is returned for the last row because the query specified TS_LAST_VALUE, and there is no data point after the 3:00:04 time slice to interpolate.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | symbol | last_bid
---------------------+--------+----------
 2009-01-01 03:00:00 | XYZ    |     10.2
 2009-01-01 03:00:02 | XYZ    |     10.4
 2009-01-01 03:00:04 | XYZ    |
(3 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;using-multiple-time-series-aggregate-functions&#34;&gt;Using multiple time series aggregate functions&lt;/h2&gt;
&lt;p&gt;Multiple time series aggregate functions can exists in the same query. They share the same &lt;em&gt;gap-filling&lt;/em&gt; policy as defined in the TIMESERIES clause; however, each time series aggregate function can specify its own interpolation policy. In the following example, there are two constant and one linear interpolation schemes, but all three functions use a three-second time slice:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT slice_time, symbol,
       TS_FIRST_VALUE(bid, &amp;#39;const&amp;#39;) fv_c,
       TS_FIRST_VALUE(bid, &amp;#39;linear&amp;#39;) fv_l,
       TS_LAST_VALUE(bid, &amp;#39;const&amp;#39;) lv_c
   FROM TickStore
   TIMESERIES slice_time AS &amp;#39;3 seconds&amp;#39; OVER(PARTITION BY symbol ORDER BY ts);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the following output, the original output is compared to output returned by multiple time series aggregate functions.

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;td &gt;









&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;    ts    | symbol | bid
----------+--------+------
 03:00:00 | XYZ    |   10
 03:00:05 | XYZ    | 10.5
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt; 

&lt;td &gt;


&lt;code&gt;==&amp;gt;&lt;/code&gt;&lt;/td&gt; 

&lt;td &gt;









&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;     slice_time      | symbol | fv_c | fv_l | lv_c
---------------------+--------+------+------+------
 2009-01-01 03:00:00 | XYZ    |   10 |   10 |   10
 2009-01-01 03:00:03 | XYZ    |   10 | 10.3 | 10.5
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;/p&gt;
&lt;h2 id=&#34;using-the-analytic-last_value-function&#34;&gt;Using the analytic LAST_VALUE function&lt;/h2&gt;
&lt;p&gt;Here&#39;s an example using LAST_VALUE(), so you can see the difference between it and the GFI syntax.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT *, LAST_VALUE(bid) OVER(PARTITION by symbol ORDER BY ts)
   AS &amp;#34;last bid&amp;#34; FROM TickStore;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;There is no gap filling and interpolation to the output values.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;         ts          | symbol | bid  | last bid
---------------------+--------+------+----------
 2009-01-01 03:00:00 | XYZ    |   10 |       10
 2009-01-01 03:00:05 | XYZ    | 10.5 |     10.5
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;using-slice_time&#34;&gt;Using slice_time&lt;/h2&gt;
&lt;p&gt;In a TIMESERIES query, you cannot use the column &lt;code&gt;slice_time&lt;/code&gt; in the WHERE clause because the WHERE clause is evaluated before the TIMESERIES clause, and the &lt;code&gt;slice_time&lt;/code&gt; column is not generated until the TIMESERIES clause is evaluated. For example, OpenText™ Analytics Database does not support the following query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT symbol, slice_time, TS_FIRST_VALUE(bid IGNORE NULLS) AS fv
   FROM TickStore
   WHERE slice_time = &amp;#39;2009-01-01 03:00:00&amp;#39;
   TIMESERIES slice_time as &amp;#39;2 seconds&amp;#39; OVER (PARTITION BY symbol ORDER BY ts);
ERROR:  Time Series timestamp alias/Time Series Aggregate Functions not allowed in WHERE clause
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Instead, you could write a subquery and put the predicate on &lt;code&gt;slice_time&lt;/code&gt; in the outer query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM (
      SELECT symbol, slice_time,
        TS_FIRST_VALUE(bid IGNORE NULLS) AS fv
      FROM TickStore
      TIMESERIES slice_time AS &amp;#39;2 seconds&amp;#39;
      OVER (PARTITION BY symbol ORDER BY ts) ) sq
   WHERE slice_time = &amp;#39;2009-01-01 03:00:00&amp;#39;;
 symbol |     slice_time      | fv
--------+---------------------+----
 XYZ    | 2009-01-01 03:00:00 | 10
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;creating-a-dense-time-series&#34;&gt;Creating a dense time series&lt;/h2&gt;
&lt;p&gt;The TIMESERIES clause provides a convenient way to create a dense time series for use in an outer join with fact data. The results represent every time point, rather than just the time points for which data exists.&lt;/p&gt;
&lt;p&gt;The examples that follow use the same TickStore schema described in &lt;a href=&#34;../../../../en/data-analysis/time-series-analytics/gap-filling-and-interpolation-gfi/#&#34;&gt;Gap filling and interpolation (GFI)&lt;/a&gt;, along with the addition of a new inner table for the purpose of creating a join:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE inner_table (
       ts TIMESTAMP,
       bid FLOAT
   );
=&amp;gt; CREATE PROJECTION inner_p (ts, bid) as SELECT * FROM inner_table
   ORDER BY ts, bid UNSEGMENTED ALL NODES;
=&amp;gt; INSERT INTO inner_table VALUES (&amp;#39;2009-01-01 03:00:02&amp;#39;, 1);
=&amp;gt; INSERT INTO inner_table VALUES (&amp;#39;2009-01-01 03:00:04&amp;#39;, 2);
=&amp;gt; COMMIT;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can create a simple union between the start and end range of the timeframe of interest in order to return every time point. This example uses a 1-second time slice:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
     SELECT &amp;#39;2009-01-01 03:00:00&amp;#39;::TIMESTAMP AS time FROM TickStore
     UNION
     SELECT &amp;#39;2009-01-01 03:00:05&amp;#39;::TIMESTAMP FROM TickStore) t
   TIMESERIES ts AS &amp;#39;1 seconds&amp;#39; OVER(ORDER BY time);
         ts
---------------------
 2009-01-01 03:00:00
 2009-01-01 03:00:01
 2009-01-01 03:00:02
 2009-01-01 03:00:03
 2009-01-01 03:00:04
 2009-01-01 03:00:05
(6 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The next query creates a union between the start and end range of the timeframe using 500-millisecond time slices:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT ts FROM (
     SELECT &amp;#39;2009-01-01 03:00:00&amp;#39;::TIMESTAMP AS time
     FROM TickStore
     UNION
     SELECT &amp;#39;2009-01-01 03:00:05&amp;#39;::TIMESTAMP FROM TickStore) t
   TIMESERIES ts AS &amp;#39;500 milliseconds&amp;#39; OVER(ORDER BY time);
          ts
-----------------------
 2009-01-01 03:00:00
 2009-01-01 03:00:00.5
 2009-01-01 03:00:01
 2009-01-01 03:00:01.5
 2009-01-01 03:00:02
 2009-01-01 03:00:02.5
 2009-01-01 03:00:03
 2009-01-01 03:00:03.5
 2009-01-01 03:00:04
 2009-01-01 03:00:04.5
 2009-01-01 03:00:05
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following query creates a union between the start- and end-range of the timeframe of interest using 1-second time slices:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM (
     SELECT ts FROM (
       SELECT &amp;#39;2009-01-01 03:00:00&amp;#39;::timestamp AS time FROM TickStore
       UNION
       SELECT &amp;#39;2009-01-01 03:00:05&amp;#39;::timestamp FROM TickStore) t
       TIMESERIES ts AS &amp;#39;1 seconds&amp;#39; OVER(ORDER BY time) ) AS outer_table
   LEFT OUTER JOIN inner_table ON outer_table.ts = inner_table.ts;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The union returns a complete set of records from the left-joined table with the matched records in the right-joined table. Where the query found no match, it extends the right side column with null values:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;         ts          |         ts          | bid
---------------------+---------------------+-----
 2009-01-01 03:00:00 |                     |
 2009-01-01 03:00:01 |                     |
 2009-01-01 03:00:02 | 2009-01-01 03:00:02 |   1
 2009-01-01 03:00:03 |                     |
 2009-01-01 03:00:04 | 2009-01-01 03:00:04 |   2
 2009-01-01 03:00:05 |                     |
(6 rows)
&lt;/code&gt;&lt;/pre&gt;

      </description>
    </item>
    
  </channel>
</rss>
