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,34 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageDeleteTable < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::DeleteTable.new()
7
- end
8
-
9
- ######################################
10
- # Action
11
- ######################################
12
-
13
- def test_table
14
- @message.table = SkyDB::Table.new('foo')
15
- refute_nil @message.table
16
- end
17
-
18
- def test_invalid_table
19
- @message.table = "foo"
20
- assert_nil @message.table
21
- end
22
-
23
-
24
- ######################################
25
- # Encoding
26
- ######################################
27
-
28
- def test_encode
29
- buffer = StringIO.new
30
- @message.table = SkyDB::Table.new("foo")
31
- @message.encode(buffer)
32
- assert_bytes "\x93\x01\xacdelete_table\xa0\x81\xa4name\xa3foo", buffer
33
- end
34
- end
@@ -1,34 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetAction < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetAction.new()
7
- end
8
-
9
- ######################################
10
- # Action
11
- ######################################
12
-
13
- def test_action_id
14
- @message.action_id = 12
15
- assert_equal 12, @message.action_id
16
- end
17
-
18
- def test_invalid_action_id
19
- @message.action_id = "foo"
20
- assert_equal 0, @message.action_id
21
- end
22
-
23
-
24
- ######################################
25
- # Encoding
26
- ######################################
27
-
28
- def test_encode
29
- buffer = StringIO.new
30
- @message.action_id = 10
31
- @message.encode(buffer)
32
- assert_bytes "\x93\x01\xaaget_action\xa0\x0a", buffer
33
- end
34
- end
@@ -1,18 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetActions < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetActions.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.encode(buffer)
16
- assert_bytes "\x93\x01\xabget_actions\xa0", buffer
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetProperties < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetProperties.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.encode(buffer)
16
- assert_bytes "\x93\x01\xaeget_properties\xa0", buffer
17
- end
18
- end
@@ -1,34 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetProperty < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetProperty.new()
7
- end
8
-
9
- ######################################
10
- # Property ID
11
- ######################################
12
-
13
- def test_property_id
14
- @message.property_id = 12
15
- assert_equal 12, @message.property_id
16
- end
17
-
18
- def test_invalid_property_id
19
- @message.property_id = "foo"
20
- assert_equal 0, @message.property_id
21
- end
22
-
23
-
24
- ######################################
25
- # Encoding
26
- ######################################
27
-
28
- def test_encode
29
- buffer = StringIO.new
30
- @message.property_id = 10
31
- @message.encode(buffer)
32
- assert_bytes "\x93\x01\xacget_property\xa0\x0a", buffer
33
- end
34
- end
@@ -1,19 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetTable < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetTable.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.name = "foo"
16
- @message.encode(buffer)
17
- assert_bytes "\x93\x01\xa9get_table\xa0\x81\xa4name\xa3foo", buffer
18
- end
19
- end
@@ -1,18 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageGetTables < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::GetTables.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.encode(buffer)
16
- assert_bytes "\x93\x01\xaaget_tables\xa0", buffer
17
- end
18
- end
@@ -1,27 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageLookup < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::Lookup.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.actions = [
16
- SkyDB::Action.new(:name => 'foo'),
17
- SkyDB::Action.new(:name => 'bar'),
18
- ]
19
- @message.properties = [
20
- SkyDB::Property.new(:name => 'xxx'),
21
- SkyDB::Property.new(:name => 'yyy'),
22
- SkyDB::Property.new(:name => 'zzz'),
23
- ]
24
- @message.encode(buffer)
25
- assert_bytes "\x93\x01\xa6lookup\xa0\x82\xabactionNames\x92\xa3foo\xa3bar\xadpropertyNames\x93\xa3xxx\xa3yyy\xa3zzz", buffer
26
- end
27
- end
@@ -1,19 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageLuaAggregate < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::Lua::Aggregate.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.source = "function aggregate(cursor, data) return {} end"
16
- @message.encode(buffer)
17
- assert_bytes "\x93\x01\xaelua::aggregate\xa0\x81\xa6source\xda\x00\x2e" + "function aggregate(cursor, data) return {} end", buffer
18
- end
19
- end
@@ -1,22 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageMulti < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::Multi.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.messages = [
16
- SkyDB::Message::GetProperty.new(12),
17
- SkyDB::Message::GetAction.new(200)
18
- ]
19
- @message.encode(buffer)
20
- assert_bytes "\x93\x01\xa5multi\xa0\x81\xa5count\x02" + "\x93\x01\xacget_property\xa0\x0c" + "\x93\x01\xaaget_action\xa0\xcc\xc8", buffer
21
- end
22
- end
@@ -1,34 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessageNextActions < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::NextActions.new()
7
- end
8
-
9
- ######################################
10
- # Object ID
11
- ######################################
12
-
13
- def test_prior_action_ids
14
- @message.prior_action_ids = [1, 2, 3]
15
- assert_equal [1, 2, 3], @message.prior_action_ids
16
- end
17
-
18
- def test_invalid_prior_action_ids
19
- @message.prior_action_ids = 12
20
- assert_equal [], @message.prior_action_ids
21
- end
22
-
23
-
24
- ######################################
25
- # Encoding
26
- ######################################
27
-
28
- def test_encode
29
- buffer = StringIO.new
30
- @message.prior_action_ids = [1, 2]
31
- @message.encode(buffer)
32
- assert_bytes "\x93\x01\xacnext_actions\xa0\x92\x01\x02", buffer
33
- end
34
- end
@@ -1,18 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessagePing < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message::Ping.new()
7
- end
8
-
9
- ######################################
10
- # Encoding
11
- ######################################
12
-
13
- def test_encode
14
- buffer = StringIO.new
15
- @message.encode(buffer)
16
- assert_bytes "\x93\x01\xa4ping\xa0", buffer
17
- end
18
- end
@@ -1,15 +0,0 @@
1
- # encoding: binary
2
- require 'test_helper'
3
-
4
- class TestMessage < MiniTest::Unit::TestCase
5
- def setup
6
- @message = SkyDB::Message.new('xyz')
7
- end
8
-
9
- def test_encode
10
- buffer = StringIO.new
11
- @message.table_name = "users"
12
- @message.encode(buffer)
13
- assert_bytes "\x93\x01\xa3xyz\xa5users", buffer
14
- end
15
- end
@@ -1,89 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestQueryAfterCondition < MiniTest::Unit::TestCase
4
- ##############################################################################
5
- #
6
- # Setup / Teardown
7
- #
8
- ##############################################################################
9
-
10
- def setup
11
- @after = SkyDB::Query::AfterCondition.new()
12
- end
13
-
14
-
15
- ##############################################################################
16
- #
17
- # Tests
18
- #
19
- ##############################################################################
20
-
21
- ######################################
22
- # Validation
23
- ######################################
24
-
25
- def test_validate_action
26
- e = assert_raises(SkyDB::Query::ValidationError) do
27
- SkyDB::Query::AfterCondition.new(:function_name => "foo").validate!
28
- end
29
- assert_match /^Action with non-zero identifier required/, e.message
30
- end
31
-
32
- def test_validate_enter_action
33
- e = assert_raises(SkyDB::Query::ValidationError) do
34
- SkyDB::Query::AfterCondition.new(:action => :enter, :function_name => "foo").validate!
35
- end
36
- assert_equal "Enter actions cannot be used with an 'after' condition. Please use an 'on' condition instead.", e.message
37
- end
38
-
39
- def test_validate_function_name
40
- e = assert_raises(SkyDB::Query::ValidationError) do
41
- SkyDB::Query::AfterCondition.new(:action => 10).validate!
42
- end
43
- assert_match /^Invalid function name ''/, e.message
44
- end
45
-
46
-
47
- ######################################
48
- # Code Generation
49
- ######################################
50
-
51
- def test_codegen
52
- @after = SkyDB::Query::AfterCondition.new(:action => 10, :function_name => "foo")
53
- expected =
54
- <<-BLOCK.unindent
55
- function foo(cursor, data)
56
- if cursor:eos() or cursor:eof() then return false end
57
- repeat
58
- if cursor.event.action_id == 10 then
59
- cursor:next()
60
- return true
61
- end
62
- until not cursor:next()
63
- return false
64
- end
65
- BLOCK
66
- assert_equal expected, @after.codegen()
67
- end
68
-
69
- def test_codegen_within_1_step
70
- @after = SkyDB::Query::AfterCondition.new(:action => 10, :within => {:quantity => 1, :unit => 'step'}, :function_name => "foo")
71
- expected =
72
- <<-BLOCK.unindent
73
- function foo(cursor, data)
74
- if cursor:eos() or cursor:eof() then return false end
75
- remaining = 1
76
- repeat
77
- if remaining <= 0 then return false end
78
- if cursor.event.action_id == 10 then
79
- cursor:next()
80
- return true
81
- end
82
- remaining = remaining - 1
83
- until not cursor:next()
84
- return false
85
- end
86
- BLOCK
87
- assert_equal expected, @after.codegen()
88
- end
89
- end
@@ -1,71 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestQueryOnCondition < MiniTest::Unit::TestCase
4
- ##############################################################################
5
- #
6
- # Setup / Teardown
7
- #
8
- ##############################################################################
9
-
10
- def setup
11
- @condition = SkyDB::Query::OnCondition.new()
12
- end
13
-
14
-
15
- ##############################################################################
16
- #
17
- # Tests
18
- #
19
- ##############################################################################
20
-
21
- ######################################
22
- # Validation
23
- ######################################
24
-
25
- def test_validate_action
26
- e = assert_raises(SkyDB::Query::ValidationError) do
27
- SkyDB::Query::OnCondition.new(:function_name => "foo").validate!
28
- end
29
- assert_match /^Action with non-zero identifier required/, e.message
30
- end
31
-
32
- def test_validate_function_name
33
- e = assert_raises(SkyDB::Query::ValidationError) do
34
- SkyDB::Query::OnCondition.new(:action => 10).validate!
35
- end
36
- assert_match /^Invalid function name ''/, e.message
37
- end
38
-
39
-
40
- ######################################
41
- # Code Generation
42
- ######################################
43
-
44
- def test_codegen
45
- @condition = SkyDB::Query::OnCondition.new(:action => 10, :function_name => "foo")
46
- expected =
47
- <<-BLOCK.unindent
48
- function foo(cursor, data)
49
- if cursor:eos() or cursor:eof() then return false end
50
- repeat
51
- if cursor.event.action_id == 10 then
52
- return true
53
- end
54
- until not cursor:next()
55
- return false
56
- end
57
- BLOCK
58
- assert_equal expected, @condition.codegen()
59
- end
60
-
61
- def test_codegen_enter
62
- @condition = SkyDB::Query::OnCondition.new(:action => :enter, :function_name => "foo")
63
- expected =
64
- <<-BLOCK.unindent
65
- function foo(cursor, data)
66
- return (cursor.session_event_index == 0)
67
- end
68
- BLOCK
69
- assert_equal expected, @condition.codegen()
70
- end
71
- end