Search in sources :

Example 1 with IsFalse

use of uk.gov.gchq.koryphe.impl.predicate.IsFalse in project Gaffer by gchq.

the class WhileHandlerTest method shouldThrowExceptionWhenPredicateCannotAcceptInputType.

@Test
public void shouldThrowExceptionWhenPredicateCannotAcceptInputType() throws OperationException {
    // Given
    final Predicate predicate = new IsFalse();
    final Object input = new EntitySeed();
    final Conditional conditional = new Conditional(predicate);
    final Context context = mock(Context.class);
    final Store store = mock(Store.class);
    final While operation = new While.Builder<>().input(input).conditional(conditional).operation(new GetElements()).build();
    final WhileHandler handler = new WhileHandler();
    // When / Then
    try {
        handler.doOperation(operation, context, store);
        fail("Exception expected");
    } catch (final OperationException e) {
        assertTrue(e.getMessage().contains("The predicate '" + predicate.getClass().getSimpleName() + "' cannot accept an input of type '" + input.getClass().getSimpleName() + "'"));
    }
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) While(uk.gov.gchq.gaffer.operation.impl.While) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Predicate(java.util.function.Predicate) Test(org.junit.jupiter.api.Test)

Example 2 with IsFalse

use of uk.gov.gchq.koryphe.impl.predicate.IsFalse in project gaffer-doc by gchq.

the class IsFalseExample method isFalse.

public void isFalse() {
    // ---------------------------------------------------------
    final IsFalse function = new IsFalse();
    // ---------------------------------------------------------
    runExample(function, null, true, false, null, "true");
}
Also used : IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse)

Example 3 with IsFalse

use of uk.gov.gchq.koryphe.impl.predicate.IsFalse in project Gaffer by gchq.

the class JavaPredicateToParquetPredicate method getPrimitiveFilter.

public FilterPredicate getPrimitiveFilter(final Predicate filterFunction, final String selection, final String group, final SchemaUtils schemaUtils) throws SerialisationException {
    // All supported filters will be in the if else statement below
    if (filterFunction instanceof IsEqual) {
        final IsEqual isEqual = (IsEqual) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isEqual.getControlValue());
        return getIsEqualFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsLessThan) {
        final IsLessThan isLessThan = (IsLessThan) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isLessThan.getControlValue());
        if (isLessThan.getOrEqualTo()) {
            return getIsLessThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
        }
        return getIsLessThanFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsMoreThan) {
        final IsMoreThan isMoreThan = (IsMoreThan) filterFunction;
        final Object[] parquetObjects = schemaUtils.getConverter(group).gafferObjectToParquetObjects(selection, isMoreThan.getControlValue());
        if (isMoreThan.getOrEqualTo()) {
            return getIsMoreThanOrEqualToFilter(selection, parquetObjects, group, schemaUtils);
        }
        return getIsMoreThanFilter(selection, parquetObjects, group, schemaUtils);
    } else if (filterFunction instanceof IsTrue) {
        return eq(booleanColumn(selection), true);
    } else if (filterFunction instanceof IsFalse) {
        return eq(booleanColumn(selection), false);
    } else {
        fullyApplied = false;
        LOGGER.warn(filterFunction.getClass().getCanonicalName() + " is not a natively supported filter by the Parquet store, therefore execution will take longer to perform this filter.");
        return null;
    }
}
Also used : IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) IsFalse(uk.gov.gchq.koryphe.impl.predicate.IsFalse) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual)

Aggregations

IsFalse (uk.gov.gchq.koryphe.impl.predicate.IsFalse)3 Predicate (java.util.function.Predicate)1 Test (org.junit.jupiter.api.Test)1 OperationException (uk.gov.gchq.gaffer.operation.OperationException)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 While (uk.gov.gchq.gaffer.operation.impl.While)1 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)1 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)1 Context (uk.gov.gchq.gaffer.store.Context)1 Store (uk.gov.gchq.gaffer.store.Store)1 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)1 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)1 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)1 IsTrue (uk.gov.gchq.koryphe.impl.predicate.IsTrue)1