activecube 0.1.42 → 0.1.45
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/activecube/processor/composer.rb +2 -2
- data/lib/activecube/processor/optimizer.rb +80 -20
- data/lib/activecube/processor/table.rb +3 -3
- data/lib/activecube/version.rb +1 -1
- data/lib/activecube/view.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69c1a36a5deeddf200296ab2809a0a0c503b06480ca6fd358585f6184ae560eb
|
4
|
+
data.tar.gz: 92fad5df5d1e723f7d6f4caa361e24dcc3aa16fa1b037b2ebe6f9461e739f4de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db7aeb2a92d01dcb7756cba754e4a429d3cbf79bc89fd7f6fa1fcdfdd98f2c42882644c1778aa9ad1fdee5c1f21bb1aad844203ab125e7f980b0e003a86f46d
|
7
|
+
data.tar.gz: 2e4ff8cb29e610bf49eb2be5c1b188d623e81b69cfb5bb4cb7ef9c16bd0dbea0f5625b668b4f1e17d0dca76bc37cdc239f44854da351e06aa5421b1e1f63213c
|
data/Gemfile.lock
CHANGED
@@ -75,11 +75,11 @@ module Activecube::Processor
|
|
75
75
|
measures_by_tables = measure_tables.group_by(&:table)
|
76
76
|
measures_by_tables.each_pair do |table, list|
|
77
77
|
@models << table.model
|
78
|
-
table_query = table.query cube_query
|
78
|
+
table_query = table.query cube_query, list.map(&:measure)
|
79
79
|
composed_query = composed_query ? table.join(cube_query, composed_query, table_query) : table_query
|
80
80
|
end
|
81
81
|
composed_query
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
85
|
-
end
|
85
|
+
end
|
@@ -6,6 +6,7 @@ module Activecube::Processor
|
|
6
6
|
MAX_ITERATIONS = 3
|
7
7
|
|
8
8
|
attr_reader :tables_count, :metrics_count, :cost_matrix
|
9
|
+
|
9
10
|
def initialize cost_matrix
|
10
11
|
@cost_matrix = cost_matrix
|
11
12
|
@cache = ActiveSupport::Cache::MemoryStore.new
|
@@ -18,10 +19,9 @@ module Activecube::Processor
|
|
18
19
|
@tables_count = cost_matrix.map(&:count).max
|
19
20
|
@metrics_count = cost_matrix.count
|
20
21
|
|
21
|
-
(tables_count==1 || metrics_count==0) ? [0]*metrics_count : do_optimize
|
22
|
-
|
23
|
-
end
|
22
|
+
(tables_count == 1 || metrics_count == 0) ? [0] * metrics_count : do_optimize
|
24
23
|
|
24
|
+
end
|
25
25
|
|
26
26
|
end
|
27
27
|
|
@@ -29,42 +29,102 @@ module Activecube::Processor
|
|
29
29
|
|
30
30
|
def generate_variants vs, metric_i
|
31
31
|
|
32
|
-
return vs if metric_i==metrics_count
|
32
|
+
return vs if metric_i == metrics_count
|
33
33
|
|
34
34
|
metric_tables = cost_matrix[metric_i].map.with_index do |c, index|
|
35
35
|
[index] if c
|
36
36
|
end.compact
|
37
37
|
|
38
|
-
vsnew = if metric_i==0
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
38
|
+
vsnew = if metric_i == 0
|
39
|
+
metric_tables
|
40
|
+
else
|
41
|
+
arry = []
|
42
|
+
vs.each do |v|
|
43
|
+
metric_tables.each { |newv|
|
44
|
+
arry << (v + newv)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
arry
|
48
|
+
end
|
49
49
|
|
50
|
-
generate_variants vsnew, metric_i+1
|
50
|
+
generate_variants vsnew, metric_i + 1
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def cost_for variant
|
55
55
|
variant.each_with_index.group_by(&:first).collect do |table_index, arry|
|
56
|
-
arry.map(&:second).map{|metric_index| cost_matrix[metric_index][table_index] }.max
|
56
|
+
arry.map(&:second).map { |metric_index| cost_matrix[metric_index][table_index] }.max
|
57
57
|
end.sum
|
58
58
|
end
|
59
59
|
|
60
60
|
def do_optimize
|
61
61
|
|
62
|
-
variants = generate_variants [], 0
|
63
|
-
|
62
|
+
# variants = generate_variants [], 0
|
63
|
+
variants = gen_reduced_variants
|
64
|
+
variant_costs = variants.map { |v| cost_for v }
|
64
65
|
variants[variant_costs.each_with_index.min.second]
|
65
66
|
|
66
67
|
end
|
67
68
|
|
68
|
-
|
69
|
+
def gen_permutations(n, k)
|
70
|
+
perm = Array.new(k, 0)
|
71
|
+
perms = []
|
72
|
+
|
73
|
+
while true
|
74
|
+
perms.push perm.dup
|
75
|
+
flag = true
|
76
|
+
i = 0
|
77
|
+
((k - 1)...-1).step(-1).each do |ii|
|
78
|
+
i = ii
|
79
|
+
if perm[ii] < n - 1
|
80
|
+
flag = false
|
81
|
+
break
|
82
|
+
end
|
83
|
+
end
|
84
|
+
return perms if flag
|
85
|
+
|
86
|
+
perm[i] += 1
|
87
|
+
((i + 1)...k).each { |j| perm[j] = 0 }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def gen_reduced_variants
|
92
|
+
# reduce size of cost_matrix deleting duplicates
|
93
|
+
uniq_rows = []
|
94
|
+
rows_indices = {}
|
95
|
+
possible_tables = {}
|
96
|
+
cost_matrix.each_with_index do |row, i|
|
97
|
+
flag = false
|
98
|
+
|
99
|
+
uniq_rows.each_with_index do |u_row, j|
|
100
|
+
if u_row.eql? row
|
101
|
+
flag = true
|
102
|
+
rows_indices[i] = j
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
unless flag
|
107
|
+
rows_indices[i] = uniq_rows.length
|
108
|
+
possible_tables[uniq_rows.length] = Hash[row.map.with_index { |c, index| [index, true] if c }.compact]
|
109
|
+
uniq_rows.push(row)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# generating variants for reduced matrix
|
114
|
+
vars = gen_permutations(tables_count, uniq_rows.length)
|
69
115
|
|
116
|
+
# filter possible variants
|
117
|
+
vars = vars.filter do |v|
|
118
|
+
v.map.with_index.all? {|t_n, i| possible_tables[i][t_n]}
|
119
|
+
end
|
120
|
+
|
121
|
+
# restore variants for full matrix
|
122
|
+
vars.map do |variant|
|
123
|
+
full_v = Array.new(metrics_count)
|
124
|
+
rows_indices.each { |k, v| full_v[k] = variant[v] }
|
125
|
+
|
126
|
+
full_v
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
70
130
|
end
|
@@ -20,12 +20,12 @@ module Activecube::Processor
|
|
20
20
|
(measure.required_column_names - model.attribute_types.keys).empty?
|
21
21
|
end
|
22
22
|
|
23
|
-
def query cube_query
|
23
|
+
def query cube_query, measures = cube_query.measures
|
24
24
|
|
25
25
|
table = model.arel_table
|
26
26
|
query = table
|
27
27
|
|
28
|
-
(cube_query.slices +
|
28
|
+
(cube_query.slices + measures + cube_query.selectors + cube_query.options).each do |s|
|
29
29
|
query = s.append_query model, cube_query, table, query
|
30
30
|
end
|
31
31
|
|
@@ -52,4 +52,4 @@ module Activecube::Processor
|
|
52
52
|
|
53
53
|
|
54
54
|
end
|
55
|
-
end
|
55
|
+
end
|
data/lib/activecube/version.rb
CHANGED
data/lib/activecube/view.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activecube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.45
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksey Studnev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|