本文整理汇总了Java中org.apache.hadoop.hbase.rest.model.RowModel.getCells方法的典型用法代码示例。如果您正苦于以下问题:Java RowModel.getCells方法的具体用法?Java RowModel.getCells怎么用?Java RowModel.getCells使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.rest.model.RowModel
的用法示例。
在下文中一共展示了RowModel.getCells方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildResultFromModel
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
protected Result[] buildResultFromModel(final CellSetModel model) {
List<Result> results = new ArrayList<Result>();
for (RowModel row: model.getRows()) {
List<Cell> kvs = new ArrayList<Cell>();
for (CellModel cell: row.getCells()) {
byte[][] split = KeyValue.parseColumn(cell.getColumn());
byte[] column = split[0];
byte[] qualifier = null;
if (split.length == 1) {
qualifier = HConstants.EMPTY_BYTE_ARRAY;
} else if (split.length == 2) {
qualifier = split[1];
} else {
throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
}
kvs.add(new KeyValue(row.getKey(), column, qualifier,
cell.getTimestamp(), cell.getValue()));
}
results.add(Result.create(kvs));
}
return results.toArray(new Result[results.size()]);
}
示例2: buildResultFromModel
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
protected Result[] buildResultFromModel(final CellSetModel model) {
List<Result> results = new ArrayList<>();
for (RowModel row: model.getRows()) {
List<Cell> kvs = new ArrayList<>(row.getCells().size());
for (CellModel cell: row.getCells()) {
byte[][] split = CellUtil.parseColumn(cell.getColumn());
byte[] column = split[0];
byte[] qualifier = null;
if (split.length == 1) {
qualifier = HConstants.EMPTY_BYTE_ARRAY;
} else if (split.length == 2) {
qualifier = split[1];
} else {
throw new IllegalArgumentException("Invalid familyAndQualifier provided.");
}
kvs.add(new KeyValue(row.getKey(), column, qualifier,
cell.getTimestamp(), cell.getValue()));
}
results.add(Result.create(kvs));
}
return results.toArray(new Result[results.size()]);
}
示例3: testStartEndRowGetPutXML
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
@Test
public void testStartEndRowGetPutXML() throws IOException, JAXBException {
String[] rows = { ROW_1, ROW_2, ROW_3 };
String[] values = { VALUE_1, VALUE_2, VALUE_3 };
Response response = null;
for (int i = 0; i < rows.length; i++) {
response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
assertEquals(200, response.getCode());
checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
}
response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel)
xmlUnmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertEquals(2, cellSet.getRows().size());
for (int i = 0; i < cellSet.getRows().size()-1; i++) {
RowModel rowModel = cellSet.getRows().get(i);
for (CellModel cell: rowModel.getCells()) {
assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
assertEquals(values[i], Bytes.toString(cell.getValue()));
}
}
for (String row : rows) {
response = deleteRow(TABLE, row);
assertEquals(200, response.getCode());
}
}
示例4: buildResultFromModel
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
protected Result[] buildResultFromModel(final CellSetModel model) {
List<Result> results = new ArrayList<Result>();
for (RowModel row: model.getRows()) {
List<KeyValue> kvs = new ArrayList<KeyValue>();
for (CellModel cell: row.getCells()) {
byte[][] split = KeyValue.parseColumn(cell.getColumn());
byte[] column = split[0];
byte[] qualifier = split.length > 1 ? split[1] : null;
kvs.add(new KeyValue(row.getKey(), column, qualifier,
cell.getTimestamp(), cell.getValue()));
}
results.add(new Result(kvs));
}
return results.toArray(new Result[results.size()]);
}
示例5: testStartEndRowGetPutXML
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
@Test
public void testStartEndRowGetPutXML() throws IOException, JAXBException {
String[] rows = { ROW_1, ROW_2, ROW_3 };
String[] values = { VALUE_1, VALUE_2, VALUE_3 };
Response response = null;
for (int i = 0; i < rows.length; i++) {
response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
assertEquals(200, response.getCode());
checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
}
response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertEquals(2, cellSet.getRows().size());
for (int i = 0; i < cellSet.getRows().size()-1; i++) {
RowModel rowModel = cellSet.getRows().get(i);
for (CellModel cell: rowModel.getCells()) {
assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
assertEquals(values[i], Bytes.toString(cell.getValue()));
}
}
for (String row : rows) {
response = deleteRow(TABLE, row);
assertEquals(200, response.getCode());
}
}
示例6: testStartEndRowGetPutXML
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
@Test
public void testStartEndRowGetPutXML() throws IOException, JAXBException {
String[] rows = { ROW_1, ROW_2, ROW_3 };
String[] values = { VALUE_1, VALUE_2, VALUE_3 };
Response response = null;
for (int i = 0; i < rows.length; i++) {
response = putValueXML(TABLE, rows[i], COLUMN_1, values[i]);
assertEquals(200, response.getCode());
checkValueXML(TABLE, rows[i], COLUMN_1, values[i]);
}
response = getValueXML(TABLE, rows[0], rows[2], COLUMN_1);
assertEquals(200, response.getCode());
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
assertEquals(2, cellSet.getRows().size());
for (int i = 0; i < cellSet.getRows().size()-1; i++) {
RowModel rowModel = cellSet.getRows().get(i);
for (CellModel cell: rowModel.getCells()) {
assertEquals(COLUMN_1, Bytes.toString(cell.getColumn()));
assertEquals(values[i], Bytes.toString(cell.getValue()));
}
}
for (String row : rows) {
response = deleteRow(TABLE, row);
assertEquals(200, response.getCode());
}
}
示例7: verifyScanFull
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
int row = 0;
int idx = 0;
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
for (CellModel cell: cells) {
assertTrue("Row mismatch",
Bytes.equals(rowModel.getKey(), kvs[idx].getRow()));
byte[][] split = KeyValue.parseColumn(cell.getColumn());
assertTrue("Family mismatch",
Bytes.equals(split[0], kvs[idx].getFamily()));
assertTrue("Qualifier mismatch",
Bytes.equals(split[1], kvs[idx].getQualifier()));
assertTrue("Value mismatch",
Bytes.equals(cell.getValue(), kvs[idx].getValue()));
idx++;
}
}
assertEquals("Expected " + kvs.length + " total keys but scanned " + idx,
kvs.length, idx);
}
示例8: verifyScanNoEarlyOut
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
private static void verifyScanNoEarlyOut(Scan s, long expectedRows,
long expectedKeys) throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
Iterator<RowModel> i = cellSet.getRows().iterator();
int j = 0;
for (boolean done = true; done; j++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but already scanned " + (j+1), expectedRows > j);
assertEquals("Expected " + expectedKeys + " keys per row but " +
"returned " + cells.size(), expectedKeys, cells.size());
}
assertEquals("Expected " + expectedRows + " rows but scanned " + j +
" rows", expectedRows, j);
}
示例9: checkAndPut
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
/**
* Validates the input request parameters, parses columns from CellSetModel,
* and invokes checkAndPut on HTable.
*
* @param model instance of CellSetModel
* @return Response 200 OK, 304 Not modified, 400 Bad request
*/
Response checkAndPut(final CellSetModel model) {
HTablePool pool = servlet.getTablePool();
HTableInterface table = null;
try {
if (model.getRows().size() != 1) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
RowModel rowModel = model.getRows().get(0);
byte[] key = rowModel.getKey();
if (key == null) {
key = rowspec.getRow();
}
List<CellModel> cellModels = rowModel.getCells();
int cellModelCount = cellModels.size();
if (key == null || cellModelCount <= 1) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
Put put = new Put(key);
CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
byte[] valueToCheckColumn = valueToCheckCell.getColumn();
byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn);
if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) {
CellModel valueToPutCell = null;
for (int i = 0, n = cellModelCount - 1; i < n ; i++) {
if(Bytes.equals(cellModels.get(i).getColumn(),
valueToCheckCell.getColumn())) {
valueToPutCell = cellModels.get(i);
break;
}
}
if (valueToPutCell != null) {
put.add(valueToPutParts[0], valueToPutParts[1], valueToPutCell
.getTimestamp(), valueToPutCell.getValue());
} else {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
} else {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
table = pool.getTable(this.tableResource.getName());
boolean retValue = table.checkAndPut(key, valueToPutParts[0],
valueToPutParts[1], valueToCheckCell.getValue(), put);
if (LOG.isDebugEnabled()) {
LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
}
table.flushCommits();
ResponseBuilder response = Response.ok();
if (!retValue) {
response = Response.status(304);
}
return response.build();
} catch (IOException e) {
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
.build();
} finally {
if (table != null) try {
table.close();
} catch (IOException ioe) { }
}
}
示例10: verifyScanFull
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(response.getCode(), 201);
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(response.getCode(), 200);
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(response.getCode(), 200);
int row = 0;
int idx = 0;
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
for (CellModel cell: cells) {
assertTrue("Row mismatch",
Bytes.equals(rowModel.getKey(), kvs[idx].getRow()));
byte[][] split = KeyValue.parseColumn(cell.getColumn());
assertTrue("Family mismatch",
Bytes.equals(split[0], kvs[idx].getFamily()));
assertTrue("Qualifier mismatch",
Bytes.equals(split[1], kvs[idx].getQualifier()));
assertTrue("Value mismatch",
Bytes.equals(cell.getValue(), kvs[idx].getValue()));
idx++;
}
}
assertEquals("Expected " + kvs.length + " total keys but scanned " + idx,
kvs.length, idx);
}
示例11: verifyScanFull
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
private static void verifyScanFull(Scan s, KeyValue [] kvs)
throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(200, response.getCode());
int row = 0;
int idx = 0;
Iterator<RowModel> i = cellSet.getRows().iterator();
for (boolean done = true; done; row++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many keys! Only expected " + kvs.length +
" total but already scanned " + (cells.size() + idx),
kvs.length >= idx + cells.size());
for (CellModel cell: cells) {
assertTrue("Row mismatch",
Bytes.equals(rowModel.getKey(), CellUtil.cloneRow(kvs[idx])));
byte[][] split = CellUtil.parseColumn(cell.getColumn());
assertTrue("Family mismatch",
Bytes.equals(split[0], CellUtil.cloneFamily(kvs[idx])));
assertTrue("Qualifier mismatch",
Bytes.equals(split[1], CellUtil.cloneQualifier(kvs[idx])));
assertTrue("Value mismatch",
Bytes.equals(cell.getValue(), CellUtil.cloneValue(kvs[idx])));
idx++;
}
}
assertEquals("Expected " + kvs.length + " total keys but scanned " + idx,
kvs.length, idx);
}
示例12: verifyScanNoEarlyOut
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
private static void verifyScanNoEarlyOut(Scan s, long expectedRows,
long expectedKeys) throws Exception {
ScannerModel model = ScannerModel.fromScan(s);
model.setBatch(Integer.MAX_VALUE); // fetch it all at once
StringWriter writer = new StringWriter();
marshaller.marshal(model, writer);
LOG.debug(writer.toString());
byte[] body = Bytes.toBytes(writer.toString());
Response response = client.put("/" + TABLE + "/scanner",
Constants.MIMETYPE_XML, body);
assertEquals(201, response.getCode());
String scannerURI = response.getLocation();
assertNotNull(scannerURI);
// get a cell set
response = client.get(scannerURI, Constants.MIMETYPE_XML);
assertEquals(200, response.getCode());
assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
CellSetModel cellSet = (CellSetModel)
unmarshaller.unmarshal(new ByteArrayInputStream(response.getBody()));
// delete the scanner
response = client.delete(scannerURI);
assertEquals(200, response.getCode());
Iterator<RowModel> i = cellSet.getRows().iterator();
int j = 0;
for (boolean done = true; done; j++) {
done = i.hasNext();
if (!done) break;
RowModel rowModel = i.next();
List<CellModel> cells = rowModel.getCells();
if (cells.isEmpty()) break;
assertTrue("Scanned too many rows! Only expected " + expectedRows +
" total but already scanned " + (j+1), expectedRows > j);
assertEquals("Expected " + expectedKeys + " keys per row but " +
"returned " + cells.size(), expectedKeys, cells.size());
}
assertEquals("Expected " + expectedRows + " rows but scanned " + j +
" rows", expectedRows, j);
}
示例13: checkAndPut
import org.apache.hadoop.hbase.rest.model.RowModel; //导入方法依赖的package包/类
/**
* Validates the input request parameters, parses columns from CellSetModel,
* and invokes checkAndPut on HTable.
*
* @param model instance of CellSetModel
* @return Response 200 OK, 304 Not modified, 400 Bad request
*/
Response checkAndPut(final CellSetModel model) {
HTableInterface table = null;
try {
if (model.getRows().size() != 1) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
RowModel rowModel = model.getRows().get(0);
byte[] key = rowModel.getKey();
if (key == null) {
key = rowspec.getRow();
}
List<CellModel> cellModels = rowModel.getCells();
int cellModelCount = cellModels.size();
if (key == null || cellModelCount <= 1) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
Put put = new Put(key);
CellModel valueToCheckCell = cellModels.get(cellModelCount - 1);
byte[] valueToCheckColumn = valueToCheckCell.getColumn();
byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn);
if (valueToPutParts.length != 2) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
CellModel valueToPutCell = null;
for (int i = 0, n = cellModelCount - 1; i < n ; i++) {
if(Bytes.equals(cellModels.get(i).getColumn(),
valueToCheckCell.getColumn())) {
valueToPutCell = cellModels.get(i);
break;
}
}
if (null == valueToPutCell) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MIMETYPE_TEXT).entity("Bad request" + CRLF)
.build();
}
put.addImmutable(valueToPutParts[0], valueToPutParts[1], valueToPutCell
.getTimestamp(), valueToPutCell.getValue());
table = servlet.getTable(this.tableResource.getName());
boolean retValue = table.checkAndPut(key, valueToPutParts[0],
valueToPutParts[1], valueToCheckCell.getValue(), put);
if (LOG.isDebugEnabled()) {
LOG.debug("CHECK-AND-PUT " + put.toString() + ", returns " + retValue);
}
table.flushCommits();
ResponseBuilder response = Response.ok();
if (!retValue) {
response = Response.status(304);
}
return response.build();
} catch (IOException e) {
return Response.status(Response.Status.SERVICE_UNAVAILABLE)
.type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
.build();
} finally {
if (table != null) try {
table.close();
} catch (IOException ioe) { }
}
}