Search in sources :

Example 1 with OperationChainOptimiser

use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.

the class OperationChainHandler method prepareOperationChain.

public <O> OperationChain<O> prepareOperationChain(final OperationChain<O> operationChain, final Context context, final Store store) {
    final ValidationResult validationResult = opChainValidator.validate(operationChain, context.getUser(), store);
    if (!validationResult.isValid()) {
        throw new IllegalArgumentException("Operation chain is invalid. " + validationResult.getErrorString());
    }
    OperationChain<O> optimisedOperationChain = operationChain;
    for (final OperationChainOptimiser opChainOptimiser : opChainOptimisers) {
        optimisedOperationChain = opChainOptimiser.optimise(optimisedOperationChain);
    }
    return optimisedOperationChain;
}
Also used : ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)

Example 2 with OperationChainOptimiser

use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.

the class OperationChainHandlerTest method shouldHandleNestedOperationChain.

@Test
public void shouldHandleNestedOperationChain() throws OperationException {
    // Given
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final StoreProperties storeProperties = new StoreProperties();
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final GetElements op2 = mock(GetElements.class);
    final Limit op3 = mock(Limit.class);
    final OperationChain opChain1 = new OperationChain(Arrays.asList(op1, op2));
    final OperationChain opChain2 = new OperationChain(Arrays.asList(opChain1, op3));
    final Entity entityA = new Entity.Builder().group(TestGroups.ENTITY).vertex("A").build();
    final Entity entityB = new Entity.Builder().group(TestGroups.ENTITY).vertex("B").build();
    given(context.getUser()).willReturn(user);
    given(store.getProperties()).willReturn(storeProperties);
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(new EntitySeed("A"), new EntitySeed("B"))));
    given(store.handleOperation(op2, context)).willReturn(new WrappedCloseableIterable<>(Lists.newArrayList(entityA, entityB)));
    given(store.handleOperation(op3, context)).willReturn(entityA);
    // When
    final Object result = opChainHandler.doOperation(opChain2, context, store);
    // Then
    assertSame(entityA, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 3 with OperationChainOptimiser

use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.

the class Store method prepareOperationChain.

protected <OUTPUT> OperationChain<OUTPUT> prepareOperationChain(final OperationChain<OUTPUT> operationChain, final Context context) {
    validateOperationChain(operationChain, context.getUser());
    OperationChain<OUTPUT> optimisedOperationChain = operationChain;
    for (final OperationChainOptimiser opChainOptimiser : opChainOptimisers) {
        optimisedOperationChain = opChainOptimiser.optimise(optimisedOperationChain);
    }
    return optimisedOperationChain;
}
Also used : CoreOperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.CoreOperationChainOptimiser) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)

Example 4 with OperationChainOptimiser

use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.

the class OperationChainHandlerTest method shouldHandleOperationChain.

@Test
public void shouldHandleOperationChain() throws OperationException {
    // Given
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final StoreProperties storeProperties = new StoreProperties();
    final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
    final GetElements op2 = mock(GetElements.class);
    final OperationChain opChain = new OperationChain(Arrays.asList(op1, op2));
    final Entity expectedResult = new Entity(TestGroups.ENTITY);
    given(context.getUser()).willReturn(user);
    given(store.getProperties()).willReturn(storeProperties);
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    given(store.handleOperation(op1, context)).willReturn(new WrappedCloseableIterable<>(Collections.singletonList(new EntitySeed())));
    given(store.handleOperation(op2, context)).willReturn(expectedResult);
    // When
    final Object result = opChainHandler.doOperation(opChain, context, store);
    // Then
    assertSame(expectedResult, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 5 with OperationChainOptimiser

use of uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser in project Gaffer by gchq.

the class OperationChainHandlerTest method shouldHandleNonInputOperation.

@Test
public void shouldHandleNonInputOperation() throws OperationException {
    // Given
    final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
    final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
    final OperationChainHandler opChainHandler = new OperationChainHandler(opChainValidator, opChainOptimisers);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final User user = mock(User.class);
    final StoreProperties storeProperties = new StoreProperties();
    final GetAllElements op = mock(GetAllElements.class);
    final OperationChain opChain = new OperationChain(Collections.singletonList(op));
    final Entity expectedResult = new Entity(TestGroups.ENTITY);
    given(context.getUser()).willReturn(user);
    given(store.getProperties()).willReturn(storeProperties);
    given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
    given(store.handleOperation(op, context)).willReturn(expectedResult);
    // When
    final Object result = opChainHandler.doOperation(opChain, context, store);
    // Then
    assertSame(expectedResult, result);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)7 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)6 Test (org.junit.jupiter.api.Test)5 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)5 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 Context (uk.gov.gchq.gaffer.store.Context)3 Store (uk.gov.gchq.gaffer.store.Store)3 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)3 User (uk.gov.gchq.gaffer.user.User)3 Set (java.util.Set)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Map (uk.gov.gchq.gaffer.operation.impl.Map)2 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)2 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)2 ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)2 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)2 FirstItem (uk.gov.gchq.koryphe.impl.function.FirstItem)2 IterableFunction (uk.gov.gchq.koryphe.impl.function.IterableFunction)2 Edge (uk.gov.gchq.gaffer.data.element.Edge)1