Search in sources :

Example 1 with ByteSequence

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;
}
Also used : Entry(java.util.Map.Entry) ByteSequence(org.apache.accumulo.core.data.ByteSequence)

Example 2 with ByteSequence

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;
}
Also used : DirtyMapWrapper(org.apache.gora.persistency.impl.DirtyMapWrapper) HashMap(java.util.HashMap) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) BinaryDecoder(org.apache.avro.io.BinaryDecoder) Field(org.apache.avro.Schema.Field) Value(org.apache.accumulo.core.data.Value) Utf8(org.apache.avro.util.Utf8) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) SpecificDatumReader(org.apache.avro.specific.SpecificDatumReader) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Key(org.apache.accumulo.core.data.Key)

Example 3 with ByteSequence

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);
    }
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Range(org.apache.accumulo.core.data.Range) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ByteSequence(org.apache.accumulo.core.data.ByteSequence)

Example 4 with ByteSequence

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);
    }
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Range(org.apache.accumulo.core.data.Range) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ByteSequence(org.apache.accumulo.core.data.ByteSequence)

Example 5 with ByteSequence

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;
    }
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) ByteSequence(org.apache.accumulo.core.data.ByteSequence)

Aggregations

ByteSequence (org.apache.accumulo.core.data.ByteSequence)5 Range (org.apache.accumulo.core.data.Range)3 Text (org.apache.hadoop.io.Text)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)1 Scanner (org.apache.accumulo.core.client.Scanner)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 Schema (org.apache.avro.Schema)1 Field (org.apache.avro.Schema.Field)1 BinaryDecoder (org.apache.avro.io.BinaryDecoder)1 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)1