Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
public Scan setCaching(int caching);
caching: the number of rows returned per single RPC.Scan scan = new Scan();scan.setCaching(500); // Each RPC returns a maximum of 500 rows
public Scan setMaxResultSize(long maxResultSize);
maxResultSize: the maximum bytes returned per single RPC.Scan scan = new Scan();scan.setMaxResultSize(1024 * 1024); // Each RPC returns a maximum of 1MB of data
public Scan setAllowPartialResults(final boolean allowPartialResults);
allowPartialResults: whether to allow returning partial row data.Scan scan = new Scan();scan.setAllowPartialResults(true); // Allows returning partial row data
public Scan withStartRow(byte[] startRow);public Scan withStopRow(byte[] stopRow);
startRow: The starting row key.stopRow: The end row key.Scan scan = new Scan();byte[] startRow = Bytes.toBytes("row1");byte[] stopRow = Bytes.toBytes("row5");scan.withStartRow(startRow);scan.withStopRow(stopRow);
public Scan setLimit(int limit);
limit: Maximum number of results.Scan scan = new Scan();scan.setLimit(100); // Returns a maximum of 100 rows of data
ResultScanner.renewLease();
ResultScanner scanner = hTable.getScanner(scan);Thread.sleep(5 * 1000);scanner.next();Thread.sleep(20 * 1000);scanner.renewLease(); // Renews the validity period of the scanner
checkExistenceOnly is used to set whether the Get operation returns only the result indicating whether data exists (obtained via the getExists() method of the Result), rather than returning the complete result set. This can be used to quickly check whether a row or cell exists, reducing network transmission and memory consumption.public Get setCheckExistenceOnly(boolean checkExistenceOnly);
checkExistenceOnly: If set to true, then the Get operation only returns whether the data exists; if set to false, then returns the complete result set.// Create a Get objectGet get = new Get(Bytes.toBytes("row1"));// Set to only check existence.get.setCheckExistenceOnly(true);// Perform the Get operationResult result = table.get(get);// Check whether the data existsboolean exists = result.getExists();System.out.println("Does the data exist: " + exists);
public Result get(Get get);
get: A Get object to specify the row key to be obtained.// Obtain the entire row of dataGet get = new Get(Bytes.toBytes("row1"));Result result = table.get(get);
public Get addFamily(byte[] family);
family: column family name.Get getFamily = new Get(Bytes.toBytes("row1"));getFamily.addFamily(Bytes.toBytes("cf1"));Result familyResult = table.get(getFamily);
public Get addColumn(byte[] family, byte[] qualifier);
family: column family name.qualifier: column name.Get getColumn = new Get(Bytes.toBytes("row1"));getColumn.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));Result columnResult = table.get(getColumn);
public Get addColumn(byte[] family, byte[] qualifier);
family: column family name.qualifier: column name.Get getMultiple = new Get(Bytes.toBytes("row1"));getMultiple.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));getMultiple.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col2"));getMultiple.addColumn(Bytes.toBytes("cf2"), Bytes.toBytes("col3"));Result multipleResult = table.get(getMultiple);
public Get setMaxVersions(int maxVersions);
maxVersions: maximum number of versions to obtain.Get getVersion = new Get(Bytes.toBytes("row1"));getVersion.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));getVersion.setMaxVersions(3); // obtain at most 3 versionsResult versionResult = table.get(getVersion);
public Get setTimeRange(long minStamp, long maxStamp);
minStamp: minimum timestamp in the time range.maxStamp: maximum timestamp in the time range.Get getTimeRange = new Get(Bytes.toBytes("row1"));getTimeRange.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));getTimeRange.setTimeRange(System.currentTimeMillis() - 3600000, System.currentTimeMillis());Result timeRangeResult = table.get(getTimeRange);
public Put addColumn(byte[] family, byte[] qualifier, byte[] value);public Put addColumn(byte[] family, byte[] qualifier, long timestamp, byte[] value);
family: column family name.qualifier: column name.value: column value.timestamp (optional): Timestamp.// 1. Basic Put operationPut put = new Put(Bytes.toBytes("row1"));put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), Bytes.toBytes("value1"));put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col2"), Bytes.toBytes("value2"));table.put(put);// 2. Put with timestampPut putWithTimestamp = new Put(Bytes.toBytes("row1"));long timestamp = System.currentTimeMillis();putWithTimestamp.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), timestamp, Bytes.toBytes("value1"));table.put(putWithTimestamp);
public Delete addColumn(byte[] family, byte[] qualifier);public Delete addColumn(byte[] family, byte[] qualifier, long timestamp);public Delete addColumns(byte[] family, byte[] qualifier);public Delete addFamily(byte[] family);
family: column family name.qualifier: column name.timestamp (optional): Timestamp.// 1. Delete the entire rowDelete deleteRow = new Delete(Bytes.toBytes("row1"));table.delete(deleteRow);// 2. Delete the specified column familyDelete deleteFamily = new Delete(Bytes.toBytes("row1"));deleteFamily.addFamily(Bytes.toBytes("cf1"));table.delete(deleteFamily);// 3. Delete the specified columnDelete deleteColumn = new Delete(Bytes.toBytes("row1"));deleteColumn.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));table.delete(deleteColumn);// 4. Delete the specified versionDelete deleteVersion = new Delete(Bytes.toBytes("row1"));deleteVersion.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), timestamp);table.delete(deleteVersion);// 5. Delete all versions of the columnDelete deleteAllVersions = new Delete(Bytes.toBytes("row1"));deleteAllVersions.addColumns(Bytes.toBytes("cf1"), Bytes.toBytes("col1"));table.delete(deleteAllVersions);
public Append add(byte[] family, byte[] qualifier, byte[] value);
family: column family name.qualifier: column name.value: the value to append.// 1. Basic Append operationAppend append = new Append(Bytes.toBytes("row1"));append.add(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), Bytes.toBytes("_appended"));Result appendResult = table.append(append);// 2. Multiple-column AppendAppend appendMultiple = new Append(Bytes.toBytes("row1"));appendMultiple.add(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), Bytes.toBytes("_suffix1"));appendMultiple.add(Bytes.toBytes("cf1"), Bytes.toBytes("col2"), Bytes.toBytes("_suffix2"));Result appendMultipleResult = table.append(appendMultiple);
public Increment addColumn(byte[] family, byte[] qualifier, long amount);
family: column family name.qualifier: column name.amount: the incrementing value.// 1. Basic Increment operationIncrement increment = new Increment(Bytes.toBytes("row1"));increment.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("counter"), 1L);Result incrementResult = table.increment(increment);
public void put(List<Put> puts);
puts: a list of multiple Put objects.List<Put> puts = new ArrayList<>();for (int i = 0; i < 100; i++) {Put put = new Put(Bytes.toBytes("row" + i));put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), Bytes.toBytes("value" + i));puts.add(put);}table.put(puts);
public Result[] get(List<Get> gets);
gets: contains a list of multiple Get objects.List<Get> gets = new ArrayList<>();for (int i = 0; i < 100; i++) {Get get = new Get(Bytes.toBytes("row" + i));gets.add(get);}Result[] results = table.get(gets);
public void delete(List<Delete> deletes);
deletes: contains a list of multiple Delete objects.List<Delete> deletes = new ArrayList<>();for (int i = 0; i < 100; i++) {Delete delete = new Delete(Bytes.toBytes("row" + i));deletes.add(delete);}table.delete(deletes);
public Object[] batch(List<? extends Row> actions, Object[] results);
actions: contains a list of multiple Row objects (such as Put, Get, Delete, Increment).results: an array used for storing the results of operations.List<Row> actions = new ArrayList<>();actions.add(new Put(Bytes.toBytes("row1")).addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("col1"), Bytes.toBytes("value1")));actions.add(new Get(Bytes.toBytes("row2")));actions.add(new Delete(Bytes.toBytes("row3")));actions.add(new Increment(Bytes.toBytes("row4")).addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("counter"), 1L));Object[] results = new Object[actions.size()];table.batch(actions, results);
피드백