Search in sources :

Example 21 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class Store method validateSchemas.

public void validateSchemas() {
    final ValidationResult validationResult = new ValidationResult();
    if (null == schema) {
        validationResult.addError("Schema is missing");
    } else {
        validationResult.add(schema.validate());
        getSchemaElements().forEach((key, value) -> value.getProperties().forEach(propertyName -> {
            final Class propertyClass = value.getPropertyClass(propertyName);
            final Serialiser serialisation = value.getPropertyTypeDef(propertyName).getSerialiser();
            if (null == serialisation) {
                validationResult.addError(String.format("Could not find a serialiser for property '%s' in the group '%s'.", propertyName, key));
            } else if (!serialisation.canHandle(propertyClass)) {
                validationResult.addError(String.format("Schema serialiser (%s) for property '%s' in the group '%s' cannot handle property found in the schema", serialisation.getClass().getName(), propertyName, key));
            }
        }));
        validateSchema(validationResult, getSchema().getVertexSerialiser());
        getSchema().getTypes().forEach((k, v) -> validateSchema(validationResult, v.getSerialiser()));
    }
    if (!validationResult.isValid()) {
        throw new SchemaException("Schema is not valid. " + validationResult.getErrorString());
    }
}
Also used : GetExportsHandler(uk.gov.gchq.gaffer.store.operation.handler.export.GetExportsHandler) SetVariable(uk.gov.gchq.gaffer.operation.impl.SetVariable) Collections.unmodifiableList(java.util.Collections.unmodifiableList) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) GenerateElements(uk.gov.gchq.gaffer.operation.impl.generate.GenerateElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Max(uk.gov.gchq.gaffer.operation.impl.compare.Max) Element(uk.gov.gchq.gaffer.data.element.Element) GetJobResultsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobResultsHandler) DiscardOutputHandler(uk.gov.gchq.gaffer.store.operation.handler.DiscardOutputHandler) SortHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.SortHandler) SchemaOptimiser(uk.gov.gchq.gaffer.store.schema.SchemaOptimiser) ValidateOperationChainHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateOperationChainHandler) ToArrayHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToArrayHandler) SetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.SetVariableHandler) Map(java.util.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Count(uk.gov.gchq.gaffer.operation.impl.Count) DeleteNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedViewHandler) ToEntitySeedsHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToEntitySeedsHandler) ToSingletonList(uk.gov.gchq.gaffer.operation.impl.output.ToSingletonList) MaxHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MaxHandler) ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) OperationDeclaration(uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclaration) AddSchemaToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddSchemaToLibraryHandler) ToEntitySeeds(uk.gov.gchq.gaffer.operation.impl.output.ToEntitySeeds) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) ForEachHandler(uk.gov.gchq.gaffer.store.operation.handler.ForEachHandler) LimitHandler(uk.gov.gchq.gaffer.store.operation.handler.LimitHandler) AddNamedViewHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedViewHandler) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Set(java.util.Set) ToListHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToListHandler) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) ReflectionUtil(uk.gov.gchq.koryphe.util.ReflectionUtil) OperationChainDAO(uk.gov.gchq.gaffer.operation.OperationChainDAO) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) AddNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.AddNamedOperationHandler) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OutputOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OutputOperationHandler) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) IfHandler(uk.gov.gchq.gaffer.store.operation.handler.IfHandler) JobTracker(uk.gov.gchq.gaffer.jobtracker.JobTracker) GetAllNamedViews(uk.gov.gchq.gaffer.named.view.GetAllNamedViews) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) FilterHandler(uk.gov.gchq.gaffer.store.operation.handler.function.FilterHandler) GetVariables(uk.gov.gchq.gaffer.operation.impl.GetVariables) ArrayList(java.util.ArrayList) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) LinkedHashMap(java.util.LinkedHashMap) GetVariable(uk.gov.gchq.gaffer.operation.impl.GetVariable) Transform(uk.gov.gchq.gaffer.operation.impl.function.Transform) ToStreamHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToStreamHandler) GetAllNamedOperations(uk.gov.gchq.gaffer.named.operation.GetAllNamedOperations) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) DeleteNamedOperation(uk.gov.gchq.gaffer.named.operation.DeleteNamedOperation) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) StreamSupport(java.util.stream.StreamSupport) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) Aggregate(uk.gov.gchq.gaffer.operation.impl.function.Aggregate) LinkedHashSet(java.util.LinkedHashSet) CancelScheduledJobHandler(uk.gov.gchq.gaffer.store.operation.handler.job.CancelScheduledJobHandler) Properties(java.util.Properties) OperationUtil(uk.gov.gchq.gaffer.store.operation.OperationUtil) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) AddStorePropertiesToLibraryHandler(uk.gov.gchq.gaffer.store.operation.handler.AddStorePropertiesToLibraryHandler) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) ToSingletonListHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToSingletonListHandler) MinHandler(uk.gov.gchq.gaffer.store.operation.handler.compare.MinHandler) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) OperationChainHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationChainHandler) AddStorePropertiesToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddStorePropertiesToLibrary) OperationHandler(uk.gov.gchq.gaffer.store.operation.handler.OperationHandler) JoinHandler(uk.gov.gchq.gaffer.store.operation.handler.join.JoinHandler) GetTraitsHandler(uk.gov.gchq.gaffer.store.operation.handler.GetTraitsHandler) GenerateElementsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateElementsHandler) Job(uk.gov.gchq.gaffer.jobtracker.Job) GetJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetJobDetailsHandler) LoggerFactory(org.slf4j.LoggerFactory) ToCsvHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToCsvHandler) ToCsv(uk.gov.gchq.gaffer.operation.impl.output.ToCsv) WhileHandler(uk.gov.gchq.gaffer.store.operation.handler.WhileHandler) GetVariableHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariableHandler) OperationDeclarations(uk.gov.gchq.gaffer.store.operation.declaration.OperationDeclarations) Filter(uk.gov.gchq.gaffer.operation.impl.function.Filter) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) GetAllNamedViewsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedViewsHandler) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ToStream(uk.gov.gchq.gaffer.operation.impl.output.ToStream) MapHandler(uk.gov.gchq.gaffer.store.operation.handler.MapHandler) GetAllNamedOperationsHandler(uk.gov.gchq.gaffer.store.operation.handler.named.GetAllNamedOperationsHandler) CacheServiceLoader(uk.gov.gchq.gaffer.cache.CacheServiceLoader) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) GetSetExport(uk.gov.gchq.gaffer.operation.impl.export.set.GetSetExport) GetTraits(uk.gov.gchq.gaffer.store.operation.GetTraits) GenerateObjectsHandler(uk.gov.gchq.gaffer.store.operation.handler.generate.GenerateObjectsHandler) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) ToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToSetHandler) GetExports(uk.gov.gchq.gaffer.operation.impl.export.GetExports) Join(uk.gov.gchq.gaffer.operation.impl.join.Join) List(java.util.List) AddSchemaToLibrary(uk.gov.gchq.gaffer.store.operation.add.AddSchemaToLibrary) ToVerticesHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToVerticesHandler) ReduceHandler(uk.gov.gchq.gaffer.store.operation.handler.ReduceHandler) CloseableUtil(uk.gov.gchq.gaffer.commonutil.CloseableUtil) OperationException(uk.gov.gchq.gaffer.operation.OperationException) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) CountHandler(uk.gov.gchq.gaffer.store.operation.handler.CountHandler) DeleteNamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.DeleteNamedOperationHandler) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) ToList(uk.gov.gchq.gaffer.operation.impl.output.ToList) Operations(uk.gov.gchq.gaffer.operation.Operations) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) GetSetExportHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.GetSetExportHandler) AggregateHandler(uk.gov.gchq.gaffer.store.operation.handler.function.AggregateHandler) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) GetAllJobDetailsHandler(uk.gov.gchq.gaffer.store.operation.handler.job.GetAllJobDetailsHandler) User(uk.gov.gchq.gaffer.user.User) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) GetWalksHandler(uk.gov.gchq.gaffer.store.operation.handler.GetWalksHandler) DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) GetJobResults(uk.gov.gchq.gaffer.operation.impl.job.GetJobResults) ExportToSetHandler(uk.gov.gchq.gaffer.store.operation.handler.export.set.ExportToSetHandler) Input(uk.gov.gchq.gaffer.operation.io.Input) NamedOperationHandler(uk.gov.gchq.gaffer.store.operation.handler.named.NamedOperationHandler) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) ToMapHandler(uk.gov.gchq.gaffer.store.operation.handler.output.ToMapHandler) Output(uk.gov.gchq.gaffer.operation.io.Output) While(uk.gov.gchq.gaffer.operation.impl.While) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Logger(org.slf4j.Logger) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) JobStatus(uk.gov.gchq.gaffer.jobtracker.JobStatus) TransformHandler(uk.gov.gchq.gaffer.store.operation.handler.function.TransformHandler) ValidateHandler(uk.gov.gchq.gaffer.store.operation.handler.ValidateHandler) ExecutorService(uk.gov.gchq.gaffer.commonutil.ExecutorService) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) Reduce(uk.gov.gchq.gaffer.operation.impl.Reduce) GetSchemaHandler(uk.gov.gchq.gaffer.store.operation.handler.GetSchemaHandler) GetVariablesHandler(uk.gov.gchq.gaffer.store.operation.handler.GetVariablesHandler) Min(uk.gov.gchq.gaffer.operation.impl.compare.Min) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) ValidationResult(uk.gov.gchq.koryphe.ValidationResult)

Example 22 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class Store method validateSchemaElementDefinition.

protected void validateSchemaElementDefinition(final Map.Entry<String, SchemaElementDefinition> schemaElementDefinitionEntry, final ValidationResult validationResult) {
    schemaElementDefinitionEntry.getValue().getProperties().forEach(propertyName -> {
        final Class propertyClass = schemaElementDefinitionEntry.getValue().getPropertyClass(propertyName);
        final Serialiser serialisation = schemaElementDefinitionEntry.getValue().getPropertyTypeDef(propertyName).getSerialiser();
        if (null == serialisation) {
            validationResult.addError(String.format("Could not find a serialiser for property '%s' in the group '%s'.", propertyName, schemaElementDefinitionEntry.getKey()));
        } else if (!serialisation.canHandle(propertyClass)) {
            validationResult.addError(String.format("Schema serialiser (%s) for property '%s' in the group '%s' cannot handle property found in the schema", serialisation.getClass().getName(), propertyName, schemaElementDefinitionEntry.getKey()));
        }
    });
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser)

Example 23 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class AccumuloStoreTest method shouldAllowRangeScanOperationsWhenVertexSerialiserDoesPreserveObjectOrdering.

@Test
public void shouldAllowRangeScanOperationsWhenVertexSerialiserDoesPreserveObjectOrdering() throws StoreException {
    // Given
    final AccumuloStore store = new AccumuloStore();
    final Serialiser serialiser = new StringSerialiser();
    store.preInitialise(BYTE_ENTITY_GRAPH, new Schema.Builder().vertexSerialiser(serialiser).build(), PROPERTIES);
    // When
    final boolean isGetElementsInRangesSupported = store.isSupported(GetElementsInRanges.class);
    final boolean isSummariseGroupOverRangesSupported = store.isSupported(SummariseGroupOverRanges.class);
    // Then
    assertTrue(isGetElementsInRangesSupported);
    assertTrue(isSummariseGroupOverRangesSupported);
}
Also used : StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) CompactRawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.CompactRawLongSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.jupiter.api.Test)

Example 24 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class AccumuloStoreTest method shouldNotAllowRangeScanOperationsWhenVertexSerialiserDoesNotPreserveObjectOrdering.

@Test
public void shouldNotAllowRangeScanOperationsWhenVertexSerialiserDoesNotPreserveObjectOrdering() throws StoreException {
    // Given
    final AccumuloStore store = new AccumuloStore();
    final Serialiser serialiser = new CompactRawLongSerialiser();
    store.preInitialise(BYTE_ENTITY_GRAPH, new Schema.Builder().vertexSerialiser(serialiser).build(), PROPERTIES);
    // When
    final boolean isGetElementsInRangesSupported = store.isSupported(GetElementsInRanges.class);
    final boolean isSummariseGroupOverRangesSupported = store.isSupported(SummariseGroupOverRanges.class);
    // Then
    assertFalse(isGetElementsInRangesSupported);
    assertFalse(isSummariseGroupOverRangesSupported);
}
Also used : Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) JavaSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser) CompactRawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.CompactRawLongSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) CompactRawLongSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.raw.CompactRawLongSerialiser) Test(org.junit.jupiter.api.Test)

Example 25 with Serialiser

use of uk.gov.gchq.gaffer.serialisation.Serialiser in project Gaffer by gchq.

the class HBaseSerialisationFactoryTest method shouldReturnCustomSerialiserForCustomClass.

@Test
public void shouldReturnCustomSerialiserForCustomClass() throws SerialisationException {
    // Given
    final SerialisationFactory factory = new HBaseSerialisationFactory();
    final Class<?> clazz = HyperLogLogPlus.class;
    // When
    final Serialiser serialiser = factory.getSerialiser(clazz);
    // Then
    assertTrue(serialiser.canHandle(clazz));
    assertEquals(HyperLogLogPlusSerialiser.class, serialiser.getClass());
}
Also used : HyperLogLogPlus(com.clearspring.analytics.stream.cardinality.HyperLogLogPlus) Serialiser(uk.gov.gchq.gaffer.serialisation.Serialiser) HyperLogLogPlusSerialiser(uk.gov.gchq.gaffer.sketches.clearspring.cardinality.serialisation.HyperLogLogPlusSerialiser) SerialisationFactory(uk.gov.gchq.gaffer.store.SerialisationFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Serialiser (uk.gov.gchq.gaffer.serialisation.Serialiser)28 Test (org.junit.jupiter.api.Test)18 JavaSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.JavaSerialiser)18 StringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser)16 ToBytesSerialiser (uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser)10 BooleanSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.BooleanSerialiser)8 OrderedIntegerSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.ordered.OrderedIntegerSerialiser)8 RawDateSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDateSerialiser)8 RawDoubleSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawDoubleSerialiser)8 RawFloatSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawFloatSerialiser)8 StringToStringSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.tostring.StringToStringSerialiser)6 MapSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.MapSerialiser)5 RawLongSerialiser (uk.gov.gchq.gaffer.serialisation.implementation.raw.RawLongSerialiser)5 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 ArrayList (java.util.ArrayList)3 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)3 AvroSerialiser (uk.gov.gchq.gaffer.serialisation.AvroSerialiser)3 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2