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;
}
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:");
}
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);
}
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.");
}
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");
}
Aggregations