Search in sources :

Example 1 with Or

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

the class FederatedAddGraphHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.

@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
    store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
    final Schema expectedSchema = new Schema.Builder().build();
    assertEquals(0, store.getGraphs(testUser, null, ignore).size());
    final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
    new FederatedAddGraphHandler().doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
    assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
    assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Or(uk.gov.gchq.koryphe.impl.predicate.Or) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Example 2 with Or

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

the class OrExample method isLessThan2EqualTo5OrIsMoreThan10.

public void isLessThan2EqualTo5OrIsMoreThan10() {
    // ---------------------------------------------------------
    final Or function = new Or<>(new IsLessThan(2), new IsEqual(5), new IsMoreThan(10));
    // ---------------------------------------------------------
    runExample(function, "When using an Or predicate with a single selected value you can just use the constructor new Or(predicates))'", 1, 2, 3, 5, 15, 1L, 3L, 5L);
}
Also used : Or(uk.gov.gchq.koryphe.impl.predicate.Or) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual)

Example 3 with Or

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

the class OrExample method firstItemIsLessThan2OrSecondItemIsMoreThan10.

public void firstItemIsLessThan2OrSecondItemIsMoreThan10() {
    // ---------------------------------------------------------
    final Or function = new Or.Builder().select(0).execute(new IsLessThan(2)).select(1).execute(new IsMoreThan(10)).build();
    // ---------------------------------------------------------
    runExample(function, "When using an Or predicate with multiple selected values, you need to use the Or.Builder to build your Or predicate, using .select() then .execute(). " + "When selecting values in the Or.Builder you need to refer to the position in the input array. I.e to use the first value use position 0 - select(0)." + "You can select multiple values to give to a predicate like isXLessThanY, this is achieved by passing 2 positions to the select method - select(0, 1)", new Tuple2<>(1, 15), new Tuple2<>(1, 1), new Tuple2<>(15, 15), new Tuple2<>(15, 1), new Tuple2<>(1L, 15L), new Tuple1<>(1));
}
Also used : Or(uk.gov.gchq.koryphe.impl.predicate.Or) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 4 with Or

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

the class JavaPredicateToParquetPredicate method getParquetPredicate.

public FilterPredicate getParquetPredicate() throws SerialisationException {
    FilterPredicate filterResult;
    if (javaPredicate instanceof AgeOff) {
        filterResult = getAgeOffPredicate((AgeOff) javaPredicate, selection, group, schemaUtils);
    } else if (javaPredicate instanceof And) {
        final And and = (And) javaPredicate;
        filterResult = getAndFilter((List<Predicate>) and.getComponents(), selection, group, schemaUtils);
    } else if (javaPredicate instanceof Or) {
        final Or or = (Or) javaPredicate;
        filterResult = getOrFilter((List<Predicate>) or.getComponents(), selection, group, schemaUtils);
    } else if (javaPredicate instanceof Not) {
        final Not not = (Not) javaPredicate;
        final JavaPredicateToParquetPredicate predicateConverter = new JavaPredicateToParquetPredicate(schemaUtils, not.getPredicate(), selection, group);
        final FilterPredicate parquetPredicate = predicateConverter.getParquetPredicate();
        if (!predicateConverter.fullyApplied) {
            fullyApplied = false;
        }
        filterResult = FilterPredicateUtils.not(parquetPredicate);
    } else {
        filterResult = getPrimitiveFilter(javaPredicate, selection[0], group, schemaUtils);
    }
    return filterResult;
}
Also used : Not(uk.gov.gchq.koryphe.impl.predicate.Not) Or(uk.gov.gchq.koryphe.impl.predicate.Or) AgeOff(uk.gov.gchq.koryphe.impl.predicate.AgeOff) And(uk.gov.gchq.koryphe.impl.predicate.And) List(java.util.List) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) FilterPredicate(org.apache.parquet.filter2.predicate.FilterPredicate) TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Predicate(java.util.function.Predicate)

Example 5 with Or

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

the class FederatedAddGraphWithHooksHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.

@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
    store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
    final Schema expectedSchema = new Schema.Builder().build();
    assertEquals(0, store.getGraphs(testUser, null, ignore).size());
    final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
    new FederatedAddGraphWithHooksHandler().doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
    assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
    assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Or(uk.gov.gchq.koryphe.impl.predicate.Or) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AdaptedPredicate(uk.gov.gchq.koryphe.predicate.AdaptedPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) CallMethod(uk.gov.gchq.koryphe.impl.function.CallMethod) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Test(org.junit.jupiter.api.Test)

Aggregations

Or (uk.gov.gchq.koryphe.impl.predicate.Or)5 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)3 Test (org.junit.jupiter.api.Test)2 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)2 Context (uk.gov.gchq.gaffer.store.Context)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)2 CallMethod (uk.gov.gchq.koryphe.impl.function.CallMethod)2 IsLessThan (uk.gov.gchq.koryphe.impl.predicate.IsLessThan)2 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)2 AdaptedPredicate (uk.gov.gchq.koryphe.predicate.AdaptedPredicate)2 List (java.util.List)1 Predicate (java.util.function.Predicate)1 FilterPredicate (org.apache.parquet.filter2.predicate.FilterPredicate)1 AgeOff (uk.gov.gchq.koryphe.impl.predicate.AgeOff)1 And (uk.gov.gchq.koryphe.impl.predicate.And)1 Not (uk.gov.gchq.koryphe.impl.predicate.Not)1 TupleAdaptedPredicate (uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate)1