Skip to content

Commit f9a04ce

Browse files
committed
fix bugs, support timestamps, fix object type mappings for JOINS, cast order by columns to LOWER
1 parent 77ee12c commit f9a04ce

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

CHANGELOG.md

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

4+
## [0.1.4] - 2025-01-08
5+
* Update to fix a bug to add support for UBigInt, HugeInt, UHugeInt
6+
* Add support for Timestamps with Timezone
7+
* Fix object type mapping on JOINS
8+
* Cast ORDER BY columns to lowercase so that field sorting yields A a B b rather than A B a b
9+
410
## [0.1.3] - 2025-01-08
511
* Bugfix for query builder
612

connector-definition/connector-metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
packagingDefinition:
22
type: PrebuiltDockerImage
3-
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.3
3+
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.4
44
supportedEnvironmentVariables:
55
- name: DUCKDB_URL
66
description: The url for the DuckDB database
77
commands:
88
update:
99
type: Dockerized
10-
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.3
10+
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.4
1111
commandArgs:
1212
- update
1313
dockerComposeWatch:

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.3",
3+
"version": "0.1.4",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/handlers/query.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
RowSet,
99
Forbidden,
1010
Conflict,
11-
Relationship
11+
Relationship,
12+
ObjectField,
13+
Type
1214
} from "@hasura/ndc-sdk-typescript";
1315
import { Configuration, State } from "..";
1416
const SqlString = require("sqlstring-sqlite");
@@ -18,16 +20,27 @@ import { MAX_32_INT } from "../constants";
1820
const escape_single = (s: any) => SqlString.escape(s);
1921
const escape_double = (s: any) => `"${SqlString.escape(s).slice(1, -1)}"`;
2022

21-
function getColumnExpression(field_def: any, collection_alias: string, column: string): string {
23+
function getColumnExpression(field_def: ObjectField, collection_alias: string, column: string): string {
2224
// Helper function to handle the actual type
23-
function handleNamedType(type: any): string {
24-
if (type.name === "BigInt") {
25-
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
25+
function handleNamedType(type: Type): string {
26+
if (type.type != "named"){
27+
throw new Forbidden("Named type must be named type", {});
28+
}
29+
switch (type.name){
30+
case "BigInt":
31+
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
32+
case "UBigInt":
33+
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
34+
case "HugeInt":
35+
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
36+
case "UHugeInt":
37+
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
38+
default:
39+
return `${escape_double(collection_alias)}.${escape_double(column)}`;
2640
}
27-
return `${escape_double(collection_alias)}.${escape_double(column)}`;
2841
}
2942
// Helper function to traverse the type structure
30-
function processType(type: any): string {
43+
function processType(type: Type): string {
3144
if (type.type === "nullable") {
3245
if (type.underlying_type.type === "named") {
3346
return handleNamedType(type.underlying_type);
@@ -56,7 +69,7 @@ function isTimestampType(field_def: any): boolean {
5669
if (type.type === "nullable") {
5770
return checkType(type.underlying_type);
5871
}
59-
return type.type === "named" && type.name === "Timestamp";
72+
return type.type === "named" && (type.name === "Timestamp" || type.name === "TimestampTz");
6073
}
6174

6275
return checkType(field_def.type);
@@ -82,7 +95,6 @@ function getIntegerType(field_def: any): string | null {
8295

8396
return checkType(field_def.type);
8497
}
85-
8698
function getRhsExpression(type: string | null): string {
8799
if (!type) return "?";
88100
return `CAST(? AS ${type})`;
@@ -338,7 +350,10 @@ function build_query(
338350
collect_rows.push(escape_single(field_name));
339351
switch (field_value.type) {
340352
case "column":
341-
const object_type = config.config?.object_types[query_request.collection];
353+
const current_collection = path.length > 1 && relationship_key
354+
? query_request.collection_relationships[relationship_key].target_collection
355+
: query_request.collection;
356+
const object_type = config.config?.object_types[current_collection];
342357
let field_def = object_type.fields[field_value.column];
343358
collect_rows.push(getColumnExpression(field_def, collection_alias, field_value.column));
344359
break;
@@ -397,7 +412,7 @@ function build_query(
397412
case "column":
398413
if (elem.target.path.length === 0){
399414
order_elems.push(
400-
`${escape_double(collection_alias)}.${escape_double(elem.target.name)} ${elem.order_direction}`
415+
`LOWER(${escape_double(collection_alias)}.${escape_double(elem.target.name)}) ${elem.order_direction}`
401416
);
402417
} else {
403418
let currentAlias = collection_alias;

0 commit comments

Comments
 (0)