hbase-adapter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +202 -0
- data/README.textile +52 -0
- data/lib/core_ext/time_ext.rb +5 -0
- data/lib/hbase-adapter.rb +18 -0
- data/lib/hbase_adapter/cell.rb +24 -0
- data/lib/hbase_adapter/column_family.rb +35 -0
- data/lib/hbase_adapter/connection.rb +52 -0
- data/lib/hbase_adapter/mutation.rb +85 -0
- data/lib/hbase_adapter/row.rb +88 -0
- data/lib/hbase_adapter/table.rb +74 -0
- metadata +122 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2010 Andrew O'Brien
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.textile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
h1. HBase Adapter
|
2
|
+
|
3
|
+
Wrapping up all of that HBase Thrift stuff so you can use it.
|
4
|
+
|
5
|
+
h2. Dependencies
|
6
|
+
|
7
|
+
Install HBase and Thrift normally (for some definition of "normally" for your platform). This code was developed against HBase 0.20.5
|
8
|
+
|
9
|
+
gem install hbase-thrift
|
10
|
+
|
11
|
+
h2. Alpha
|
12
|
+
|
13
|
+
This is very alpha and may not be production ready. Contributions are welcome though.
|
14
|
+
|
15
|
+
h2. TODO
|
16
|
+
|
17
|
+
h3. Thrift
|
18
|
+
|
19
|
+
All Thrift structures and services (even redundant ones) are represented as more idiomatic Ruby classes and methods except the following:
|
20
|
+
|
21
|
+
Thrift data structures:
|
22
|
+
|
23
|
+
* Some of the attributes on ColumnDescriptor
|
24
|
+
* TRegionInfo: probably just going to wrap in something with Ruby style attribute names.
|
25
|
+
|
26
|
+
Thrift service methods:
|
27
|
+
|
28
|
+
* atomicIncrement (spec'd & implemented, but there's a Java error)
|
29
|
+
* scannerOpen
|
30
|
+
* scannerOpenWithStop
|
31
|
+
* scannerOpenWithPrefix
|
32
|
+
* scannerOpenTs
|
33
|
+
* scannerOpenWithStopTs
|
34
|
+
* scannerGet
|
35
|
+
* scannerGetList
|
36
|
+
* scannerClose
|
37
|
+
|
38
|
+
h3. Documentation
|
39
|
+
|
40
|
+
Some documentation would be good...
|
41
|
+
|
42
|
+
h3. Other
|
43
|
+
|
44
|
+
A lot of the code could be DRYer. Also, I'd like to make it so we don't have to keep dropping and creating tables in tests.
|
45
|
+
|
46
|
+
h2. Contributing
|
47
|
+
|
48
|
+
Fork the repository at http://github.com/AndrewO/hbase-adapter and send me a pull request.
|
49
|
+
|
50
|
+
Happy hacking.
|
51
|
+
|
52
|
+
–Andrew O'Brien
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hbase-thrift'
|
5
|
+
|
6
|
+
module HbaseAdapter
|
7
|
+
IOError = Apache::Hadoop::Hbase::Thrift::IOError
|
8
|
+
IllegalArgument = Apache::Hadoop::Hbase::Thrift::IllegalArgument
|
9
|
+
TableAlreadyExists = Apache::Hadoop::Hbase::Thrift::AlreadyExists
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'core_ext/time_ext'
|
13
|
+
|
14
|
+
require 'hbase_adapter/connection'
|
15
|
+
require 'hbase_adapter/table'
|
16
|
+
require 'hbase_adapter/column_family'
|
17
|
+
require 'hbase_adapter/row'
|
18
|
+
require 'hbase_adapter/mutation'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module HbaseAdapter
|
2
|
+
class Cell
|
3
|
+
attr_reader :connection, :row, :col_name, :cell
|
4
|
+
|
5
|
+
def initialize(connection, row, col_name, cell)
|
6
|
+
@connection, @row, @col_name, @cell = connection, row, col_name.to_sym, cell
|
7
|
+
end
|
8
|
+
|
9
|
+
def timestamp
|
10
|
+
cell.timestamp
|
11
|
+
end
|
12
|
+
|
13
|
+
def value
|
14
|
+
cell.value
|
15
|
+
end
|
16
|
+
|
17
|
+
# Causes HBase to freak out with an ArrayIndexOutOfBoundsException. Have no idea if it's my fault, but ignoring for now
|
18
|
+
# def incr!(incr_val = 1)
|
19
|
+
# connection.client.atomicIncrement(row.table.name.to_s, row.key.to_s, col_name.to_s, incr_val)
|
20
|
+
# end
|
21
|
+
|
22
|
+
# TODO: easy version access
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module HbaseAdapter
|
2
|
+
class ColumnFamily
|
3
|
+
KEY_MAP = {
|
4
|
+
:name => :name,
|
5
|
+
:max_versions => :maxVersions
|
6
|
+
}
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def translate_hash(hash)
|
10
|
+
Hash[*(hash.map {|(k,v)| [KEY_MAP[k.to_sym], v]}.flatten)]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :column_descriptor
|
15
|
+
def initialize(args = {})
|
16
|
+
@column_descriptor = case args
|
17
|
+
when Apache::Hadoop::Hbase::Thrift::ColumnDescriptor
|
18
|
+
args
|
19
|
+
when Hash
|
20
|
+
Apache::Hadoop::Hbase::Thrift::ColumnDescriptor.new(self.class.translate_hash(args))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def name
|
25
|
+
column_descriptor.name
|
26
|
+
end
|
27
|
+
|
28
|
+
def max_versions
|
29
|
+
column_descriptor.maxVersions
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: support other keys
|
33
|
+
# TODO: use delegator
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'hbase_adapter/table'
|
2
|
+
|
3
|
+
module HbaseAdapter
|
4
|
+
class Connection
|
5
|
+
attr_reader :host, :port
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@host = options[:host] || options["host"]
|
9
|
+
@port = options[:port] || options["port"]
|
10
|
+
|
11
|
+
@client = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def connected?
|
15
|
+
@client
|
16
|
+
end
|
17
|
+
|
18
|
+
def client
|
19
|
+
connect! unless connected?
|
20
|
+
@client
|
21
|
+
end
|
22
|
+
|
23
|
+
def connect!
|
24
|
+
t = Thrift::BufferedTransport.new(Thrift::Socket.new(host, port))
|
25
|
+
p = Thrift::BinaryProtocol.new(t)
|
26
|
+
c = Apache::Hadoop::Hbase::Thrift::Hbase::Client.new(p)
|
27
|
+
t.open
|
28
|
+
|
29
|
+
@client = c
|
30
|
+
end
|
31
|
+
|
32
|
+
def table_names
|
33
|
+
client.getTableNames
|
34
|
+
end
|
35
|
+
|
36
|
+
def tables
|
37
|
+
table_names.inject({}) do|hash, table_name|
|
38
|
+
hash[table_name.to_sym] = HbaseAdapter::Table.new(client, table_name)
|
39
|
+
hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_table!(table_name, *column_families)
|
44
|
+
client.createTable(table_name.to_s, column_families.map {|cd| cd.column_descriptor})
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete_table!(table_name)
|
48
|
+
client.disableTable(table_name.to_s)
|
49
|
+
client.deleteTable(table_name.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module HbaseAdapter
|
2
|
+
class Mutation
|
3
|
+
attr_reader :column, :value
|
4
|
+
|
5
|
+
def initialize(column)
|
6
|
+
@column = column
|
7
|
+
@value = nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def is_delete?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_thrift
|
15
|
+
Apache::Hadoop::Hbase::Thrift::Mutation.new(
|
16
|
+
:isDelete => is_delete?,
|
17
|
+
:column => column,
|
18
|
+
:value => value
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class UpdateMutation < Mutation
|
24
|
+
def initialize(column, value)
|
25
|
+
super(column)
|
26
|
+
@value = value
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class DeleteMutation < Mutation
|
31
|
+
def is_delete?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class MutationList
|
37
|
+
def initialize(&blk)
|
38
|
+
@mutations = []
|
39
|
+
|
40
|
+
self.instance_eval(&blk)
|
41
|
+
end
|
42
|
+
|
43
|
+
def batch_mutation(key, &blk)
|
44
|
+
@mutations << BatchMutation.new(key, &blk)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update(column, value)
|
48
|
+
@mutations << UpdateMutation.new(column, value)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete(column)
|
52
|
+
@mutations << DeleteMutation.new(column)
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_thrift
|
56
|
+
@mutations.map {|m| m.to_thrift}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class BatchMutation
|
61
|
+
attr_reader :key, :mutations
|
62
|
+
|
63
|
+
def initialize(key, &blk)
|
64
|
+
@key = key
|
65
|
+
@mutations = []
|
66
|
+
|
67
|
+
self.instance_eval(&blk)
|
68
|
+
end
|
69
|
+
|
70
|
+
def update(column, value)
|
71
|
+
@mutations << UpdateMutation.new(column, value)
|
72
|
+
end
|
73
|
+
|
74
|
+
def delete(column)
|
75
|
+
@mutations << DeleteMutation.new(column)
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_thrift
|
79
|
+
Apache::Hadoop::Hbase::Thrift::BatchMutation.new(
|
80
|
+
:row => key,
|
81
|
+
:mutations => mutations.map {|m| m.to_thrift}
|
82
|
+
)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'hbase_adapter/cell'
|
2
|
+
require 'hbase_adapter/mutation'
|
3
|
+
|
4
|
+
module HbaseAdapter
|
5
|
+
class Row
|
6
|
+
attr_reader :connection, :table, :key
|
7
|
+
|
8
|
+
def initialize(connection, table, key)
|
9
|
+
@connection = connection
|
10
|
+
@table = table
|
11
|
+
@key = key
|
12
|
+
end
|
13
|
+
|
14
|
+
def [](column, options = {})
|
15
|
+
num_versions = options[:num_versions]
|
16
|
+
timestamp = options[:timestamp]
|
17
|
+
|
18
|
+
if num_versions.nil? && timestamp.nil?
|
19
|
+
# One column, no options. Simple get. Return a single cell
|
20
|
+
tcell = connection.client.get(table.name, key, column).first
|
21
|
+
HbaseAdapter::Cell.new(connection, self, column, tcell) if tcell
|
22
|
+
else
|
23
|
+
if timestamp.nil?
|
24
|
+
# One column, versions specified. getVer
|
25
|
+
tcells = connection.client.getVer(table.name, key, column, num_versions)
|
26
|
+
else
|
27
|
+
# One column, versions specified, max time specified. getVerTs
|
28
|
+
tcells = connection.client.getVerTs(table.name, key, column, timestamp.to_i64, num_versions)
|
29
|
+
end
|
30
|
+
|
31
|
+
tcells.compact.map {|tcell| HbaseAdapter::Cell.new(connection, self, column, tcell)}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def cells(*columns)
|
36
|
+
options = columns.pop if columns.last.is_a?(Hash)
|
37
|
+
options ||= {}
|
38
|
+
timestamp = options[:timestamp]
|
39
|
+
|
40
|
+
if columns.empty?
|
41
|
+
if timestamp.nil?
|
42
|
+
# getRow
|
43
|
+
trow_results = connection.client.getRow(table.name, key)
|
44
|
+
else
|
45
|
+
# getRowTs
|
46
|
+
trow_results = connection.client.getRowTs(table.name, key, timestamp.to_i64)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
if timestamp.nil?
|
50
|
+
# getRowWithColumns
|
51
|
+
trow_results = connection.client.getRowWithColumns(table.name, key, columns)
|
52
|
+
else
|
53
|
+
# getRowWithColumnsTs
|
54
|
+
trow_results = connection.client.getRowWithColumnsTs(table.name, key, columns, timestamp.to_i64)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
unless trow_results.empty?
|
59
|
+
trow_results.first.columns.inject({}) do |hash, (col_name, tcell)|
|
60
|
+
hash[col_name.to_sym] = HbaseAdapter::Cell.new(connection, self, col_name, tcell) if tcell
|
61
|
+
hash
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete!(col, options = {})
|
67
|
+
timestamp = options[:timestamp]
|
68
|
+
|
69
|
+
if timestamp.nil?
|
70
|
+
connection.client.deleteAll(table.name, key.to_s, col.to_s)
|
71
|
+
else
|
72
|
+
connection.client.deleteAllTs(table.name, key.to_s, col.to_s, timestamp.to_i64)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def mutate!(options = {}, &blk)
|
77
|
+
timestamp = options[:timestamp]
|
78
|
+
|
79
|
+
ml = HbaseAdapter::MutationList.new(&blk)
|
80
|
+
|
81
|
+
if timestamp.nil?
|
82
|
+
connection.client.mutateRow(table.name, key, ml.to_thrift)
|
83
|
+
else
|
84
|
+
connection.client.mutateRowTs(table.name, key, ml.to_thrift, timestamp.to_i64)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'hbase_adapter/column_family'
|
2
|
+
require 'hbase_adapter/mutation'
|
3
|
+
|
4
|
+
module HbaseAdapter
|
5
|
+
class Table
|
6
|
+
attr_reader :connection, :table_name
|
7
|
+
|
8
|
+
def initialize(connection, table_name)
|
9
|
+
@connection = connection
|
10
|
+
@table_name = table_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
table_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def enable!
|
18
|
+
connection.client.enableTable(table_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def disable!
|
22
|
+
connection.client.disableTable(table_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def enabled?
|
26
|
+
connection.client.isTableEnabled(table_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
def compact!
|
30
|
+
connection.client.compact(table_name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def major_compact!
|
34
|
+
connection.client.majorCompact(table_name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def columns
|
38
|
+
connection.client.getColumnDescriptors(table_name).inject({}) do|hash, (col_name, col)|
|
39
|
+
hash[col_name.to_sym] = HbaseAdapter::ColumnFamily.new(col)
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def regions
|
45
|
+
connection.client.getTableRegions(table_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
def [](row_key)
|
49
|
+
HbaseAdapter::Row.new(connection, self, row_key)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_row!(key, options = {})
|
53
|
+
timestamp = options[:timestamp]
|
54
|
+
|
55
|
+
if timestamp.nil?
|
56
|
+
connection.client.deleteAllRow(table_name, key.to_s)
|
57
|
+
else
|
58
|
+
connection.client.deleteAllRowTs(table_name, key.to_s, timestamp.to_i64)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def mutate!(options = {}, &blk)
|
63
|
+
timestamp = options[:timestamp]
|
64
|
+
|
65
|
+
ml = HbaseAdapter::MutationList.new(&blk)
|
66
|
+
|
67
|
+
if timestamp.nil?
|
68
|
+
connection.client.mutateRows(table_name, ml.to_thrift)
|
69
|
+
else
|
70
|
+
connection.client.mutateRowsTs(table_name, ml.to_thrift, timestamp.to_i64)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hbase-adapter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew O'Brien
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-14 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: hbase-thrift
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 69
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 20
|
33
|
+
- 5
|
34
|
+
version: 0.20.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: ruby-debug
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
description: Wrapping up all of that HBase Thrift stuff so you can use it.
|
66
|
+
email:
|
67
|
+
- obrien.andrew@gmail.com
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- lib/core_ext/time_ext.rb
|
76
|
+
- lib/hbase-adapter.rb
|
77
|
+
- lib/hbase_adapter/cell.rb
|
78
|
+
- lib/hbase_adapter/column_family.rb
|
79
|
+
- lib/hbase_adapter/connection.rb
|
80
|
+
- lib/hbase_adapter/mutation.rb
|
81
|
+
- lib/hbase_adapter/row.rb
|
82
|
+
- lib/hbase_adapter/table.rb
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.textile
|
85
|
+
has_rdoc: true
|
86
|
+
homepage: http://github.com/AndrewO/hbase-adapter
|
87
|
+
licenses: []
|
88
|
+
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 23
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 3
|
112
|
+
- 6
|
113
|
+
version: 1.3.6
|
114
|
+
requirements: []
|
115
|
+
|
116
|
+
rubyforge_project: hbase-adapter
|
117
|
+
rubygems_version: 1.3.7
|
118
|
+
signing_key:
|
119
|
+
specification_version: 3
|
120
|
+
summary: A Ruby wrapper for the HBase Thrift interface.
|
121
|
+
test_files: []
|
122
|
+
|