-
Notifications
You must be signed in to change notification settings - Fork 2
/
FastParquetSchemaValidator.cs
47 lines (40 loc) · 1.3 KB
/
FastParquetSchemaValidator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Collections.Generic;
using Akka.Streams.Dsl;
using Arcane.Framework.Sources.Base;
using Arcane.Framework.Sources.Exceptions;
using Parquet.Data;
using ParquetColumn = Parquet.Data.DataColumn;
namespace Arcane.Framework.Sources.SqlServer;
/// <summary>
/// Validates the schema of a Parquet data source
/// </summary>
public class FastParquetSchemaValidator : ISchemaValidator<List<ParquetColumn>>
{
private readonly Schema schema;
/// <summary>
/// Creates a new Parquet schema validator
/// </summary>
/// <param name="schema">Parquet schema</param>
public FastParquetSchemaValidator(Schema schema)
{
this.schema = schema;
}
/// <inheritdoc />
public Flow<List<ParquetColumn>, List<ParquetColumn>, TMat> Validate<TMat>()
{
return Flow.Create<List<ParquetColumn>, TMat>().Select(this.ValidateCellGroup);
}
private List<ParquetColumn> ValidateCellGroup(List<ParquetColumn> cellGroups)
{
if (cellGroups.Count <= 0)
{
return cellGroups;
}
var (srcFields, sinkFields) = (cellGroups.Count, this.schema.GetDataFields().Length);
if (srcFields != sinkFields)
{
throw new SchemaInconsistentException(srcFields, sinkFields);
}
return cellGroups;
}
}