2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import java
.io
.IOException
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Iterator
;
23 import java
.util
.List
;
25 import java
.util
.concurrent
.TimeUnit
;
26 import org
.apache
.hadoop
.conf
.Configuration
;
27 import org
.apache
.hadoop
.hbase
.Cell
;
28 import org
.apache
.hadoop
.hbase
.TableName
;
29 import org
.apache
.hadoop
.hbase
.client
.Append
;
30 import org
.apache
.hadoop
.hbase
.client
.Delete
;
31 import org
.apache
.hadoop
.hbase
.client
.Durability
;
32 import org
.apache
.hadoop
.hbase
.client
.Get
;
33 import org
.apache
.hadoop
.hbase
.client
.Increment
;
34 import org
.apache
.hadoop
.hbase
.client
.Put
;
35 import org
.apache
.hadoop
.hbase
.client
.RegionLocator
;
36 import org
.apache
.hadoop
.hbase
.client
.Result
;
37 import org
.apache
.hadoop
.hbase
.client
.ResultScanner
;
38 import org
.apache
.hadoop
.hbase
.client
.Row
;
39 import org
.apache
.hadoop
.hbase
.client
.RowMutations
;
40 import org
.apache
.hadoop
.hbase
.client
.Scan
;
41 import org
.apache
.hadoop
.hbase
.client
.Table
;
42 import org
.apache
.hadoop
.hbase
.client
.TableDescriptor
;
43 import org
.apache
.hadoop
.hbase
.client
.coprocessor
.Batch
.Call
;
44 import org
.apache
.hadoop
.hbase
.client
.coprocessor
.Batch
.Callback
;
45 import org
.apache
.hadoop
.hbase
.client
.metrics
.ScanMetrics
;
46 import org
.apache
.hadoop
.hbase
.filter
.Filter
;
47 import org
.apache
.hadoop
.hbase
.ipc
.CoprocessorRpcChannel
;
49 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.Descriptors
.MethodDescriptor
;
50 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.Message
;
51 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.Service
;
52 import org
.apache
.hbase
.thirdparty
.com
.google
.protobuf
.ServiceException
;
55 * An implementation of {@link Table} that sits directly on a Region; it decorates the passed in
56 * Region instance with the Table API. Some API is not implemented yet (throws
57 * {@link UnsupportedOperationException}) mostly because no need as yet or it necessitates copying
58 * a load of code local from RegionServer.
60 * <p>Use as an instance of a {@link Table} in-the-small -- no networking or servers
61 * necessary -- or to write a test that can run directly against the datastore and then
64 public class RegionAsTable
implements Table
{
65 private final Region region
;
68 * @param region Region to decorate with Table API.
70 public RegionAsTable(final Region region
) {
75 public TableName
getName() {
76 return this.region
.getTableDescriptor().getTableName();
80 public Configuration
getConfiguration() {
81 throw new UnsupportedOperationException();
85 public TableDescriptor
getDescriptor() throws IOException
{
86 return this.region
.getTableDescriptor();
90 public boolean exists(Get get
) throws IOException
{
91 if (!get
.isCheckExistenceOnly()) throw new IllegalArgumentException();
92 return get(get
) != null;
96 public boolean[] exists(List
<Get
> gets
) throws IOException
{
97 boolean [] results
= new boolean[gets
.size()];
100 results
[index
++] = exists(get
);
106 public void batch(List
<?
extends Row
> actions
, Object
[] results
)
107 throws IOException
, InterruptedException
{
108 throw new UnsupportedOperationException();
112 public <R
> void batchCallback(List
<?
extends Row
> actions
, Object
[] results
,
113 Callback
<R
> callback
)
114 throws IOException
, InterruptedException
{
115 throw new UnsupportedOperationException();
119 public Result
get(Get get
) throws IOException
{
120 return this.region
.get(get
);
124 public Result
[] get(List
<Get
> gets
) throws IOException
{
125 Result
[] results
= new Result
[gets
.size()];
127 for (Get get
: gets
) {
128 results
[index
++] = get(get
);
133 static class RegionScannerToResultScannerAdaptor
implements ResultScanner
{
134 private static final Result
[] EMPTY_RESULT_ARRAY
= new Result
[0];
135 private final RegionScanner regionScanner
;
137 RegionScannerToResultScannerAdaptor(final RegionScanner regionScanner
) {
138 this.regionScanner
= regionScanner
;
142 public Iterator
<Result
> iterator() {
143 throw new UnsupportedOperationException();
147 public Result
next() throws IOException
{
148 List
<Cell
> cells
= new ArrayList
<>();
149 return regionScanner
.next(cells
)? Result
.create(cells
): null;
153 public Result
[] next(int nbRows
) throws IOException
{
154 List
<Result
> results
= new ArrayList
<>(nbRows
);
155 for (int i
= 0; i
< nbRows
; i
++) {
156 Result result
= next();
157 if (result
== null) break;
160 return results
.toArray(EMPTY_RESULT_ARRAY
);
164 public void close() {
166 regionScanner
.close();
167 } catch (IOException e
) {
168 throw new RuntimeException(e
);
173 public boolean renewLease() {
174 throw new UnsupportedOperationException();
178 public ScanMetrics
getScanMetrics() {
179 throw new UnsupportedOperationException();
184 public ResultScanner
getScanner(Scan scan
) throws IOException
{
185 return new RegionScannerToResultScannerAdaptor(this.region
.getScanner(scan
));
189 public ResultScanner
getScanner(byte[] family
) throws IOException
{
190 return getScanner(new Scan().addFamily(family
));
194 public ResultScanner
getScanner(byte[] family
, byte[] qualifier
) throws IOException
{
195 return getScanner(new Scan().addColumn(family
, qualifier
));
199 public void put(Put put
) throws IOException
{
200 this.region
.put(put
);
204 public void put(List
<Put
> puts
) throws IOException
{
205 for (Put put
: puts
) put(put
);
209 public void delete(Delete delete
) throws IOException
{
210 this.region
.delete(delete
);
214 public void delete(List
<Delete
> deletes
) throws IOException
{
215 for(Delete delete
: deletes
) delete(delete
);
219 public CheckAndMutateBuilder
checkAndMutate(byte[] row
, byte[] family
) {
220 throw new UnsupportedOperationException();
224 public CheckAndMutateWithFilterBuilder
checkAndMutate(byte[] row
, Filter filter
) {
225 throw new UnsupportedOperationException();
229 public Result
mutateRow(RowMutations rm
) throws IOException
{
230 throw new UnsupportedOperationException();
234 public Result
append(Append append
) throws IOException
{
235 return this.region
.append(append
);
239 public Result
increment(Increment increment
) throws IOException
{
240 return this.region
.increment(increment
);
244 public long incrementColumnValue(byte[] row
, byte[] family
, byte[] qualifier
, long amount
)
246 throw new UnsupportedOperationException();
250 public long incrementColumnValue(byte[] row
, byte[] family
, byte[] qualifier
, long amount
,
251 Durability durability
)
253 throw new UnsupportedOperationException();
257 * This call will NOT close the underlying region.
260 public void close() throws IOException
{
264 public CoprocessorRpcChannel
coprocessorService(byte[] row
) {
265 throw new UnsupportedOperationException();
269 public <T
extends Service
, R
> Map
<byte[], R
> coprocessorService(Class
<T
> service
, byte[] startKey
,
270 byte[] endKey
, Call
<T
, R
> callable
)
271 throws ServiceException
, Throwable
{
272 throw new UnsupportedOperationException();
276 public <T
extends Service
, R
> void coprocessorService(Class
<T
> service
, byte[] startKey
,
277 byte[] endKey
, Call
<T
, R
> callable
, Callback
<R
> callback
)
278 throws ServiceException
, Throwable
{
279 throw new UnsupportedOperationException();
283 public <R
extends Message
> Map
<byte[], R
> batchCoprocessorService(MethodDescriptor
284 methodDescriptor
, Message request
,
285 byte[] startKey
, byte[] endKey
, R responsePrototype
)
286 throws ServiceException
, Throwable
{
287 throw new UnsupportedOperationException();
291 public <R
extends Message
> void batchCoprocessorService(MethodDescriptor methodDescriptor
,
292 Message request
, byte[] startKey
, byte[] endKey
, R responsePrototype
, Callback
<R
> callback
)
293 throws ServiceException
, Throwable
{
294 throw new UnsupportedOperationException();
298 public long getReadRpcTimeout(TimeUnit unit
) {
299 throw new UnsupportedOperationException();
303 public long getOperationTimeout(TimeUnit unit
) {
304 throw new UnsupportedOperationException();
308 public long getWriteRpcTimeout(TimeUnit unit
) {
309 throw new UnsupportedOperationException();
313 public long getRpcTimeout(TimeUnit unit
) {
314 throw new UnsupportedOperationException();
318 public RegionLocator
getRegionLocator() throws IOException
{
319 throw new UnsupportedOperationException();