skydb 0.2.3 → 0.3.0

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.
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,63 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class Lua
4
- class Aggregate < SkyDB::Message
5
- ########################################################################
6
- #
7
- # Constructor
8
- #
9
- ########################################################################
10
-
11
- # Initializes the 'lua::aggregate' message.
12
- #
13
- # @param [String] source the Lua source to execute.
14
- def initialize(source=nil, options={})
15
- super('lua::aggregate')
16
- self.source = source
17
- end
18
-
19
-
20
- ##########################################################################
21
- #
22
- # Attributes
23
- #
24
- ##########################################################################
25
-
26
- ##################################
27
- # Source
28
- ##################################
29
-
30
- # The Lua source code.
31
- attr_reader :source
32
-
33
- def source=(value)
34
- @source = value.to_s
35
- end
36
-
37
-
38
- ##########################################################################
39
- #
40
- # Methods
41
- #
42
- ##########################################################################
43
-
44
- ####################################
45
- # Encoding
46
- ####################################
47
-
48
- # Encodes the message body.
49
- #
50
- # @param [IO] buffer the buffer to write the header to.
51
- def encode_body(buffer)
52
- buffer << {
53
- :source => source
54
- }.to_msgpack
55
- end
56
-
57
- def process_response(response)
58
- return response['data']
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,57 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class Multi < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'multi' message.
11
- def initialize(options={})
12
- super('multi')
13
- self.messages = []
14
- end
15
-
16
-
17
- ##########################################################################
18
- #
19
- # Attributes
20
- #
21
- ##########################################################################
22
-
23
- ##################################
24
- # Messages
25
- ##################################
26
-
27
- # A list of message to send to the server.
28
- attr_accessor :messages
29
-
30
-
31
- ##########################################################################
32
- #
33
- # Methods
34
- #
35
- ##########################################################################
36
-
37
- ####################################
38
- # Encoding
39
- ####################################
40
-
41
- # Encodes the message body.
42
- #
43
- # @param [IO] buffer the buffer to write to.
44
- def encode_body(buffer)
45
- # Encode the message count.
46
- buffer << {
47
- :count => messages.length
48
- }.to_msgpack
49
-
50
- # Encode all the messages.
51
- messages.each do |message|
52
- message.encode(buffer)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,55 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class NextActions < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'next action' message.
11
- #
12
- # @param [Array] prior_action_ids the prior action ids.
13
- def initialize(prior_action_ids=nil, options={})
14
- super('next_actions')
15
- self.prior_action_ids = prior_action_ids
16
- end
17
-
18
-
19
- ##########################################################################
20
- #
21
- # Attributes
22
- #
23
- ##########################################################################
24
-
25
- ##################################
26
- # Prior Action IDs
27
- ##################################
28
-
29
- # The prior action ids.
30
- attr_reader :prior_action_ids
31
-
32
- def prior_action_ids=(value)
33
- @prior_action_ids = value.is_a?(Array) ? value : []
34
- end
35
-
36
-
37
- ##########################################################################
38
- #
39
- # Methods
40
- #
41
- ##########################################################################
42
-
43
- ####################################
44
- # Encoding
45
- ####################################
46
-
47
- # Encodes the message body.
48
- #
49
- # @param [IO] buffer the buffer to write the header to.
50
- def encode_body(buffer)
51
- buffer << prior_action_ids.to_msgpack
52
- end
53
- end
54
- end
55
- end
@@ -1,32 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class Ping < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'ping' message.
11
- def initialize(options={})
12
- super('ping')
13
- end
14
-
15
-
16
- ########################################################################
17
- #
18
- # Methods
19
- #
20
- ########################################################################
21
-
22
- ##################################
23
- # Validation
24
- ##################################
25
-
26
- # A flag stating if the table is required for this type of message.
27
- def require_table?
28
- return false
29
- end
30
- end
31
- end
32
- end
@@ -1,40 +0,0 @@
1
- class SkyDB
2
- class Property
3
- class Type
4
- ########################################################################
5
- #
6
- # Constants
7
- #
8
- ########################################################################
9
-
10
- OBJECT = 1
11
-
12
- ACTION = 2
13
-
14
-
15
- ########################################################################
16
- #
17
- # Static Methods
18
- #
19
- ########################################################################
20
-
21
- # Encodes the type into it's numeric enum value.
22
- #
23
- # @param type [Symbol] the type.
24
- # @return [Fixnum] the enum value for the property type.
25
- def self.encode(type)
26
- return nil unless [:object, :action].index(type)
27
- return type == :object ? OBJECT : ACTION
28
- end
29
-
30
- # Decodes the numeric enum value into its symbol.
31
- #
32
- # @param value [Fixnum] the numeric enum value.
33
- # @return [Symbol] the type symbol.
34
- def self.decode(value)
35
- return nil unless [OBJECT, ACTION].index(value)
36
- return value == OBJECT ? :object : :action
37
- end
38
- end
39
- end
40
- end
@@ -1,183 +0,0 @@
1
- require 'skydb/query/selection'
2
- require 'skydb/query/condition'
3
- require 'skydb/query/after_condition'
4
- require 'skydb/query/on_condition'
5
- require 'skydb/query/validation_error'
6
-
7
- class SkyDB
8
- # The Query object represents a high level abstraction of how data is
9
- # processed and retrieved from the database. It is inspired by ActiveRecord
10
- # in the sense that commands can be chained together.
11
- #
12
- # The query is not executed until the execute() method is called.
13
- class Query
14
- ##########################################################################
15
- #
16
- # Constructor
17
- #
18
- ##########################################################################
19
-
20
- def initialize(options={})
21
- self.client = options[:client]
22
- self.selection = options[:selection]
23
- end
24
-
25
-
26
- ##########################################################################
27
- #
28
- # Attributes
29
- #
30
- ##########################################################################
31
-
32
- # The client that is used for executing the query.
33
- attr_accessor :client
34
-
35
- # The properties that should be selected from the database.
36
- attr_reader :selection
37
-
38
- def selection=(value)
39
- @selection = value
40
- value.query = self unless value.nil?
41
- return value
42
- end
43
-
44
- # The number of idle seconds that separates sessions.
45
- attr_accessor :session_idle_time
46
-
47
-
48
- ##########################################################################
49
- #
50
- # Methods
51
- #
52
- ##########################################################################
53
-
54
- ####################################
55
- # Helpers
56
- ####################################
57
-
58
- # Creates and appends a new selection to the query.
59
- #
60
- # @param [String] fields A list of fields to add to the selection.
61
- #
62
- # @return [Selection] The newly created selection object is returned.
63
- def select(*fields)
64
- self.selection = SkyDB::Query::Selection.new()
65
- selection.select(*fields)
66
- return selection
67
- end
68
-
69
- # Sets the session idle seconds and returns the query object.
70
- #
71
- # @param [Fixnum] seconds The number of idle seconds.
72
- #
73
- # @return [Query] The query object is returned.
74
- def session(seconds)
75
- self.session_idle_time = seconds
76
- return self
77
- end
78
-
79
-
80
- ####################################
81
- # Execution
82
- ####################################
83
-
84
- # Executes the query and returns the resulting data.
85
- def execute
86
- # Generate the Lua code for this query.
87
- code = codegen()
88
-
89
- # Send it to the server.
90
- results = client.aggregate(code)
91
-
92
- # Return the results.
93
- return results
94
- end
95
-
96
-
97
- ####################################
98
- # Validation
99
- ####################################
100
-
101
- # Validates that all the elements of the query are valid.
102
- def validate!
103
- selection.validate!
104
- end
105
-
106
-
107
- ####################################
108
- # Codegen
109
- ####################################
110
-
111
- # Generates the Lua code that represents the query.
112
- def codegen
113
- # Lookup all actions & properties.
114
- lookup_identifiers()
115
-
116
- # Validate everything in query before proceeding.
117
- validate!
118
-
119
- # Generate selection.
120
- code = []
121
- code << selection.codegen()
122
-
123
- # Generate aggregate() function.
124
- code << "function aggregate(cursor, data)"
125
- code << " cursor:set_session_idle(#{session_idle_time.to_i})" if session_idle_time.to_i > 0
126
- code << " select_all(cursor, data)"
127
- code << "end"
128
- code << ""
129
-
130
- return code.join("\n")
131
- end
132
-
133
-
134
- ####################################
135
- # Serialization
136
- ####################################
137
-
138
- # Serializes the query object into a JSON string.
139
- def to_json(*a); to_hash.to_json(*a); end
140
-
141
- # Serializes the query object into a hash.
142
- def to_hash(*a)
143
- hash = {}
144
- hash['selections'] = [selection.to_hash(*a)] unless selection.nil?
145
- hash['sessionIdleTime'] = session_idle_time.to_i
146
- hash
147
- end
148
-
149
- # Deserializes the query object into a hash.
150
- def from_hash(hash, *a)
151
- return if hash.nil?
152
- selection_hash, x = *hash['selections']
153
- self.selection = SkyDB::Query::Selection.new.from_hash(selection_hash)
154
- self.session_idle_time = hash['sessionIdleTime'].to_i
155
- return self
156
- end
157
-
158
-
159
- ####################################
160
- # Utility
161
- ####################################
162
-
163
- # Generates a sequence number used for uniquely naming objects and
164
- # functions in the query.
165
- def nextseq
166
- @sequence = (@sequence || 0) + 1
167
- end
168
-
169
- # Looks up all actions and properties that are missing an identifier.
170
- def lookup_identifiers
171
- # Find all the actions on the selection that are missing an id.
172
- actions = []
173
- actions.concat(selection.get_identifiers())
174
-
175
- # Lookup all the actions.
176
- if actions.length > 0
177
- client.lookup(:actions => actions)
178
- end
179
-
180
- return nil
181
- end
182
- end
183
- end
@@ -1,104 +0,0 @@
1
- class SkyDB
2
- class Query
3
- # The 'after' condition filters out selection only after the condition
4
- # has been fulfilled.
5
- class AfterCondition < SkyDB::Query::Condition
6
- ##########################################################################
7
- #
8
- # Constructor
9
- #
10
- ##########################################################################
11
-
12
- def initialize(action=nil, options={})
13
- options.merge!(action.is_a?(Hash) ? action : {:action => action})
14
- super(options)
15
- self.within = options[:within]
16
- end
17
-
18
-
19
- ##########################################################################
20
- #
21
- # Attributes
22
- #
23
- ##########################################################################
24
-
25
- attr_accessor :within
26
-
27
-
28
- ##########################################################################
29
- #
30
- # Methods
31
- #
32
- ##########################################################################
33
-
34
- ##################################
35
- # Validation
36
- ##################################
37
-
38
- # Validates that the object is correct before executing a codegen.
39
- def validate!
40
- # Do not allow the :enter action. That is reserved for the 'On'
41
- # condition.
42
- if action == :enter
43
- raise SkyDB::Query::ValidationError.new("Enter actions cannot be used with an 'after' condition. Please use an 'on' condition instead.")
44
- end
45
-
46
- super
47
-
48
- return nil
49
- end
50
-
51
-
52
- ##################################
53
- # Codegen
54
- ##################################
55
-
56
- # Generates Lua code to match a given action.
57
- def codegen(options={})
58
- header, body, footer = "function #{function_name.to_s}(cursor, data)\n", [], "end\n"
59
- within_unit = (within.nil? ? nil : within[:unit])
60
-
61
- # Find the matching event and then move to the next one for selection.
62
- body << "if cursor:eos() or cursor:eof() then return false end"
63
- body << "remaining = #{within[:quantity].to_i}" if within_unit == 'step'
64
- body << "repeat"
65
- body << " if remaining <= 0 then return false end" if within_unit == 'step'
66
- body << " if cursor.event.action_id == #{action.id.to_i} then"
67
- body << " cursor:next()"
68
- body << " return true"
69
- body << " end"
70
- body << " remaining = remaining - 1" if within_unit == 'step'
71
- body << "until not cursor:next()"
72
- body << "return false"
73
-
74
- # Indent body and return.
75
- body.map! {|line| " " + line}
76
- return header + body.join("\n") + "\n" + footer
77
- end
78
-
79
-
80
- ####################################
81
- # Serialization
82
- ####################################
83
-
84
- # Serializes the condition into a hash.
85
- def to_hash(*a)
86
- json = super(*a)
87
- json['within'] = within.to_hash(*a) unless within.nil?
88
- json
89
- end
90
-
91
- # Deserializes the condition from a hash.
92
- def from_hash(hash, *a)
93
- super(hash, *a)
94
- return nil if hash.nil?
95
-
96
- hash['within']._symbolize_keys! unless hash['within'].nil?
97
- self.within = hash['within']
98
-
99
- return self
100
- end
101
- end
102
- end
103
- end
104
-