-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
CreateAggregate state is shared, breaking multiple use of an aggregate function in the same query #26070
Comments
/cc @bricelam |
Hmm yes, I agree we're handling the seed parameter (and accumulate argument) incorrectly. We're currently passing it as user data, but as you've found, this is shared across all invocations of the function within a query. Instead, we need to pass it as part of the aggregate context. We should consider adding a separate way to specify (and access) the user data when we fix this. |
Invocations in subsequent queries are probably also broken by this. |
It should work correctly if you change AggClass to a |
It doesn't work with struct. as a workaround I'm using something like this var handle = connection.Handle;
var map = new Dictionary<sqlite3_context, AggClass>();
raw.sqlite3_create_function(handle, "testCount2", 1, map,
static (ctx, data, values) =>
{
var map = (Dictionary<sqlite3_context, AggClass>)data;
if (!map.TryGetValue(ctx, out AggClass? i))
{
i = new AggClass();
map.Add(ctx, i);
}
i.Counter++;
},
static(ctx, data) =>
{
var map = (Dictionary<sqlite3_context, AggClass>)data;
if (!map.Remove(ctx, out AggClass? i))
{
raw.sqlite3_result_int(ctx, 0);
return;
}
raw.sqlite3_result_int(ctx, i.Counter);
}); |
How can I help here? To me, this is an absolutely critical update. I'm not sure I understand the value of |
@pimbrouwers #26070 (comment) gives a sketch of the solution if you're interested in giving it a go. |
… CreateAggregate Fixes dotnet#26070
Microsoft.Data.Sqlite version: 5.0.10
Target framework: (e.g. .NET 5.0) .NET 5.0
Operating system: Windows 10 / MacOS 11.5.2
The text was updated successfully, but these errors were encountered: