Skip to content
Permalink
Browse files
Updated Ruby client code and documentation (#15)
  • Loading branch information
mikewalch committed Dec 20, 2019
1 parent 099e686 commit 32e2c09a3c00442c6ea9afd181d36934bc308e2c
Showing 7 changed files with 108 additions and 1 deletion.
@@ -54,7 +54,7 @@ thrift -r --gen <language> <Thrift filename>

# Create an Accumulo client using Python

Run the commands below to install the Python bindings and create an example client:
Run the commands below to install the Python bindings and create an example Python client:

```bash
mkdir accumulo-client/
@@ -68,6 +68,21 @@ vim example.py
pipenv run python2 example.py
```

# Create an Accumulo client using Ruby

Run the command below to create an example Ruby client:

```bash
mkdir accumulo-client/
cd accumulo-client/
cp /path/to/accumulo-proxy/src/main/ruby/Gemfile .
vim Gemfile # Set correct path
cp /path/to/accumulo-proxy/src/main/ruby/client.rb .
gem install bundler
bundle install
bundle exec client.rb
```

[accumulo]: https://accumulo.apache.org
[Thrift]: https://thrift.apache.org
[Thrift tutorial]: https://thrift.apache.org/tutorial/
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ruby '>2.5'
source "https://rubygems.org"
gem 'thrift', '0.11.0.0'
gem 'accumulo', :path => "/path/to/accumulo-proxy/src/main/ruby/accumulo"
@@ -0,0 +1,27 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Gem::Specification.new do |s|
s.name = 'accumulo'
s.version = '1.0.0'
s.date = '2019-12-18'
s.summary = "Accumulo Client library using Proxy"
s.description = "Code that lets you communicate with Accumulo using the Proxy"
s.authors = ["Apache Accumulo committers"]
s.email = 'user@accumulo.apache.org'
s.files = ["lib/accumulo_proxy.rb", "lib/proxy_types.rb", "lib/proxy_constants.rb"]
s.homepage = 'https://github.com/apache/accumulo-proxy'
s.license = 'Apache-2.0'
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,47 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/env ruby

require 'rubygems'
require 'thrift'
require 'accumulo_proxy'

server = ARGV[0] || 'localhost'

socket = Thrift::Socket.new(server, 42424, 9001)
transport = Thrift::FramedTransport.new(socket)
proto = Thrift::CompactProtocol.new(transport)
proxy = Accumulo::AccumuloProxy::Client.new(proto)

# open up the connect
transport.open()

# Test if the server is up
login = proxy.login('root', {'password' => 'secret'})

# print out a table list
puts "List of tables: #{proxy.listTables(login).inspect}"

testtable = "rubytest"
proxy.createTable(login, testtable, true, Accumulo::TimeType::MILLIS) unless proxy.tableExists(login,testtable)

update1 = Accumulo::ColumnUpdate.new({'colFamily' => "cf1", 'colQualifier' => "cq1", 'value'=> "a"})
update2 = Accumulo::ColumnUpdate.new({'colFamily' => "cf2", 'colQualifier' => "cq2", 'value'=> "b"})
proxy.updateAndFlush(login,testtable,{'row1' => [update1,update2]})

cookie = proxy.createScanner(login,testtable,nil)
result = proxy.nextK(cookie,10)
result.results.each{ |keyvalue| puts "Key: #{keyvalue.key.inspect} Value: #{keyvalue.value}" }

0 comments on commit 32e2c09

Please sign in to comment.