CREATE CONTINUOUS VIEW test2 AS SELECT to_char(to_timestamp((item->>'eventTimestamp')::bigint+3600*9), 'YYYY-MM-DD HH24:MI:00') as jst, (item->>'platform')::text as platform, (item->>'action')::text as action, count(*) as cnt FROM sn_action_stream WHERE minute(arrival_timestamp) > clock_timestamp() -interval'3 days' AND to_timestamp((item->>'t')::bigint) > clock_timestamp() -interval'3 days' GROUPBY jst, platform, action;
ERROR: clock_timestamp() may only appear once in a WHERE clause
そもそも、なぜこのようにしているかと言うと、直近3日間に到着したログだけを対象にしたいが、ログは遅延して送られてくる事が多く(数日遅れて来る場合もある..)レコードの日付も3日以内である事をチェックしたい場合などです。 その場合、レコードの時間だけを対象にすれば良いのですが、それだとPipelineDBのレコードとしてのLifetimeを設定できないのです。 WITH (max_age)使えば良いのですが。
どうしても複数使いたい場合は、サブクエリで回避できます。
CREATE CONTINUOUS VIEW test2 AS SELECT to_char(to_timestamp((item->>'eventTimestamp')::bigint+3600*9), 'YYYY-MM-DD HH24:MI:00') as jst, (item->>'platform')::text as platform, (item->>'action')::text as action, count(*) as cnt FROM (SELECT arrival_timestamp, item FROM sn_action_stream WHERE to_timestamp((item->>'eventTimestamp')::bigint) > clock_timestamp() -interval'3 days') _ WHERE minute(arrival_timestamp) > clock_timestamp() -interval'3 days' GROUPBY jst, platform, action;
CREATE CONTINUOUS TRANSFORM test_etl AS SELECT item::jsonb FROM strm_test1 WHERE to_timestamp((item->>'eventTimestamp')::bigint) > clock_timestamp() -interval'3 days' THENEXECUTEPROCEDURE pipeline_stream_insert('strm_test2') ;
このように定義して、綺麗になったtest2を参照するCVを定義します。
CREATE CONTINUOUS VIEW test2 AS SELECT to_char(to_timestamp((item->>'eventTimestamp')::bigint+3600*9), 'YYYY-MM-DD HH24:MI:00') as jst, (item->>'platform')::text as platform, (item->>'action')::text as action, count(*) as cnt FROM strm_test2 WHERE minute(arrival_timestamp) > clock_timestamp() -interval'3 days' GROUPBY jst, platform, action;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters