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.
- checksums.yaml +15 -0
- data/README.md +165 -1
- data/lib/skydb.rb +18 -61
- data/lib/skydb/client.rb +186 -186
- data/lib/skydb/event.rb +47 -76
- data/lib/skydb/property.rb +34 -67
- data/lib/skydb/table.rb +121 -41
- data/lib/skydb/version.rb +1 -1
- data/test/integration/client_test.rb +88 -0
- data/test/test_helper.rb +3 -51
- data/test/unit/client_test.rb +135 -32
- metadata +17 -278
- data/bin/sky +0 -89
- data/lib/ext/hash.rb +0 -11
- data/lib/ext/string.rb +0 -11
- data/lib/ext/treetop.rb +0 -19
- data/lib/skydb/action.rb +0 -76
- data/lib/skydb/import.rb +0 -7
- data/lib/skydb/import/importer.rb +0 -435
- data/lib/skydb/import/transforms/apache.yml +0 -4
- data/lib/skydb/import/transforms/sky.yml +0 -28
- data/lib/skydb/import/transforms/snowplow.yml +0 -1
- data/lib/skydb/import/translator.rb +0 -119
- data/lib/skydb/message.rb +0 -146
- data/lib/skydb/message/add_action.rb +0 -53
- data/lib/skydb/message/add_event.rb +0 -72
- data/lib/skydb/message/add_property.rb +0 -55
- data/lib/skydb/message/create_table.rb +0 -64
- data/lib/skydb/message/delete_table.rb +0 -66
- data/lib/skydb/message/get_action.rb +0 -55
- data/lib/skydb/message/get_actions.rb +0 -38
- data/lib/skydb/message/get_properties.rb +0 -38
- data/lib/skydb/message/get_property.rb +0 -55
- data/lib/skydb/message/get_table.rb +0 -74
- data/lib/skydb/message/get_tables.rb +0 -43
- data/lib/skydb/message/lookup.rb +0 -79
- data/lib/skydb/message/lua/aggregate.rb +0 -63
- data/lib/skydb/message/multi.rb +0 -57
- data/lib/skydb/message/next_actions.rb +0 -55
- data/lib/skydb/message/ping.rb +0 -32
- data/lib/skydb/property/type.rb +0 -40
- data/lib/skydb/query.rb +0 -183
- data/lib/skydb/query/after_condition.rb +0 -104
- data/lib/skydb/query/ast/selection_field_syntax_node.rb +0 -26
- data/lib/skydb/query/ast/selection_fields_syntax_node.rb +0 -16
- data/lib/skydb/query/ast/selection_group_syntax_node.rb +0 -16
- data/lib/skydb/query/ast/selection_groups_syntax_node.rb +0 -16
- data/lib/skydb/query/condition.rb +0 -113
- data/lib/skydb/query/on_condition.rb +0 -53
- data/lib/skydb/query/selection.rb +0 -398
- data/lib/skydb/query/selection_field.rb +0 -99
- data/lib/skydb/query/selection_fields_grammar.treetop +0 -46
- data/lib/skydb/query/selection_fields_parse_error.rb +0 -30
- data/lib/skydb/query/selection_group.rb +0 -78
- data/lib/skydb/query/selection_groups_grammar.treetop +0 -31
- data/lib/skydb/query/selection_groups_parse_error.rb +0 -30
- data/lib/skydb/query/validation_error.rb +0 -8
- data/lib/skydb/timestamp.rb +0 -22
- data/test/integration/query_test.rb +0 -102
- data/test/unit/event_test.rb +0 -32
- data/test/unit/import/importer_test.rb +0 -208
- data/test/unit/import/translator_test.rb +0 -88
- data/test/unit/message/add_action_message_test.rb +0 -34
- data/test/unit/message/add_event_message_test.rb +0 -35
- data/test/unit/message/add_property_message_test.rb +0 -41
- data/test/unit/message/create_table_message_test.rb +0 -34
- data/test/unit/message/delete_table_message_test.rb +0 -34
- data/test/unit/message/get_action_message_test.rb +0 -34
- data/test/unit/message/get_actions_message_test.rb +0 -18
- data/test/unit/message/get_properties_message_test.rb +0 -18
- data/test/unit/message/get_property_message_test.rb +0 -34
- data/test/unit/message/get_table_message_test.rb +0 -19
- data/test/unit/message/get_tables_message_test.rb +0 -18
- data/test/unit/message/lookup_message_test.rb +0 -27
- data/test/unit/message/lua_aggregate_message_test.rb +0 -19
- data/test/unit/message/multi_message_test.rb +0 -22
- data/test/unit/message/next_action_message_test.rb +0 -34
- data/test/unit/message/ping_message_test.rb +0 -18
- data/test/unit/message_test.rb +0 -15
- data/test/unit/query/after_test.rb +0 -89
- data/test/unit/query/on_test.rb +0 -71
- data/test/unit/query/selection_test.rb +0 -273
- data/test/unit/query_test.rb +0 -182
- data/test/unit/skydb_test.rb +0 -20
data/lib/skydb/event.rb
CHANGED
@@ -6,14 +6,12 @@ class SkyDB
|
|
6
6
|
#
|
7
7
|
##########################################################################
|
8
8
|
|
9
|
-
# Initializes
|
9
|
+
# Initializes the event.
|
10
10
|
def initialize(options={})
|
11
|
-
self.
|
12
|
-
self.
|
13
|
-
self.action = options[:action]
|
14
|
-
self.data = options[:data]
|
11
|
+
self.timestamp = options[:timestamp] || DateTime.now
|
12
|
+
self.data = options[:data] || {}
|
15
13
|
end
|
16
|
-
|
14
|
+
|
17
15
|
|
18
16
|
##########################################################################
|
19
17
|
#
|
@@ -21,90 +19,63 @@ class SkyDB
|
|
21
19
|
#
|
22
20
|
##########################################################################
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
##################################
|
22
|
+
# The moment the event occurred.
|
23
|
+
attr_accessor :timestamp
|
27
24
|
|
28
|
-
# The
|
29
|
-
attr_accessor :
|
30
|
-
|
31
|
-
##################################
|
32
|
-
# Timestamp
|
33
|
-
##################################
|
25
|
+
# The data associated with the event.
|
26
|
+
attr_accessor :data
|
34
27
|
|
35
|
-
# The timestamp
|
36
|
-
|
37
|
-
|
38
|
-
def timestamp=(value)
|
39
|
-
@timestamp = value.to_time if value.class.method_defined?(:to_time)
|
28
|
+
# The timestamp as ISO8601 formatted string with fractional seconds.
|
29
|
+
def formatted_timestamp()
|
30
|
+
return SkyDB.format_timestamp(timestamp)
|
40
31
|
end
|
41
32
|
|
42
|
-
##################################
|
43
|
-
# Action
|
44
|
-
##################################
|
45
33
|
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
clone = {}
|
34
|
+
##########################################################################
|
35
|
+
#
|
36
|
+
# Methods
|
37
|
+
#
|
38
|
+
##########################################################################
|
52
39
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# Only copy keys with valid value types.
|
57
|
-
if v.is_a?(String) || v.is_a?(Fixnum) || v.is_a?(Float) || v == true || v == false
|
58
|
-
clone[k] = value[k]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
40
|
+
####################################
|
41
|
+
# Encoding
|
42
|
+
####################################
|
62
43
|
|
63
|
-
|
64
|
-
|
44
|
+
# Encodes the event into a hash.
|
45
|
+
def to_hash(*a)
|
46
|
+
{
|
47
|
+
'timestamp' => formatted_timestamp,
|
48
|
+
'data' => data
|
49
|
+
}
|
65
50
|
end
|
66
51
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# a String, Fixnum, Float or Boolean.
|
73
|
-
attr_reader :data
|
74
|
-
|
75
|
-
def data=(value)
|
76
|
-
clone = {}
|
77
|
-
|
78
|
-
# Copy over keys
|
79
|
-
if !value.nil?
|
80
|
-
value.each_pair do |k, v|
|
81
|
-
# Only copy keys with valid value types.
|
82
|
-
if v.is_a?(String) || v.is_a?(Fixnum) || v.is_a?(Float) || v == true || v == false
|
83
|
-
clone[k] = value[k]
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Only set the data if we have keys.
|
89
|
-
@data = clone.keys.length > 0 ? clone : nil
|
52
|
+
# Decodes a hash into a event.
|
53
|
+
def from_hash(hash, *a)
|
54
|
+
self.timestamp = !hash.nil? ? parse_timestamp(hash['timestamp']) : Time.now.utc.to_datetime()
|
55
|
+
self.data = !hash.nil? ? hash['data'] : {}
|
56
|
+
return self
|
90
57
|
end
|
91
58
|
|
59
|
+
def as_json(*a); return to_hash(*a); end
|
60
|
+
def to_json(*a); return as_json(*a).to_json; end
|
92
61
|
|
93
|
-
|
62
|
+
####################################
|
63
|
+
# Timestamp
|
64
|
+
####################################
|
65
|
+
|
66
|
+
# Parses an ISO8601 date string with fractional seconds.
|
94
67
|
#
|
95
|
-
#
|
68
|
+
# @param [String] str The date string to parse.
|
96
69
|
#
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
obj[:data] = data unless data.nil? || data.empty?
|
107
|
-
return obj.to_msgpack
|
70
|
+
# @return [DateTime] The parsed date.
|
71
|
+
def parse_timestamp(str)
|
72
|
+
# Try to parse with fractional seconds first and then fallback to
|
73
|
+
# a regular ISO8601 format.
|
74
|
+
begin
|
75
|
+
return DateTime.strptime(str, '%Y-%m-%dT%H:%M:%S.%NZ')
|
76
|
+
rescue ArgumentError
|
77
|
+
return DateTime.strptime(str, '%Y-%m-%dT%H:%M:%SZ')
|
78
|
+
end
|
108
79
|
end
|
109
80
|
end
|
110
81
|
end
|
data/lib/skydb/property.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'skydb/property/type'
|
2
|
-
|
3
1
|
class SkyDB
|
4
2
|
class Property
|
5
3
|
##########################################################################
|
@@ -10,10 +8,10 @@ class SkyDB
|
|
10
8
|
|
11
9
|
# Initializes the property.
|
12
10
|
def initialize(options={})
|
13
|
-
self.id = options[:id]
|
14
|
-
self.type = options[:type]
|
15
|
-
self.data_type = options[:data_type]
|
11
|
+
self.id = options[:id].to_i
|
16
12
|
self.name = options[:name]
|
13
|
+
self.transient = options[:transient] || false
|
14
|
+
self.data_type = options[:data_type] || "string"
|
17
15
|
end
|
18
16
|
|
19
17
|
|
@@ -23,55 +21,17 @@ class SkyDB
|
|
23
21
|
#
|
24
22
|
##########################################################################
|
25
23
|
|
26
|
-
##################################
|
27
|
-
# ID
|
28
|
-
##################################
|
29
|
-
|
30
24
|
# The property identifier.
|
31
|
-
|
32
|
-
|
33
|
-
def id=(value)
|
34
|
-
@id = value.to_i
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
##################################
|
39
|
-
# Type
|
40
|
-
##################################
|
41
|
-
|
42
|
-
# The property type. This can be either :object or :action.
|
43
|
-
attr_reader :type
|
44
|
-
|
45
|
-
def type=(value)
|
46
|
-
value = :object unless [:object, :action].index(value)
|
47
|
-
@type = value
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
##################################
|
52
|
-
# Data Type
|
53
|
-
##################################
|
54
|
-
|
55
|
-
# The property data type. This can be either 'String', 'Int', 'Float',
|
56
|
-
# or 'Boolean'.
|
57
|
-
attr_reader :data_type
|
58
|
-
|
59
|
-
def data_type=(value)
|
60
|
-
value = nil unless ['String', 'Int', 'Float', 'Boolean'].index(value)
|
61
|
-
@data_type = value
|
62
|
-
end
|
25
|
+
attr_accessor :id
|
63
26
|
|
27
|
+
# The name of the property.
|
28
|
+
attr_accessor :name
|
64
29
|
|
65
|
-
|
66
|
-
|
67
|
-
##################################
|
30
|
+
# A flag stating if the value of the property only exists for a single moment.
|
31
|
+
attr_accessor :transient
|
68
32
|
|
69
|
-
# The
|
70
|
-
|
71
|
-
|
72
|
-
def name=(value)
|
73
|
-
@name = value.to_s
|
74
|
-
end
|
33
|
+
# The property's data type.
|
34
|
+
attr_accessor :data_type
|
75
35
|
|
76
36
|
|
77
37
|
##########################################################################
|
@@ -79,25 +39,32 @@ class SkyDB
|
|
79
39
|
# Methods
|
80
40
|
#
|
81
41
|
##########################################################################
|
82
|
-
|
83
|
-
# Encodes the property into MsgPack format.
|
84
|
-
def to_msgpack
|
85
|
-
return {
|
86
|
-
id:id,
|
87
|
-
type:SkyDB::Property::Type.encode(type),
|
88
|
-
dataType:data_type,
|
89
|
-
name:name
|
90
|
-
}.to_msgpack
|
91
|
-
end
|
92
42
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
43
|
+
####################################
|
44
|
+
# Encoding
|
45
|
+
####################################
|
46
|
+
|
47
|
+
# Encodes the property into a hash.
|
48
|
+
def to_hash(*a)
|
49
|
+
hash = {
|
50
|
+
'name' => name,
|
51
|
+
'transient' => transient,
|
98
52
|
'dataType' => data_type,
|
99
|
-
|
100
|
-
|
53
|
+
}
|
54
|
+
hash['id'] = id if id < 0 || id > 0
|
55
|
+
return hash
|
101
56
|
end
|
57
|
+
|
58
|
+
# Decodes a hash into a property.
|
59
|
+
def from_hash(hash, *a)
|
60
|
+
self.id = !hash.nil? ? hash['id'].to_i : 0
|
61
|
+
self.name = !hash.nil? ? hash['name'] : ''
|
62
|
+
self.transient = !hash.nil? ? hash['transient'] : false
|
63
|
+
self.data_type = !hash.nil? ? hash['dataType'] : ''
|
64
|
+
return self
|
65
|
+
end
|
66
|
+
|
67
|
+
def as_json(*a); return to_hash(*a); end
|
68
|
+
def to_json(*a); return as_json(*a).to_json; end
|
102
69
|
end
|
103
70
|
end
|
data/lib/skydb/table.rb
CHANGED
@@ -2,75 +2,155 @@ class SkyDB
|
|
2
2
|
class Table
|
3
3
|
##########################################################################
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# Constructor
|
6
6
|
#
|
7
7
|
##########################################################################
|
8
8
|
|
9
|
-
|
9
|
+
# Initializes the table.
|
10
|
+
def initialize(options={})
|
11
|
+
self.client = options[:client]
|
12
|
+
self.name = options[:name]
|
13
|
+
end
|
10
14
|
|
11
15
|
|
12
16
|
##########################################################################
|
13
17
|
#
|
14
|
-
#
|
18
|
+
# Attributes
|
15
19
|
#
|
16
20
|
##########################################################################
|
17
21
|
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
# The client this table is associated with.
|
23
|
+
attr_accessor :client
|
24
|
+
|
25
|
+
# The name of the table.
|
26
|
+
attr_accessor :name
|
27
|
+
|
24
28
|
|
25
29
|
##########################################################################
|
26
30
|
#
|
27
|
-
#
|
31
|
+
# Methods
|
28
32
|
#
|
29
33
|
##########################################################################
|
30
34
|
|
31
|
-
|
32
|
-
#
|
33
|
-
|
35
|
+
####################################
|
36
|
+
# Property API
|
37
|
+
####################################
|
34
38
|
|
35
|
-
#
|
36
|
-
|
37
|
-
|
38
|
-
def
|
39
|
-
|
39
|
+
# Retrieves a list of all properties for the table.
|
40
|
+
#
|
41
|
+
# @return [Array] the list of properties on the table.
|
42
|
+
def get_properties(options={})
|
43
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
44
|
+
return client.get_properties(self, options)
|
40
45
|
end
|
41
46
|
|
47
|
+
# Retrieves a single property by name from the table.
|
48
|
+
#
|
49
|
+
# @param [String] name The name of the property to retrieve.
|
50
|
+
#
|
51
|
+
# @return [Array] the list of properties on the table.
|
52
|
+
def get_property(name, options={})
|
53
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
54
|
+
return client.get_property(self, name, options)
|
55
|
+
end
|
42
56
|
|
43
|
-
|
44
|
-
#
|
45
|
-
|
57
|
+
# Creates a property on a table.
|
58
|
+
#
|
59
|
+
# @param [Property] property the property to create.
|
60
|
+
def create_property(property, options={})
|
61
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
62
|
+
return client.create_property(self, property, options)
|
63
|
+
end
|
46
64
|
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
def
|
51
|
-
|
65
|
+
# Updates a property on a table.
|
66
|
+
#
|
67
|
+
# @param [Property] property the property to update.
|
68
|
+
def update_property(property, options={})
|
69
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
70
|
+
return client.update_property(self, property, options)
|
52
71
|
end
|
53
72
|
|
73
|
+
# Deletes a property on a table.
|
74
|
+
#
|
75
|
+
# @param [Property] property the property to delete.
|
76
|
+
def delete_property(property, options={})
|
77
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
78
|
+
return client.delete_property(self, property, options)
|
79
|
+
end
|
54
80
|
|
55
|
-
|
81
|
+
|
82
|
+
####################################
|
83
|
+
# Event API
|
84
|
+
####################################
|
85
|
+
|
86
|
+
# Retrieves all events for a given object.
|
56
87
|
#
|
57
|
-
#
|
88
|
+
# @return [Array] the list of events on the table.
|
89
|
+
def get_events(object_id, options={})
|
90
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
91
|
+
return client.get_events(self, object_id, options)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Retrieves the event that occurred at a given point in time for an object.
|
58
95
|
#
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
return {
|
64
|
-
name: name,
|
65
|
-
tablet_count: tablet_count
|
66
|
-
}.to_msgpack
|
96
|
+
# @return [Event] the event.
|
97
|
+
def get_event(object_id, timestamp, options={})
|
98
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
99
|
+
return client.get_event(self, object_id, timestamp, options)
|
67
100
|
end
|
68
101
|
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
102
|
+
# Adds an event to an object.
|
103
|
+
#
|
104
|
+
# @param [String] object_id the object's identifier.
|
105
|
+
# @param [Event] event the event to add.
|
106
|
+
#
|
107
|
+
# @return [Event] the event.
|
108
|
+
def add_event(object_id, event, options={})
|
109
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
110
|
+
return client.add_event(self, object_id, event, options)
|
111
|
+
end
|
112
|
+
|
113
|
+
# Deletes an event for an object on a table.
|
114
|
+
#
|
115
|
+
# @param [String] object_id the object's identifier.
|
116
|
+
# @param [Event] event the event to delete.
|
117
|
+
def delete_event(object_id, event, options={})
|
118
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
119
|
+
return client.delete_event(self, object_id, event, options)
|
74
120
|
end
|
121
|
+
|
122
|
+
|
123
|
+
####################################
|
124
|
+
# Query API
|
125
|
+
####################################
|
126
|
+
|
127
|
+
# Runs a query against a given table.
|
128
|
+
#
|
129
|
+
# @param [Hash] q The query definition to run.
|
130
|
+
#
|
131
|
+
# @return [Results] the results of the query.
|
132
|
+
def query(q)
|
133
|
+
raise ArgumentError.new("Table not associated with client") if client.nil?
|
134
|
+
return client.query(self, q)
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
####################################
|
139
|
+
# Encoding
|
140
|
+
####################################
|
141
|
+
|
142
|
+
# Encodes the table into a hash.
|
143
|
+
def to_hash(*a)
|
144
|
+
{'name' => name}
|
145
|
+
end
|
146
|
+
|
147
|
+
# Decodes a hash into a table.
|
148
|
+
def from_hash(hash, *a)
|
149
|
+
self.name = hash.nil? ? '' : hash['name']
|
150
|
+
return self
|
151
|
+
end
|
152
|
+
|
153
|
+
def as_json(*a); return to_hash(*a); end
|
154
|
+
def to_json(*a); return as_json(*a).to_json; end
|
75
155
|
end
|
76
156
|
end
|