use of org.apache.accumulo.core.data.ByteSequence in project gora by apache.
the class AccumuloResult method nextInner.
/**
* Gets the next item
*/
@Override
protected boolean nextInner() throws IOException {
if (!iterator.hasNext())
return false;
key = null;
Iterator<Entry<Key, Value>> nextRow = iterator.next();
ByteSequence row = getDataStore().populate(nextRow, persistent);
key = ((AccumuloStore<K, T>) dataStore).fromBytes(getKeyClass(), row.toArray());
return true;
}
use of org.apache.accumulo.core.data.ByteSequence in project gora by apache.
the class AccumuloStore method populate.
public ByteSequence populate(Iterator<Entry<Key, Value>> iter, T persistent) throws IOException {
ByteSequence row = null;
Map<Utf8, Object> currentMap = null;
List currentArray = null;
Text currentFam = null;
int currentPos = 0;
Schema currentSchema = null;
Field currentField = null;
BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(new byte[0], null);
while (iter.hasNext()) {
Entry<Key, Value> entry = iter.next();
if (row == null) {
row = entry.getKey().getRowData();
}
byte[] val = entry.getValue().get();
Field field = fieldMap.get(getFieldName(entry));
if (currentMap != null) {
if (currentFam.equals(entry.getKey().getColumnFamily())) {
currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get()));
continue;
} else {
persistent.put(currentPos, currentMap);
currentMap = null;
}
} else if (currentArray != null) {
if (currentFam.equals(entry.getKey().getColumnFamily())) {
currentArray.add(fromBytes(currentSchema, entry.getValue().get()));
continue;
} else {
persistent.put(currentPos, new GenericData.Array<T>(currentField.schema(), currentArray));
currentArray = null;
}
}
switch(field.schema().getType()) {
case // first entry only. Next are handled above on the next loop
MAP:
currentMap = new DirtyMapWrapper<>(new HashMap<Utf8, Object>());
currentPos = field.pos();
currentFam = entry.getKey().getColumnFamily();
currentSchema = field.schema().getValueType();
currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get()));
break;
case ARRAY:
currentArray = new DirtyListWrapper<>(new ArrayList<>());
currentPos = field.pos();
currentFam = entry.getKey().getColumnFamily();
currentSchema = field.schema().getElementType();
currentField = field;
currentArray.add(fromBytes(currentSchema, entry.getValue().get()));
break;
case // default value of null acts like union with null
UNION:
Schema effectiveSchema = field.schema().getTypes().get(firstNotNullSchemaTypeIndex(field.schema()));
// map and array were coded without union index so need to be read the same way
if (effectiveSchema.getType() == Type.ARRAY) {
currentArray = new DirtyListWrapper<>(new ArrayList<>());
currentPos = field.pos();
currentFam = entry.getKey().getColumnFamily();
currentSchema = field.schema().getElementType();
currentField = field;
currentArray.add(fromBytes(currentSchema, entry.getValue().get()));
break;
} else if (effectiveSchema.getType() == Type.MAP) {
currentMap = new DirtyMapWrapper<>(new HashMap<Utf8, Object>());
currentPos = field.pos();
currentFam = entry.getKey().getColumnFamily();
currentSchema = effectiveSchema.getValueType();
currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get()));
break;
}
// continue like a regular top-level union
case RECORD:
SpecificDatumReader<?> reader = new SpecificDatumReader<Schema>(field.schema());
persistent.put(field.pos(), reader.read(null, DecoderFactory.get().binaryDecoder(val, decoder)));
break;
default:
persistent.put(field.pos(), fromBytes(field.schema(), entry.getValue().get()));
}
}
if (currentMap != null) {
persistent.put(currentPos, currentMap);
} else if (currentArray != null) {
persistent.put(currentPos, new GenericData.Array<T>(currentField.schema(), currentArray));
}
persistent.clearDirty();
return row;
}
use of org.apache.accumulo.core.data.ByteSequence in project Gaffer by gchq.
the class BloomFilter18IT method seek.
private void seek(final FileSKVIterator reader, final EntitySeed seed, final RangeFactory rangeFactory) throws IOException, RangeFactoryException {
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
final GetElements<ElementSeed, ?> operation = new GetElements<>(view);
final List<Range> range = rangeFactory.getRange(seed, operation);
for (final Range ran : range) {
reader.seek(ran, new ArrayList<ByteSequence>(), false);
}
}
use of org.apache.accumulo.core.data.ByteSequence in project Gaffer by gchq.
the class BloomFilterIT method seek.
private void seek(final FileSKVIterator reader, final EntitySeed seed, final RangeFactory rangeFactory) throws IOException, RangeFactoryException {
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
final GetElements<ElementSeed, ?> operation = new GetElements<>(view);
final List<Range> range = rangeFactory.getRange(seed, operation);
for (final Range ran : range) {
reader.seek(ran, new ArrayList<ByteSequence>(), false);
}
}
use of org.apache.accumulo.core.data.ByteSequence in project gora by apache.
the class AccumuloStore method get.
@Override
public T get(K key, String[] fields) {
try {
// TODO make isolated scanner optional?
Scanner scanner = new IsolatedScanner(conn.createScanner(mapping.tableName, Authorizations.EMPTY));
Range rowRange = new Range(new Text(toBytes(key)));
scanner.setRange(rowRange);
setFetchColumns(scanner, fields);
T persistent = newPersistent();
ByteSequence row = populate(scanner.iterator(), persistent);
if (row == null)
return null;
return persistent;
} catch (TableNotFoundException e) {
LOG.error(e.getMessage(), e);
return null;
} catch (IOException e) {
LOG.error(e.getMessage(), e);
return null;
}
}
Aggregations