skydb 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/bin/sky +85 -0
  2. data/lib/ext/hash.rb +11 -0
  3. data/lib/ext/treetop.rb +19 -0
  4. data/lib/skydb.rb +10 -3
  5. data/lib/skydb/client.rb +92 -28
  6. data/lib/skydb/import.rb +7 -0
  7. data/lib/skydb/import/importer.rb +258 -0
  8. data/lib/skydb/import/transforms/sky.yml +20 -0
  9. data/lib/skydb/import/transforms/snowplow.yml +1 -0
  10. data/lib/skydb/import/translator.rb +119 -0
  11. data/lib/skydb/message.rb +17 -12
  12. data/lib/skydb/message/create_table.rb +64 -0
  13. data/lib/skydb/message/delete_table.rb +66 -0
  14. data/lib/skydb/message/get_table.rb +74 -0
  15. data/lib/skydb/message/lookup.rb +79 -0
  16. data/lib/skydb/property.rb +5 -5
  17. data/lib/skydb/query.rb +198 -0
  18. data/lib/skydb/query/after.rb +103 -0
  19. data/lib/skydb/query/ast/selection_field_syntax_node.rb +26 -0
  20. data/lib/skydb/query/ast/selection_fields_syntax_node.rb +16 -0
  21. data/lib/skydb/query/ast/selection_group_syntax_node.rb +16 -0
  22. data/lib/skydb/query/ast/selection_groups_syntax_node.rb +16 -0
  23. data/lib/skydb/query/selection.rb +268 -0
  24. data/lib/skydb/query/selection_field.rb +74 -0
  25. data/lib/skydb/query/selection_fields_grammar.treetop +46 -0
  26. data/lib/skydb/query/selection_fields_parse_error.rb +30 -0
  27. data/lib/skydb/query/selection_group.rb +57 -0
  28. data/lib/skydb/query/selection_groups_grammar.treetop +31 -0
  29. data/lib/skydb/query/selection_groups_parse_error.rb +30 -0
  30. data/lib/skydb/query/validation_error.rb +8 -0
  31. data/lib/skydb/table.rb +69 -0
  32. data/lib/skydb/version.rb +1 -1
  33. data/test/import/importer_test.rb +42 -0
  34. data/test/import/translator_test.rb +88 -0
  35. data/test/message/add_event_message_test.rb +1 -1
  36. data/test/message/add_property_message_test.rb +2 -2
  37. data/test/message/create_table_message_test.rb +34 -0
  38. data/test/message/delete_table_message_test.rb +34 -0
  39. data/test/message/get_table_message_test.rb +19 -0
  40. data/test/message/lookup_message_test.rb +27 -0
  41. data/test/message_test.rb +1 -1
  42. data/test/query/after_test.rb +71 -0
  43. data/test/query/selection_test.rb +273 -0
  44. data/test/query_test.rb +156 -0
  45. data/test/test_helper.rb +3 -0
  46. metadata +129 -3
@@ -0,0 +1,156 @@
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.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.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
+ repeat
91
+ if cursor.event.action_id == 10 then
92
+ cursor:next()
93
+ return true
94
+ end
95
+ until not cursor:next()
96
+ return false
97
+ end
98
+
99
+ function __condition2(cursor, data)
100
+ repeat
101
+ if cursor.event.action_id == 20 then
102
+ cursor:next()
103
+ return true
104
+ end
105
+ until not cursor:next()
106
+ return false
107
+ end
108
+
109
+ function aggregate(cursor, data)
110
+ while cursor:next_session() do
111
+ while cursor:next() do
112
+ if __condition1(cursor, data) and __condition2(cursor, data) then
113
+ select(cursor, data)
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ function merge(results, data)
120
+ a = results
121
+ b = data
122
+ a.count = (a.count or 0) + (b.count or 0)
123
+ end
124
+ BLOCK
125
+ assert_equal expected.chomp, @query.codegen().chomp
126
+ end
127
+
128
+ def test_codegen_with_session
129
+ @query.select('count()').session(7200)
130
+ expected =
131
+ <<-BLOCK.unindent
132
+ function select(cursor, data)
133
+ target = data
134
+ target.count = (target.count or 0) + 1
135
+ end
136
+
137
+ function aggregate(cursor, data)
138
+ cursor:set_session_idle(7200)
139
+ while cursor:next_session() do
140
+ while cursor:next() do
141
+ if true then
142
+ select(cursor, data)
143
+ end
144
+ end
145
+ end
146
+ end
147
+
148
+ function merge(results, data)
149
+ a = results
150
+ b = data
151
+ a.count = (a.count or 0) + (b.count or 0)
152
+ end
153
+ BLOCK
154
+ assert_equal expected.chomp, @query.codegen().chomp
155
+ end
156
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
+ require 'bundler/setup'
1
2
  require 'minitest/autorun'
2
3
  require 'mocha'
4
+ require 'unindentable'
3
5
  require 'skydb'
6
+ require 'skydb/import'
4
7
 
5
8
  class MiniTest::Unit::TestCase
6
9
  def assert_bytes exp, act, msg = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skydb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -27,6 +27,70 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 0.4.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: commander
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 4.1.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 4.1.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: ruby-progressbar
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: chronic
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.9.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.9.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: treetop
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.4.12
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.4.12
30
94
  - !ruby/object:Gem::Dependency
31
95
  name: rake
32
96
  requirement: !ruby/object:Gem::Requirement
@@ -75,24 +139,52 @@ dependencies:
75
139
  - - ~>
76
140
  - !ruby/object:Gem::Version
77
141
  version: 0.12.5
142
+ - !ruby/object:Gem::Dependency
143
+ name: unindentable
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.1.0
150
+ type: :runtime
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.1.0
78
158
  description:
79
159
  email:
80
160
  - benbjohnson@yahoo.com
81
- executables: []
161
+ executables:
162
+ - sky
82
163
  extensions: []
83
164
  extra_rdoc_files: []
84
165
  files:
166
+ - lib/ext/hash.rb
85
167
  - lib/ext/string.rb
168
+ - lib/ext/treetop.rb
86
169
  - lib/skydb/action.rb
87
170
  - lib/skydb/client.rb
88
171
  - lib/skydb/event.rb
172
+ - lib/skydb/import/importer.rb
173
+ - lib/skydb/import/transforms/sky.yml
174
+ - lib/skydb/import/transforms/snowplow.yml
175
+ - lib/skydb/import/translator.rb
176
+ - lib/skydb/import.rb
89
177
  - lib/skydb/message/add_action.rb
90
178
  - lib/skydb/message/add_event.rb
91
179
  - lib/skydb/message/add_property.rb
180
+ - lib/skydb/message/create_table.rb
181
+ - lib/skydb/message/delete_table.rb
92
182
  - lib/skydb/message/get_action.rb
93
183
  - lib/skydb/message/get_actions.rb
94
184
  - lib/skydb/message/get_properties.rb
95
185
  - lib/skydb/message/get_property.rb
186
+ - lib/skydb/message/get_table.rb
187
+ - lib/skydb/message/lookup.rb
96
188
  - lib/skydb/message/lua/aggregate.rb
97
189
  - lib/skydb/message/multi.rb
98
190
  - lib/skydb/message/next_actions.rb
@@ -100,26 +192,51 @@ files:
100
192
  - lib/skydb/message.rb
101
193
  - lib/skydb/property/type.rb
102
194
  - lib/skydb/property.rb
195
+ - lib/skydb/query/after.rb
196
+ - lib/skydb/query/ast/selection_field_syntax_node.rb
197
+ - lib/skydb/query/ast/selection_fields_syntax_node.rb
198
+ - lib/skydb/query/ast/selection_group_syntax_node.rb
199
+ - lib/skydb/query/ast/selection_groups_syntax_node.rb
200
+ - lib/skydb/query/selection.rb
201
+ - lib/skydb/query/selection_field.rb
202
+ - lib/skydb/query/selection_fields_grammar.treetop
203
+ - lib/skydb/query/selection_fields_parse_error.rb
204
+ - lib/skydb/query/selection_group.rb
205
+ - lib/skydb/query/selection_groups_grammar.treetop
206
+ - lib/skydb/query/selection_groups_parse_error.rb
207
+ - lib/skydb/query/validation_error.rb
208
+ - lib/skydb/query.rb
209
+ - lib/skydb/table.rb
103
210
  - lib/skydb/timestamp.rb
104
211
  - lib/skydb/version.rb
105
212
  - lib/skydb.rb
106
213
  - README.md
107
214
  - test/client_test.rb
108
215
  - test/event_test.rb
216
+ - test/import/importer_test.rb
217
+ - test/import/translator_test.rb
109
218
  - test/message/add_action_message_test.rb
110
219
  - test/message/add_event_message_test.rb
111
220
  - test/message/add_property_message_test.rb
221
+ - test/message/create_table_message_test.rb
222
+ - test/message/delete_table_message_test.rb
112
223
  - test/message/get_action_message_test.rb
113
224
  - test/message/get_actions_message_test.rb
114
225
  - test/message/get_properties_message_test.rb
115
226
  - test/message/get_property_message_test.rb
227
+ - test/message/get_table_message_test.rb
228
+ - test/message/lookup_message_test.rb
116
229
  - test/message/lua_aggregate_message_test.rb
117
230
  - test/message/multi_message_test.rb
118
231
  - test/message/next_action_message_test.rb
119
232
  - test/message/ping_message_test.rb
120
233
  - test/message_test.rb
234
+ - test/query/after_test.rb
235
+ - test/query/selection_test.rb
236
+ - test/query_test.rb
121
237
  - test/skydb_test.rb
122
238
  - test/test_helper.rb
239
+ - bin/sky
123
240
  homepage: http://github.com/skydb/sky.rb
124
241
  licenses: []
125
242
  post_install_message:
@@ -147,17 +264,26 @@ summary: A Ruby client for the Sky database
147
264
  test_files:
148
265
  - test/client_test.rb
149
266
  - test/event_test.rb
267
+ - test/import/importer_test.rb
268
+ - test/import/translator_test.rb
150
269
  - test/message/add_action_message_test.rb
151
270
  - test/message/add_event_message_test.rb
152
271
  - test/message/add_property_message_test.rb
272
+ - test/message/create_table_message_test.rb
273
+ - test/message/delete_table_message_test.rb
153
274
  - test/message/get_action_message_test.rb
154
275
  - test/message/get_actions_message_test.rb
155
276
  - test/message/get_properties_message_test.rb
156
277
  - test/message/get_property_message_test.rb
278
+ - test/message/get_table_message_test.rb
279
+ - test/message/lookup_message_test.rb
157
280
  - test/message/lua_aggregate_message_test.rb
158
281
  - test/message/multi_message_test.rb
159
282
  - test/message/next_action_message_test.rb
160
283
  - test/message/ping_message_test.rb
161
284
  - test/message_test.rb
285
+ - test/query/after_test.rb
286
+ - test/query/selection_test.rb
287
+ - test/query_test.rb
162
288
  - test/skydb_test.rb
163
289
  - test/test_helper.rb