Skip to content

Commit 4144f5d

Browse files
committed
duckdb, googlesql, mssql: nested types, parameters, MAX, defaults and alias types in the core
DuckDB hands the core a type's whole spelling, so a struct's fields, a map's key and value, a union's members, a fixed-size array's length and a list of lists all arrive, with a varchar's length dropped and a bare decimal filled in as decimal(18,3), as DuckDB stores them. GoogleSQL spells ARRAY<T>, STRUCT<...>, RANGE<T> and a parameter list in the same call form, and reads MAX as the word it is. SQL Server's converter carries a type's parameters and MAX, qualifies a user-defined type by its schema, reports CREATE TYPE ... FROM as the domain it is, and canonicalizes as sys.types does: float(24) is real, sysname is nvarchar(128), and a length or precision left out takes its default. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qryf7a1doPFuCz2eGT3bCr
1 parent efc83d3 commit 4144f5d

26 files changed

Lines changed: 2285 additions & 48 deletions

File tree

‎internal/endtoend/testdata/analyze_basic/duckdb/stdout.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
{
2929
"name": "royalties",
3030
"type": {
31-
"name": "decimal"
31+
"name": "decimal",
32+
"args": [
33+
{
34+
"int": 10
35+
},
36+
{
37+
"int": 2
38+
}
39+
]
3240
},
3341
"table": "authors"
3442
},

‎internal/endtoend/testdata/analyze_basic/mssql/stdout.json‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,52 @@
1313
{
1414
"name": "name",
1515
"type": {
16-
"name": "nvarchar"
16+
"name": "nvarchar",
17+
"args": [
18+
{
19+
"int": 100
20+
}
21+
]
1722
},
1823
"table": "authors"
1924
},
2025
{
2126
"name": "bio",
2227
"type": {
2328
"name": "nvarchar",
24-
"nullable": true
29+
"nullable": true,
30+
"args": [
31+
{
32+
"ident": "max"
33+
}
34+
]
2535
},
2636
"table": "authors"
2737
},
2838
{
2939
"name": "royalties",
3040
"type": {
31-
"name": "decimal"
41+
"name": "decimal",
42+
"args": [
43+
{
44+
"int": 10
45+
},
46+
{
47+
"int": 2
48+
}
49+
]
3250
},
3351
"table": "authors"
3452
},
3553
{
3654
"name": "created",
3755
"type": {
38-
"name": "datetime2"
56+
"name": "datetime2",
57+
"args": [
58+
{
59+
"int": 7
60+
}
61+
]
3962
},
4063
"table": "authors"
4164
}

‎internal/endtoend/testdata/analyze_dml/duckdb/stdout.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,15 @@
126126
"name": "price",
127127
"type": {
128128
"name": "decimal",
129-
"nullable": true
129+
"nullable": true,
130+
"args": [
131+
{
132+
"int": 10
133+
},
134+
{
135+
"int": 2
136+
}
137+
]
130138
},
131139
"table": "books"
132140
}

‎internal/endtoend/testdata/analyze_dml/mssql/stdout.json‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
"column": {
1818
"name": "name",
1919
"type": {
20-
"name": "nvarchar"
20+
"name": "nvarchar",
21+
"args": [
22+
{
23+
"int": 100
24+
}
25+
]
2126
},
2227
"table": "authors"
2328
}
@@ -28,7 +33,12 @@
2833
"name": "bio",
2934
"type": {
3035
"name": "nvarchar",
31-
"nullable": true
36+
"nullable": true,
37+
"args": [
38+
{
39+
"ident": "max"
40+
}
41+
]
3242
},
3343
"table": "authors"
3444
}
@@ -45,7 +55,12 @@
4555
"column": {
4656
"name": "name",
4757
"type": {
48-
"name": "nvarchar"
58+
"name": "nvarchar",
59+
"args": [
60+
{
61+
"int": 100
62+
}
63+
]
4964
},
5065
"table": "authors"
5166
}
@@ -73,7 +88,15 @@
7388
"name": "price",
7489
"type": {
7590
"name": "decimal",
76-
"nullable": true
91+
"nullable": true,
92+
"args": [
93+
{
94+
"int": 10
95+
},
96+
{
97+
"int": 2
98+
}
99+
]
77100
},
78101
"table": "books"
79102
}
@@ -83,7 +106,12 @@
83106
"column": {
84107
"name": "name",
85108
"type": {
86-
"name": "nvarchar"
109+
"name": "nvarchar",
110+
"args": [
111+
{
112+
"int": 100
113+
}
114+
]
87115
},
88116
"table": "authors"
89117
}
@@ -100,7 +128,12 @@
100128
"column": {
101129
"name": "name",
102130
"type": {
103-
"name": "nvarchar"
131+
"name": "nvarchar",
132+
"args": [
133+
{
134+
"int": 100
135+
}
136+
]
104137
},
105138
"table": "authors"
106139
}

‎internal/endtoend/testdata/analyze_params/duckdb/stdout.json‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,15 @@
7474
"column": {
7575
"name": "royalties",
7676
"type": {
77-
"name": "decimal"
77+
"name": "decimal",
78+
"args": [
79+
{
80+
"int": 10
81+
},
82+
{
83+
"int": 2
84+
}
85+
]
7886
},
7987
"table": "authors"
8088
}

‎internal/endtoend/testdata/analyze_params/mssql/stdout.json‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,25 @@
1313
{
1414
"name": "name",
1515
"type": {
16-
"name": "nvarchar"
16+
"name": "nvarchar",
17+
"args": [
18+
{
19+
"int": 100
20+
}
21+
]
1722
},
1823
"table": "authors"
1924
},
2025
{
2126
"name": "bio",
2227
"type": {
2328
"name": "nvarchar",
24-
"nullable": true
29+
"nullable": true,
30+
"args": [
31+
{
32+
"ident": "max"
33+
}
34+
]
2535
},
2636
"table": "authors"
2737
}
@@ -53,7 +63,12 @@
5363
{
5464
"name": "name",
5565
"type": {
56-
"name": "nvarchar"
66+
"name": "nvarchar",
67+
"args": [
68+
{
69+
"int": 100
70+
}
71+
]
5772
},
5873
"table": "authors"
5974
}
@@ -64,7 +79,12 @@
6479
"column": {
6580
"name": "name",
6681
"type": {
67-
"name": "nvarchar"
82+
"name": "nvarchar",
83+
"args": [
84+
{
85+
"int": 100
86+
}
87+
]
6888
},
6989
"table": "authors"
7090
}
@@ -74,7 +94,15 @@
7494
"column": {
7595
"name": "royalties",
7696
"type": {
77-
"name": "decimal"
97+
"name": "decimal",
98+
"args": [
99+
{
100+
"int": 10
101+
},
102+
{
103+
"int": 2
104+
}
105+
]
78106
},
79107
"table": "authors"
80108
}
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", "duckdb", "--schema", "schema.sql", "query.sql"],
4+
"contexts": ["base"]
5+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-- name: AllTypes :many
2+
SELECT * FROM things;
3+
4+
-- name: Casts :one
5+
SELECT
6+
$1::DECIMAL(5,2) AS a,
7+
$2::INTEGER[] AS b,
8+
$3::STRUCT(a INTEGER) AS c,
9+
$4::mood AS d,
10+
CAST($5 AS VARCHAR(5)) AS e,
11+
$6::MAP(VARCHAR, INTEGER) AS f,
12+
$7::INTEGER[3] AS g
13+
FROM things;
14+
15+
-- name: Params :one
16+
SELECT id FROM things
17+
WHERE ints = $1 AND point = $2 AND price = $3 AND m = $4 AND either = $5 AND grid = $6;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TYPE mood AS ENUM ('sad', 'ok');
2+
3+
CREATE TABLE things (
4+
id INTEGER PRIMARY KEY,
5+
ints INTEGER[],
6+
fixed INTEGER[3],
7+
point STRUCT(a INTEGER, b VARCHAR),
8+
attrs MAP(VARCHAR, INTEGER),
9+
either UNION(num INTEGER, str VARCHAR),
10+
price DECIMAL(18,3),
11+
title VARCHAR(10),
12+
kind ENUM('a','b'),
13+
m mood,
14+
big HUGEINT,
15+
ubig UHUGEINT,
16+
data BLOB,
17+
bits BIT,
18+
uid UUID,
19+
tstz TIMESTAMP WITH TIME ZONE,
20+
tsns TIMESTAMP_NS,
21+
iv INTERVAL,
22+
doc JSON,
23+
grid INTEGER[][],
24+
vi VARINT,
25+
f4 FLOAT4,
26+
points STRUCT(a INTEGER)[],
27+
lists MAP(VARCHAR, INTEGER[]),
28+
body TEXT,
29+
n NUMERIC
30+
);

0 commit comments

Comments
 (0)