Skip to content

Commit df5bb91

Browse files
committed
add table comments and special case Timestamps & Bigints
1 parent 97fdfa4 commit df5bb91

File tree

7 files changed

+354
-33
lines changed

7 files changed

+354
-33
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# DuckDB Connector Changelog
22
This changelog documents changes between release tags.
33

4+
## [0.1.1] - 2025-01-08
5+
* Add table comments to descriptions
6+
* Special case Timestamps and BigInt filtering
7+
48
## [0.1.0] - 2024-08-22
59
* Update Documentation for ndc-hub
610

generate-config.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const con = db.connect();
1616
const determineType = (t: string): string => {
1717
switch (t) {
1818
case "BIGINT":
19-
return "Int";
19+
return "BigInt";
2020
case "BIT":
2121
return "String";
2222
case "BOOLEAN":
@@ -28,7 +28,7 @@ const determineType = (t: string): string => {
2828
case "DOUBLE":
2929
return "Float";
3030
case "HUGEINT":
31-
return "String";
31+
return "HugeInt";
3232
case "INTEGER":
3333
return "Int";
3434
case "INTERVAL":
@@ -42,13 +42,15 @@ const determineType = (t: string): string => {
4242
case "TIME":
4343
return "String";
4444
case "TIMESTAMP":
45-
return "String";
45+
return "Timestamp";
4646
case "TIMESTAMP WITH TIME ZONE":
47-
return "String";
47+
return "TimestampTz";
4848
case "TINYINT":
4949
return "Int";
5050
case "UBIGINT":
51-
return "String";
51+
return "UBigInt";
52+
case "UHUGEINT":
53+
return "UHugeInt"
5254
case "UINTEGER":
5355
return "Int";
5456
case "USMALLINT":
@@ -59,8 +61,6 @@ const determineType = (t: string): string => {
5961
return "String";
6062
case "VARCHAR":
6163
return "String";
62-
case "HUGEINT":
63-
return "String";
6464
default:
6565
if (t.startsWith("DECIMAL")){
6666
return "Float";
@@ -86,22 +86,55 @@ async function main() {
8686
const tableAliases: {[k: string]: string} = {};
8787
const objectTypes: { [k: string]: ObjectType } = {};
8888
const tables = await queryAll(con, "SHOW ALL TABLES");
89+
90+
// Get table comments
91+
const tableComments = await queryAll(con, `
92+
SELECT table_name, comment
93+
FROM duckdb_tables()
94+
WHERE schema_name = 'main'
95+
`);
96+
97+
// Create a map of table comments for easier lookup
98+
const tableCommentMap = new Map(
99+
tableComments.map(row => [row.table_name, row.comment || "No description available"])
100+
);
101+
// Get all column comments upfront
102+
const columnComments = await queryAll(con, `
103+
SELECT table_name, column_name, comment
104+
FROM duckdb_columns()
105+
WHERE schema_name = 'main'
106+
`);
107+
// Create a nested map for column comments: table_name -> column_name -> comment
108+
const columnCommentMap = new Map();
109+
for (const row of columnComments) {
110+
if (!columnCommentMap.has(row.table_name)) {
111+
columnCommentMap.set(row.table_name, new Map());
112+
}
113+
columnCommentMap.get(row.table_name).set(row.column_name, row.comment || "No description available");
114+
}
115+
89116
for (let table of tables){
90-
const tableName = `${table.database}_${table.schema}_${table.name}`;
117+
const tableName = table.name;
91118
const aliasName = `${table.database}.${table.schema}.${table.name}`;
92119
tableNames.push(tableName);
93120
tableAliases[tableName] = aliasName;
94121
if (!objectTypes[tableName]){
95122
objectTypes[tableName] = {
96-
fields: {}
123+
fields: {},
124+
description: tableCommentMap.get(tableName) || "No Description Available"
97125
};
98126
}
99127
for (let i = 0; i < table.column_names.length; i++){
100-
objectTypes[tableName]['fields'][table.column_names[i]] = {
128+
const columnName = table.column_names[i];
129+
objectTypes[tableName]["fields"][columnName] = {
101130
type: {
102-
type: "named",
103-
name: determineType(table.column_types[i])
104-
}
131+
type: "nullable",
132+
underlying_type: {
133+
type: "named",
134+
name: determineType(table.column_types[i]),
135+
},
136+
},
137+
description: columnCommentMap.get(tableName)?.get(columnName) || "No description available"
105138
}
106139
}
107140
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "duckdb-sdk",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/constants.ts

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,197 @@ export const CAPABILITIES_RESPONSE: Capabilities = {
1616
};
1717
export const MAX_32_INT: number = 2147483647;
1818
export const SCALAR_TYPES: { [key: string]: ScalarType } = {
19+
BigInt: {
20+
representation: {
21+
type: "biginteger"
22+
},
23+
aggregate_functions: {
24+
// sum: {
25+
// result_type: {
26+
// type: "named",
27+
// name: "Int"
28+
// }
29+
// }
30+
},
31+
comparison_operators: {
32+
_eq: {
33+
type: "equal",
34+
},
35+
_gt: {
36+
type: "custom",
37+
argument_type: {
38+
type: "named",
39+
name: "BigInt",
40+
},
41+
},
42+
_lt: {
43+
type: "custom",
44+
argument_type: {
45+
type: "named",
46+
name: "BigInt",
47+
},
48+
},
49+
_gte: {
50+
type: "custom",
51+
argument_type: {
52+
type: "named",
53+
name: "BigInt",
54+
},
55+
},
56+
_lte: {
57+
type: "custom",
58+
argument_type: {
59+
type: "named",
60+
name: "BigInt",
61+
},
62+
},
63+
_neq: {
64+
type: "custom",
65+
argument_type: {
66+
type: "named",
67+
name: "BigInt",
68+
},
69+
},
70+
},
71+
},
72+
UBigInt: {
73+
representation: {
74+
type: "biginteger"
75+
},
76+
aggregate_functions: {},
77+
comparison_operators: {
78+
_eq: { type: "equal" },
79+
_gt: { type: "custom", argument_type: { type: "named", name: "UBigInt" }},
80+
_lt: { type: "custom", argument_type: { type: "named", name: "UBigInt" }},
81+
_gte: { type: "custom", argument_type: { type: "named", name: "UBigInt" }},
82+
_lte: { type: "custom", argument_type: { type: "named", name: "UBigInt" }},
83+
_neq: { type: "custom", argument_type: { type: "named", name: "UBigInt" }},
84+
},
85+
},
86+
HugeInt: {
87+
representation: {
88+
type: "biginteger"
89+
},
90+
aggregate_functions: {},
91+
comparison_operators: {
92+
_eq: { type: "equal" },
93+
_gt: { type: "custom", argument_type: { type: "named", name: "HugeInt" }},
94+
_lt: { type: "custom", argument_type: { type: "named", name: "HugeInt" }},
95+
_gte: { type: "custom", argument_type: { type: "named", name: "HugeInt" }},
96+
_lte: { type: "custom", argument_type: { type: "named", name: "HugeInt" }},
97+
_neq: { type: "custom", argument_type: { type: "named", name: "HugeInt" }},
98+
},
99+
},
100+
UHugeInt: {
101+
representation: {
102+
type: "biginteger"
103+
},
104+
aggregate_functions: {},
105+
comparison_operators: {
106+
_eq: { type: "equal" },
107+
_gt: { type: "custom", argument_type: { type: "named", name: "UHugeInt" }},
108+
_lt: { type: "custom", argument_type: { type: "named", name: "UHugeInt" }},
109+
_gte: { type: "custom", argument_type: { type: "named", name: "UHugeInt" }},
110+
_lte: { type: "custom", argument_type: { type: "named", name: "UHugeInt" }},
111+
_neq: { type: "custom", argument_type: { type: "named", name: "UHugeInt" }},
112+
},
113+
},
114+
Timestamp: {
115+
representation: {
116+
type: "timestamp"
117+
},
118+
aggregate_functions: {},
119+
comparison_operators: {
120+
_eq: {
121+
type: "equal",
122+
},
123+
_gt: {
124+
type: "custom",
125+
argument_type: {
126+
type: "named",
127+
name: "Timestamp",
128+
},
129+
},
130+
_lt: {
131+
type: "custom",
132+
argument_type: {
133+
type: "named",
134+
name: "Timestamp",
135+
},
136+
},
137+
_gte: {
138+
type: "custom",
139+
argument_type: {
140+
type: "named",
141+
name: "Timestamp",
142+
},
143+
},
144+
_lte: {
145+
type: "custom",
146+
argument_type: {
147+
type: "named",
148+
name: "Timestamp",
149+
},
150+
},
151+
_neq: {
152+
type: "custom",
153+
argument_type: {
154+
type: "named",
155+
name: "Timestamp",
156+
},
157+
},
158+
},
159+
},
160+
TimestampTz: {
161+
representation: {
162+
type: "timestamptz"
163+
},
164+
aggregate_functions: {},
165+
comparison_operators: {
166+
_eq: {
167+
type: "equal",
168+
},
169+
_gt: {
170+
type: "custom",
171+
argument_type: {
172+
type: "named",
173+
name: "TimestampTz",
174+
},
175+
},
176+
_lt: {
177+
type: "custom",
178+
argument_type: {
179+
type: "named",
180+
name: "TimestampTz",
181+
},
182+
},
183+
_gte: {
184+
type: "custom",
185+
argument_type: {
186+
type: "named",
187+
name: "TimestampTz",
188+
},
189+
},
190+
_lte: {
191+
type: "custom",
192+
argument_type: {
193+
type: "named",
194+
name: "TimestampTz",
195+
},
196+
},
197+
_neq: {
198+
type: "custom",
199+
argument_type: {
200+
type: "named",
201+
name: "TimestampTz",
202+
},
203+
},
204+
},
205+
},
19206
Int: {
207+
representation: {
208+
type: "int64"
209+
},
20210
aggregate_functions: {
21211
// sum: {
22212
// result_type: {
@@ -67,6 +257,9 @@ export const SCALAR_TYPES: { [key: string]: ScalarType } = {
67257
}
68258
},
69259
Float: {
260+
representation: {
261+
type: "float64"
262+
},
70263
aggregate_functions: {
71264
// sum: {
72265
// result_type: {
@@ -117,6 +310,9 @@ export const SCALAR_TYPES: { [key: string]: ScalarType } = {
117310
}
118311
},
119312
String: {
313+
representation: {
314+
type: "string"
315+
},
120316
aggregate_functions: {},
121317
comparison_operators: {
122318
_eq: {
@@ -174,6 +370,9 @@ export const SCALAR_TYPES: { [key: string]: ScalarType } = {
174370
}
175371
},
176372
Boolean: {
373+
representation: {
374+
type: "boolean"
375+
},
177376
aggregate_functions: {},
178377
comparison_operators: {
179378
_eq: {

0 commit comments

Comments
 (0)