Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump hierarchical continuous aggregates in the right order #70

Closed
jonatas opened this issue Jul 11, 2024 · 1 comment
Closed

Dump hierarchical continuous aggregates in the right order #70

jonatas opened this issue Jul 11, 2024 · 1 comment

Comments

@jonatas
Copy link
Collaborator

jonatas commented Jul 11, 2024

I fall into a problem while implementing rubygems/rubygems.org#4642 which I have multiple views that are interdependent but the dump is in the wrong order.

Here we go with the error:

rake aborted!
   (3.3ms)  CREATE MATERIALIZED VIEW downloads_gems_per_month
WITH (
  timescaledb.continuous
  ,timescaledb.materialized_only=true

  ,timescaledb.finalized=true
) AS
    SELECT time_bucket('P1M'::interval, ts) AS ts,
      gem_name,
      count(*) AS downloads
     FROM downloads_gems_per_day
    GROUP BY (time_bucket('P1M'::interval, ts)), gem_name

WITH NO DATA;

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "downloads_gems_per_day" does not exist (ActiveRecord::StatementInvalid)
LINE 11:      FROM downloads_gems_per_day
                   ^
/Users/jonatasdp/code/rubygems.org/db/downloads_schema.rb:622:in `block in <main>'

Because the schema file is bringing _per_day before the _per_hour.

@jonatas
Copy link
Collaborator Author

jonatas commented Jul 11, 2024

Query example to get the views in the proper order:

WITH RECURSIVE caggs AS (
  SELECT mat_hypertable_id, parent_mat_hypertable_id, user_view_name
  FROM _timescaledb_catalog.continuous_agg
  WHERE user_view_name = 'metrics_by_week'
  UNION ALL
  SELECT continuous_agg.mat_hypertable_id, continuous_agg.parent_mat_hypertable_id, continuous_agg.user_view_name
  FROM _timescaledb_catalog.continuous_agg
  JOIN caggs ON caggs.parent_mat_hypertable_id = continuous_agg.mat_hypertable_id
)
SELECT * FROM caggs ORDER BY mat_hypertable_id;

From Timescaledb Community Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant