public static IEnumerable <T> Deserialize <T>(Stream input) where T : new() { var result = new List <T>(); IColumnClrMapper mapper = new SlowReflectionColumnClrMapper(typeof(T)); using (var reader = new ParquetReader3(input)) { Schema fileSchema = reader.Schema; List <DataField> dataFields = fileSchema.GetDataFields(); for (int i = 0; i < reader.RowGroupCount; i++) { using (ParquetRowGroupReader groupReader = reader.OpenRowGroupReader(i)) { List <DataColumn> groupColumns = dataFields .Select(groupReader.ReadColumn) .ToList(); IReadOnlyCollection <T> groupClrObjects = mapper.CreateClassInstances <T>(groupColumns); result.AddRange(groupClrObjects); } } } return(result); }
/// <summary> /// Extracts data columns from a collection of CLR class instances /// </summary> /// <typeparam name="TClass">Class type</typeparam> /// <param name="classInstances">Collection of class instances</param> /// <param name="schema">Schema to operate on</param> public IReadOnlyCollection <DataColumn> ExtractColumns <TClass>(IEnumerable <TClass> classInstances, Schema schema) { List <DataField> dataFields = schema.GetDataFields(); IColumnClrMapper valuesExtractor = new SlowReflectionColumnClrMapper(typeof(TClass)); IReadOnlyCollection <DataColumn> result = valuesExtractor.ExtractDataColumns(dataFields, classInstances); return(result); }