|
| 1 | +import { bench, describe } from "vitest"; |
| 2 | +import { |
| 3 | + recognizeSqlRelationQuerySite, |
| 4 | + type SqlQuerySiteDialect, |
| 5 | +} from "../query-site.js"; |
| 6 | +import { createIdentitySqlSource } from "../source.js"; |
| 7 | +import { |
| 8 | + buildSqlStatementIndex, |
| 9 | + DUCKDB_SQL_LEXICAL_PROFILE, |
| 10 | + findSqlStatementSlot, |
| 11 | +} from "../statement-index.js"; |
| 12 | + |
| 13 | +const dialect: SqlQuerySiteDialect = { |
| 14 | + decodeRelationPath: (rawPath, cursorOffset) => ({ |
| 15 | + finalSegment: { from: 0, to: rawPath.length }, |
| 16 | + prefix: { |
| 17 | + quoted: false, |
| 18 | + value: rawPath.slice(0, cursorOffset), |
| 19 | + }, |
| 20 | + qualifier: [], |
| 21 | + quality: "exact", |
| 22 | + status: "decoded", |
| 23 | + }), |
| 24 | + lexicalProfile: DUCKDB_SQL_LEXICAL_PROFILE, |
| 25 | +}; |
| 26 | +const tenKilobyteQuery = `SELECT ${Array.from( |
| 27 | + { length: 1_100 }, |
| 28 | + (_, index) => `value_${index}`, |
| 29 | +).join(", ")} FROM schema_prefix`; |
| 30 | +const source = createIdentitySqlSource(tenKilobyteQuery); |
| 31 | +const index = buildSqlStatementIndex( |
| 32 | + source.analysisText, |
| 33 | + dialect.lexicalProfile, |
| 34 | +); |
| 35 | +const position = tenKilobyteQuery.length; |
| 36 | +const slot = findSqlStatementSlot(index, position, "left"); |
| 37 | + |
| 38 | +describe("query-site recognizer", () => { |
| 39 | + bench("10 KiB active statement", () => { |
| 40 | + recognizeSqlRelationQuerySite(source, slot, position, dialect); |
| 41 | + }); |
| 42 | +}); |
0 commit comments