Skip to content

Commit 34bc380

Browse files
EliSauderCopilot
andcommitted
feat(mssql): seed more built-in functions
GROUPING, GROUPING_ID, APPROX_COUNT_DISTINCT, CHECKSUM_AGG and PERCENTILE_CONT; the metadata functions, as DB_NAME, OBJECT_ID and IDENT_CURRENT; the ERROR_* functions, XACT_STATE and SESSION_CONTEXT; STRING_ESCAPE, SOUNDEX, DIFFERENCE, FORMATMESSAGE, COMPRESS and DECOMPRESS; the bit functions; DATE_BUCKET; the REGEXP_* functions; VECTOR_DISTANCE; and LTRIM and RTRIM given the characters to trim. Each was untyped. Their types are those SQL Server reports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f04eaba commit 34bc380

5 files changed

Lines changed: 468 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"command": "analyze",
3+
"args": ["--dialect", "mssql", "--schema", "schema.sql", "query.sql"],
4+
"contexts": ["base"]
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- name: Grouping :many
2+
SELECT g, GROUPING(g) AS gr, GROUPING_ID(g, id) AS gid, APPROX_COUNT_DISTINCT(id) AS approx, CHECKSUM_AGG(id) AS ca
3+
FROM s GROUP BY ROLLUP(g, id);
4+
5+
-- name: Percentiles :many
6+
SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY v) OVER (PARTITION BY g) AS med FROM s;
7+
8+
-- name: Metadata :one
9+
SELECT DB_NAME() AS d, SCHEMA_NAME() AS sn, OBJECT_ID(N'dbo.s') AS o, OBJECT_NAME(@oid) AS obj,
10+
IDENT_CURRENT(N's') AS ic, ROWCOUNT_BIG() AS rc, ORIGINAL_LOGIN() AS ol, DB_ID() AS dbid,
11+
ERROR_MESSAGE() AS em, ERROR_NUMBER() AS en, XACT_STATE() AS xs, SESSION_CONTEXT(N'k') AS sc;
12+
13+
-- name: Strings :many
14+
SELECT STRING_ESCAPE(g, 'json') AS se, SOUNDEX(g) AS sx, DIFFERENCE(g, @other) AS df,
15+
LTRIM(g, N'x') AS lt, RTRIM(g, N'x') AS rt, COMPRESS(g) AS c, REGEXP_REPLACE(g, @pattern, N'b') AS rr,
16+
REGEXP_SUBSTR(g, N'a') AS rs, REGEXP_COUNT(g, N'a') AS rc
17+
FROM s;
18+
19+
-- name: Bits :many
20+
SELECT BIT_COUNT(id) AS bc, LEFT_SHIFT(id, 1) AS ls, GET_BIT(id, 1) AS gb, SET_BIT(id, @bit) AS sb,
21+
DATE_BUCKET(week, 2, CAST(SYSDATETIME() AS date)) AS db
22+
FROM s;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE s (id INT NOT NULL, g NVARCHAR(10) NOT NULL, v DECIMAL(10,2) NOT NULL, f FLOAT NULL);
Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
[
2+
{
3+
"name": "Grouping",
4+
"cmd": ":many",
5+
"columns": [
6+
{
7+
"name": "g",
8+
"type": {
9+
"name": "nvarchar",
10+
"args": [
11+
{
12+
"int": 10
13+
}
14+
]
15+
},
16+
"table": "s"
17+
},
18+
{
19+
"name": "gr",
20+
"type": {
21+
"name": "tinyint"
22+
}
23+
},
24+
{
25+
"name": "gid",
26+
"type": {
27+
"name": "int"
28+
}
29+
},
30+
{
31+
"name": "approx",
32+
"type": {
33+
"name": "bigint",
34+
"nullable": true
35+
}
36+
},
37+
{
38+
"name": "ca",
39+
"type": {
40+
"name": "int",
41+
"nullable": true
42+
}
43+
}
44+
],
45+
"params": []
46+
},
47+
{
48+
"name": "Percentiles",
49+
"cmd": ":many",
50+
"columns": [
51+
{
52+
"name": "med",
53+
"type": {
54+
"name": "float",
55+
"nullable": true
56+
}
57+
}
58+
],
59+
"params": []
60+
},
61+
{
62+
"name": "Metadata",
63+
"cmd": ":one",
64+
"columns": [
65+
{
66+
"name": "d",
67+
"type": {
68+
"name": "nvarchar",
69+
"nullable": true,
70+
"args": [
71+
{
72+
"int": 128
73+
}
74+
]
75+
}
76+
},
77+
{
78+
"name": "sn",
79+
"type": {
80+
"name": "nvarchar",
81+
"nullable": true,
82+
"args": [
83+
{
84+
"int": 128
85+
}
86+
]
87+
}
88+
},
89+
{
90+
"name": "o",
91+
"type": {
92+
"name": "int",
93+
"nullable": true
94+
}
95+
},
96+
{
97+
"name": "obj",
98+
"type": {
99+
"name": "nvarchar",
100+
"nullable": true,
101+
"args": [
102+
{
103+
"int": 128
104+
}
105+
]
106+
}
107+
},
108+
{
109+
"name": "ic",
110+
"type": {
111+
"name": "decimal",
112+
"nullable": true,
113+
"args": [
114+
{
115+
"int": 38
116+
},
117+
{
118+
"int": 0
119+
}
120+
]
121+
}
122+
},
123+
{
124+
"name": "rc",
125+
"type": {
126+
"name": "bigint"
127+
}
128+
},
129+
{
130+
"name": "ol",
131+
"type": {
132+
"name": "nvarchar",
133+
"nullable": true,
134+
"args": [
135+
{
136+
"int": 4000
137+
}
138+
]
139+
}
140+
},
141+
{
142+
"name": "dbid",
143+
"type": {
144+
"name": "smallint",
145+
"nullable": true
146+
}
147+
},
148+
{
149+
"name": "em",
150+
"type": {
151+
"name": "nvarchar",
152+
"nullable": true,
153+
"args": [
154+
{
155+
"int": 4000
156+
}
157+
]
158+
}
159+
},
160+
{
161+
"name": "en",
162+
"type": {
163+
"name": "int",
164+
"nullable": true
165+
}
166+
},
167+
{
168+
"name": "xs",
169+
"type": {
170+
"name": "smallint",
171+
"nullable": true
172+
}
173+
},
174+
{
175+
"name": "sc",
176+
"type": {
177+
"name": "sql_variant",
178+
"nullable": true
179+
}
180+
}
181+
],
182+
"params": [
183+
{
184+
"number": 1,
185+
"column": {
186+
"name": "oid",
187+
"type": {
188+
"name": "int"
189+
}
190+
}
191+
}
192+
]
193+
},
194+
{
195+
"name": "Strings",
196+
"cmd": ":many",
197+
"columns": [
198+
{
199+
"name": "se",
200+
"type": {
201+
"name": "nvarchar",
202+
"nullable": true,
203+
"args": [
204+
{
205+
"ident": "max"
206+
}
207+
]
208+
}
209+
},
210+
{
211+
"name": "sx",
212+
"type": {
213+
"name": "varchar",
214+
"nullable": true,
215+
"args": [
216+
{
217+
"int": 5
218+
}
219+
]
220+
}
221+
},
222+
{
223+
"name": "df",
224+
"type": {
225+
"name": "int",
226+
"nullable": true
227+
}
228+
},
229+
{
230+
"name": "lt",
231+
"type": {
232+
"name": "nvarchar",
233+
"nullable": true,
234+
"args": [
235+
{
236+
"int": 10
237+
}
238+
]
239+
}
240+
},
241+
{
242+
"name": "rt",
243+
"type": {
244+
"name": "nvarchar",
245+
"nullable": true,
246+
"args": [
247+
{
248+
"int": 10
249+
}
250+
]
251+
}
252+
},
253+
{
254+
"name": "c",
255+
"type": {
256+
"name": "varbinary",
257+
"nullable": true,
258+
"args": [
259+
{
260+
"ident": "max"
261+
}
262+
]
263+
}
264+
},
265+
{
266+
"name": "rr",
267+
"type": {
268+
"name": "nvarchar",
269+
"nullable": true,
270+
"args": [
271+
{
272+
"int": 4000
273+
}
274+
]
275+
}
276+
},
277+
{
278+
"name": "rs",
279+
"type": {
280+
"name": "nvarchar",
281+
"nullable": true,
282+
"args": [
283+
{
284+
"int": 10
285+
}
286+
]
287+
}
288+
},
289+
{
290+
"name": "rc",
291+
"type": {
292+
"name": "int",
293+
"nullable": true
294+
}
295+
}
296+
],
297+
"params": [
298+
{
299+
"number": 1,
300+
"column": {
301+
"name": "other",
302+
"type": {
303+
"name": "varchar"
304+
}
305+
}
306+
},
307+
{
308+
"number": 2,
309+
"column": {
310+
"name": "pattern"
311+
}
312+
}
313+
]
314+
},
315+
{
316+
"name": "Bits",
317+
"cmd": ":many",
318+
"columns": [
319+
{
320+
"name": "bc",
321+
"type": {
322+
"name": "bigint",
323+
"nullable": true
324+
}
325+
},
326+
{
327+
"name": "ls",
328+
"type": {
329+
"name": "int",
330+
"nullable": true
331+
}
332+
},
333+
{
334+
"name": "gb",
335+
"type": {
336+
"name": "bit",
337+
"nullable": true
338+
}
339+
},
340+
{
341+
"name": "sb",
342+
"type": {
343+
"name": "int",
344+
"nullable": true
345+
}
346+
},
347+
{
348+
"name": "db",
349+
"type": {
350+
"name": "date",
351+
"nullable": true
352+
}
353+
}
354+
],
355+
"params": [
356+
{
357+
"number": 1,
358+
"column": {
359+
"name": "bit",
360+
"type": {
361+
"name": "int"
362+
}
363+
}
364+
}
365+
]
366+
}
367+
]

0 commit comments

Comments
 (0)