Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi committed Nov 19, 2024
1 parent 8b6980c commit ae2decb
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions DuckDB.NET.Test/TableFunctionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Numerics;
using DuckDB.NET.Native;
using Xunit;

namespace DuckDB.NET.Test;
Expand Down Expand Up @@ -100,9 +102,9 @@ public void RegisterTableFunctionWithFourParameters()
var param2 = parameters[1].GetValue<decimal>();
var param3 = parameters[2].GetValue<byte>();
var param4 = parameters[3].GetValue<Guid>();
var enumerable = param4.ToByteArray(param1).Append(param3);
return new TableFunction(new List<ColumnInfo>()
{
new ColumnInfo("foo", typeof(byte)),
Expand Down Expand Up @@ -148,4 +150,28 @@ public void RegisterTableFunctionWithEmptyResult()

data.Should().BeEquivalentTo(Enumerable.Empty<int>());
}

[Fact]
public void RegisterTableFunctionWithBigInteger()
{
Connection.RegisterTableFunction<BigInteger, TimeSpan>("demo6", parameters =>
{
var param1 = parameters[0].GetValue<BigInteger>();
var param2 = parameters[1].GetValue<TimeSpan>();
var timeSpans = param1.ToByteArray().Select(b => param2.Add(TimeSpan.FromDays(b)));
return new TableFunction(new List<ColumnInfo>()
{
new ColumnInfo("foo", typeof(TimeSpan)),
}, timeSpans);
}, (item, writers, rowIndex) =>
{
writers[0].WriteValue((TimeSpan)item, rowIndex);
});

var data = Connection.Query<TimeSpan>("SELECT * FROM demo6('123456789876543210'::HUGEINT, '24:00:00'::INTERVAL);").ToList();

data.Should().BeEquivalentTo(BigInteger.Parse("123456789876543210").ToByteArray().Select(b => TimeSpan.FromDays(1 + b)));
}
}

0 comments on commit ae2decb

Please sign in to comment.