/
Best Practices for Developing Applications
Best Practices for Developing Applications
Scanning Over Tables with Byte Array Keys
In the CDAP Java API, Bytes.stopKeyForPrefix() is a very handy tool when performing scans over tables with byte array (byte[]
) keys.
The method returns a given prefix, incremented by one, in a form that is suitable for prefix matching. Here is an example, showing stopKeyForPrefix
being used to generate, from a provided index key, an incremented stop key:
// Returns first that matches
@Nullable
public <T> T get(Key id, Class<T> classOfT) {
try {
Scanner scan = table.scan(id.getKey(), Bytes.stopKeyForPrefix(id.getKey()));
Row row = scan.next();
if (row == null || row.isEmpty()) {
return null;
}
byte[] value = row.get(COLUMN);
if (value == null) {
return null;
}
return deserialize(value, classOfT);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
, multiple selections available,
Related content
Development Environment Setup
Development Environment Setup
More like this
Applications
Applications
Read with this
Configuring Program Resources
Configuring Program Resources
Read with this
Developing Pipelines
Developing Pipelines
Read with this
Namespaces
Namespaces
Read with this
Program Retry Policies
Program Retry Policies
Read with this
Created in 2020 by Google Inc.