gotime-cassandra_object 4.7.2 → 4.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gotime-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/schema.rb +16 -3
- data/lib/cassandra_object/types/float_type.rb +0 -1
- data/lib/cassandra_object/types/integer_type.rb +0 -1
- data/lib/cassandra_object/types/time_type.rb +1 -2
- data/test/support/connect.rb +3 -1
- data/test/unit/schema_test.rb +34 -0
- data/test/unit/types/float_type_test.rb +1 -4
- data/test/unit/types/integer_type_test.rb +1 -0
- data/test/unit/types/time_type_test.rb +6 -0
- metadata +2 -2
@@ -31,12 +31,25 @@ module CassandraObject
|
|
31
31
|
execute statement_with_options(stmt, options)
|
32
32
|
end
|
33
33
|
|
34
|
-
def alter_column_family(column_family, options)
|
35
|
-
stmt = "ALTER TABLE #{column_family}"
|
34
|
+
def alter_column_family(column_family, instruction, options = {})
|
35
|
+
stmt = "ALTER TABLE #{column_family} #{instruction}"
|
36
36
|
execute statement_with_options(stmt, options)
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
39
|
+
def drop_column_family(column_family)
|
40
|
+
stmt = "DROP TABLE #{column_family}"
|
41
|
+
execute stmt
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_index(column_family, column, index_name = nil)
|
45
|
+
stmt = "CREATE INDEX #{index_name.nil? ? '' : index_name} ON #{column_family} (#{column})"
|
46
|
+
execute stmt
|
47
|
+
end
|
48
|
+
|
49
|
+
def drop_index(index_name)
|
50
|
+
# If the index was not given a name during creation, the index name is <columnfamily_name>_<column_name>_idx.
|
51
|
+
stmt = "DROP INDEX #{index_name}"
|
52
|
+
execute stmt
|
40
53
|
end
|
41
54
|
|
42
55
|
private
|
@@ -15,8 +15,7 @@ module CassandraObject
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def decode(str)
|
18
|
-
return nil
|
19
|
-
raise ArgumentError.new("Cannot convert #{str} into a Time") unless str.kind_of?(String) && str.match(TimeType::REGEX)
|
18
|
+
return nil unless str && str.match(TimeType::REGEX)
|
20
19
|
Time.xmlschema(str).in_time_zone
|
21
20
|
end
|
22
21
|
end
|
data/test/support/connect.rb
CHANGED
data/test/unit/schema_test.rb
CHANGED
@@ -10,4 +10,38 @@ class CassandraObject::SchemaTest < CassandraObject::TestCase
|
|
10
10
|
rescue Exception => e
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
test "drop_column_family" do
|
15
|
+
CassandraObject::Schema.create_column_family 'TestCFToDrop'
|
16
|
+
|
17
|
+
CassandraObject::Schema.drop_column_family 'TestCFToDrop'
|
18
|
+
|
19
|
+
begin
|
20
|
+
CassandraObject::Schema.drop_column_family 'TestCFToDrop'
|
21
|
+
assert false, 'TestCFToDrop should not exist'
|
22
|
+
rescue Exception => e
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
test "create_index" do
|
27
|
+
CassandraObject::Schema.create_column_family 'TestIndexed'
|
28
|
+
|
29
|
+
CassandraObject::Schema.alter_column_family 'TestIndexed', "ADD id_value varchar"
|
30
|
+
|
31
|
+
CassandraObject::Schema.add_index 'TestIndexed', 'id_value'
|
32
|
+
end
|
33
|
+
|
34
|
+
test "drop_index" do
|
35
|
+
CassandraObject::Schema.create_column_family 'TestDropIndexes'
|
36
|
+
|
37
|
+
CassandraObject::Schema.alter_column_family 'TestDropIndexes', "ADD id_value1 varchar"
|
38
|
+
CassandraObject::Schema.alter_column_family 'TestDropIndexes', "ADD id_value2 varchar"
|
39
|
+
|
40
|
+
CassandraObject::Schema.add_index 'TestDropIndexes', 'id_value1'
|
41
|
+
CassandraObject::Schema.add_index 'TestDropIndexes', 'id_value2', 'special_name'
|
42
|
+
|
43
|
+
CassandraObject::Schema.drop_index 'TestDropIndexes_id_value1_idx'
|
44
|
+
CassandraObject::Schema.drop_index 'special_name'
|
45
|
+
end
|
46
|
+
|
13
47
|
end
|
@@ -10,11 +10,8 @@ class CassandraObject::Types::FloatTypeTest < CassandraObject::Types::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'decode' do
|
13
|
+
assert_equal 0.0, coder.decode('xyz')
|
13
14
|
assert_equal 3.14, coder.decode('3.14')
|
14
15
|
assert_equal 5, coder.decode('5')
|
15
|
-
|
16
|
-
assert_raise ArgumentError do
|
17
|
-
coder.decode('xyz')
|
18
|
-
end
|
19
16
|
end
|
20
17
|
end
|
@@ -4,4 +4,10 @@ class CassandraObject::Types::TimeTypeTest < CassandraObject::Types::TestCase
|
|
4
4
|
test 'encode' do
|
5
5
|
assert_equal '2004-12-24T01:02:03.000000Z', coder.encode(Time.utc(2004, 12, 24, 1, 2, 3))
|
6
6
|
end
|
7
|
+
|
8
|
+
test 'decode' do
|
9
|
+
assert_nil coder.decode(nil)
|
10
|
+
assert_nil coder.decode('bad format')
|
11
|
+
assert_equal Time.utc(2004, 12, 24, 1, 2, 3), coder.decode('2004-12-24T01:02:03.000000Z')
|
12
|
+
end
|
7
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotime-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.7.
|
4
|
+
version: 4.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|