HBASE-936 REST Interface: enable to get numbers of rows from scanner interface
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@708631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c18a713726
commit
cb41078c8d
|
@ -78,6 +78,8 @@ Release 0.19.0 - Unreleased
|
|||
its used checking batch size
|
||||
HBASE-959 Be able to get multiple RowResult at one time from client side
|
||||
(Sishen Freecity via Stack)
|
||||
HBASE-936 REST Interface: enable get number of rows from scanner interface
|
||||
(Sishen Freecity via Stack)
|
||||
|
||||
NEW FEATURES
|
||||
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.URLDecoder;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -56,6 +57,8 @@ public abstract class GenericHandler {
|
|||
protected static final String ROW = "row";
|
||||
protected static final String REGIONS = "regions";
|
||||
protected static final String VERSION = "version";
|
||||
protected static final String OFFSET = "offset";
|
||||
protected static final String LIMIT = "limit";
|
||||
|
||||
protected final Log LOG = LogFactory.getLog(this.getClass());
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ package org.apache.hadoop.hbase.rest;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
@ -37,13 +39,13 @@ import org.apache.hadoop.hbase.util.Bytes;
|
|||
import org.apache.hadoop.hbase.util.JenkinsHash;
|
||||
import org.apache.hadoop.hbase.io.Cell;
|
||||
import org.apache.hadoop.hbase.io.RowResult;
|
||||
import org.mortbay.servlet.MultiPartResponse;
|
||||
import org.znerd.xmlenc.XMLOutputter;
|
||||
|
||||
/**
|
||||
* ScannderHandler fields all scanner related requests.
|
||||
*/
|
||||
public class ScannerHandler extends GenericHandler {
|
||||
private static final String ROWS = "rows";
|
||||
|
||||
public ScannerHandler(HBaseConfiguration conf, HBaseAdmin admin)
|
||||
throws ServletException{
|
||||
|
@ -52,20 +54,24 @@ public class ScannerHandler extends GenericHandler {
|
|||
|
||||
private class ScannerRecord {
|
||||
private final Scanner scanner;
|
||||
private RowResult next;
|
||||
private List<RowResult> nextRows;
|
||||
|
||||
ScannerRecord(final Scanner s) {
|
||||
this.scanner = s;
|
||||
nextRows = new ArrayList<RowResult>();
|
||||
}
|
||||
|
||||
public Scanner getScanner() {
|
||||
return this.scanner;
|
||||
}
|
||||
|
||||
public boolean hasNext() throws IOException {
|
||||
if (next == null) {
|
||||
next = scanner.next();
|
||||
return next != null;
|
||||
public boolean hasNext(int nbRows) throws IOException {
|
||||
if (nextRows.size() < nbRows) {
|
||||
RowResult[] results = scanner.next(nbRows - nextRows.size());
|
||||
for (RowResult result : results) {
|
||||
nextRows.add(result);
|
||||
}
|
||||
return nextRows.size() > 0;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
@ -76,12 +82,12 @@ public class ScannerHandler extends GenericHandler {
|
|||
* @return Null if finished, RowResult otherwise
|
||||
* @throws IOException
|
||||
*/
|
||||
public RowResult next() throws IOException {
|
||||
if (!hasNext()) {
|
||||
public RowResult[] next(int nbRows) throws IOException {
|
||||
if (!hasNext(nbRows)) {
|
||||
return null;
|
||||
}
|
||||
RowResult temp = next;
|
||||
next = null;
|
||||
RowResult[] temp = nextRows.toArray(new RowResult[nextRows.size()]);
|
||||
nextRows.clear();
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
@ -142,10 +148,15 @@ public class ScannerHandler extends GenericHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
if (sr.hasNext()) {
|
||||
String limitString = request.getParameter(LIMIT);
|
||||
int limit = 1;
|
||||
if (limitString != null && limitString.length() > 0) {
|
||||
limit = Integer.valueOf(limitString);
|
||||
}
|
||||
if (sr.hasNext(limit)) {
|
||||
switch (ContentType.getContentType(request.getHeader(ACCEPT))) {
|
||||
case XML:
|
||||
outputScannerEntryXML(response, sr);
|
||||
outputScannerEntryXML(response, sr, limit);
|
||||
break;
|
||||
case MIME:
|
||||
/* outputScannerEntryMime(response, sr);*/
|
||||
|
@ -162,16 +173,24 @@ public class ScannerHandler extends GenericHandler {
|
|||
}
|
||||
|
||||
private void outputScannerEntryXML(final HttpServletResponse response,
|
||||
final ScannerRecord sr)
|
||||
final ScannerRecord sr, int limit)
|
||||
throws IOException {
|
||||
RowResult rowResult = sr.next();
|
||||
|
||||
// respond with a 200 and Content-type: text/xml
|
||||
setResponseHeader(response, 200, ContentType.XML.toString());
|
||||
|
||||
// setup an xml outputter
|
||||
XMLOutputter outputter = getXMLOutputter(response.getWriter());
|
||||
|
||||
boolean rows = false;
|
||||
|
||||
if (limit > 1) {
|
||||
outputter.startTag(ROWS);
|
||||
rows = true;
|
||||
}
|
||||
|
||||
RowResult[] rowResults = sr.next(limit);
|
||||
|
||||
for (RowResult rowResult: rowResults) {
|
||||
outputter.startTag(ROW);
|
||||
|
||||
// write the row key
|
||||
|
@ -180,6 +199,12 @@ public class ScannerHandler extends GenericHandler {
|
|||
|
||||
outputColumnsXml(outputter, rowResult);
|
||||
outputter.endTag();
|
||||
}
|
||||
|
||||
if (rows) {
|
||||
outputter.endTag();
|
||||
}
|
||||
|
||||
outputter.endDocument();
|
||||
outputter.getWriter().close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue