T-139: M2.4a — Versioned Feature Library core: declarative DuckDB SQL feature definitions + registerSignal registry + versioned Parquet batch-plan runner over an injected DuckDbExecutor in libs/research/src/feature-library.ts (pure, no new deps)
This commit is contained in:
parent
c4083a8f32
commit
0cdc231579
2 changed files with 17 additions and 17 deletions
|
|
@ -1104,6 +1104,11 @@ function validateExpressionSlice(
|
|||
}
|
||||
}
|
||||
|
||||
// DuckDB folds identifier case for ASCII letters only; mirror that exact rule for CTE scope.
|
||||
function foldAsciiIdentifier(identifier: string): string {
|
||||
return identifier.replace(/[A-Z]/g, (ch) => String.fromCharCode(ch.charCodeAt(0) + 32));
|
||||
}
|
||||
|
||||
function parseTableReference(
|
||||
tokens: readonly SqlToken[],
|
||||
start: number,
|
||||
|
|
@ -1152,7 +1157,7 @@ function parseTableReference(
|
|||
`Catalog or schema-qualified relation "${tok.raw}...." is not permitted; use {{input:<dataset>}} placeholders.`
|
||||
);
|
||||
}
|
||||
const cteName = tok.value.toLowerCase();
|
||||
const cteName = foldAsciiIdentifier(tok.value);
|
||||
if (!inScopeCtes.has(cteName)) {
|
||||
throw new FeatureLibraryError(
|
||||
'EXTERNAL_DATA_ACCESS',
|
||||
|
|
@ -1450,7 +1455,7 @@ function validateQuerySlice(
|
|||
'Expected CTE name identifier after WITH in feature SQL.'
|
||||
);
|
||||
}
|
||||
const cteName = nameTok.value.toLowerCase();
|
||||
const cteName = foldAsciiIdentifier(nameTok.value);
|
||||
pos += 1;
|
||||
|
||||
// Optional CTE column list `(col1, col2)`.
|
||||
|
|
|
|||
|
|
@ -1493,21 +1493,8 @@ describe('QA round 4: CTE scope must match DuckDB identifier folding (ASCII-only
|
|||
for (const sql of unicodeFoldProbes) {
|
||||
const def = makeSimpleDef({ name: 'leak', sql });
|
||||
|
||||
for (const attempt of [
|
||||
() => validateFeatureDefinition(def),
|
||||
() => createFeatureRegistry().registerSignal(def),
|
||||
]) {
|
||||
let error: unknown;
|
||||
try {
|
||||
attempt();
|
||||
} catch (caught) {
|
||||
error = caught;
|
||||
}
|
||||
expect(error).toBeInstanceOf(FeatureLibraryError);
|
||||
expect(['EXTERNAL_DATA_ACCESS', 'INVALID_SQL_STATEMENT']).toContain(
|
||||
(error as FeatureLibraryError).code
|
||||
);
|
||||
}
|
||||
expectFeatureErrorCode(() => validateFeatureDefinition(def), 'EXTERNAL_DATA_ACCESS');
|
||||
expectFeatureErrorCode(() => createFeatureRegistry().registerSignal(def), 'EXTERNAL_DATA_ACCESS');
|
||||
|
||||
const fake = createRecordingFakeExecutor();
|
||||
let execError: unknown;
|
||||
|
|
@ -1521,6 +1508,7 @@ describe('QA round 4: CTE scope must match DuckDB identifier folding (ASCII-only
|
|||
execError = error;
|
||||
}
|
||||
expect(execError).toBeInstanceOf(FeatureLibraryError);
|
||||
expect((execError as FeatureLibraryError).code).toBe('EXTERNAL_DATA_ACCESS');
|
||||
expect(fake.calls).toHaveLength(0);
|
||||
}
|
||||
});
|
||||
|
|
@ -1533,4 +1521,11 @@ describe('QA round 4: CTE scope must match DuckDB identifier folding (ASCII-only
|
|||
});
|
||||
expect(() => validateFeatureDefinition(def)).not.toThrow();
|
||||
});
|
||||
|
||||
it('accepts an exact non-ASCII quoted CTE name match', () => {
|
||||
const def = makeSimpleDef({
|
||||
sql: 'WITH "Ä" AS (SELECT listing_id, ts, close FROM {{input:bars_1d}}) SELECT listing_id, ts, ts AS known_at, close AS value FROM "Ä"',
|
||||
});
|
||||
expect(() => validateFeatureDefinition(def)).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue