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;
}
}
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"))));
}
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);
}
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();
}
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);
}
Aggregations