factbase 0.14.2 → 0.14.4
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/.github/workflows/typos.yml +1 -1
- data/Gemfile.lock +1 -3
- data/lib/factbase/impatient.rb +22 -16
- data/lib/factbase/indexed/indexed_term.rb +21 -0
- data/lib/factbase/version.rb +1 -1
- data/test/factbase/indexed/test_indexed_term.rb +17 -0
- data/test/factbase/test_impatient.rb +0 -28
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b99886e9a1cb9ecdefc3a02b7a673fcaa0ffd5f5d43f7099b72ed46f8a73f48
|
4
|
+
data.tar.gz: ad9e84bd91eb52b2b310f716cd93754acd42d9007e3230f9d2449165a83ff2ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98e0a29e89ddf89635488ce7c08dba7cad6ef408c4538ba242d6112d45cebdfa6e8b4229dd3289040f022e1dadb714bb70d3f12133c1b7104b2a83b368dc9dc8
|
7
|
+
data.tar.gz: 7d57a91ded2d07f78be19ed288b1f4915cdd2fdaae172202da2eb3d584b368113f2adc239075557dd4c7815852339f9350a0ab5e8cb130394e0ab94f5e090c9d
|
data/.github/workflows/typos.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -72,7 +72,7 @@ GEM
|
|
72
72
|
psych (>= 4.0.0)
|
73
73
|
regexp_parser (2.10.0)
|
74
74
|
rexml (3.4.1)
|
75
|
-
rubocop (1.79.
|
75
|
+
rubocop (1.79.2)
|
76
76
|
json (~> 2.3)
|
77
77
|
language_server-protocol (~> 3.17.0.2)
|
78
78
|
lint_roller (~> 1.1.0)
|
@@ -82,7 +82,6 @@ GEM
|
|
82
82
|
regexp_parser (>= 2.9.3, < 3.0)
|
83
83
|
rubocop-ast (>= 1.46.0, < 2.0)
|
84
84
|
ruby-progressbar (~> 1.7)
|
85
|
-
tsort (>= 0.2.0)
|
86
85
|
unicode-display_width (>= 2.4.0, < 4.0)
|
87
86
|
rubocop-ast (1.46.0)
|
88
87
|
parser (>= 3.3.7.2)
|
@@ -113,7 +112,6 @@ GEM
|
|
113
112
|
threads (0.4.1)
|
114
113
|
backtrace (~> 0)
|
115
114
|
concurrent-ruby (~> 1.0)
|
116
|
-
tsort (0.2.0)
|
117
115
|
unicode-display_width (3.1.4)
|
118
116
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
119
117
|
unicode-emoji (4.0.4)
|
data/lib/factbase/impatient.rb
CHANGED
@@ -20,7 +20,7 @@ class Factbase::Impatient
|
|
20
20
|
def initialize(fb, timeout: 15)
|
21
21
|
raise 'The "fb" is nil' if fb.nil?
|
22
22
|
@origin = fb
|
23
|
-
@timeout = timeout
|
23
|
+
@timeout = timeout.to_f
|
24
24
|
end
|
25
25
|
|
26
26
|
decoor(:origin)
|
@@ -56,31 +56,37 @@ class Factbase::Impatient
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def each(fb = @fb, params = {}, &)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
a =
|
60
|
+
impatient('each') do
|
61
|
+
@fb.query(@term, @maps).each(fb, params).to_a
|
62
|
+
end
|
63
|
+
return a unless block_given?
|
64
|
+
yielded = 0
|
65
|
+
a.each do |f|
|
66
|
+
yield f
|
67
|
+
yielded += 1
|
63
68
|
end
|
64
|
-
|
65
|
-
raise "each() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
69
|
+
yielded
|
66
70
|
end
|
67
71
|
|
68
72
|
def one(fb = @fb, params = {})
|
69
|
-
|
70
|
-
|
71
|
-
qry.one(fb, params)
|
73
|
+
impatient('one') do
|
74
|
+
@fb.query(@term, @maps).one(fb, params)
|
72
75
|
end
|
73
|
-
rescue Timeout::Error => e
|
74
|
-
raise "one() timed out after #{@timeout.seconds} (#{e.message}): #{@term}"
|
75
76
|
end
|
76
77
|
|
77
78
|
def delete!(fb = @fb)
|
78
|
-
|
79
|
-
|
80
|
-
qry.delete!(fb)
|
79
|
+
impatient('delete!') do
|
80
|
+
@fb.query(@term, @maps).delete!(fb)
|
81
81
|
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def impatient(name, &)
|
87
|
+
Timeout.timeout(@timeout, &)
|
82
88
|
rescue Timeout::Error => e
|
83
|
-
raise "
|
89
|
+
raise "#{name}() timed out after #{@timeout.seconds} (#{e.message}), fb size is #{@fb.size}: #{@term}"
|
84
90
|
end
|
85
91
|
end
|
86
92
|
end
|
@@ -74,6 +74,27 @@ module Factbase::IndexedTerm
|
|
74
74
|
(maps & []) | j
|
75
75
|
end
|
76
76
|
end
|
77
|
+
when :gt
|
78
|
+
if @operands.first.is_a?(Symbol) && _scalar?(@operands[1])
|
79
|
+
prop = @operands.first.to_s
|
80
|
+
cache_key = [maps.object_id, @operands.first, :sorted]
|
81
|
+
if @idx[cache_key].nil?
|
82
|
+
@idx[cache_key] = []
|
83
|
+
maps.to_a.each do |m|
|
84
|
+
values = m[prop]
|
85
|
+
next if values.nil?
|
86
|
+
values.each do |v|
|
87
|
+
@idx[cache_key] << [v, m]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
@idx[cache_key].sort_by! { |pair| pair[0] }
|
91
|
+
end
|
92
|
+
threshold = @operands[1].is_a?(Symbol) ? params[@operands[1].to_s]&.first : @operands[1]
|
93
|
+
return nil if threshold.nil?
|
94
|
+
i = @idx[cache_key].bsearch_index { |pair| pair[0] > threshold } || @idx[cache_key].size
|
95
|
+
result = @idx[cache_key][i..].map { |pair| pair[1] }.uniq
|
96
|
+
(maps & []) | result
|
97
|
+
end
|
77
98
|
when :and
|
78
99
|
r = nil
|
79
100
|
if @operands.all? { |o| o.op == :eq } && @operands.size > 1 \
|
data/lib/factbase/version.rb
CHANGED
@@ -103,4 +103,21 @@ class TestIndexedTerm < Factbase::Test
|
|
103
103
|
n = term.predict(maps, {})
|
104
104
|
assert_nil(n)
|
105
105
|
end
|
106
|
+
|
107
|
+
def test_predicts_on_gt
|
108
|
+
term = Factbase::Term.new(:gt, [:foo, 42])
|
109
|
+
idx = {}
|
110
|
+
term.redress!(Factbase::IndexedTerm, idx:)
|
111
|
+
maps = Factbase::Taped.new([
|
112
|
+
{ 'foo' => [10] },
|
113
|
+
{ 'foo' => [43] },
|
114
|
+
{ 'foo' => [42] },
|
115
|
+
{ 'foo' => [100, 5] },
|
116
|
+
{ 'bar' => [50] },
|
117
|
+
{ 'foo' => [41, 42, 43] }
|
118
|
+
])
|
119
|
+
n = term.predict(maps, {})
|
120
|
+
assert_equal(3, n.size)
|
121
|
+
assert_kind_of(Factbase::Taped, n)
|
122
|
+
end
|
106
123
|
end
|
@@ -81,20 +81,6 @@ class TestImpatient < Factbase::Test
|
|
81
81
|
assert_equal([42], fb.query('(agg (exists bar) (first bar))').one)
|
82
82
|
end
|
83
83
|
|
84
|
-
def test_query_timeout
|
85
|
-
fb = Factbase::Impatient.new(Factbase.new, timeout: 0.1)
|
86
|
-
1000.times do
|
87
|
-
fb.insert.value = rand(1000)
|
88
|
-
end
|
89
|
-
ex =
|
90
|
-
assert_raises(StandardError) do
|
91
|
-
fb.query('(always)').each do
|
92
|
-
sleep 0.2
|
93
|
-
end
|
94
|
-
end
|
95
|
-
assert_includes(ex.message, 'timed out after')
|
96
|
-
end
|
97
|
-
|
98
84
|
def test_query_one_timeout
|
99
85
|
slow = SlowFactbase.new
|
100
86
|
10_000.times do
|
@@ -131,20 +117,6 @@ class TestImpatient < Factbase::Test
|
|
131
117
|
assert_equal(1, fb.size)
|
132
118
|
end
|
133
119
|
|
134
|
-
def test_with_txn_timeout
|
135
|
-
fb = Factbase::Impatient.new(Factbase.new, timeout: 0.1)
|
136
|
-
fb.txn do |fbt|
|
137
|
-
fbt.insert.slow = 42
|
138
|
-
ex =
|
139
|
-
assert_raises(StandardError) do
|
140
|
-
fbt.query('(always)').each do
|
141
|
-
sleep 0.2
|
142
|
-
end
|
143
|
-
end
|
144
|
-
assert_includes(ex.message, 'timed out after')
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
120
|
def test_returns_int
|
149
121
|
fb = Factbase.new
|
150
122
|
fb.insert
|