Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nuget package name and delta-rs version #78

Merged
merged 12 commits into from
Sep 30, 2024
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ jobs:
run: dotnet format --verify-no-changes

- name: Test
run: dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info --logger "console;verbosity=detailed" --blame-crash -v n
env:
RUST_BACKTRACE: 1
# increased stack size currently necessary for osx
DOTNET_DefaultStackSize: "180000"
run: dotnet test -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=lcov /p:CoverletOutput=./lcov.info --logger "console;verbosity=detailed" --blame-crash -v n

- name: Upload test failure
if: ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: test-fail-${{ matrix.os }}
path: tests/DeltaLake.Tests/TestResults
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ jobs:

- name: Upload bridge library
if: ${{ !matrix.alternative-target }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.out-prefix }}-bridge
path: src/DeltaLake/Bridge/target/release/${{ matrix.out-file }}

- name: Upload bridge library alternative target
if: ${{ matrix.alternative-target != '' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.out-prefix }}-bridge
path: src/DeltaLake/Bridge/target/${{ matrix.alternative-target }}/release/${{ matrix.out-file }}
Expand All @@ -109,7 +109,7 @@ jobs:
run: dotnet pack src/DeltaLake/DeltaLake.csproj -c Release /p:BridgeLibraryRoot=${{ github.workspace }}/bridge-libraries

- name: Upload NuGet artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: |
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This library also takes advantage of the [Apache Arrow](https://github.com/apach
The bridge library incorporates delta-rs and [tokio-rs](https://tokio.rs/) as shown in the image below.
![alt text](/media/images/bridge-library.png "Rust bridge library with tokio")

NOTE: On unix systems, there is the possibility of a stack overflow due to small stack sizes for the .NET framework. The default size should correspond to `ulimit -s`, but we can override this by setting the environment variable `DOTNET_DefaultStackSize` to a hexadecimal number of bytes. The unit tests use `180000`.
## Quick Start

```csharp
Expand Down Expand Up @@ -53,7 +54,7 @@ public static Task<DeltaTable> CreateDeltaTable(
runtime,
new TableCreateOptions(uri, schema)
{
Configuration = new Dictionary<string, string?>(),
Configuration = new Dictionary<string, string>(),
},
cancellationToken);
}
Expand Down
113 changes: 56 additions & 57 deletions examples/local/Program.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Apache.Arrow;
using Apache.Arrow.Memory;
using Apache.Arrow.Types;
using DeltaLake.Runtime;
using DeltaLake.Table;

namespace local;

public class Program
{
public static async Task Main(string[] args)
{
var uri = args[0];
int length;
if (args.Length < 2 || !int.TryParse(args[1], out length))
{
length = 10;
}

var runtime = new DeltaRuntime(RuntimeOptions.Default);
{
var builder = new Apache.Arrow.Schema.Builder();
builder.Field(fb =>
{
fb.Name("test");
fb.DataType(Int32Type.Default);
fb.Nullable(false);
});
var schema = builder.Build();
var allocator = new NativeMemoryAllocator();
var recordBatchBuilder = new RecordBatch.Builder(allocator)
.Append("test", false, col => col.Int32(arr => arr.AppendRange(Enumerable.Range(0, length))));
using var table = await DeltaTable.CreateAsync(
runtime,
new TableCreateOptions(uri, schema)
{
Configuration = new Dictionary<string, string?>
{
["delta.dataSkippingNumIndexedCols"] = "32",
["delta.setTransactionRetentionDuration"] = null,
}
},
CancellationToken.None);
var options = new InsertOptions
{
SaveMode = SaveMode.Append,
};
await table.InsertAsync([recordBatchBuilder.Build()], schema, options, CancellationToken.None);
}

runtime.Dispose();
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Apache.Arrow;
using Apache.Arrow.Memory;
using Apache.Arrow.Types;
using DeltaLake.Runtime;
using DeltaLake.Table;

namespace local;

public class Program
{
public static async Task Main(string[] args)
{
var uri = args[0];
int length;
if (args.Length < 2 || !int.TryParse(args[1], out length))
{
length = 10;
}

var runtime = new DeltaRuntime(RuntimeOptions.Default);
{
var builder = new Apache.Arrow.Schema.Builder();
builder.Field(fb =>
{
fb.Name("test");
fb.DataType(Int32Type.Default);
fb.Nullable(false);
});
var schema = builder.Build();
var allocator = new NativeMemoryAllocator();
var recordBatchBuilder = new RecordBatch.Builder(allocator)
.Append("test", false, col => col.Int32(arr => arr.AppendRange(Enumerable.Range(0, length))));
using var table = await DeltaTable.CreateAsync(
runtime,
new TableCreateOptions(uri, schema)
{
Configuration = new Dictionary<string, string>
{
["delta.dataSkippingNumIndexedCols"] = "32",
}
},
CancellationToken.None);
var options = new InsertOptions
{
SaveMode = SaveMode.Append,
};
await table.InsertAsync([recordBatchBuilder.Build()], schema, options, CancellationToken.None);
}

runtime.Dispose();
}
}
122 changes: 61 additions & 61 deletions src/DeltaLake/Bridge/ByteArray.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
using System;
using System.Runtime.InteropServices;

namespace DeltaLake.Bridge
{
/// <summary>
/// Representation of a byte array owned by Core.
/// </summary>
internal sealed class ByteArray : SafeHandle
{
private readonly Runtime runtime;
private readonly unsafe Interop.ByteArray* byteArray;

/// <summary>
/// Initializes a new instance of the <see cref="ByteArray"/> class.
/// </summary>
/// <param name="runtime">Runtime to use to free the byte array.</param>
/// <param name="byteArray">Byte array pointer.</param>
public unsafe ByteArray(Runtime runtime, Interop.ByteArray* byteArray)
: base((IntPtr)byteArray, true)
{
this.runtime = runtime;
this.byteArray = byteArray;
}

/// <inheritdoc/>
public override unsafe bool IsInvalid => false;

/// <summary>
/// Convert the byte array to a UTF8 string.
/// </summary>
/// <returns>Converted string.</returns>
public string ToUTF8()
{
unsafe
{
return ByteArrayRef.StrictUTF8.GetString(byteArray->data, (int)byteArray->size);
}
}

/// <summary>
/// Copy the byte array to a new byte array.
/// </summary>
/// <returns>The new byte array.</returns>
public byte[] ToByteArray()
{
unsafe
{
var bytes = new byte[(int)byteArray->size];
Marshal.Copy((IntPtr)byteArray->data, bytes, 0, (int)byteArray->size);
return bytes;
}
}

/// <inheritdoc/>
protected override unsafe bool ReleaseHandle()
{
runtime.FreeByteArray(byteArray);
return true;
}
}
using System;
using System.Runtime.InteropServices;
namespace DeltaLake.Bridge
{
/// <summary>
/// Representation of a byte array owned by Core.
/// </summary>
internal sealed class ByteArray : SafeHandle
{
private readonly Runtime runtime;
private readonly unsafe Interop.ByteArray* byteArray;
/// <summary>
/// Initializes a new instance of the <see cref="ByteArray"/> class.
/// </summary>
/// <param name="runtime">Runtime to use to free the byte array.</param>
/// <param name="byteArray">Byte array pointer.</param>
public unsafe ByteArray(Runtime runtime, Interop.ByteArray* byteArray)
: base((IntPtr)byteArray, true)
{
this.runtime = runtime;
this.byteArray = byteArray;
}
/// <inheritdoc/>
public override unsafe bool IsInvalid => false;
/// <summary>
/// Convert the byte array to a UTF8 string.
/// </summary>
/// <returns>Converted string.</returns>
public string ToUTF8()
{
unsafe
{
return ByteArrayRef.StrictUTF8.GetString(byteArray->data, (int)byteArray->size);
}
}
/// <summary>
/// Copy the byte array to a new byte array.
/// </summary>
/// <returns>The new byte array.</returns>
public byte[] ToByteArray()
{
unsafe
{
var bytes = new byte[(int)byteArray->size];
Marshal.Copy((IntPtr)byteArray->data, bytes, 0, (int)byteArray->size);
return bytes;
}
}
/// <inheritdoc/>
protected override unsafe bool ReleaseHandle()
{
runtime.FreeByteArray(byteArray);
return true;
}
}
}
Loading
Loading