skydb 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +165 -1
  3. data/lib/skydb.rb +18 -61
  4. data/lib/skydb/client.rb +186 -186
  5. data/lib/skydb/event.rb +47 -76
  6. data/lib/skydb/property.rb +34 -67
  7. data/lib/skydb/table.rb +121 -41
  8. data/lib/skydb/version.rb +1 -1
  9. data/test/integration/client_test.rb +88 -0
  10. data/test/test_helper.rb +3 -51
  11. data/test/unit/client_test.rb +135 -32
  12. metadata +17 -278
  13. data/bin/sky +0 -89
  14. data/lib/ext/hash.rb +0 -11
  15. data/lib/ext/string.rb +0 -11
  16. data/lib/ext/treetop.rb +0 -19
  17. data/lib/skydb/action.rb +0 -76
  18. data/lib/skydb/import.rb +0 -7
  19. data/lib/skydb/import/importer.rb +0 -435
  20. data/lib/skydb/import/transforms/apache.yml +0 -4
  21. data/lib/skydb/import/transforms/sky.yml +0 -28
  22. data/lib/skydb/import/transforms/snowplow.yml +0 -1
  23. data/lib/skydb/import/translator.rb +0 -119
  24. data/lib/skydb/message.rb +0 -146
  25. data/lib/skydb/message/add_action.rb +0 -53
  26. data/lib/skydb/message/add_event.rb +0 -72
  27. data/lib/skydb/message/add_property.rb +0 -55
  28. data/lib/skydb/message/create_table.rb +0 -64
  29. data/lib/skydb/message/delete_table.rb +0 -66
  30. data/lib/skydb/message/get_action.rb +0 -55
  31. data/lib/skydb/message/get_actions.rb +0 -38
  32. data/lib/skydb/message/get_properties.rb +0 -38
  33. data/lib/skydb/message/get_property.rb +0 -55
  34. data/lib/skydb/message/get_table.rb +0 -74
  35. data/lib/skydb/message/get_tables.rb +0 -43
  36. data/lib/skydb/message/lookup.rb +0 -79
  37. data/lib/skydb/message/lua/aggregate.rb +0 -63
  38. data/lib/skydb/message/multi.rb +0 -57
  39. data/lib/skydb/message/next_actions.rb +0 -55
  40. data/lib/skydb/message/ping.rb +0 -32
  41. data/lib/skydb/property/type.rb +0 -40
  42. data/lib/skydb/query.rb +0 -183
  43. data/lib/skydb/query/after_condition.rb +0 -104
  44. data/lib/skydb/query/ast/selection_field_syntax_node.rb +0 -26
  45. data/lib/skydb/query/ast/selection_fields_syntax_node.rb +0 -16
  46. data/lib/skydb/query/ast/selection_group_syntax_node.rb +0 -16
  47. data/lib/skydb/query/ast/selection_groups_syntax_node.rb +0 -16
  48. data/lib/skydb/query/condition.rb +0 -113
  49. data/lib/skydb/query/on_condition.rb +0 -53
  50. data/lib/skydb/query/selection.rb +0 -398
  51. data/lib/skydb/query/selection_field.rb +0 -99
  52. data/lib/skydb/query/selection_fields_grammar.treetop +0 -46
  53. data/lib/skydb/query/selection_fields_parse_error.rb +0 -30
  54. data/lib/skydb/query/selection_group.rb +0 -78
  55. data/lib/skydb/query/selection_groups_grammar.treetop +0 -31
  56. data/lib/skydb/query/selection_groups_parse_error.rb +0 -30
  57. data/lib/skydb/query/validation_error.rb +0 -8
  58. data/lib/skydb/timestamp.rb +0 -22
  59. data/test/integration/query_test.rb +0 -102
  60. data/test/unit/event_test.rb +0 -32
  61. data/test/unit/import/importer_test.rb +0 -208
  62. data/test/unit/import/translator_test.rb +0 -88
  63. data/test/unit/message/add_action_message_test.rb +0 -34
  64. data/test/unit/message/add_event_message_test.rb +0 -35
  65. data/test/unit/message/add_property_message_test.rb +0 -41
  66. data/test/unit/message/create_table_message_test.rb +0 -34
  67. data/test/unit/message/delete_table_message_test.rb +0 -34
  68. data/test/unit/message/get_action_message_test.rb +0 -34
  69. data/test/unit/message/get_actions_message_test.rb +0 -18
  70. data/test/unit/message/get_properties_message_test.rb +0 -18
  71. data/test/unit/message/get_property_message_test.rb +0 -34
  72. data/test/unit/message/get_table_message_test.rb +0 -19
  73. data/test/unit/message/get_tables_message_test.rb +0 -18
  74. data/test/unit/message/lookup_message_test.rb +0 -27
  75. data/test/unit/message/lua_aggregate_message_test.rb +0 -19
  76. data/test/unit/message/multi_message_test.rb +0 -22
  77. data/test/unit/message/next_action_message_test.rb +0 -34
  78. data/test/unit/message/ping_message_test.rb +0 -18
  79. data/test/unit/message_test.rb +0 -15
  80. data/test/unit/query/after_test.rb +0 -89
  81. data/test/unit/query/on_test.rb +0 -71
  82. data/test/unit/query/selection_test.rb +0 -273
  83. data/test/unit/query_test.rb +0 -182
  84. data/test/unit/skydb_test.rb +0 -20
@@ -1,273 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestQuerySelection < MiniTest::Unit::TestCase
4
- ##############################################################################
5
- #
6
- # Setup / Teardown
7
- #
8
- ##############################################################################
9
-
10
- def setup
11
- @selection = SkyDB::Query::Selection.new()
12
- end
13
-
14
-
15
- ##############################################################################
16
- #
17
- # Tests
18
- #
19
- ##############################################################################
20
-
21
- ######################################
22
- # Field parsing
23
- ######################################
24
-
25
- def test_parse_single_field
26
- fields = SkyDB::Query::Selection.parse_fields("foo")
27
- assert_equal 1, fields.length
28
- assert_equal "foo", fields[0].expression
29
- end
30
-
31
- def test_parse_multiple_fields
32
- fields = SkyDB::Query::Selection.parse_fields(" foo , bar, baz_12 ")
33
- assert_equal 3, fields.length
34
- assert_equal "foo", fields[0].expression
35
- assert_equal "bar", fields[1].expression
36
- assert_equal "baz_12", fields[2].expression
37
- end
38
-
39
- def test_parse_aliased_fields
40
- fields = SkyDB::Query::Selection.parse_fields("foo bar, baz bat")
41
- assert_equal 2, fields.length
42
- assert_equal "foo", fields[0].expression
43
- assert_equal "bar", fields[0].alias_name
44
- assert_equal "baz", fields[1].expression
45
- assert_equal "bat", fields[1].alias_name
46
- end
47
-
48
- def test_parse_aggregated_fields
49
- fields = SkyDB::Query::Selection.parse_fields("sum(foo), MIN(bar)")
50
- assert_equal 2, fields.length
51
- assert_equal "foo", fields[0].expression
52
- assert_equal :sum, fields[0].aggregation_type
53
- assert_equal "bar", fields[1].expression
54
- assert_equal :min, fields[1].aggregation_type
55
- end
56
-
57
- def test_parse_aliased_aggregated_fields
58
- fields = SkyDB::Query::Selection.parse_fields("sum(foo) baz, MIN(bar) bat")
59
- assert_equal 2, fields.length
60
- assert_equal "foo", fields[0].expression
61
- assert_equal "baz", fields[0].alias_name
62
- assert_equal :sum, fields[0].aggregation_type
63
- assert_equal "bar", fields[1].expression
64
- assert_equal "bat", fields[1].alias_name
65
- assert_equal :min, fields[1].aggregation_type
66
- end
67
-
68
-
69
- ######################################
70
- # Group parsing
71
- ######################################
72
-
73
- def test_parse_single_group
74
- groups = SkyDB::Query::Selection.parse_groups("foo")
75
- assert_equal 1, groups.length
76
- assert_equal "foo", groups[0].expression
77
- end
78
-
79
- def test_parse_multiple_groups
80
- groups = SkyDB::Query::Selection.parse_groups("foo, bar")
81
- assert_equal 2, groups.length
82
- assert_equal "foo", groups[0].expression
83
- assert_equal "bar", groups[1].expression
84
- end
85
-
86
-
87
-
88
- ######################################
89
- # Aggregation Generation
90
- ######################################
91
-
92
- def test_simple_codegen
93
- @selection.fields = SkyDB::Query::Selection.parse_fields("foo, bar my_alias")
94
- expected =
95
- <<-BLOCK.unindent
96
- function select(cursor, data)
97
- target = data
98
- target.foo = cursor.event.foo()
99
- target.my_alias = cursor.event.bar()
100
- end
101
- BLOCK
102
- assert_equal expected, @selection.codegen_select()
103
- end
104
-
105
- def test_count_codegen
106
- @selection.fields = SkyDB::Query::Selection.parse_fields("count() bar")
107
- expected =
108
- <<-BLOCK.unindent
109
- function select(cursor, data)
110
- target = data
111
- target.bar = (target.bar or 0) + 1
112
- end
113
- BLOCK
114
- assert_equal expected, @selection.codegen_select()
115
- end
116
-
117
- def test_sum_codegen
118
- @selection.fields = SkyDB::Query::Selection.parse_fields("SUM(foo) bar")
119
- expected =
120
- <<-BLOCK.unindent
121
- function select(cursor, data)
122
- target = data
123
- target.bar = (target.bar or 0) + cursor.event.foo()
124
- end
125
- BLOCK
126
- assert_equal expected, @selection.codegen_select()
127
- end
128
-
129
- def test_min_codegen
130
- @selection.fields = SkyDB::Query::Selection.parse_fields("min(foo) bar")
131
- expected =
132
- <<-BLOCK.unindent
133
- function select(cursor, data)
134
- target = data
135
- if(target.bar == nil or target.bar > cursor.event.foo()) then
136
- target.bar = cursor.event.foo()
137
- end
138
- end
139
- BLOCK
140
- assert_equal expected, @selection.codegen_select()
141
- end
142
-
143
- def test_max_codegen
144
- @selection.fields = SkyDB::Query::Selection.parse_fields("max(foo) bar")
145
- expected =
146
- <<-BLOCK.unindent
147
- function select(cursor, data)
148
- target = data
149
- if(target.bar == nil or target.bar < cursor.event.foo()) then
150
- target.bar = cursor.event.foo()
151
- end
152
- end
153
- BLOCK
154
- assert_equal expected, @selection.codegen_select()
155
- end
156
-
157
- def test_grouped_codegen
158
- @selection.fields = SkyDB::Query::Selection.parse_fields("foo, bar my_alias")
159
- @selection.groups = SkyDB::Query::Selection.parse_groups("baz")
160
- expected =
161
- <<-BLOCK.unindent
162
- function select(cursor, data)
163
- target = data
164
-
165
- group_value = cursor.event.baz()
166
- if target[group_value] == nil then
167
- target[group_value] = {}
168
- end
169
- target = target[group_value]
170
-
171
- target.foo = cursor.event.foo()
172
- target.my_alias = cursor.event.bar()
173
- end
174
- BLOCK
175
- assert_equal expected, @selection.codegen_select()
176
- end
177
-
178
- def test_multiple_group_codegen
179
- @selection.fields = SkyDB::Query::Selection.parse_fields("foo, bar my_alias")
180
- @selection.groups = SkyDB::Query::Selection.parse_groups("aaa, bbb, ccc")
181
- expected =
182
- <<-BLOCK.unindent
183
- function select(cursor, data)
184
- target = data
185
-
186
- group_value = cursor.event.aaa()
187
- if target[group_value] == nil then
188
- target[group_value] = {}
189
- end
190
- target = target[group_value]
191
-
192
- group_value = cursor.event.bbb()
193
- if target[group_value] == nil then
194
- target[group_value] = {}
195
- end
196
- target = target[group_value]
197
-
198
- group_value = cursor.event.ccc()
199
- if target[group_value] == nil then
200
- target[group_value] = {}
201
- end
202
- target = target[group_value]
203
-
204
- target.foo = cursor.event.foo()
205
- target.my_alias = cursor.event.bar()
206
- end
207
- BLOCK
208
- assert_equal expected, @selection.codegen_select()
209
- end
210
-
211
-
212
- ######################################
213
- # Merge Codegen
214
- ######################################
215
-
216
- def test_simple_merge_codegen
217
- @selection.fields = SkyDB::Query::Selection.parse_fields("foo, sum(bar) my_alias, count(), min(x), max(y)")
218
- expected =
219
- <<-BLOCK.unindent
220
- function merge(results, data)
221
- a = results
222
- b = data
223
- a.foo = b.foo
224
- a.my_alias = (a.my_alias or 0) + (b.my_alias or 0)
225
- a.count = (a.count or 0) + (b.count or 0)
226
- if(a.x == nil or a.x > b.x) then
227
- a.x = b.x
228
- end
229
- if(a.y == nil or a.y < b.y) then
230
- a.y = b.y
231
- end
232
- end
233
- BLOCK
234
- assert_equal expected, @selection.codegen_merge()
235
- end
236
-
237
- def test_grouped_merge_codegen
238
- @selection = SkyDB::Query::Selection.new.select("sum(foo), count()").group_by(:bar)
239
- expected =
240
- <<-BLOCK.unindent
241
- function merge(results, data)
242
- for k0,v0 in pairs(data) do
243
- if results[k0] == nil then results[k0] = {} end
244
- a = results[k0]
245
- b = data[k0]
246
- a.foo = (a.foo or 0) + (b.foo or 0)
247
- a.count = (a.count or 0) + (b.count or 0)
248
- end
249
- end
250
- BLOCK
251
- assert_equal expected, @selection.codegen_merge()
252
- end
253
-
254
- def test_multigroup_merge_codegen
255
- @selection = SkyDB::Query::Selection.new.select("sum(foo), count()").group_by(:bar, :baz)
256
- expected =
257
- <<-BLOCK.unindent
258
- function merge(results, data)
259
- for k0,v0 in pairs(data) do
260
- if results[k0] == nil then results[k0] = {} end
261
- for k1,v1 in pairs(data[k0]) do
262
- if results[k0][k1] == nil then results[k0][k1] = {} end
263
- a = results[k0][k1]
264
- b = data[k0][k1]
265
- a.foo = (a.foo or 0) + (b.foo or 0)
266
- a.count = (a.count or 0) + (b.count or 0)
267
- end
268
- end
269
- end
270
- BLOCK
271
- assert_equal expected, @selection.codegen_merge()
272
- end
273
- end
@@ -1,182 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestQuery < MiniTest::Unit::TestCase
4
- ##############################################################################
5
- #
6
- # Setup / Teardown
7
- #
8
- ##############################################################################
9
-
10
- def setup
11
- @query = SkyDB::Query.new()
12
- end
13
-
14
-
15
- ##############################################################################
16
- #
17
- # Tests
18
- #
19
- ##############################################################################
20
-
21
- ######################################
22
- # Select
23
- ######################################
24
-
25
- def test_select
26
- @query.select('foo, bar')
27
- assert_equal 'foo', @query.selection.fields[0].expression
28
- assert_equal 'bar', @query.selection.fields[1].expression
29
- end
30
-
31
- def test_select_array
32
- @query.select('foo', 'bar')
33
- assert_equal 'foo', @query.selection.fields[0].expression
34
- assert_equal 'bar', @query.selection.fields[1].expression
35
- end
36
-
37
- def test_select_mixed
38
- @query.select(:foo, :bar, 'baz, bat')
39
- assert_equal 'foo', @query.selection.fields[0].expression
40
- assert_equal 'bar', @query.selection.fields[1].expression
41
- assert_equal 'baz', @query.selection.fields[2].expression
42
- assert_equal 'bat', @query.selection.fields[3].expression
43
- end
44
-
45
-
46
- ######################################
47
- # Group by
48
- ######################################
49
-
50
- def test_group_by
51
- @query.select(:foo, :bar).group_by('baz, bat', :xxx)
52
- assert_equal 'foo', @query.selection.fields[0].expression
53
- assert_equal 'bar', @query.selection.fields[1].expression
54
- assert_equal 'baz', @query.selection.groups[0].expression
55
- assert_equal 'bat', @query.selection.groups[1].expression
56
- assert_equal 'xxx', @query.selection.groups[2].expression
57
- end
58
-
59
-
60
- ######################################
61
- # After
62
- ######################################
63
-
64
- def test_after
65
- @query.select('count()').after('foo')
66
- assert_equal :count, @query.selection.fields[0].aggregation_type
67
- assert_equal 'foo', @query.selection.conditions[0].action.name
68
- end
69
-
70
- def test_after_with_hash
71
- @query.select('count()').after(:action => 'foo')
72
- assert_equal 'foo', @query.selection.conditions[0].action.name
73
- end
74
-
75
-
76
- ######################################
77
- # Codegen
78
- ######################################
79
-
80
- def test_codegen
81
- @query.select('count()').after(10).after(20)
82
- expected =
83
- <<-BLOCK.unindent
84
- function select(cursor, data)
85
- target = data
86
- target.count = (target.count or 0) + 1
87
- end
88
-
89
- function __condition1(cursor, data)
90
- if cursor:eos() or cursor:eof() then return false end
91
- repeat
92
- if cursor.event.action_id == 10 then
93
- cursor:next()
94
- return true
95
- end
96
- until not cursor:next()
97
- return false
98
- end
99
-
100
- function __condition2(cursor, data)
101
- if cursor:eos() or cursor:eof() then return false end
102
- repeat
103
- if cursor.event.action_id == 20 then
104
- cursor:next()
105
- return true
106
- end
107
- until not cursor:next()
108
- return false
109
- end
110
-
111
- function select_all(cursor, data)
112
- while cursor:next_session() do
113
- while cursor:next() do
114
- if __condition1(cursor, data) and __condition2(cursor, data) then
115
- select(cursor, data)
116
- end
117
- end
118
- end
119
- end
120
-
121
- function merge(results, data)
122
- a = results
123
- b = data
124
- a.count = (a.count or 0) + (b.count or 0)
125
- end
126
-
127
- function aggregate(cursor, data)
128
- select_all(cursor, data)
129
- end
130
- BLOCK
131
- assert_equal expected.chomp, @query.codegen().chomp
132
- end
133
-
134
- def test_codegen_with_session
135
- @query.session(7200).select('count()')
136
- expected =
137
- <<-BLOCK.unindent
138
- function select(cursor, data)
139
- target = data
140
- target.count = (target.count or 0) + 1
141
- end
142
-
143
-
144
- function select_all(cursor, data)
145
- while cursor:next_session() do
146
- while cursor:next() do
147
- if true then
148
- select(cursor, data)
149
- end
150
- end
151
- end
152
- end
153
-
154
- function merge(results, data)
155
- a = results
156
- b = data
157
- a.count = (a.count or 0) + (b.count or 0)
158
- end
159
-
160
- function aggregate(cursor, data)
161
- cursor:set_session_idle(7200)
162
- select_all(cursor, data)
163
- end
164
- BLOCK
165
- assert_equal expected.chomp, @query.codegen().chomp
166
- end
167
-
168
-
169
- ######################################
170
- # Serialization
171
- ######################################
172
-
173
- def test_to_hash
174
- @query.select('count()').group_by("action_id").on(:enter).after(:action => 10, :within => {:quantity => 1, :unit => 'step'}).after(20)
175
- assert_equal IO.read("fixtures/unit/query/query.json"), JSON.pretty_generate(@query.to_hash)
176
- end
177
-
178
- def test_from_json
179
- @query.from_hash(JSON.parse(IO.read("fixtures/unit/query/query.json")))
180
- assert_equal IO.read("fixtures/unit/query/query.json"), JSON.pretty_generate(@query.to_hash)
181
- end
182
- end