Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Eakan,</p> <p>I don't have access to a Vertica environment to test this but I think that the issue with your second example is that your result set only has one date in it, since there's only one date in the a table. However there are multiple id4s. So when you ask, in your query to interpolate across date gaps there are no gaps to interpolate over. The gaps that you see in the values from your b table are actually on different id4 values from the a table.</p> <p>I'm not sure if you can have more than one interpolate in the join clause but how about this:</p> <pre><code>SELECT a.family, a.family_name, a.industry, a.style_flag, a.id, a.id_name, a.id1, a.id2, a.id3, a.date, a.id4, b.id4, b.flag, b.period, b.datapoint FROM a LEFT JOIN b ON a.id4 INTERPOLATE PREVIOUS VALUE b.id4 AND a.date INTERPOLATE PREVIOUS VALUE b.date; </code></pre> <p>I think this will fill down the values from the b table but this might not be what you want. Perhaps you only mean to interpolate over dates and you are thinking that it didn't work just because you don't have more than one date in your a table. Put a few more dates in that a table and then re-run the query to see what I mean.</p> <p>Contact me offline if you want to discuss in more detail. If you can hook me up with access to a working vertica environment to play with then I can try out some more ideas for you.</p> <p>Alan</p> <p>FOLLOW UP:</p> <p>Ok, so I managed to get access to a test Vertica environment.</p> <p>Firstly it seems that you can’t have more than one interpolated join predicate …</p> <pre><code>vmartdb=&gt; SELECT a.family, a.family_name, a.industry, a.style_flag, a.id, a.id_name, vmartdb-&gt; a.id1, a.id2, a.id3, a.date, a.id4, b.id4, b.flag, b.period, b.datapoint vmartdb-&gt; FROM est_cal.a AS a vmartdb-&gt; LEFT JOIN est_cal.b AS b vmartdb-&gt; ON a.id4 INTERPOLATE PREVIOUS VALUE b.id4 AND vmartdb-&gt; a.date INTERPOLATE PREVIOUS VALUE b.date; ERROR 2093: A join can have only one set of interpolated predicates vmartdb=&gt; </code></pre> <p>So that’s that.</p> <p>Then I tried to add a few more dates to the a table and saw that your original query did indeed interpolate over the gaps for the b table fields …</p> <pre><code>CREATE TABLE est_cal.a ( family int, family_name varchar(50), industry varchar(15), style_flag varchar(1), id int, id_name varchar(50), id1 int, id2 int, id3 int, date DATE, id4 int ); CREATE TABLE est_cal.b ( id4 int, flag int, period int, date DATE, datapoint float ); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 1, '1 id', 101, 201, 301, '20130603', 401); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 2, '2 id', 102, 202, 302, '20130603', 402); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 3, '3 id', 103, 203, 303, '20130603', 403); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 5, '5 id', 105, 205, 305, '20130603', 405); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 7, '7 id', 107, 207, 307, '20130603', 407); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 9, '9 id', 109, 209, 309, '20130603', 409); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 1, '1 id', 101, 201, 301, '20130604', 401); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 2, '2 id', 102, 202, 302, '20130604', 402); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 3, '3 id', 103, 203, 303, '20130604', 403); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 5, '5 id', 105, 205, 305, '20130605', 405); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 7, '7 id', 107, 207, 307, '20130605', 407); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 9, '9 id', 109, 209, 309, '20130605', 409); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 1, '1 id', 101, 201, 301, '20130605', 401); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 2, '2 id', 102, 202, 302, '20130605', 402); INSERT INTO est_cal.a VALUES (1, '1family', 'comp', 'A', 3, '3 id', 103, 203, 303, '20130605', 403); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 5, '5 id', 105, 205, 305, '20130605', 405); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 7, '7 id', 107, 207, 307, '20130605', 407); INSERT INTO est_cal.a VALUES (2, '2family', 'bio', 'A', 9, '9 id', 109, 209, 309, '20130605', 409); INSERT INTO est_cal.b VALUES (401, 1, 10, '20130501', 2.00); INSERT INTO est_cal.b VALUES (401, 1, 20, '20130501', 1.50); INSERT INTO est_cal.b VALUES (401, 2, 10, '20130409', 12.34); INSERT INTO est_cal.b VALUES (401, 2, 20, '20130401', 10.56); INSERT INTO est_cal.b VALUES (402, 1, 10, '20130501', 2.00); INSERT INTO est_cal.b VALUES (402, 2, 20, '20130409', 12.34); INSERT INTO est_cal.b VALUES (402, 2, 20, '20130401', 10.56); INSERT INTO est_cal.b VALUES (402, 2, 20, '20130515', 20.55); SELECT a.family, a.family_name, a.industry, a.style_flag, a.id, a.id_name, a.id1, a.id2, a.id3, a.date AS a_date, b.date AS b_date, a.id4 AS a_id4, b.id4 AS b_id4, b.flag, b.period, b.datapoint FROM est_cal.a AS a LEFT JOIN est_cal.b AS b ON a.id4 = b.id4 AND a.date INTERPOLATE PREVIOUS VALUE b.date; </code></pre> <p>Which generated the following results ...</p> <pre><code>family | family_name | industry | style_flag | id | id_name | id1 | id2 | id3 | a_date | b_date | a_id4 | b_id4 | flag | period | datapoint --------+-------------+----------+------------+----+---------+-----+-----+-----+------------+------------+-------+-------+------+--------+----------- 2 | 2family | bio | A | 7 | 7 id | 107 | 207 | 307 | 2013-06-03 | | 407 | | | | 2 | 2family | bio | A | 7 | 7 id | 107 | 207 | 307 | 2013-06-04 | | 407 | | | | 2 | 2family | bio | A | 7 | 7 id | 107 | 207 | 307 | 2013-06-05 | | 407 | | | | 2 | 2family | bio | A | 7 | 7 id | 107 | 207 | 307 | 2013-06-05 | | 407 | | | | 2 | 2family | bio | A | 5 | 5 id | 105 | 205 | 305 | 2013-06-03 | | 405 | | | | 2 | 2family | bio | A | 5 | 5 id | 105 | 205 | 305 | 2013-06-04 | | 405 | | | | 2 | 2family | bio | A | 5 | 5 id | 105 | 205 | 305 | 2013-06-05 | | 405 | | | | 2 | 2family | bio | A | 5 | 5 id | 105 | 205 | 305 | 2013-06-05 | | 405 | | | | 2 | 2family | bio | A | 9 | 9 id | 109 | 209 | 309 | 2013-06-03 | | 409 | | | | 2 | 2family | bio | A | 9 | 9 id | 109 | 209 | 309 | 2013-06-04 | | 409 | | | | 2 | 2family | bio | A | 9 | 9 id | 109 | 209 | 309 | 2013-06-05 | | 409 | | | | 2 | 2family | bio | A | 9 | 9 id | 109 | 209 | 309 | 2013-06-05 | | 409 | | | | 1 | 1family | comp | A | 1 | 1 id | 101 | 201 | 301 | 2013-06-03 | 2013-05-01 | 401 | 401 | 1 | 10 | 2 1 | 1family | comp | A | 1 | 1 id | 101 | 201 | 301 | 2013-06-04 | 2013-05-01 | 401 | 401 | 1 | 10 | 2 1 | 1family | comp | A | 1 | 1 id | 101 | 201 | 301 | 2013-06-05 | 2013-05-01 | 401 | 401 | 1 | 10 | 2 1 | 1family | comp | A | 3 | 3 id | 103 | 203 | 303 | 2013-06-03 | | 403 | | | | 1 | 1family | comp | A | 3 | 3 id | 103 | 203 | 303 | 2013-06-04 | | 403 | | | | 1 | 1family | comp | A | 3 | 3 id | 103 | 203 | 303 | 2013-06-05 | | 403 | | | | 1 | 1family | comp | A | 2 | 2 id | 102 | 202 | 302 | 2013-06-03 | 2013-05-15 | 402 | 402 | 2 | 20 | 20.55 1 | 1family | comp | A | 2 | 2 id | 102 | 202 | 302 | 2013-06-04 | 2013-05-15 | 402 | 402 | 2 | 20 | 20.55 1 | 1family | comp | A | 2 | 2 id | 102 | 202 | 302 | 2013-06-05 | 2013-05-15 | 402 | 402 | 2 | 20 | 20.55 (21 rows) </code></pre> <p>So this shows that the date interpolation is working as it should.</p> <p>Alan</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload