Search in sources :

Example 1 with ChainedIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.

the class GetTraitsHandler method createCurrentTraits.

private Set<StoreTrait> createCurrentTraits(final Store store) {
    final Set<StoreTrait> traits = Sets.newHashSet(store.getTraits());
    final Schema schema = store.getSchema();
    final boolean hasAggregatedGroups = isNotEmpty(schema.getAggregatedGroups());
    final boolean hasVisibility = nonNull(schema.getVisibilityProperty());
    boolean hasGroupBy = false;
    boolean hasValidation = false;
    for (final SchemaElementDefinition def : new ChainedIterable<SchemaElementDefinition>(schema.getEntities().values(), schema.getEdges().values())) {
        hasValidation = hasValidation || def.hasValidation();
        hasGroupBy = hasGroupBy || isNotEmpty(def.getGroupBy());
        if (hasGroupBy && hasValidation) {
            break;
        }
    }
    if (!hasAggregatedGroups) {
        traits.remove(StoreTrait.INGEST_AGGREGATION);
        traits.remove(StoreTrait.QUERY_AGGREGATION);
    }
    if (!hasGroupBy && traits.contains(StoreTrait.INGEST_AGGREGATION)) {
        traits.remove(StoreTrait.QUERY_AGGREGATION);
    }
    if (!hasValidation) {
        traits.remove(StoreTrait.STORE_VALIDATION);
    }
    if (!hasVisibility) {
        traits.remove(StoreTrait.VISIBILITY);
    }
    return traits;
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 2 with ChainedIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.

the class RoadTrafficCsvElementGenerator method _apply.

@Override
public Iterable<Element> _apply(final CSVRecord record) {
    // Check that the record has the expected number of fields
    if (!record.isConsistent()) {
        return Collections.emptyList();
    }
    final FreqMap vehicleCountsByType = getVehicleCounts(record);
    final Date startDate = getDate(record.get(dCount.fieldName()), record.get(Hour.fieldName()));
    final Date endDate = null != startDate ? DateUtils.addMilliseconds(DateUtils.addHours(startDate, 1), -1) : null;
    final String region = record.get(Region_Name.fieldName());
    final String location = record.get(ONS_LA_Name.fieldName());
    final String road = record.get(Road.fieldName());
    final String junctionA = road + ":" + record.get(A_Junction.fieldName());
    final String junctionB = road + ":" + record.get(B_Junction.fieldName());
    final String junctionALocation = record.get(A_Ref_E.fieldName()) + "," + record.get(A_Ref_N.fieldName());
    final String junctionBLocation = record.get(B_Ref_E.fieldName()) + "," + record.get(B_Ref_N.fieldName());
    final List<Edge> edges = Arrays.asList(new Edge.Builder().group(ElementGroup.REGION_CONTAINS_LOCATION).source(region).dest(location).directed(true).build(), new Edge.Builder().group(ElementGroup.LOCATION_CONTAINS_ROAD).source(location).dest(road).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_HAS_JUNCTION).source(road).dest(junctionA).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_HAS_JUNCTION).source(road).dest(junctionB).directed(true).build(), new Edge.Builder().group(ElementGroup.JUNCTION_LOCATED_AT).source(junctionA).dest(junctionALocation).directed(true).build(), new Edge.Builder().group(ElementGroup.JUNCTION_LOCATED_AT).source(junctionB).dest(junctionBLocation).directed(true).build(), new Edge.Builder().group(ElementGroup.ROAD_USE).source(junctionA).dest(junctionB).directed(true).property("startDate", startDate).property("endDate", endDate).property("count", getTotalCount(vehicleCountsByType)).property("countByVehicleType", vehicleCountsByType).build());
    final List<Entity> entities = Arrays.asList(new Entity.Builder().group(ElementGroup.JUNCTION_USE).vertex(junctionA).property("countByVehicleType", vehicleCountsByType).property("startDate", startDate).property("endDate", endDate).property("count", getTotalCount(vehicleCountsByType)).build(), new Entity.Builder().group(ElementGroup.JUNCTION_USE).vertex(junctionB).property("countByVehicleType", vehicleCountsByType).property("endDate", endDate).property("startDate", startDate).property("count", getTotalCount(vehicleCountsByType)).build());
    final List<Entity> cardinalityEntities = createCardinalities(edges);
    // Create an iterable containing all the edges and entities
    return new ChainedIterable<>(edges, entities, cardinalityEntities);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) Edge(uk.gov.gchq.gaffer.data.element.Edge) Date(java.util.Date)

Example 3 with ChainedIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.

the class AccumuloStore method validateSchema.

@Override
protected void validateSchema(final ValidationResult validationResult, final Serialiser serialiser) {
    super.validateSchema(validationResult, serialiser);
    final String timestampProperty = getSchema().getConfig(AccumuloStoreConstants.TIMESTAMP_PROPERTY);
    if (null != timestampProperty) {
        final Iterable<SchemaElementDefinition> defs = new ChainedIterable<>(getSchema().getEntities().values(), getSchema().getEdges().values());
        for (final SchemaElementDefinition def : defs) {
            final TypeDefinition typeDef = def.getPropertyTypeDef(timestampProperty);
            if (null != typeDef && null != typeDef.getAggregateFunction() && !(typeDef.getAggregateFunction() instanceof Max)) {
                validationResult.addError("The aggregator for the " + timestampProperty + " property must be set to: " + Max.class.getName() + " this cannot be overridden for this Accumulo Store, as you have told Accumulo to store this property in the timestamp column.");
            }
        }
    }
}
Also used : Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 4 with ChainedIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.

the class FederatedGetAllElementsHandlerTest method validateMergeResultsFromFieldObjects.

@Override
protected boolean validateMergeResultsFromFieldObjects(final CloseableIterable<? extends Element> result, final Object... resultParts) {
    assertNotNull(result);
    final Iterable[] resultPartItrs = Arrays.copyOf(resultParts, resultParts.length, Iterable[].class);
    final ArrayList<Object> elements = Lists.newArrayList(new ChainedIterable<>(resultPartItrs));
    int i = 0;
    for (Element e : result) {
        assertTrue(e instanceof Entity);
        elements.contains(e);
        i++;
    }
    assertEquals(elements.size(), i);
    return true;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) Element(uk.gov.gchq.gaffer.data.element.Element)

Example 5 with ChainedIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable in project Gaffer by gchq.

the class FederatedGetElementsHandlerTest method validateMergeResultsFromFieldObjects.

@Override
protected boolean validateMergeResultsFromFieldObjects(final CloseableIterable<? extends Element> result, final Object... resultParts) {
    assertNotNull(result);
    final Iterable[] resultPartItrs = Arrays.copyOf(resultParts, resultParts.length, Iterable[].class);
    final ArrayList<Object> elements = Lists.newArrayList(new ChainedIterable<>(resultPartItrs));
    int i = 0;
    for (Element e : result) {
        assertTrue(e instanceof Entity);
        elements.contains(e);
        i++;
    }
    assertEquals(elements.size(), i);
    return true;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ChainedIterable(uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable) Element(uk.gov.gchq.gaffer.data.element.Element)

Aggregations

ChainedIterable (uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable)9 Entity (uk.gov.gchq.gaffer.data.element.Entity)5 Element (uk.gov.gchq.gaffer.data.element.Element)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)2 FreqMap (uk.gov.gchq.gaffer.types.FreqMap)2 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)1 StoreTrait (uk.gov.gchq.gaffer.store.StoreTrait)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)1 Max (uk.gov.gchq.koryphe.impl.binaryoperator.Max)1