-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jack Dermody
committed
Apr 13, 2024
1 parent
c142419
commit 7a9a8e6
Showing
31 changed files
with
543 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BrightData.Types; | ||
using Parquet; | ||
using Parquet.Data; | ||
|
||
namespace BrightData.Parquet.BufferAdaptors | ||
{ | ||
internal class ParquetBufferAdaptor<T>(RowGroupReaderProvider rowGroupProvider, int columnIndex, MetaData metaData) : IReadOnlyBufferWithMetaData<T> | ||
where T : notnull | ||
{ | ||
public uint Size => rowGroupProvider.Size; | ||
public uint[] BlockSizes => rowGroupProvider.RowGroupSizes; | ||
public Type DataType => typeof(T); | ||
|
||
public async IAsyncEnumerable<object> EnumerateAll() | ||
{ | ||
for (uint i = 0; i < rowGroupProvider.RowGroupCount; i++) | ||
{ | ||
var column = await rowGroupProvider.GetColumn(i, columnIndex); | ||
foreach (var item in GetArray(column)) | ||
yield return item; | ||
} | ||
} | ||
|
||
public async Task<Array> GetBlock(uint blockIndex) | ||
{ | ||
var column = await rowGroupProvider.GetColumn(blockIndex, columnIndex); | ||
return GetArray(column); | ||
} | ||
|
||
public MetaData MetaData { get; } = metaData; | ||
|
||
public async Task ForEachBlock(BlockCallback<T> callback, INotifyOperationProgress? notify = null, string? message = null, CancellationToken ct = default) | ||
{ | ||
var guid = Guid.NewGuid(); | ||
notify?.OnStartOperation(guid, message); | ||
for (uint i = 0; i < rowGroupProvider.RowGroupCount; i++) | ||
{ | ||
var column = await rowGroupProvider.GetColumn(i, columnIndex); | ||
var data = GetArray(column); | ||
callback(data); | ||
notify?.OnOperationProgress(guid, (float)i / rowGroupProvider.RowGroupCount); | ||
} | ||
notify?.OnCompleteOperation(guid, ct.IsCancellationRequested); | ||
} | ||
|
||
public async Task<ReadOnlyMemory<T>> GetTypedBlock(uint blockIndex) | ||
{ | ||
var column = await rowGroupProvider.GetColumn(blockIndex, columnIndex); | ||
var data = GetArray(column); | ||
return data; | ||
} | ||
|
||
public async IAsyncEnumerable<T> EnumerateAllTyped() | ||
{ | ||
for (uint i = 0; i < rowGroupProvider.RowGroupCount; i++) | ||
{ | ||
var column = await rowGroupProvider.GetColumn(i, columnIndex); | ||
var data = GetArray(column); | ||
foreach (var item in data) | ||
yield return item; | ||
} | ||
} | ||
|
||
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken ct = default) => EnumerateAllTyped().GetAsyncEnumerator(ct); | ||
|
||
protected virtual T[] GetArray(DataColumn column) => (T[])column.Data; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
BrightData.Parquet/BufferAdaptors/ParquetMappedBufferAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using BrightData.Types; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Parquet.Data; | ||
|
||
namespace BrightData.Parquet.BufferAdaptors | ||
{ | ||
internal class ParquetMappedBufferAdaptor<DT, T>(RowGroupReaderProvider rowGroupProvider, int columnIndex, MetaData metaData, Func<DT, T> mappingFunction) : ParquetBufferAdaptor<T>(rowGroupProvider, columnIndex, metaData) | ||
where T : notnull | ||
{ | ||
protected override T[] GetArray(DataColumn column) | ||
{ | ||
var data = (DT[])column.Data; | ||
var ret = new T[data.Length]; | ||
var index = 0; | ||
|
||
foreach (var item in data) | ||
ret[index++] = mappingFunction(item); | ||
return ret; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
BrightData.Parquet/BufferAdaptors/ParquetNullableBufferAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using BrightData.Types; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Parquet.Data; | ||
|
||
namespace BrightData.Parquet.BufferAdaptors | ||
{ | ||
internal class ParquetNullableBufferAdaptor<T>(RowGroupReaderProvider rowGroupProvider, int columnIndex, MetaData metaData, T defaultValue) : ParquetBufferAdaptor<T>(rowGroupProvider, columnIndex, metaData) | ||
where T : struct | ||
{ | ||
protected override T[] GetArray(DataColumn column) | ||
{ | ||
var data = (T?[])column.Data; | ||
var ret = new T[data.Length]; | ||
var index = 0; | ||
|
||
foreach (var item in data) | ||
ret[index++] = item ?? defaultValue; | ||
return ret; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
BrightData.Parquet/BufferAdaptors/ParquetNullableStringAdaptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using BrightData.Types; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Parquet.Data; | ||
|
||
namespace BrightData.Parquet.BufferAdaptors | ||
{ | ||
internal class ParquetNullableStringAdaptor(RowGroupReaderProvider rowGroupProvider, int columnIndex, MetaData metaData, string defaultValue) : ParquetBufferAdaptor<string>(rowGroupProvider, columnIndex, metaData) | ||
{ | ||
protected override string[] GetArray(DataColumn column) | ||
{ | ||
var data = (string?[])column.Data; | ||
var ret = new string[data.Length]; | ||
var index = 0; | ||
|
||
foreach (var item in data) | ||
ret[index++] = item ?? defaultValue; | ||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.