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,4 +0,0 @@
1
- translate: |
2
- output[:object_id] = input[:ip_address]
3
- output[:timestamp] = input[:timestamp]
4
- output[:action][:name] = input[:url]
@@ -1,28 +0,0 @@
1
- fields:
2
- object_id: object_id
3
- timestamp: timestamp:date
4
-
5
- translate: |
6
- def process(_input, _output)
7
- _input.each_pair do |k, v|
8
- if v.is_a?(Hash)
9
- _output[k] = {}
10
- process(v, _output[k])
11
- else
12
- m, prefix, field, data_type = *k.match(/^(?:(action|data)\.)?(\w+)(?:\:(\w+))?$/)
13
- next unless ["object_id", "timestamp"].index(field).nil?
14
-
15
- _output[prefix] ||= {} unless prefix.nil?
16
- target = prefix.nil? ? _output : _output[prefix]
17
-
18
- target[field] = case data_type.to_s.downcase
19
- when "int" then v.to_i
20
- when "float" then v.to_f
21
- when "boolean" then (v.downcase == "true" || v.downcase == "yes" || v.downcase == "y")
22
- when "date" then Chronic.parse(v)
23
- else v.to_s
24
- end
25
- end
26
- end
27
- end
28
- process(input, output)
@@ -1 +0,0 @@
1
- fields:
@@ -1,119 +0,0 @@
1
- require 'chronic'
2
-
3
- class SkyDB
4
- class Import
5
- class Translator
6
- ##########################################################################
7
- #
8
- # Constructor
9
- #
10
- ##########################################################################
11
-
12
- # Initializes the translator.
13
- def initialize(options={})
14
- self.input_field = options[:input_field]
15
- self.output_field = options[:output_field]
16
- self.format = options[:format]
17
- self.translate_function = options[:translate_function]
18
- end
19
-
20
-
21
- ##########################################################################
22
- #
23
- # Attributes
24
- #
25
- ##########################################################################
26
-
27
- # The name of the input field to read from.
28
- attr_accessor :input_field
29
-
30
- # The name of the output field to write to.
31
- attr_accessor :output_field
32
-
33
- # The format of the field (String, Integer, Float, Date).
34
- attr_reader :format
35
-
36
- def format=(value)
37
- value = 'string' if value.nil?
38
- value = 'int' if value == 'integer'
39
- @format = value.to_s.downcase
40
- end
41
-
42
- # The translation function to execute. This can be a Proc or it can be
43
- # a String that is evaluated into a proc with "input" and "output"
44
- # arguments.
45
- attr_reader :translate_function
46
-
47
- def translate_function=(value)
48
- # Only allow nils, procs & strings.
49
- if !value.nil? && !value.is_a?(Proc) && !value.is_a?(String)
50
- raise "Unable to convert #{value.class} to a translation function."
51
- end
52
-
53
- # If this is a string then eval it into a proc.
54
- if value.is_a?(String)
55
- # If there's no output field set then it's free form.
56
- if output_field.nil?
57
- @translate_function = eval("lambda { |input,output| #{value} }")
58
-
59
- # If there is an output field set then make the lamda an assignment.
60
- else
61
- keys = output_field.is_a?(Array) ? output_field : [output_field]
62
- keys.map! {|key| "['" + key.gsub("'", "\\'") + "']"}
63
- @translate_function = eval("lambda { |input,output| output#{keys.join('')} = #{value.to_s} }")
64
- end
65
-
66
- # If this is a proc or a nil then just pass it through.
67
- else
68
- @translate_function = value
69
- end
70
- end
71
-
72
-
73
- ##########################################################################
74
- #
75
- # Methods
76
- #
77
- ##########################################################################
78
-
79
- # Translate a field from the input hash into a field into the
80
- # output hash.
81
- #
82
- # @param [Hash] the input data.
83
- # @param [Hash] the output data.
84
- def translate(input, output)
85
- # If a translation function is set then use it.
86
- if !translate_function.nil?
87
- translate_function.call(input, output)
88
-
89
- # If the input field and output field are set then apply them.
90
- elsif !input_field.nil? && !output_field.nil?
91
- value = input[input_field]
92
-
93
- # Navigate down to nested output hash if necessary.
94
- if output_field.is_a?(Array)
95
- output_field[0..-2].each do |field|
96
- output[field] = {} unless output.has_key?(field)
97
- output = output[field]
98
- end
99
-
100
- output_field = self.output_field.last
101
- else
102
- output_field = self.output_field
103
- end
104
-
105
- # Convert type.
106
- output[output_field] = case format
107
- when "int" then value.to_i
108
- when "float" then value.to_f
109
- when "boolean" then (value.downcase == "true" || value.downcase == "yes" || value.downcase == "y")
110
- when "date" then Chronic.parse(value)
111
- else value.to_s
112
- end
113
- end
114
-
115
- return nil
116
- end
117
- end
118
- end
119
- end
@@ -1,146 +0,0 @@
1
- class SkyDB
2
- class Message
3
- ##########################################################################
4
- #
5
- # Constants
6
- #
7
- ##########################################################################
8
-
9
- # The version of the message. This must be compatible with the server's
10
- # version for the client to work.
11
- VERSION = 1
12
-
13
-
14
- ##########################################################################
15
- #
16
- # Constructor
17
- #
18
- ##########################################################################
19
-
20
- # Initializes the message.
21
- def initialize(message_name)
22
- @message_name = message_name
23
- @table_name = ""
24
- end
25
-
26
-
27
- ##########################################################################
28
- #
29
- # Attributes
30
- #
31
- ##########################################################################
32
-
33
- ####################################
34
- # Name
35
- ####################################
36
-
37
- # The name of message being sent. This is defined by the subclass.
38
- attr_reader :message_name
39
-
40
-
41
- ####################################
42
- # Table Name
43
- ####################################
44
-
45
- # The name of the table the message is being sent to/from.
46
- attr_accessor :table_name
47
-
48
- def table_name=(value)
49
- @table_name = value.to_s
50
- end
51
-
52
-
53
- ##########################################################################
54
- #
55
- # Methods
56
- #
57
- ##########################################################################
58
-
59
- ####################################
60
- # Validation
61
- ####################################
62
-
63
- # A flag stating if the table is required for this type of message.
64
- def require_table?
65
- return true
66
- end
67
-
68
- # Validates that the message is ready to be sent. If any validation issues
69
- # are found then an error is raised.
70
- def validate!
71
- if require_table? && (table_name.nil? || table_name.empty?)
72
- raise SkyDB::TableRequiredError.new('Table name required')
73
- end
74
- end
75
-
76
-
77
- ####################################
78
- # Encoding
79
- ####################################
80
-
81
- # Encodes the message contents to a buffer.
82
- #
83
- # @param [IO] buffer the buffer to write to.
84
- def encode(buffer)
85
- buffer.set_encoding(Encoding::BINARY, Encoding::BINARY)
86
-
87
- # Encode the header and body.
88
- encode_header(buffer)
89
- encode_body(buffer)
90
-
91
- return nil
92
- end
93
-
94
- # Encodes the message header.
95
- #
96
- # @param [IO] buffer the buffer to write the header to.
97
- def encode_header(buffer)
98
- buffer << [
99
- SkyDB::Message::VERSION,
100
- message_name,
101
- table_name
102
- ].to_msgpack
103
- end
104
-
105
- # Encodes the message body.
106
- #
107
- # @param [IO] buffer the buffer to write the header to.
108
- def encode_body(buffer)
109
- # To be implemented by the subclass.
110
- end
111
-
112
-
113
- ####################################
114
- # Response processing
115
- ####################################
116
-
117
- # Performs any necessary post-processing on the response.
118
- #
119
- # @param [Object] response
120
- def process_response(response)
121
- return response
122
- end
123
- end
124
- end
125
-
126
- require 'skydb/message/create_table'
127
- require 'skydb/message/delete_table'
128
- require 'skydb/message/get_table'
129
- require 'skydb/message/get_tables'
130
-
131
- require 'skydb/message/add_action'
132
- require 'skydb/message/get_action'
133
- require 'skydb/message/get_actions'
134
-
135
- require 'skydb/message/add_property'
136
- require 'skydb/message/get_property'
137
- require 'skydb/message/get_properties'
138
-
139
- require 'skydb/message/add_event'
140
- require 'skydb/message/next_actions'
141
-
142
- require 'skydb/message/lua/aggregate'
143
-
144
- require 'skydb/message/ping'
145
- require 'skydb/message/lookup'
146
- require 'skydb/message/multi'
@@ -1,53 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class AddAction < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'action add' message.
11
- def initialize(action=nil, options={})
12
- super('add_action')
13
- self.action = action
14
- end
15
-
16
-
17
- ##########################################################################
18
- #
19
- # Attributes
20
- #
21
- ##########################################################################
22
-
23
- ##################################
24
- # Action
25
- ##################################
26
-
27
- # The action to add.
28
- attr_reader :action
29
-
30
- def action=(value)
31
- @action = value if value.is_a?(Action)
32
- end
33
-
34
-
35
- ##########################################################################
36
- #
37
- # Methods
38
- #
39
- ##########################################################################
40
-
41
- ####################################
42
- # Encoding
43
- ####################################
44
-
45
- # Encodes the message body.
46
- #
47
- # @param [IO] buffer the buffer to write the header to.
48
- def encode_body(buffer)
49
- buffer << action.to_msgpack
50
- end
51
- end
52
- end
53
- end
@@ -1,72 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class AddEvent < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'event add' message.
11
- #
12
- # @param [Event] event the event to add.
13
- def initialize(event=nil, options={})
14
- super('add_event')
15
- self.event = event
16
- end
17
-
18
-
19
- ##########################################################################
20
- #
21
- # Attributes
22
- #
23
- ##########################################################################
24
-
25
- ##################################
26
- # Event
27
- ##################################
28
-
29
- # The event to add.
30
- attr_reader :event
31
-
32
- def event=(value)
33
- @event = value if value.is_a?(Event)
34
- end
35
-
36
-
37
- ##########################################################################
38
- #
39
- # Methods
40
- #
41
- ##########################################################################
42
-
43
- ####################################
44
- # Validation
45
- ####################################
46
-
47
- def validate!
48
- super
49
-
50
- if event.object_id.nil?
51
- raise SkyDB::ObjectIdRequiredError.new('Object ID required')
52
- end
53
-
54
- if event.timestamp.nil?
55
- raise SkyDB::TimestampRequiredError.new('Timestamp required')
56
- end
57
- end
58
-
59
-
60
- ####################################
61
- # Encoding
62
- ####################################
63
-
64
- # Encodes the message body.
65
- #
66
- # @param [IO] buffer the buffer to write the header to.
67
- def encode_body(buffer)
68
- buffer << event.to_msgpack
69
- end
70
- end
71
- end
72
- end
@@ -1,55 +0,0 @@
1
- class SkyDB
2
- class Message
3
- class AddProperty < SkyDB::Message
4
- ########################################################################
5
- #
6
- # Constructor
7
- #
8
- ########################################################################
9
-
10
- # Initializes the 'property add' message.
11
- #
12
- # @param [Property] property the property to add.
13
- def initialize(property=nil, options={})
14
- super('add_property')
15
- self.property = property
16
- end
17
-
18
-
19
- ##########################################################################
20
- #
21
- # Attributes
22
- #
23
- ##########################################################################
24
-
25
- ##################################
26
- # Property
27
- ##################################
28
-
29
- # The property to add.
30
- attr_reader :property
31
-
32
- def property=(value)
33
- @property = value if value.is_a?(Property)
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 << property.to_msgpack
52
- end
53
- end
54
- end
55
- end