-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix using internal F# types with the row oriented API (#332)
- Loading branch information
Showing
7 changed files
with
194 additions
and
6 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
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 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 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 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 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,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net6.0</TargetFrameworks> | ||
<!-- Avoid building for older frameworks when testing locally. --> | ||
<!-- This is to speed up the build process and avoid errors when the required runtimes are not installed. --> | ||
<TargetFrameworks Condition="'$(CI)' == 'true'">$(TargetFrameworks);netcoreapp3.1;net5.0</TargetFrameworks> | ||
<TargetFrameworks Condition="'$(CI)' == 'true' AND '$(OS)'=='Windows_NT'">$(TargetFrameworks);net472</TargetFrameworks> | ||
<PlatformTarget Condition="'$(TargetFramework)'=='net472'">x64</PlatformTarget> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FsUnit" Version="5.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="NUnit" Version="3.13.3" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\csharp\ParquetSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="TestRowOrientedApi.fs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,86 @@ | ||
namespace ParquetSharp.Test.FSharp | ||
|
||
open System | ||
open System.IO | ||
open NUnit.Framework | ||
open FsUnit | ||
open ParquetSharp.RowOriented | ||
|
||
module TestRowOrientedApi = | ||
|
||
type PublicRecord = | ||
{ | ||
Field : int | ||
} | ||
|
||
type PublicRecordWithMappedField = | ||
{ | ||
[<MapToColumn("field")>] | ||
Field : int | ||
} | ||
|
||
type internal InternalRecord = | ||
{ | ||
Field : int | ||
} | ||
|
||
type internal InternalRecordWithMappedField = | ||
{ | ||
[<MapToColumn("field")>] | ||
Field : int | ||
} | ||
|
||
[<Struct>] | ||
type internal InternalStructRecordWithMappedField = | ||
{ | ||
[<MapToColumn("field")>] | ||
Field : int | ||
} | ||
|
||
let TestWritingRecord<'T> record verify = | ||
let dir = Path.Combine(Path.GetTempPath (), Guid.NewGuid().ToString ()) |> Directory.CreateDirectory | ||
try | ||
let path = Path.Combine (dir.FullName, "test.parquet") | ||
|
||
using (ParquetFile.CreateRowWriter<'T> path) ( fun writer -> | ||
writer.WriteRow record | ||
) | ||
|
||
use reader = ParquetFile.CreateRowReader<'T> path | ||
let got = | ||
seq { | ||
for i in 0 .. reader.FileMetaData.NumRowGroups-1 do | ||
for r in reader.ReadRows i do | ||
yield r | ||
} |> Seq.toList | ||
|
||
got |> Seq.length |> should equal 1 | ||
got |> Seq.head |> verify | ||
finally | ||
dir.Delete true | ||
|
||
[<Test>] | ||
let TestErrorWritingInternalRecord () = | ||
let dir = Path.Combine(Path.GetTempPath (), Guid.NewGuid().ToString ()) |> Directory.CreateDirectory | ||
try | ||
let path = Path.Combine (dir.FullName, "test.parquet") | ||
(fun () -> ParquetFile.CreateRowWriter<InternalRecord> path |> ignore) | ||
|> should throw typeof<System.ArgumentException> | ||
finally | ||
dir.Delete true | ||
|
||
[<Test>] | ||
let TestWritingPublicRecord () = | ||
TestWritingRecord<PublicRecord> { Field = 1 } ( fun readField -> readField.Field |> should equal 1) | ||
|
||
[<Test>] | ||
let TestWritingPublicRecordWithMappedField () = | ||
TestWritingRecord<PublicRecordWithMappedField> { Field = 1 } ( fun readField -> readField.Field |> should equal 1) | ||
|
||
[<Test>] | ||
let TestWritingInternalRecordWithMappedField () = | ||
TestWritingRecord<InternalRecordWithMappedField> { Field = 1 } ( fun readField -> readField.Field |> should equal 1) | ||
|
||
[<Test>] | ||
let TestWritingInternalStructRecordWithMappedField () = | ||
TestWritingRecord<InternalStructRecordWithMappedField> { Field = 1 } ( fun readField -> readField.Field |> should equal 1) |