activecube 0.1.42 → 0.1.43
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/activecube/processor/composer.rb +2 -2
- data/lib/activecube/processor/optimizer.rb +74 -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: aec3cd5d380f65b797c530930d4cfaac15b39918527b7c90e2ec54a064207729
|
4
|
+
data.tar.gz: 14c6c81f226ed03143e84478b52a056ed63de31be67bc5f5bbed98fb4004490f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 508fc6bf05c575b0f7417a3e56a03eb306deafcc9655c166e34233fd98e6ec42321409c0a30a6143195e4eddee352e1114d01d6cce305a0cfb9ca9f6ba243732
|
7
|
+
data.tar.gz: edc18eadd6d0bee5d96423f141e70f480dced3b38afd8f0a05e31112c8ced58fe8ec33b4924790101706cfcf9c5f9364da6be41e31164b5f58f6b4b7fff08b9f
|
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,96 @@ 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
|
+
seq = *(0...n)
|
71
|
+
perm = seq.slice(0, k)
|
72
|
+
perms = []
|
73
|
+
|
74
|
+
while true
|
75
|
+
perms.push perm.dup
|
76
|
+
flag = true
|
77
|
+
i = 0
|
78
|
+
((k - 1)...-1).step(-1).each do |ii|
|
79
|
+
i = ii
|
80
|
+
if perm[ii] < n - 1
|
81
|
+
flag = false
|
82
|
+
break
|
83
|
+
end
|
84
|
+
end
|
85
|
+
return perms if flag
|
86
|
+
|
87
|
+
perm[i] += 1
|
88
|
+
((i + 1)...k).each { |j| perm[j] = 0 }
|
89
|
+
end
|
90
|
+
end
|
69
91
|
|
92
|
+
def gen_reduced_variants
|
93
|
+
# reduce size of cost_matrix deleting duplicates
|
94
|
+
uniq_rows = []
|
95
|
+
rows_indices = {}
|
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
|
+
uniq_rows.push(row)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# generating variants for reduced matrix
|
113
|
+
vars = gen_permutations(tables_count, uniq_rows.length)
|
114
|
+
|
115
|
+
# restore variants for full matrix
|
116
|
+
vars.map do |variant|
|
117
|
+
full_v = Array.new(metrics_count)
|
118
|
+
rows_indices.each { |k, v| full_v[k] = variant[v] }
|
119
|
+
|
120
|
+
full_v
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
70
124
|
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.43
|
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-04-
|
11
|
+
date: 2022-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|