mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-25 08:48:08 +02:00
fix(sqlserver): hoist leading CTEs out of row-limit derived-table wrap (#311)
* test(sql): cover leading CTE row-limit wrapping * fix(sql): hoist leading CTEs before generic row limits * fix(sqlserver): hoist leading CTEs before TOP row limits * test(scan): note relationship limiter coverage boundary * chore: sync uv.lock to ktx-daemon/ktx-sl 0.13.0
This commit is contained in:
parent
9f715f93f1
commit
c815e10fb3
6 changed files with 275 additions and 5 deletions
|
|
@ -404,6 +404,50 @@ describe('KtxSqlServerScanConnector', () => {
|
|||
await connector.cleanup();
|
||||
});
|
||||
|
||||
it('hoists leading CTEs before applying the SQL Server TOP wrapper', async () => {
|
||||
const queries: string[] = [];
|
||||
const request = {
|
||||
input: vi.fn((_name: string, _value: unknown) => request),
|
||||
query: vi.fn(async (sql: string): Promise<KtxSqlServerQueryResult> => {
|
||||
queries.push(sql);
|
||||
return result([{ value: 1 }], ['value']);
|
||||
}),
|
||||
};
|
||||
const poolFactory: KtxSqlServerPoolFactory = {
|
||||
createPool: vi.fn(async () => ({
|
||||
request: () => request,
|
||||
close: vi.fn(async () => undefined),
|
||||
})),
|
||||
};
|
||||
const connector = new KtxSqlServerScanConnector({
|
||||
connectionId: 'warehouse',
|
||||
connection: {
|
||||
driver: 'sqlserver',
|
||||
host: 'db.example.test',
|
||||
database: 'analytics',
|
||||
username: 'reader',
|
||||
schema: 'dbo',
|
||||
},
|
||||
poolFactory,
|
||||
});
|
||||
|
||||
await expect(
|
||||
connector.executeReadOnly(
|
||||
{
|
||||
connectionId: 'warehouse',
|
||||
sql: 'WITH child_values AS (SELECT 1 AS value) SELECT value FROM child_values',
|
||||
maxRows: 1,
|
||||
},
|
||||
{ runId: 'scan-run-sqlserver-cte-limit' },
|
||||
),
|
||||
).resolves.toMatchObject({ headers: ['value'], rows: [[1]], rowCount: 1 });
|
||||
|
||||
expect(queries).toEqual([
|
||||
'WITH child_values AS (SELECT 1 AS value) SELECT TOP 1 * FROM (SELECT value FROM child_values) AS ktx_query_result',
|
||||
]);
|
||||
expect(queries[0]).not.toContain('FROM (WITH');
|
||||
});
|
||||
|
||||
it('limits introspection to tables in tableScope', async () => {
|
||||
const queries: string[] = [];
|
||||
const inputs: Array<{ name: string; value: unknown }> = [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue