Search in sources :

Example 6 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class ElementSerialisation method getColumnVisibility.

public byte[] getColumnVisibility(final String group, final Properties properties) throws SerialisationException {
    final SchemaElementDefinition elementDefinition = schema.getElement(group);
    if (null == elementDefinition) {
        throw new SerialisationException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
    }
    if (null != schema.getVisibilityProperty()) {
        final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
        if (null != propertyDef) {
            final Object property = properties.get(schema.getVisibilityProperty());
            final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
            if (null != property) {
                try {
                    return serialiser.serialise(property);
                } catch (final SerialisationException e) {
                    throw new SerialisationException(e.getMessage(), e);
                }
            } else {
                return serialiser.serialiseNull();
            }
        }
    }
    return HBaseStoreConstants.EMPTY_BYTES;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ToBytesSerialiser(uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition)

Example 7 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class FilterHandlerTest method shouldFailValidationWhenTypeArgumentOfPredicateIsIncorrect.

@Test
public void shouldFailValidationWhenTypeArgumentOfPredicateIsIncorrect() {
    // Given
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("junctionA").destination("junctionB").property(TestPropertyNames.COUNT, "count.long").build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("junctionA").destination("junctionB").property(TestPropertyNames.COUNT, "count.long").build()).type("count.long", new TypeDefinition(Long.class)).build();
    given(store.getSchema()).willReturn(schema);
    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").property(TestPropertyNames.COUNT, 2L).build();
    final Edge edge1 = new Edge.Builder().group(TestGroups.EDGE).source("junctionA").dest("junctionB").property(TestPropertyNames.COUNT, 1L).build();
    input.add(edge);
    input.add(edge1);
    final Filter filter = new Filter.Builder().input(input).globalEdges(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan("abcd")).build()).build();
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(filter, context, store)).withMessageContaining("is not compatible with the input type:");
}
Also used : Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 8 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class FilterHandlerTest method shouldFilterBasedOnAdjacentMatchedVertex.

@Test
public void shouldFilterBasedOnAdjacentMatchedVertex() throws OperationException {
    // Given
    final Schema schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().source("vertex").destination("vertex").property(TestPropertyNames.COUNT, "count.long").build()).type("vertex", new TypeDefinition(String.class)).type("count.long", new TypeDefinition(Long.class)).build();
    given(store.getSchema()).willReturn(schema);
    final Filter filter = new Filter.Builder().input(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal2").dest("destVal2").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal4").dest("destVal4").matchedVertex(EdgeId.MatchedVertex.DESTINATION).build()).edge(TestGroups.EDGE, new ElementFilter.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new IsIn("destVal1", "srcVal3")).build()).build();
    // When
    final Iterable<? extends Element> results = handler.doOperation(filter, context, store);
    // Then
    ElementUtil.assertElementEquals(Arrays.asList(new Edge.Builder().group(TestGroups.EDGE).source("srcVal1").dest("destVal1").matchedVertex(EdgeId.MatchedVertex.SOURCE).build(), new Edge.Builder().group(TestGroups.EDGE).source("srcVal3").dest("destVal3").matchedVertex(EdgeId.MatchedVertex.SOURCE).build()), results);
}
Also used : Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) Edge(uk.gov.gchq.gaffer.data.element.Edge) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Example 9 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class AggregateHandlerTest method shouldFailValidationWhenTypeArgumentOfBinaryOperatorInFunctionIsIncorrect.

@Test
public void shouldFailValidationWhenTypeArgumentOfBinaryOperatorInFunctionIsIncorrect() {
    // Given
    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.TIMESTAMP, "timestamp.long").build()).type("timestamp.long", new TypeDefinition(Long.class)).build();
    given(store.getSchema()).willReturn(schema);
    input.add(entity);
    input.add(entity1);
    input.add(entity2);
    entities.put(TestGroups.ENTITY, new AggregatePair(new ElementAggregator.Builder().select(TestPropertyNames.TIMESTAMP).execute(new Or()).build()));
    final Aggregate aggregate = new Aggregate.Builder().input(input).entities(entities).build();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(aggregate, context, store)).withMessageContaining("Incompatible types.");
}
Also used : Or(uk.gov.gchq.koryphe.impl.binaryoperator.Or) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AggregatePair(uk.gov.gchq.gaffer.operation.util.AggregatePair) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 10 with TypeDefinition

use of uk.gov.gchq.gaffer.store.schema.TypeDefinition in project Gaffer by gchq.

the class TransformHandlerTest method shouldFailValidationWhenFunctionSignatureIsInvalid.

@Test
public void shouldFailValidationWhenFunctionSignatureIsInvalid() {
    // Given
    final Schema schema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property(TestPropertyNames.PROP_1, TestPropertyNames.STRING).build()).type(TestPropertyNames.STRING, new TypeDefinition(String.class)).build();
    given(store.getSchema()).willReturn(schema);
    final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
    final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
    final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(new Divide()).project(TestPropertyNames.PROP_3).build();
    input.add(entity);
    input.add(entity1);
    final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
    // When / Then
    assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(transform, context, store)).withMessageContaining("Incompatible number of types");
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Divide(uk.gov.gchq.koryphe.impl.function.Divide) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)18 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)9 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)9 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)8 Test (org.junit.jupiter.api.Test)5 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 IOException (java.io.IOException)3 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)3 Edge (uk.gov.gchq.gaffer.data.element.Edge)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 Filter (uk.gov.gchq.gaffer.operation.impl.function.Filter)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)2 IsIn (uk.gov.gchq.koryphe.impl.predicate.IsIn)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MessageType (org.apache.parquet.schema.MessageType)1 ChainedIterable (uk.gov.gchq.gaffer.commonutil.iterable.ChainedIterable)1