Skip to content

Commit

Permalink
fix bugs, support timestamps, fix object type mappings for JOINS, cas…
Browse files Browse the repository at this point in the history
…t order by columns to LOWER
  • Loading branch information
TristenHarr committed Jan 8, 2025
1 parent 77ee12c commit f9a04ce
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# DuckDB Connector Changelog
This changelog documents changes between release tags.

## [0.1.4] - 2025-01-08
* Update to fix a bug to add support for UBigInt, HugeInt, UHugeInt
* Add support for Timestamps with Timezone
* Fix object type mapping on JOINS
* Cast ORDER BY columns to lowercase so that field sorting yields A a B b rather than A B a b

## [0.1.3] - 2025-01-08
* Bugfix for query builder

Expand Down
4 changes: 2 additions & 2 deletions connector-definition/connector-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
packagingDefinition:
type: PrebuiltDockerImage
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.3
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.4
supportedEnvironmentVariables:
- name: DUCKDB_URL
description: The url for the DuckDB database
commands:
update:
type: Dockerized
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.3
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.4
commandArgs:
- update
dockerComposeWatch:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "duckdb-sdk",
"version": "0.1.3",
"version": "0.1.4",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
37 changes: 26 additions & 11 deletions src/handlers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
RowSet,
Forbidden,
Conflict,
Relationship
Relationship,
ObjectField,
Type
} from "@hasura/ndc-sdk-typescript";
import { Configuration, State } from "..";
const SqlString = require("sqlstring-sqlite");
Expand All @@ -18,16 +20,27 @@ import { MAX_32_INT } from "../constants";
const escape_single = (s: any) => SqlString.escape(s);
const escape_double = (s: any) => `"${SqlString.escape(s).slice(1, -1)}"`;

function getColumnExpression(field_def: any, collection_alias: string, column: string): string {
function getColumnExpression(field_def: ObjectField, collection_alias: string, column: string): string {
// Helper function to handle the actual type
function handleNamedType(type: any): string {
if (type.name === "BigInt") {
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
function handleNamedType(type: Type): string {
if (type.type != "named"){
throw new Forbidden("Named type must be named type", {});
}
switch (type.name){
case "BigInt":
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
case "UBigInt":
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
case "HugeInt":
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
case "UHugeInt":
return `CAST(${escape_double(collection_alias)}.${escape_double(column)} AS TEXT)`;
default:
return `${escape_double(collection_alias)}.${escape_double(column)}`;
}
return `${escape_double(collection_alias)}.${escape_double(column)}`;
}
// Helper function to traverse the type structure
function processType(type: any): string {
function processType(type: Type): string {
if (type.type === "nullable") {
if (type.underlying_type.type === "named") {
return handleNamedType(type.underlying_type);
Expand Down Expand Up @@ -56,7 +69,7 @@ function isTimestampType(field_def: any): boolean {
if (type.type === "nullable") {
return checkType(type.underlying_type);
}
return type.type === "named" && type.name === "Timestamp";
return type.type === "named" && (type.name === "Timestamp" || type.name === "TimestampTz");
}

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

return checkType(field_def.type);
}

function getRhsExpression(type: string | null): string {
if (!type) return "?";
return `CAST(? AS ${type})`;
Expand Down Expand Up @@ -338,7 +350,10 @@ function build_query(
collect_rows.push(escape_single(field_name));
switch (field_value.type) {
case "column":
const object_type = config.config?.object_types[query_request.collection];
const current_collection = path.length > 1 && relationship_key
? query_request.collection_relationships[relationship_key].target_collection
: query_request.collection;
const object_type = config.config?.object_types[current_collection];
let field_def = object_type.fields[field_value.column];
collect_rows.push(getColumnExpression(field_def, collection_alias, field_value.column));
break;
Expand Down Expand Up @@ -397,7 +412,7 @@ function build_query(
case "column":
if (elem.target.path.length === 0){
order_elems.push(
`${escape_double(collection_alias)}.${escape_double(elem.target.name)} ${elem.order_direction}`
`LOWER(${escape_double(collection_alias)}.${escape_double(elem.target.name)}) ${elem.order_direction}`
);
} else {
let currentAlias = collection_alias;
Expand Down

0 comments on commit f9a04ce

Please sign in to comment.