priam 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gem "thrift", "~> 0.7.0"
7
7
  gem "thrift_client", "~> 0.7.1"
8
8
  gem "simple_uuid", "~> 0.2.0"
9
9
  gem "cassandra", "~> 0.12.1"
10
+ gem "json", ">= 1.6.5"
10
11
 
11
12
  # Add dependencies to develop your gem here.
12
13
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -38,6 +38,7 @@ DEPENDENCIES
38
38
  bundler (>= 1.0.0)
39
39
  cassandra (~> 0.12.1)
40
40
  jeweler (~> 1.8.4)
41
+ json (>= 1.6.5)
41
42
  rcov
42
43
  rdoc (~> 3.12)
43
44
  rspec (~> 2.8.0)
data/README.rdoc CHANGED
@@ -24,6 +24,14 @@ insert value:
24
24
  [2012-12-12 10:16:46](INFO) insert into cassandra://cassandra-server:9160/TestKS/TestCF
25
25
  [2012-12-12 10:16:46](INFO) inserted 2 columns into cassandra://cassandra-server:9160/TestKS/TestCF
26
26
 
27
+ insert json:
28
+ $ cat input.txt
29
+ key1 {"d":"val2"}
30
+ key2 {"d":"val2"}
31
+ $ cat input.txt | priam insert -h cassandra-server -p 9160 --keyspace TestKS --column-family TestCF --json --verbose
32
+ [2012-12-12 10:16:46](INFO) insert into cassandra://cassandra-server:9160/TestKS/TestCF
33
+ [2012-12-12 10:16:46](INFO) inserted 2 columns into cassandra://cassandra-server:9160/TestKS/TestCF
34
+
27
35
  get record in json:
28
36
  $ cat keys.txt
29
37
  key1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -5,19 +5,20 @@ module Priam::Command
5
5
  usage: priam COMMAND [-h HOST] [-p PORT]
6
6
  [--keyspace KEYSPACE] [--column-family COLUMN_FAMILY]
7
7
  [--super-column SUPER_COLUMN] [--value-column COLUMN_NAME]
8
- [--retry COUNT] [--weight MSEC]
8
+ [--json] [--retry COUNT] [--weight MSEC]
9
9
  [--raise-exception] [--unit-size COUNT] [--verbose]
10
10
  -h HOST cassandra server address. default is localhost.
11
11
  -p PORT port number. default is 9160.
12
12
  --keyspace KEYSPACE keyspace.
13
13
  --column-family COLUMN_FAMILY column-family.
14
14
  --super-column SUPER_COLUMN super-column.
15
- --value-column COLUMN_NAME column name for each column.
16
- --retry COUNT max retry count for put/get.
17
- --weight MSEC weight time for retry.
18
- --raise-exception raise exception.
19
- --unit-size COUNT unit size for log.
20
- --verbose turn on verbose output, with all the available data.
15
+ --value-column COLUMN_NAME column name for each column. default is 'd' only in insert.
16
+ --json put column value in json format. default is off.
17
+ --retry COUNT max retry count for put/get. default is 0.
18
+ --weight MSEC weight time for retry. default is 1000.
19
+ --raise-exception raise exception. default is off.
20
+ --unit-size COUNT unit size for log. default is 10000.
21
+ --verbose turn on verbose output, with all the available data. default is off.
21
22
  EOF
22
23
  return 0
23
24
  end
@@ -13,6 +13,7 @@ module Priam::Command
13
13
  weight_second = params[:weight_second]
14
14
  retry_max_count = params[:retry_max_count]
15
15
  count_log_path = params[:count_log_path]
16
+ json_flag = params[:json_flag]
16
17
 
17
18
  keyspace = argv.shift if 0 < argv.length
18
19
  column_family = argv.shift if 0 < argv.length
@@ -72,10 +73,15 @@ module Priam::Command
72
73
  begin
73
74
  # STDERR.puts "#{retry_count} #{retry_max_count}"
74
75
  # raise "Test Error"
76
+ if json_flag
77
+ column = JSON.parse(value)
78
+ else
79
+ column = {value_column=>value}
80
+ end
75
81
  if super_column then
76
- client.insert(column_family, super_column, {key=>{value_column=>value}})
82
+ client.insert(column_family, super_column, {key=>column})
77
83
  else
78
- client.insert(column_family, key, {value_column=>value})
84
+ client.insert(column_family, key, column)
79
85
  end
80
86
  count += 1
81
87
  if count % unit_size == 0 then
@@ -7,12 +7,14 @@ module Priam::Core
7
7
 
8
8
  unit_size = 10000
9
9
  retry_max_count = 0
10
+ weight_second = 1
10
11
 
11
12
  check_exist_flag = false
12
13
  output_keys_flag = false
13
14
 
14
15
  replication_factor = 1
15
16
 
17
+ json_flag = false
16
18
  verbose_flag = false
17
19
 
18
20
  next_argv = []
@@ -50,6 +52,8 @@ module Priam::Core
50
52
  output_keys_flag = true
51
53
  when '--replication-factor'
52
54
  replication_factor = argv.shift.to_i
55
+ when '--json'
56
+ json_flag = true
53
57
  when '--verbose'
54
58
  verbose_flag = true
55
59
  else
@@ -80,6 +84,7 @@ module Priam::Core
80
84
  :check_exist_flag=>check_exist_flag,
81
85
  :output_keys_flag=>output_keys_flag,
82
86
  :replication_factor=>replication_factor,
87
+ :json_flag=>json_flag,
83
88
  :verbose_flag=>verbose_flag
84
89
  }
85
90
  end
data/priam.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "priam"
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenji Hara"]
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
63
63
  s.add_runtime_dependency(%q<thrift_client>, ["~> 0.7.1"])
64
64
  s.add_runtime_dependency(%q<simple_uuid>, ["~> 0.2.0"])
65
65
  s.add_runtime_dependency(%q<cassandra>, ["~> 0.12.1"])
66
+ s.add_runtime_dependency(%q<json>, [">= 1.6.5"])
66
67
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
67
68
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
68
69
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
@@ -73,6 +74,7 @@ Gem::Specification.new do |s|
73
74
  s.add_dependency(%q<thrift_client>, ["~> 0.7.1"])
74
75
  s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
75
76
  s.add_dependency(%q<cassandra>, ["~> 0.12.1"])
77
+ s.add_dependency(%q<json>, [">= 1.6.5"])
76
78
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
77
79
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
78
80
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -84,6 +86,7 @@ Gem::Specification.new do |s|
84
86
  s.add_dependency(%q<thrift_client>, ["~> 0.7.1"])
85
87
  s.add_dependency(%q<simple_uuid>, ["~> 0.2.0"])
86
88
  s.add_dependency(%q<cassandra>, ["~> 0.12.1"])
89
+ s.add_dependency(%q<json>, [">= 1.6.5"])
87
90
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
88
91
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
89
92
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -42,26 +42,51 @@ describe "bin/priam" do
42
42
  end
43
43
 
44
44
  context "when command = insert" do
45
- it "should insert values" do
46
- input = [
47
- ["key1", "val10"],
48
- ["key2", "val2"]
49
- ]
50
- tmpfile = Tempfile.new("bin_priam")
51
- input.each do |record|
52
- tmpfile.puts record.join("\t")
45
+ context "with json option" do
46
+ it "should insert values" do
47
+ input = [
48
+ ["key3", {"data"=>"val3"}.to_json],
49
+ ["key4", {"data"=>"val4"}.to_json]
50
+ ]
51
+ tmpfile = Tempfile.new("bin_priam")
52
+ input.each do |record|
53
+ tmpfile.puts record.join("\t")
54
+ end
55
+ tmpfile.close
56
+ `cat #{tmpfile.path} | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam insert --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --json --verbose #{@stderr_dst}`
57
+ tmpfile.unlink
58
+
59
+ result = `echo key3 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --value-column data 2> /dev/null`
60
+ result.chomp!
61
+ result.should == "val3"
62
+
63
+ result = `echo key4 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --value-column data 2> /dev/null`
64
+ result.chomp!
65
+ result.should == "val4"
66
+ end
67
+ end
68
+ context "without json option" do
69
+ it "should insert values" do
70
+ input = [
71
+ ["key1", "val10"],
72
+ ["key2", "val2"]
73
+ ]
74
+ tmpfile = Tempfile.new("bin_priam")
75
+ input.each do |record|
76
+ tmpfile.puts record.join("\t")
77
+ end
78
+ tmpfile.close
79
+ `cat #{tmpfile.path} | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam insert --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --verbose #{@stderr_dst}`
80
+ tmpfile.unlink
81
+
82
+ result = `echo key1 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d 2> /dev/null`
83
+ result.chomp!
84
+ result.should == "val10"
85
+
86
+ result = `echo key2 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d 2> /dev/null`
87
+ result.chomp!
88
+ result.should == "val2"
53
89
  end
54
- tmpfile.close
55
- `cat #{tmpfile.path} | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam insert --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --verbose #{@stderr_dst}`
56
- tmpfile.unlink
57
-
58
- result = `echo key1 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d 2> /dev/null`
59
- result.chomp!
60
- result.should == "val10"
61
-
62
- result = `echo key2 | #{Priam::RUBY_CMD} -I #{Priam::LIB_DIR} #{Priam::BIN_DIR}/priam get --keyspace PriamTest --column-family PriamCF -h #{@hostname} -p 9160 --name d 2> /dev/null`
63
- result.chomp!
64
- result.should == "val2"
65
90
  end
66
91
  end
67
92
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: priam
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kenji Hara
@@ -81,11 +81,27 @@ dependencies:
81
81
  - 1
82
82
  version: 0.12.1
83
83
  version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: json
86
+ prerelease: false
87
+ type: :runtime
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 5
94
+ segments:
95
+ - 1
96
+ - 6
97
+ - 5
98
+ version: 1.6.5
99
+ version_requirements: *id005
84
100
  - !ruby/object:Gem::Dependency
85
101
  name: rspec
86
102
  prerelease: false
87
103
  type: :development
88
- requirement: &id005 !ruby/object:Gem::Requirement
104
+ requirement: &id006 !ruby/object:Gem::Requirement
89
105
  none: false
90
106
  requirements:
91
107
  - - ~>
@@ -96,12 +112,12 @@ dependencies:
96
112
  - 8
97
113
  - 0
98
114
  version: 2.8.0
99
- version_requirements: *id005
115
+ version_requirements: *id006
100
116
  - !ruby/object:Gem::Dependency
101
117
  name: rdoc
102
118
  prerelease: false
103
119
  type: :development
104
- requirement: &id006 !ruby/object:Gem::Requirement
120
+ requirement: &id007 !ruby/object:Gem::Requirement
105
121
  none: false
106
122
  requirements:
107
123
  - - ~>
@@ -111,12 +127,12 @@ dependencies:
111
127
  - 3
112
128
  - 12
113
129
  version: "3.12"
114
- version_requirements: *id006
130
+ version_requirements: *id007
115
131
  - !ruby/object:Gem::Dependency
116
132
  name: bundler
117
133
  prerelease: false
118
134
  type: :development
119
- requirement: &id007 !ruby/object:Gem::Requirement
135
+ requirement: &id008 !ruby/object:Gem::Requirement
120
136
  none: false
121
137
  requirements:
122
138
  - - ">="
@@ -127,12 +143,12 @@ dependencies:
127
143
  - 0
128
144
  - 0
129
145
  version: 1.0.0
130
- version_requirements: *id007
146
+ version_requirements: *id008
131
147
  - !ruby/object:Gem::Dependency
132
148
  name: jeweler
133
149
  prerelease: false
134
150
  type: :development
135
- requirement: &id008 !ruby/object:Gem::Requirement
151
+ requirement: &id009 !ruby/object:Gem::Requirement
136
152
  none: false
137
153
  requirements:
138
154
  - - ~>
@@ -143,12 +159,12 @@ dependencies:
143
159
  - 8
144
160
  - 4
145
161
  version: 1.8.4
146
- version_requirements: *id008
162
+ version_requirements: *id009
147
163
  - !ruby/object:Gem::Dependency
148
164
  name: rcov
149
165
  prerelease: false
150
166
  type: :development
151
- requirement: &id009 !ruby/object:Gem::Requirement
167
+ requirement: &id010 !ruby/object:Gem::Requirement
152
168
  none: false
153
169
  requirements:
154
170
  - - ">="
@@ -157,7 +173,7 @@ dependencies:
157
173
  segments:
158
174
  - 0
159
175
  version: "0"
160
- version_requirements: *id009
176
+ version_requirements: *id010
161
177
  description: Command-base client for Cassandra.
162
178
  email: haracane@gmail.com
163
179
  executables: