public virtual SchemaValidationResult Validate(DatasetResultSchema actualSchema) { var result = SchemaValidationResult.Ok(Shape); foreach (var field in Fields) { var actualField = actualSchema.Get(field); // required fields missing --> error if (actualField == null && field.Required) { result.State = SchemaValidationState.Error; result.AddMessage($"Required field '{field.Name}' is missing"); continue; } // type mismatch on recognized field --> error if (actualField != null && !actualField.Matches(field)) { result.State = SchemaValidationState.Error; result.AddMessage($"'{field.Name}' expected type '{field.Type}' but received '{actualField.Type}'"); } } if (result.State == SchemaValidationState.Ok) { return(CheckOverflow(actualSchema)); } return(result); }
public SchemaValidationResult CheckOverflow(DatasetResultSchema actualSchema) { var result = SchemaValidationResult.Ok(Shape); var overflow = Fields.Except <BaseSchemaField>(actualSchema.Fields, (a, b) => a.Equals(b)); if (overflow.Any()) { result.State = SchemaValidationState.Warning; foreach (var unrec in overflow) { result.AddMessage($"unrecognized field {unrec.Name} is not a member of {Shape.ToString()} and will be dropped"); } } return(result); }
public SchemaValidationResult CheckOverflow(DatasetResultSchema actualSchema) { var result = SchemaValidationResult.Ok(Shape); var overflow = Fields .Except <BaseSchemaField>(actualSchema.Fields, (a, b) => a.Equals(b)) .Where(f => !f.Name.Equals(DatasetColumns.Salt, StringComparison.InvariantCultureIgnoreCase)); if (overflow.Any()) { result.State = SchemaValidationState.Warning; foreach (var unrec in overflow) { result.AddMessage($"Unrecognized field '{unrec.Name}' is not a member of {Shape} and will be dropped"); } } return(result); }