timescaledb 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 89553264709636b53e3d56174f3e244561c10f2c4801b922ba25adb8bf32aca7
4
- data.tar.gz: f254f76133d13d6854f8f7dee865a0f3bb4adc57617c200ee276d1408541475a
3
+ metadata.gz: a20c2f12a3673694b39fd99aa005d743bbc027031d3abc7c25fda904f71ee33f
4
+ data.tar.gz: fd27816a15c114baa3d75a08bd083de5493efd7ce60ebe200d6543a3dcb266bf
5
5
  SHA512:
6
- metadata.gz: b30bbba9b0da08b3cad42fbc80e73c7aed2e37763d01cfd2b93d569e4bd65768a507fc6e25a757c7b83bd4f9ad3e7e18d98090b7a2f2e8bebcb5d16fb3a63d7c
7
- data.tar.gz: bb0ba7379e86631d71256cf66cc506eb42511145f17e343e749bc10e28b7c394a482e9d4a3380ff9ee2af511be51d44529556566fe08421aa92b924755d492c8
6
+ metadata.gz: db6642dbdb2588359fc63fff080f34479725cef75d7972f081aa2a1beb680314cf1555ba7ec94956d16cceb3ac3b7724de131e010ba1d06361350f162ed3250c
7
+ data.tar.gz: df04ac079954e4b815d922d2a076929e6c4d5f5e9c11d46a54287138e8485fb171b276361a3bae43618c068709fa9f07c0ec34faa88c3afff18ac9d65d511766
@@ -62,4 +62,3 @@ module Timescaledb
62
62
  end
63
63
  end
64
64
 
65
- ActiveRecord::Base.extend Timescaledb::ActsAsHypertable
@@ -14,6 +14,30 @@ module Timescaledb
14
14
  total: count
15
15
  }
16
16
  end
17
+
18
+ scope :hierarchical, -> do
19
+ with_recursive = <<~SQL
20
+ WITH RECURSIVE caggs AS (
21
+ SELECT mat_hypertable_id, parent_mat_hypertable_id, user_view_name
22
+ FROM _timescaledb_catalog.continuous_agg
23
+ UNION ALL
24
+ SELECT continuous_agg.mat_hypertable_id, continuous_agg.parent_mat_hypertable_id, continuous_agg.user_view_name
25
+ FROM _timescaledb_catalog.continuous_agg
26
+ JOIN caggs ON caggs.parent_mat_hypertable_id = continuous_agg.mat_hypertable_id
27
+ )
28
+ SELECT * FROM caggs
29
+ ORDER BY mat_hypertable_id
30
+ SQL
31
+ views = unscoped
32
+ .select("distinct user_view_name")
33
+ .from("(#{with_recursive}) as caggs")
34
+ .pluck(:user_view_name)
35
+ .uniq
36
+
37
+ views.map do |view|
38
+ find_by(view_name: view)
39
+ end
40
+ end
17
41
  end
18
42
  ContinuousAggregates = ContinuousAggregate
19
43
  end
@@ -49,7 +49,7 @@ module Timescaledb
49
49
  original_logger = ActiveRecord::Base.logger
50
50
  ActiveRecord::Base.logger = Logger.new(STDOUT)
51
51
 
52
- options = ["chunk_time_interval => INTERVAL '#{chunk_time_interval}'"]
52
+ options = ["chunk_time_interval => #{chunk_time_interval_clause(chunk_time_interval)}"]
53
53
  options += hypertable_options.map { |k, v| "#{k} => #{quote(v)}" }
54
54
 
55
55
  arguments = [
@@ -165,6 +165,14 @@ module Timescaledb
165
165
  value = options[option_key] ? 'true' : 'false'
166
166
  ",timescaledb.#{option_key}=#{value}"
167
167
  end
168
+
169
+ def chunk_time_interval_clause(chunk_time_interval)
170
+ if chunk_time_interval.is_a?(Numeric)
171
+ chunk_time_interval
172
+ else
173
+ "INTERVAL '#{chunk_time_interval}'"
174
+ end
175
+ end
168
176
  end
169
177
  end
170
178
 
@@ -78,7 +78,7 @@ module Timescaledb
78
78
 
79
79
  options = {
80
80
  time_column: time.column_name,
81
- chunk_time_interval: time.time_interval.inspect,
81
+ chunk_time_interval: time.time_interval ? time.time_interval.inspect : time.integer_interval,
82
82
  **timescale_compression_settings_for(hypertable),
83
83
  **timescale_space_partition_for(hypertable),
84
84
  **timescale_index_options_for(hypertable)
@@ -154,19 +154,19 @@ module Timescaledb
154
154
  def timescale_continuous_aggregates(stream)
155
155
  return unless Timescaledb::ContinuousAggregates.table_exists?
156
156
 
157
- Timescaledb::ContinuousAggregates.all.find_each do |aggregate|
157
+ Timescaledb::ContinuousAggregates.hierarchical.each do |aggregate|
158
158
  refresh_policies_opts = if (refresh_policy = aggregate.jobs.refresh_continuous_aggregate.first)
159
159
  interval = timescale_interval(refresh_policy.schedule_interval)
160
160
  end_offset = timescale_interval(refresh_policy.config["end_offset"])
161
161
  start_offset = timescale_interval(refresh_policy.config["start_offset"])
162
- %(refresh_policies: { start_offset: "#{start_offset}", end_offset: "#{end_offset}", schedule_interval: "#{interval}"})
162
+ %(refresh_policies: { start_offset: "#{start_offset}", end_offset: "#{end_offset}", schedule_interval: "#{interval}"}, )
163
163
  else
164
164
  ""
165
165
  end
166
166
 
167
167
  with_clause_opts = "materialized_only: #{aggregate[:materialized_only]}, finalized: #{aggregate[:finalized]}"
168
168
  stream.puts <<~AGG.indent(2)
169
- create_continuous_aggregate("#{aggregate.view_name}", <<-SQL, #{refresh_policies_opts}, #{with_clause_opts})
169
+ create_continuous_aggregate("#{aggregate.view_name}", <<-SQL, #{refresh_policies_opts}#{with_clause_opts})
170
170
  #{aggregate.view_definition.strip.gsub(/;$/, '')}
171
171
  SQL
172
172
  AGG
@@ -1,3 +1,3 @@
1
1
  module Timescaledb
2
- VERSION = '0.2.9'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timescaledb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Davi Paganini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-05 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg