Skip to content

Commit

Permalink
Merge pull request #24 from hasura:fix-variables-again
Browse files Browse the repository at this point in the history
Fix-variables-again
  • Loading branch information
BenoitRanque authored Aug 17, 2024
2 parents 3da8729 + f10c9d3 commit a5df7ec
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.1]

- Bug fix: remove erroneous group by and order by clauses in `foreach` queries. Remote relationships should now function as expected. The previous fix was incorrect.

## [1.0.0]

- Stable Release
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ members = [
]
resolver = "2"

package.version = "1.0.0"
package.version = "1.0.1"
package.edition = "2021"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://github.com/LukeMathWalker/cargo-chef
FROM rust:1.75.0 as chef
FROM rust:1.80.1 as chef
RUN cargo install cargo-chef
WORKDIR /app

Expand Down
24 changes: 0 additions & 24 deletions crates/ndc-clickhouse/src/sql/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,10 @@ impl<'r, 'c> QueryBuilder<'r, 'c> {
vec![rowset_subquery.into_table_with_joins(vec![])]
};

let order_by = if self.request.variables.is_some() {
vec![OrderByExpr {
expr: Expr::CompoundIdentifier(vec![
Ident::new_quoted("_vars"),
Ident::new_quoted("_varset_id"),
]),
asc: Some(true),
nulls_first: None,
}]
} else {
vec![]
};

let group_by = if self.request.variables.is_some() {
vec![Expr::CompoundIdentifier(vec![
Ident::new_quoted("_vars"),
Ident::new_quoted("_varset_id"),
])]
} else {
vec![]
};

Ok(Query::new()
.with(with)
.select(select)
.from(from)
.group_by(group_by)
.order_by(order_by)
.into_statement()
.format("TabSeparatedRaw"))
}
Expand Down
4 changes: 4 additions & 0 deletions crates/ndc-clickhouse/tests/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ mod variables {
async fn empty_variable_sets() -> Result<(), Box<dyn Error>> {
test_generated_sql("02_empty_variable_sets").await
}
#[tokio::test]
async fn singe_set() -> Result<(), Box<dyn Error>> {
test_generated_sql("03_single_set").await
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"variables": [
{
"ArtistId": 1
},
{
"ArtistId": 2
}
],
"query": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WITH "_vars" AS (
FROM
format(
JSONColumns,
'{"_varset_id":[1],"_var_ArtistId":[1]}'
'{"_varset_id":[1,2],"_var_ArtistId":[1,2]}'
)
)
SELECT
Expand Down Expand Up @@ -45,8 +45,4 @@ FROM
) AS "_row"
GROUP BY
"_row"."_varset_id"
) AS "_rowset" ON "_vars"."_varset_id" = "_rowset"."_varset_id"
GROUP BY
"_vars"."_varset_id"
ORDER BY
"_vars"."_varset_id" ASC FORMAT TabSeparatedRaw;
) AS "_rowset" ON "_vars"."_varset_id" = "_rowset"."_varset_id" FORMAT TabSeparatedRaw;
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,4 @@ FROM
) AS "_row"
GROUP BY
"_row"."_varset_id"
) AS "_rowset" ON "_vars"."_varset_id" = "_rowset"."_varset_id"
GROUP BY
"_vars"."_varset_id"
ORDER BY
"_vars"."_varset_id" ASC FORMAT TabSeparatedRaw;
) AS "_rowset" ON "_vars"."_varset_id" = "_rowset"."_varset_id" FORMAT TabSeparatedRaw;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"$schema": "../../request.schema.json",
"collection": "Chinook_Album",
"variables": [
{
"ArtistId": 1
}
],
"query": {
"fields": {
"albumId": {
"type": "column",
"column": "AlbumId",
"fields": null
},
"artistId": {
"type": "column",
"column": "ArtistId",
"fields": null
},
"title": {
"type": "column",
"column": "Title",
"fields": null
}
},
"predicate": {
"type": "and",
"expressions": [
{
"type": "and",
"expressions": [
{
"type": "binary_comparison_operator",
"column": {
"type": "column",
"name": "ArtistId",
"path": []
},
"operator": "_eq",
"value": {
"type": "variable",
"name": "ArtistId"
}
}
]
}
]
}
},
"arguments": {},
"collection_relationships": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
WITH "_vars" AS (
SELECT
*
FROM
format(
JSONColumns,
'{"_varset_id":[1],"_var_ArtistId":[1]}'
)
)
SELECT
toJSONString(
groupArray(
cast(
"_rowset"."_rowset",
'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))'
)
)
) AS "rowsets"
FROM
"_vars" AS "_vars"
LEFT JOIN (
SELECT
tuple(
groupArray(
tuple(
"_row"."_field_albumId",
"_row"."_field_artistId",
"_row"."_field_title"
)
)
) AS "_rowset",
"_row"."_varset_id" AS "_varset_id"
FROM
(
SELECT
"_origin"."AlbumId" AS "_field_albumId",
"_origin"."ArtistId" AS "_field_artistId",
"_origin"."Title" AS "_field_title",
"_vars"."_varset_id" AS "_varset_id"
FROM
"_vars" AS "_vars"
CROSS JOIN "Chinook"."Album" AS "_origin"
WHERE
"_origin"."ArtistId" = "_vars"."_var_ArtistId"
) AS "_row"
GROUP BY
"_row"."_varset_id"
) AS "_rowset" ON "_vars"."_varset_id" = "_rowset"."_varset_id" FORMAT TabSeparatedRaw;
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
services:
ndc-clickhouse:
image: ndc-clickhouse-debug
build:
context: .
args:
Expand Down

0 comments on commit a5df7ec

Please sign in to comment.