Path: redb/redb.SQLite/Query/SqliteQueryProvider.Window.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.SQLite/Query/SqliteQueryProvider.Window.cs
----
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using redb.Core.Query.QueryExpressions;
using redb.Core.Query.Window;
namespace redb.SQLite.Query;
///
/// PVT-backed window functions for free SQLite. Generates the SELECT
/// SQL via the server-side compiler pvt_build_window_sql and wraps
/// it with json_agg(row_to_json(t)) to materialize a JSON array in
/// one round-trip.
///
/// Window calls are expressed as scalar $over nodes inside the
/// p_select array; all funcs share the same partition_by / order_by
/// / frame supplied through the public API.
///
public partial class SqliteQueryProvider
{
///
public override Task ExecuteWindowQueryAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson = null,
string? frameJson = null,
int? take = null,
int? skip = null, CancellationToken cancellationToken = default)
{
return ExecuteWindowQueryInternalAsync(schemeId, selectFields, windowFuncs, partitionBy, orderBy,
filterJson, frameJson, take, skip);
}
///
public override Task ExecuteWindowQueryAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
FilterExpression? filter,
string? frameJson = null,
int? take = null,
int? skip = null, CancellationToken cancellationToken = default)
{
var filterJson = filter is null ? null : _facetBuilder.BuildFacetFilters(filter);
return ExecuteWindowQueryInternalAsync(schemeId, selectFields, windowFuncs, partitionBy, orderBy,
filterJson, frameJson, take, skip);
}
private async Task ExecuteWindowQueryInternalAsync(
long schemeId,
IEnumerable selectFields,
IEnumerable windowFuncs,
IEnumerable partitionBy,
IEnumerable orderBy,
string? filterJson,
string? frameJson,
int? take,
int? skip)
{
var innerSql = await BuildWindowInnerSqlAsync(schemeId, selectFields, windowFuncs, partitionBy, orderBy,
filterJson, frameJson, take, skip);
// SQLite has no json_agg/row_to_json: run the inner SQL and serialize rows in C#.
var jsonArray = await _context.QueryRowsAsJsonAsync(innerSql, System.Array.Empty