Skip to content

Commit

Permalink
fix casts
Browse files Browse the repository at this point in the history
  • Loading branch information
TristenHarr committed Jan 15, 2025
1 parent f9a04ce commit 52629bd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# DuckDB Connector Changelog
This changelog documents changes between release tags.

## [0.1.5] - 2025-01-15
* Fix order by LOWER cast

## [0.1.4] - 2025-01-08
* Update to fix a bug to add support for UBigInt, HugeInt, UHugeInt
* Add support for Timestamps with Timezone
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.4
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.5
supportedEnvironmentVariables:
- name: DUCKDB_URL
description: The url for the DuckDB database
commands:
update:
type: Dockerized
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.4
dockerImage: ghcr.io/hasura/ndc-duckdb:v0.1.5
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.4",
"version": "0.1.5",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
34 changes: 30 additions & 4 deletions src/handlers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,23 @@ function getColumnExpression(field_def: ObjectField, collection_alias: string, c
return processType(field_def.type);
}

function isTimestampType(field_def: any): boolean {
function isStringType(field_def: ObjectField | undefined): boolean {
if (!field_def) return false;

function checkType(type: any): boolean {
if (type.type === "nullable") {
return checkType(type.underlying_type);
}
if (type.type === "array") {
return false;
}
return type.type === "named" && type.name === "String";
}

return checkType(field_def.type);
}

function isTimestampType(field_def: ObjectField | undefined): boolean {
if (!field_def) return false;

function checkType(type: any): boolean {
Expand All @@ -74,7 +90,7 @@ function isTimestampType(field_def: any): boolean {

return checkType(field_def.type);
}
function getIntegerType(field_def: any): string | null {
function getIntegerType(field_def: ObjectField | undefined): string | null {
if (!field_def) return null;

function checkType(type: any): string | null {
Expand Down Expand Up @@ -411,11 +427,16 @@ function build_query(
switch (elem.target.type) {
case "column":
if (elem.target.path.length === 0){
const field_def = config.config.object_types[query_request.collection].fields[elem.target.name];
const is_string = isStringType(field_def);
const field_name = is_string ? `LOWER(${escape_double(collection_alias)}.${escape_double(elem.target.name)})` : `${escape_double(collection_alias)}.${escape_double(elem.target.name)}`
order_elems.push(
`LOWER(${escape_double(collection_alias)}.${escape_double(elem.target.name)}) ${elem.order_direction}`
`${field_name} ${elem.order_direction}`
);
} else {
let currentAlias = collection_alias;
let current_collection = query_request.collection;
let field_def = config.config.object_types[current_collection].fields[elem.target.name];
for (let path_elem of elem.target.path) {
const relationship = collection_relationships[path_elem.relationship];
const nextAlias = `${currentAlias}_${relationship.target_collection}`;
Expand All @@ -425,9 +446,13 @@ function build_query(
filter_joins.push(join_str);
}
currentAlias = nextAlias;
current_collection = relationship.target_collection;
field_def = config.config.object_types[current_collection].fields[elem.target.name];
}
const is_string = isStringType(field_def);
const field_name = is_string ? `LOWER(${escape_double(currentAlias)}.${escape_double(elem.target.name)})` : `${escape_double(currentAlias)}.${escape_double(elem.target.name)}`;
order_elems.push(
`${escape_double(currentAlias)}.${escape_double(elem.target.name)} ${elem.order_direction}`
`${field_name} ${elem.order_direction}`
);
}
break;
Expand Down Expand Up @@ -569,6 +594,7 @@ export async function do_query(
state: State,
query: QueryRequest
): Promise<QueryResponse> {
// console.log(JSON.stringify(query, null, 4));
let query_plans = await plan_queries(configuration, query);
return await perform_query(state, query_plans);
}

0 comments on commit 52629bd

Please sign in to comment.