Search in sources :

Example 76 with Key

use of org.apache.accumulo.core.data.Key in project hive by apache.

the class HiveAccumuloRecordReader method next.

@Override
public boolean next(Text rowKey, AccumuloHiveRow row) throws IOException {
    Text key = recordReader.createKey();
    PeekingIterator<Map.Entry<Key, Value>> iter = recordReader.createValue();
    if (recordReader.next(key, iter)) {
        row.clear();
        row.setRowId(key.toString());
        List<Key> keys = Lists.newArrayList();
        List<Value> values = Lists.newArrayList();
        while (iter.hasNext()) {
            // collect key/values for this row.
            Map.Entry<Key, Value> kv = iter.next();
            keys.add(kv.getKey());
            values.add(kv.getValue());
        }
        if (iteratorCount == 0) {
            // no encoded values, we can push directly to row.
            pushToValue(keys, values, row);
        } else {
            for (int i = 0; i < iteratorCount; i++) {
                // each iterator creates a level of encoding.
                SortedMap<Key, Value> decoded = PrimitiveComparisonFilter.decodeRow(keys.get(0), values.get(0));
                keys = Lists.newArrayList(decoded.keySet());
                values = Lists.newArrayList(decoded.values());
            }
            // after decoding we can push to value.
            pushToValue(keys, values, row);
        }
        return true;
    } else {
        return false;
    }
}
Also used : Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Map(java.util.Map) SortedMap(java.util.SortedMap) Key(org.apache.accumulo.core.data.Key)

Example 77 with Key

use of org.apache.accumulo.core.data.Key in project hive by apache.

the class TestAccumuloPredicateHandler method rangeLessThan.

@Test
public void rangeLessThan() throws SerDeException {
    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
    List<ExprNodeDesc> children = Lists.newArrayList();
    children.add(column);
    children.add(constant);
    ExprNodeGenericFuncDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPLessThan(), children);
    assertNotNull(node);
    String filterExpr = SerializationUtilities.serializeExpression(node);
    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
    Collection<Range> ranges = handler.getRanges(conf, columnMapper);
    assertEquals(ranges.size(), 1);
    Range range = ranges.iterator().next();
    assertTrue(range.isStartKeyInclusive());
    assertFalse(range.isEndKeyInclusive());
    assertFalse(range.contains(new Key(new Text("aaa"))));
    assertTrue(range.afterEndKey(new Key(new Text("ccccc"))));
    assertTrue(range.contains(new Key(new Text("aa"))));
    assertTrue(range.afterEndKey(new Key(new Text("aab"))));
    assertTrue(range.afterEndKey(new Key(new Text("aaa"))));
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) Text(org.apache.hadoop.io.Text) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Range(org.apache.accumulo.core.data.Range) GenericUDFOPLessThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 78 with Key

use of org.apache.accumulo.core.data.Key in project hive by apache.

the class TestAccumuloPredicateHandler method testMultipleRanges.

@Test
public void testMultipleRanges() throws SerDeException {
    ExprNodeDesc column = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
    ExprNodeDesc constant = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "aaa");
    List<ExprNodeDesc> children = Lists.newArrayList();
    children.add(column);
    children.add(constant);
    ExprNodeDesc node = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPEqualOrGreaterThan(), children);
    assertNotNull(node);
    ExprNodeDesc column2 = new ExprNodeColumnDesc(TypeInfoFactory.stringTypeInfo, "rid", null, false);
    ExprNodeDesc constant2 = new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, "bbb");
    List<ExprNodeDesc> children2 = Lists.newArrayList();
    children2.add(column2);
    children2.add(constant2);
    ExprNodeDesc node2 = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPLessThan(), children2);
    assertNotNull(node2);
    List<ExprNodeDesc> bothFilters = Lists.newArrayList();
    bothFilters.add(node);
    bothFilters.add(node2);
    ExprNodeGenericFuncDesc both = new ExprNodeGenericFuncDesc(TypeInfoFactory.stringTypeInfo, new GenericUDFOPAnd(), bothFilters);
    String filterExpr = SerializationUtilities.serializeExpression(both);
    conf.set(TableScanDesc.FILTER_EXPR_CONF_STR, filterExpr);
    List<Range> ranges = handler.getRanges(conf, columnMapper);
    assertEquals(1, ranges.size());
    Range range = ranges.get(0);
    assertEquals(new Range(new Key("aaa"), true, new Key("bbb"), false), range);
}
Also used : ExprNodeConstantDesc(org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc) ExprNodeColumnDesc(org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) ExprNodeDesc(org.apache.hadoop.hive.ql.plan.ExprNodeDesc) Range(org.apache.accumulo.core.data.Range) GenericUDFOPLessThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPLessThan) GenericUDFOPEqualOrGreaterThan(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPEqualOrGreaterThan) Key(org.apache.accumulo.core.data.Key) GenericUDFOPAnd(org.apache.hadoop.hive.ql.udf.generic.GenericUDFOPAnd) Test(org.junit.Test)

Example 79 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class RowIDAggregator method next.

@Override
public void next() throws IOException {
    topKey = null;
    workKey = new Key();
    if (!source.hasTop()) {
        return;
    }
    source.next();
    findTop();
}
Also used : Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey)

Example 80 with Key

use of org.apache.accumulo.core.data.Key in project Gaffer by gchq.

the class AddElementsFromHdfsMapper method map.

@Override
protected void map(final Element element, final Context context) throws IOException, InterruptedException {
    final Pair<Key> keyPair;
    try {
        keyPair = elementConverter.getKeysFromElement(element);
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    final Value value;
    try {
        value = elementConverter.getValueFromElement(element);
    } catch (final AccumuloElementConversionException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
    context.write(keyPair.getFirst(), value);
    if (keyPair.getSecond() != null) {
        context.write(keyPair.getSecond(), value);
    }
    context.getCounter("Bulk import", element.getClass().getSimpleName() + " count").increment(1L);
}
Also used : Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) AccumuloElementConversionException(uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)

Aggregations

Key (org.apache.accumulo.core.data.Key)115 Value (org.apache.accumulo.core.data.Value)68 Test (org.junit.Test)66 Edge (uk.gov.gchq.gaffer.data.element.Edge)44 Range (org.apache.accumulo.core.data.Range)35 HashMap (java.util.HashMap)29 Text (org.apache.hadoop.io.Text)23 Element (uk.gov.gchq.gaffer.data.element.Element)23 Scanner (org.apache.accumulo.core.client.Scanner)19 Authorizations (org.apache.accumulo.core.security.Authorizations)18 Mutation (org.apache.accumulo.core.data.Mutation)17 Entity (uk.gov.gchq.gaffer.data.element.Entity)15 Entry (java.util.Map.Entry)14 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 Connector (org.apache.accumulo.core.client.Connector)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)11 ExprNodeColumnDesc (org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc)11 ExprNodeConstantDesc (org.apache.hadoop.hive.ql.plan.ExprNodeConstantDesc)11 ExprNodeDesc (org.apache.hadoop.hive.ql.plan.ExprNodeDesc)11