use of uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder in project Gaffer by gchq.
the class ClassicIteratorSettingsFactory method getEdgeEntityDirectionFilterIteratorSetting.
@Override
public IteratorSetting getEdgeEntityDirectionFilterIteratorSetting(final GetElementsOperation<?, ?> operation) {
final boolean includeEntities = operation.isIncludeEntities();
final IncludeEdgeType includeEdgeType = operation.getIncludeEdges();
final IncludeIncomingOutgoingType includeIncomingOutgoingType = operation.getIncludeIncomingOutGoing();
final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
if (includeIncomingOutgoingType == IncludeIncomingOutgoingType.BOTH && includeEdgeType == IncludeEdgeType.ALL && !deduplicateUndirectedEdges) {
return null;
}
return new IteratorSettingBuilder(AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.EDGE_ENTITY_DIRECTED_UNDIRECTED_INCOMING_OUTGOING_FILTER_ITERATOR_NAME, EDGE_DIRECTED_UNDIRECTED_FILTER).includeIncomingOutgoing(includeIncomingOutgoingType).includeEdges(includeEdgeType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
}
use of uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder in project Gaffer by gchq.
the class AbstractCoreKeyIteratorSettingsFactory method getQueryTimeAggregatorIteratorSetting.
@Override
public IteratorSetting getQueryTimeAggregatorIteratorSetting(final View view, final AccumuloStore store) throws IteratorSettingException {
if (!queryTimeAggregatorRequired(view, store)) {
LOGGER.debug("Returning null from getQueryTimeAggregatorIteratorSetting as queryTimeAggregatorRequired(view, store) = {}", queryTimeAggregatorRequired(view, store));
return null;
}
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.COLUMN_QUALIFIER_AGGREGATOR_ITERATOR_PRIORITY, AccumuloStoreConstants.COLUMN_QUALIFIER_AGGREGATOR_ITERATOR_NAME, CoreKeyGroupByAggregatorIterator.class).combinerColumnFamilies(store.getSchema().getAggregatedGroups()).schema(store.getSchema()).view(view).keyConverter(store.getKeyPackage().getKeyConverter()).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}, " + "combinerColumnFamilies = {}, schema = {}, view = {}, keyConverter = {}", CoreKeyGroupByAggregatorIterator.class.getName(), AccumuloStoreConstants.COLUMN_QUALIFIER_AGGREGATOR_ITERATOR_PRIORITY, store.getSchema().getAggregatedGroups(), store.getSchema(), view, store.getKeyPackage().getKeyConverter());
return is;
}
use of uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder in project Gaffer by gchq.
the class AbstractCoreKeyIteratorSettingsFactory method getBloomFilterIteratorSetting.
@Override
public IteratorSetting getBloomFilterIteratorSetting(final BloomFilter filter) throws IteratorSettingException {
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.BLOOM_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.BLOOM_FILTER_ITERATOR_NAME, CoreKeyBloomFilterIterator.class).bloomFilter(filter).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}", CoreKeyBloomFilterIterator.class.getName(), AccumuloStoreConstants.BLOOM_FILTER_ITERATOR_PRIORITY);
return is;
}
use of uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder in project Gaffer by gchq.
the class AbstractCoreKeyIteratorSettingsFactory method getElementPreAggregationFilterIteratorSetting.
@Override
public IteratorSetting getElementPreAggregationFilterIteratorSetting(final View view, final AccumuloStore store) throws IteratorSettingException {
if (!view.hasPreAggregationFilters()) {
LOGGER.debug("Returning null from getElementPreAggregationFilterIteratorSetting as view.hasPreAggregationFilters = {}", view.hasPreAggregationFilters());
return null;
}
final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.ELEMENT_PRE_AGGREGATION_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.ELEMENT_PRE_AGGREGATION_FILTER_ITERATOR_NAME, ElementPreAggregationFilter.class).schema(store.getSchema()).view(view).keyConverter(store.getKeyPackage().getKeyConverter()).build();
LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}, " + "schema = {}, view = {}, keyConverter = {}", ElementPreAggregationFilter.class.getName(), AccumuloStoreConstants.ELEMENT_PRE_AGGREGATION_FILTER_ITERATOR_PRIORITY, store.getSchema(), view, store.getKeyPackage().getKeyConverter());
return is;
}
use of uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder in project Gaffer by gchq.
the class CoreKeyGroupByAggregatorIteratorTest method shouldAggregateEverythingWhenGroupByIsSetToBlank.
public void shouldAggregateEverythingWhenGroupByIsSetToBlank(final AccumuloStore store, final AccumuloElementConverter elementConverter) throws StoreException {
final String visibilityString = "public";
try {
// Create edge
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 1).build();
final Edge edge2 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 1).build();
final Edge edge3 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 1).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 1).build();
// THIS EDGE WILL BE REDUCED MEANING ITS CQ (columnQualifier) will only occur once because its key is equal.
final Edge edge4 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 1).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 4).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 2).build();
final Edge edge5 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 3).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 5).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 10).build();
final Edge edge6 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 3).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 5).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).property(AccumuloPropertyNames.COUNT, 5).build();
// Accumulo key
final Key key = elementConverter.getKeysFromEdge(edge).getFirst();
final Key key2 = elementConverter.getKeysFromEdge(edge2).getFirst();
final Key key3 = elementConverter.getKeysFromEdge(edge3).getFirst();
final Key key4 = elementConverter.getKeysFromEdge(edge4).getFirst();
final Key key5 = elementConverter.getKeysFromEdge(edge5).getFirst();
final Key key6 = elementConverter.getKeysFromEdge(edge6).getFirst();
// Accumulo values
final Value value1 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge.getProperties());
final Value value2 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge2.getProperties());
final Value value3 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge3.getProperties());
final Value value4 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge4.getProperties());
final Value value5 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge5.getProperties());
final Value value6 = elementConverter.getValueFromProperties(TestGroups.EDGE, edge6.getProperties());
// Create mutation
final Mutation m1 = new Mutation(key.getRow());
m1.put(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp(), value1);
final Mutation m2 = new Mutation(key2.getRow());
m2.put(key2.getColumnFamily(), key2.getColumnQualifier(), new ColumnVisibility(key2.getColumnVisibility()), key2.getTimestamp(), value2);
final Mutation m3 = new Mutation(key.getRow());
m3.put(key3.getColumnFamily(), key3.getColumnQualifier(), new ColumnVisibility(key3.getColumnVisibility()), key3.getTimestamp(), value3);
final Mutation m4 = new Mutation(key.getRow());
m4.put(key4.getColumnFamily(), key4.getColumnQualifier(), new ColumnVisibility(key4.getColumnVisibility()), key4.getTimestamp(), value4);
final Mutation m5 = new Mutation(key.getRow());
m5.put(key5.getColumnFamily(), key5.getColumnQualifier(), new ColumnVisibility(key5.getColumnVisibility()), key5.getTimestamp(), value5);
final Mutation m6 = new Mutation(key.getRow());
m6.put(key6.getColumnFamily(), key6.getColumnQualifier(), new ColumnVisibility(key6.getColumnVisibility()), key6.getTimestamp(), value6);
// Write mutation
final BatchWriterConfig writerConfig = new BatchWriterConfig();
writerConfig.setMaxMemory(1000000L);
writerConfig.setMaxLatency(1000L, TimeUnit.MILLISECONDS);
writerConfig.setMaxWriteThreads(1);
final BatchWriter writer = store.getConnection().createBatchWriter(store.getTableName(), writerConfig);
writer.addMutation(m1);
writer.addMutation(m2);
writer.addMutation(m3);
writer.addMutation(m4);
writer.addMutation(m5);
writer.addMutation(m6);
writer.close();
Edge expectedEdge1 = new Edge.Builder().group(TestGroups.EDGE).source("1").dest("2").directed(true).property(AccumuloPropertyNames.COLUMN_QUALIFIER, 5).property(AccumuloPropertyNames.COLUMN_QUALIFIER_2, 10).property(AccumuloPropertyNames.COUNT, 20).property(AccumuloPropertyNames.PROP_1, 0).property(AccumuloPropertyNames.PROP_2, 0).property(AccumuloPropertyNames.PROP_3, 0).property(AccumuloPropertyNames.PROP_4, 0).build();
// Read data back and check we get one merged element
final Authorizations authorizations = new Authorizations(visibilityString);
final Scanner scanner = store.getConnection().createScanner(store.getTableName(), authorizations);
final IteratorSetting iteratorSetting = new IteratorSettingBuilder(AccumuloStoreConstants.COLUMN_QUALIFIER_AGGREGATOR_ITERATOR_PRIORITY, "KeyCombiner", CoreKeyGroupByAggregatorIterator.class).all().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().groupBy().build()).build()).schema(store.getSchema()).keyConverter(store.getKeyPackage().getKeyConverter()).build();
scanner.addScanIterator(iteratorSetting);
final Iterator<Entry<Key, Value>> it = scanner.iterator();
Entry<Key, Value> entry = it.next();
Element readEdge = elementConverter.getFullElement(entry.getKey(), entry.getValue(), false);
assertEquals(expectedEdge1, readEdge);
assertEquals(5, readEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER));
assertEquals(10, readEdge.getProperty(AccumuloPropertyNames.COLUMN_QUALIFIER_2));
assertEquals(20, readEdge.getProperty(AccumuloPropertyNames.COUNT));
if (it.hasNext()) {
fail("Additional row found.");
}
} catch (final AccumuloException | TableNotFoundException e) {
fail(this.getClass().getSimpleName() + " failed with exception: " + e);
}
}
Aggregations