From 923cbab85c5023928f41c6fcd184f6cefe1ceeb9 Mon Sep 17 00:00:00 2001 From: Benoit Ranque Date: Wed, 12 Jun 2024 13:11:30 -0400 Subject: [PATCH] add more tests --- crates/ndc-clickhouse/tests/query_builder.rs | 212 +++++++++--- .../01_select_rows.request.json | 25 ++ .../01_select_rows.statement.sql | 31 ++ .../02_with_predicate.request.json | 48 +++ .../02_with_predicate.statement.sql | 33 ++ .../03_larger_predicate.request.json | 84 +++++ .../03_larger_predicate.statement.sql | 36 ++ .../01_simple_queries/04_limit.request.json | 26 ++ .../01_simple_queries/04_limit.statement.sql | 33 ++ .../01_simple_queries/05_offset.request.json | 26 ++ .../01_simple_queries/05_offset.statement.sql | 31 ++ .../06_limit_offset.request.json | 27 ++ .../06_limit_offset.statement.sql | 33 ++ .../07_order_by.request.json | 37 ++ .../07_order_by.statement.sql | 33 ++ ...edicate_limit_offset_order_by.request.json | 62 ++++ ...dicate_limit_offset_order_by.statement.sql | 37 ++ .../01_object_relationship.request.json | 53 +++ .../01_object_relationship.statement.sql | 53 +++ .../02_array_relationship.request.json | 58 ++++ .../02_array_relationship.statement copy.sql | 58 ++++ .../02_array_relationship.statement.sql | 58 ++++ .../03_parent_predicate.request.json | 81 +++++ .../03_parent_predicate.statement.sql | 60 ++++ .../04_child_predicate.request.json | 104 ++++++ .../04_child_predicate.statement.sql | 62 ++++ ...rse_relationship_in_predicate.request.json | 102 ++++++ ...se_relationship_in_predicate.statement.sql | 71 ++++ ...erse_relationship_in_order_by.request.json | 97 ++++++ ...rse_relationship_in_order_by.statement.sql | 77 +++++ ...ggregate_across_relationships.request.json | 116 +++++++ ...gregate_across_relationships.statement.sql | 73 ++++ .../chinook/_config/configuration.json | 246 +++++++++++++ .../_config}/configuration.json | 0 .../01_generate_column_accessor.request.json | 0 .../01_generate_column_accessor.statement.sql | 0 .../02_skip_if_not_required.request.json | 0 .../02_skip_if_not_required.statement.sql | 0 ...relationships_on_nested_field.request.json | 0 ...elationships_on_nested_field.statement.sql | 0 ...onships_on_array_nested_field.request.json | 0 .../05_complex_example.request.json | 0 .../05_complex_example.statement.sql | 0 ...6_no_useless_nested_accessors.request.json | 0 ..._no_useless_nested_accessors.statement.sql | 0 .../01_native_query.request.json | 15 + .../01_native_query.statement.sql | 30 ++ .../star_schema/_config/configuration.json | 322 ++++++++++++++++++ .../star_schema/_config/queries/q1.1.sql | 3 + .../star_schema/_config/queries/q1.2.sql | 3 + .../star_schema/_config/queries/q1.3.sql | 5 + .../star_schema/_config/queries/q2.1.sql | 12 + .../star_schema/_config/queries/q2.2.sql | 12 + .../star_schema/_config/queries/q2.3.sql | 12 + .../star_schema/_config/queries/q3.1.sql | 14 + .../star_schema/_config/queries/q3.2.sql | 14 + .../star_schema/_config/queries/q3.3.sql | 14 + .../star_schema/_config/queries/q3.4.sql | 15 + .../star_schema/_config/queries/q4.1.sql | 12 + .../star_schema/_config/queries/q4.2.sql | 15 + .../star_schema/_config/queries/q4.3.sql | 16 + 61 files changed, 2651 insertions(+), 46 deletions(-) create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement copy.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/chinook/_config/configuration.json rename crates/ndc-clickhouse/tests/query_builder/{field_selector/config => complex_columns/_config}/configuration.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/01_generate_column_accessor.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/01_generate_column_accessor.statement.sql (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/02_skip_if_not_required.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/02_skip_if_not_required.statement.sql (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/03_support_relationships_on_nested_field.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/03_support_relationships_on_nested_field.statement.sql (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/04_error_on_relationships_on_array_nested_field.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/05_complex_example.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/05_complex_example.statement.sql (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/06_no_useless_nested_accessors.request.json (100%) rename crates/ndc-clickhouse/tests/query_builder/{ => complex_columns}/field_selector/06_no_useless_nested_accessors.statement.sql (100%) create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.request.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.statement.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/configuration.json create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.1.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.2.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.3.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.1.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.2.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.3.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.1.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.2.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.3.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.4.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.1.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.2.sql create mode 100644 crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.3.sql diff --git a/crates/ndc-clickhouse/tests/query_builder.rs b/crates/ndc-clickhouse/tests/query_builder.rs index 8dbb9b8..70b0c39 100644 --- a/crates/ndc-clickhouse/tests/query_builder.rs +++ b/crates/ndc-clickhouse/tests/query_builder.rs @@ -3,7 +3,6 @@ use ndc_clickhouse::sql::QueryBuilderError; use ndc_sdk::models; use schemars::schema_for; use std::error::Error; -use test_utils::{test_error, test_generated_sql}; use tokio::fs; mod test_utils { @@ -21,43 +20,58 @@ mod test_utils { /// we don't want that behavior when running CI, so this value should be false in commited code const UPDATE_GENERATED_SQL: bool = false; - fn base_path(group_dir: &str) -> PathBuf { + fn base_path(schema_dir: &str) -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("tests") .join("query_builder") - .join(group_dir) + .join(schema_dir) } - async fn read_mock_configuration(group_dir: &str) -> Result> { + fn tests_dir_path(schema_dir: &str, group_dir: &str) -> PathBuf { + base_path(schema_dir).join(group_dir) + } + fn config_dir_path(schema_dir: &str) -> PathBuf { + base_path(schema_dir).join("_config") + } + async fn read_mock_configuration(schema_dir: &str) -> Result> { // set mock values for required env vars, we won't be reading these anyways env::set_var("CLICKHOUSE_URL", ""); env::set_var("CLICKHOUSE_USERNAME", ""); env::set_var("CLICKHOUSE_PASSWORD", ""); - let config_dir = base_path(group_dir).join("config"); + let config_dir = config_dir_path(schema_dir); let configuration = read_server_config(config_dir).await?; Ok(configuration) } async fn read_request( + schema_dir: &str, group_dir: &str, test_name: &str, ) -> Result> { - let request_path = base_path(group_dir).join(format!("{test_name}.request.json")); + let request_path = + tests_dir_path(schema_dir, group_dir).join(format!("{test_name}.request.json")); let file_content = fs::read_to_string(request_path).await?; let request: models::QueryRequest = serde_json::from_str(&file_content)?; Ok(request) } - async fn read_expected_sql(group_dir: &str, test_name: &str) -> Result> { - let statement_path = base_path(group_dir).join(format!("{test_name}.statement.sql")); + async fn read_expected_sql( + schema_dir: &str, + group_dir: &str, + test_name: &str, + ) -> Result> { + let statement_path = + tests_dir_path(schema_dir, group_dir).join(format!("{test_name}.statement.sql")); let expected_statement = fs::read_to_string(&statement_path).await?; Ok(expected_statement) } async fn write_expected_sql( + schema_dir: &str, group_dir: &str, test_name: &str, generated_statement: &str, ) -> Result<(), Box> { - let statement_path = base_path(group_dir).join(format!("{test_name}.statement.sql")); + let statement_path = + tests_dir_path(schema_dir, group_dir).join(format!("{test_name}.statement.sql")); let pretty_statement = pretty_print_sql(&generated_statement); fs::write(&statement_path, &pretty_statement).await?; Ok(()) @@ -85,31 +99,33 @@ mod test_utils { Ok(generated_statement) } pub async fn test_generated_sql( + schema_dir: &str, group_dir: &str, test_name: &str, ) -> Result<(), Box> { - let configuration = read_mock_configuration(group_dir).await?; - let request = read_request(group_dir, test_name).await?; + let configuration = read_mock_configuration(schema_dir).await?; + let request = read_request(schema_dir, group_dir, test_name).await?; let generated_sql = generate_sql(&configuration, &request)?; - let expected_sql = read_expected_sql(group_dir, test_name).await?; - if UPDATE_GENERATED_SQL { - write_expected_sql(group_dir, test_name, &generated_sql).await?; - } + write_expected_sql(schema_dir, group_dir, test_name, &generated_sql).await?; + } else { + let expected_sql = read_expected_sql(schema_dir, group_dir, test_name).await?; - assert_eq!(generated_sql, expected_sql); + assert_eq!(generated_sql, expected_sql); + } Ok(()) } pub async fn test_error( + schema_dir: &str, group_dir: &str, test_name: &str, err: QueryBuilderError, ) -> Result<(), Box> { - let configuration = read_mock_configuration(group_dir).await?; - let request = read_request(group_dir, test_name).await?; + let configuration = read_mock_configuration(schema_dir).await?; + let request = read_request(schema_dir, group_dir, test_name).await?; let result = generate_sql(&configuration, &request); @@ -135,35 +151,139 @@ async fn update_json_schema() -> Result<(), Box> { Ok(()) } -#[tokio::test] -async fn generate_column_accessor() -> Result<(), Box> { - test_generated_sql("field_selector", "01_generate_column_accessor").await -} -#[tokio::test] -async fn skip_if_not_required() -> Result<(), Box> { - test_generated_sql("field_selector", "02_skip_if_not_required").await -} -#[tokio::test] -async fn support_relationships_on_nested_field() -> Result<(), Box> { - test_generated_sql("field_selector", "03_support_relationships_on_nested_field").await + +#[cfg(test)] +mod simple_queries { + use super::*; + + async fn test_generated_sql(name: &str) -> Result<(), Box> { + super::test_utils::test_generated_sql("chinook", "01_simple_queries", name).await + } + + #[tokio::test] + async fn select_rows() -> Result<(), Box> { + test_generated_sql("01_select_rows").await + } + #[tokio::test] + async fn with_predicate() -> Result<(), Box> { + test_generated_sql("02_with_predicate").await + } + #[tokio::test] + async fn larger_predicate() -> Result<(), Box> { + test_generated_sql("03_larger_predicate").await + } + #[tokio::test] + async fn limit() -> Result<(), Box> { + test_generated_sql("04_limit").await + } + #[tokio::test] + async fn offset() -> Result<(), Box> { + test_generated_sql("05_offset").await + } + #[tokio::test] + async fn limit_offset() -> Result<(), Box> { + test_generated_sql("06_limit_offset").await + } + + #[tokio::test] + async fn order_by() -> Result<(), Box> { + test_generated_sql("07_order_by").await + } + #[tokio::test] + async fn predicate_limit_offset_order_by() -> Result<(), Box> { + test_generated_sql("08_predicate_limit_offset_order_by").await + } } -/// We do not support relationships on nested fileds if an array has been traversed -#[tokio::test] -async fn error_on_relationships_on_array_nested_field() -> Result<(), Box> { - let err = - QueryBuilderError::NotSupported("Relationships with fields nested in arrays".to_string()); - test_error( - "field_selector", - "04_error_on_relationships_on_array_nested_field", - err, - ) - .await + +#[cfg(test)] +mod relationships { + use super::*; + + async fn test_generated_sql(name: &str) -> Result<(), Box> { + super::test_utils::test_generated_sql("chinook", "02_relationships", name).await + } + + #[tokio::test] + async fn object_relationship() -> Result<(), Box> { + test_generated_sql("01_object_relationship").await + } + #[tokio::test] + async fn array_relationship() -> Result<(), Box> { + test_generated_sql("02_array_relationship").await + } + #[tokio::test] + async fn parent_predicate() -> Result<(), Box> { + test_generated_sql("03_parent_predicate").await + } + #[tokio::test] + async fn child_predicate() -> Result<(), Box> { + test_generated_sql("04_child_predicate").await + } + #[tokio::test] + async fn traverse_relationship_in_predicate() -> Result<(), Box> { + test_generated_sql("05_traverse_relationship_in_predicate").await + } + #[tokio::test] + async fn traverse_relationship_in_order_by() -> Result<(), Box> { + test_generated_sql("06_traverse_relationship_in_order_by").await + } + #[tokio::test] + async fn order_by_aggregate_across_relationships() -> Result<(), Box> { + test_generated_sql("07_order_by_aggregate_across_relationships").await + } } -#[tokio::test] -async fn complex_example() -> Result<(), Box> { - test_generated_sql("field_selector", "05_complex_example").await + +#[cfg(test)] +mod native_queries { + use super::*; + + async fn test_generated_sql(name: &str) -> Result<(), Box> { + super::test_utils::test_generated_sql("star_schema", "01_native_queries", name).await + } + + #[tokio::test] + async fn native_query() -> Result<(), Box> { + test_generated_sql("01_native_query").await + } } -#[tokio::test] -async fn no_useless_nested_accessors() -> Result<(), Box> { - test_generated_sql("field_selector", "06_no_useless_nested_accessors").await + +#[cfg(test)] +mod field_selector { + use super::*; + + async fn test_generated_sql(name: &str) -> Result<(), Box> { + super::test_utils::test_generated_sql("complex_columns", "field_selector", name).await + } + async fn test_error(name: &str, err: QueryBuilderError) -> Result<(), Box> { + super::test_utils::test_error("complex_columns", "field_selector", name, err).await + } + + #[tokio::test] + async fn generate_column_accessor() -> Result<(), Box> { + test_generated_sql("01_generate_column_accessor").await + } + #[tokio::test] + async fn skip_if_not_required() -> Result<(), Box> { + test_generated_sql("02_skip_if_not_required").await + } + #[tokio::test] + async fn support_relationships_on_nested_field() -> Result<(), Box> { + test_generated_sql("03_support_relationships_on_nested_field").await + } + /// We do not support relationships on nested fileds if an array has been traversed + #[tokio::test] + async fn error_on_relationships_on_array_nested_field() -> Result<(), Box> { + let err = QueryBuilderError::NotSupported( + "Relationships with fields nested in arrays".to_string(), + ); + test_error("04_error_on_relationships_on_array_nested_field", err).await + } + #[tokio::test] + async fn complex_example() -> Result<(), Box> { + test_generated_sql("05_complex_example").await + } + #[tokio::test] + async fn no_useless_nested_accessors() -> Result<(), Box> { + test_generated_sql("06_no_useless_nested_accessors").await + } } diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.request.json new file mode 100644 index 0000000..44df377 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.request.json @@ -0,0 +1,25 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.statement.sql new file mode 100644 index 0000000..6d3e6f9 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/01_select_rows.statement.sql @@ -0,0 +1,31 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.request.json new file mode 100644 index 0000000..92f5846 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.request.json @@ -0,0 +1,48 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "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": "scalar", + "value": "1" + } + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.statement.sql new file mode 100644 index 0000000..f3a8cb4 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/02_with_predicate.statement.sql @@ -0,0 +1,33 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + WHERE + "_origin"."ArtistId" = '1' + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.request.json new file mode 100644 index 0000000..a41e8fe --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.request.json @@ -0,0 +1,84 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "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": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "ArtistId", + "path": [] + }, + "operator": "_eq", + "value": { + "type": "scalar", + "value": "1" + } + } + ] + }, + { + "type": "not", + "expression": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "ArtistId", + "path": [] + }, + "operator": "_eq", + "value": { + "type": "scalar", + "value": "2" + } + } + ] + } + ] + } + } + ] + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.statement.sql new file mode 100644 index 0000000..146636b --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/03_larger_predicate.statement.sql @@ -0,0 +1,36 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + WHERE + ( + "_origin"."ArtistId" = '1' + AND NOT ("_origin"."ArtistId" = '2') + ) + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.request.json new file mode 100644 index 0000000..acb33fa --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.request.json @@ -0,0 +1,26 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + }, + "limit": 10 + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.statement.sql new file mode 100644 index 0000000..3063baa --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/04_limit.statement.sql @@ -0,0 +1,33 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + LIMIT + 10 + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.request.json new file mode 100644 index 0000000..63d6984 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.request.json @@ -0,0 +1,26 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + }, + "offset": 10 + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.statement.sql new file mode 100644 index 0000000..c54bca3 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/05_offset.statement.sql @@ -0,0 +1,31 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" OFFSET 10 + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.request.json new file mode 100644 index 0000000..b69b6c4 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.request.json @@ -0,0 +1,27 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + }, + "limit": 10, + "offset": 10 + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.statement.sql new file mode 100644 index 0000000..20d8f04 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/06_limit_offset.statement.sql @@ -0,0 +1,33 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + LIMIT + 10 OFFSET 10 + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.request.json new file mode 100644 index 0000000..27b8008 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.request.json @@ -0,0 +1,37 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "ArtistId", + "path": [] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.statement.sql new file mode 100644 index 0000000..d9df4f4 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/07_order_by.statement.sql @@ -0,0 +1,33 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + ORDER BY + "_origin"."ArtistId" ASC + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.request.json new file mode 100644 index 0000000..c1275db --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.request.json @@ -0,0 +1,62 @@ +{ + "$schema": "../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + } + }, + "limit": 10, + "offset": 10, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "ArtistId", + "path": [] + } + } + ] + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "ArtistId", + "path": [] + }, + "operator": "_gt", + "value": { + "type": "scalar", + "value": "10" + } + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.statement.sql new file mode 100644 index 0000000..3e74d6d --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/01_simple_queries/08_predicate_limit_offset_order_by.statement.sql @@ -0,0 +1,37 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title" + FROM + "Chinook"."Album" AS "_origin" + WHERE + "_origin"."ArtistId" > '10' + ORDER BY + "_origin"."ArtistId" ASC + LIMIT + 10 OFFSET 10 + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.request.json new file mode 100644 index 0000000..99c578e --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.request.json @@ -0,0 +1,53 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + }, + "Artist": { + "type": "relationship", + "query": { + "fields": { + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {} + } + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Artist", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.statement.sql new file mode 100644 index 0000000..80d4b9a --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/01_object_relationship.statement.sql @@ -0,0 +1,53 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Artist" Tuple(rows Array(Tuple("artistId" Int32, "name" Nullable(String)))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Artist" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Artist"."_rowset" AS "_field_Artist" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple("_row"."_field_artistId", "_row"."_field_name") + ) + ) AS "_rowset", + "_row"."_relkey_ArtistId" AS "_relkey_ArtistId" + FROM + ( + SELECT + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Name" AS "_field_name", + "_origin"."ArtistId" AS "_relkey_ArtistId" + FROM + "Chinook"."Artist" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_ArtistId" + ) AS "_rel_0_Artist" ON "_origin"."ArtistId" = "_rel_0_Artist"."_relkey_ArtistId" + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.request.json new file mode 100644 index 0000000..895b14a --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.request.json @@ -0,0 +1,58 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + }, + "Tracks": { + "type": "relationship", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + }, + "unitPrice": { + "type": "column", + "column": "UnitPrice", + "fields": null + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]", + "arguments": {} + } + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "array", + "target_collection": "Chinook_Track", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement copy.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement copy.sql new file mode 100644 index 0000000..ebf6a7d --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement copy.sql @@ -0,0 +1,58 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Tracks" Tuple(rows Array(Tuple("trackId" Int32, "name" String, "unitPrice" Float64))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Tracks" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Tracks"."_rowset" AS "_field_Tracks" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_unitPrice" + ) + ) + ) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_origin"."UnitPrice" AS "_field_unitPrice", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Track" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Tracks" ON "_origin"."AlbumId" = "_rel_0_Tracks"."_relkey_AlbumId" + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement.sql new file mode 100644 index 0000000..ebf6a7d --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/02_array_relationship.statement.sql @@ -0,0 +1,58 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Tracks" Tuple(rows Array(Tuple("trackId" Int32, "name" String, "unitPrice" Float64))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Tracks" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Tracks"."_rowset" AS "_field_Tracks" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_unitPrice" + ) + ) + ) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_origin"."UnitPrice" AS "_field_unitPrice", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Track" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Tracks" ON "_origin"."AlbumId" = "_rel_0_Tracks"."_relkey_AlbumId" + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.request.json new file mode 100644 index 0000000..8065a62 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.request.json @@ -0,0 +1,81 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + }, + "Tracks": { + "type": "relationship", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + }, + "unitPrice": { + "type": "column", + "column": "UnitPrice", + "fields": null + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]", + "arguments": {} + } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "ArtistId", + "path": [] + }, + "operator": "_gt", + "value": { + "type": "scalar", + "value": "10" + } + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "array", + "target_collection": "Chinook_Track", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.statement.sql new file mode 100644 index 0000000..374b8b7 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/03_parent_predicate.statement.sql @@ -0,0 +1,60 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Tracks" Tuple(rows Array(Tuple("trackId" Int32, "name" String, "unitPrice" Float64))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Tracks" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Tracks"."_rowset" AS "_field_Tracks" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_unitPrice" + ) + ) + ) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_origin"."UnitPrice" AS "_field_unitPrice", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Track" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Tracks" ON "_origin"."AlbumId" = "_rel_0_Tracks"."_relkey_AlbumId" + WHERE + "_origin"."ArtistId" > '10' + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.request.json new file mode 100644 index 0000000..929e20d --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.request.json @@ -0,0 +1,104 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + }, + "Tracks": { + "type": "relationship", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + }, + "unitPrice": { + "type": "column", + "column": "UnitPrice", + "fields": null + } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "TrackId", + "path": [] + }, + "operator": "_gt", + "value": { + "type": "scalar", + "value": "10" + } + } + ] + } + ] + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]", + "arguments": {} + } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "ArtistId", + "path": [] + }, + "operator": "_gt", + "value": { + "type": "scalar", + "value": "10" + } + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "array", + "target_collection": "Chinook_Track", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.statement.sql new file mode 100644 index 0000000..eea2e1e --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/04_child_predicate.statement.sql @@ -0,0 +1,62 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Tracks" Tuple(rows Array(Tuple("trackId" Int32, "name" String, "unitPrice" Float64))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Tracks" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Tracks"."_rowset" AS "_field_Tracks" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_unitPrice" + ) + ) + ) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_origin"."UnitPrice" AS "_field_unitPrice", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Track" AS "_origin" + WHERE + "_origin"."TrackId" > '10' + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Tracks" ON "_origin"."AlbumId" = "_rel_0_Tracks"."_relkey_AlbumId" + WHERE + "_origin"."ArtistId" > '10' + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.request.json new file mode 100644 index 0000000..75521ff --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.request.json @@ -0,0 +1,102 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Album", + "query": { + "fields": { + "albumId": { + "type": "column", + "column": "AlbumId", + "fields": null + }, + "artistId": { + "type": "column", + "column": "ArtistId", + "fields": null + }, + "title": { + "type": "column", + "column": "Title", + "fields": null + }, + "Tracks": { + "type": "relationship", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + }, + "unitPrice": { + "type": "column", + "column": "UnitPrice", + "fields": null + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]", + "arguments": {} + } + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "exists", + "in_collection": { + "type": "related", + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {} + }, + "predicate": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "Name", + "path": [] + }, + "operator": "_eq", + "value": { + "type": "scalar", + "value": "AC/DC" + } + } + ] + } + ] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Artist", + "arguments": {} + }, + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Tracks\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "array", + "target_collection": "Chinook_Track", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.statement.sql new file mode 100644 index 0000000..ab269b8 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/05_traverse_relationship_in_predicate.statement.sql @@ -0,0 +1,71 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("albumId" Int32, "artistId" Int32, "title" String, "Tracks" Tuple(rows Array(Tuple("trackId" Int32, "name" String, "unitPrice" Float64))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_albumId", + "_row"."_field_artistId", + "_row"."_field_title", + "_row"."_field_Tracks" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."AlbumId" AS "_field_albumId", + "_origin"."ArtistId" AS "_field_artistId", + "_origin"."Title" AS "_field_title", + "_rel_0_Tracks"."_rowset" AS "_field_Tracks" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_unitPrice" + ) + ) + ) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_origin"."UnitPrice" AS "_field_unitPrice", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Track" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Tracks" ON "_origin"."AlbumId" = "_rel_0_Tracks"."_relkey_AlbumId" + LEFT JOIN ( + SELECT + TRUE AS "_exists_0", + "_exists_1"."ArtistId" AS "_relkey_ArtistId" + FROM + "Chinook"."Artist" AS "_exists_1" + WHERE + "_exists_1"."Name" = 'AC/DC' + LIMIT + 1 BY "_exists_1"."ArtistId" + ) AS "_exists_0" ON "_origin"."ArtistId" = "_exists_0"."_relkey_ArtistId" + WHERE + "_exists_0"."_exists_0" = TRUE + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.request.json new file mode 100644 index 0000000..38b4a79 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.request.json @@ -0,0 +1,97 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Track", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + }, + "Album": { + "type": "relationship", + "query": { + "fields": { + "Artist": { + "type": "relationship", + "query": { + "fields": { + "name": { + "type": "column", + "column": "Name", + "fields": null + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {} + } + } + }, + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]", + "arguments": {} + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "Name", + "path": [ + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + }, + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + } + ] + } + }, + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "Name", + "path": [] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Artist", + "arguments": {} + }, + "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Album", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.statement.sql new file mode 100644 index 0000000..712119f --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/06_traverse_relationship_in_order_by.statement.sql @@ -0,0 +1,77 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("trackId" Int32, "name" String, "Album" Tuple(rows Array(Tuple("Artist" Tuple(rows Array(Tuple("name" Nullable(String))))))))))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple( + "_row"."_field_trackId", + "_row"."_field_name", + "_row"."_field_Album" + ) + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name", + "_rel_0_Album"."_rowset" AS "_field_Album" + FROM + "Chinook"."Track" AS "_origin" + LEFT JOIN ( + SELECT + tuple(groupArray(tuple("_row"."_field_Artist"))) AS "_rowset", + "_row"."_relkey_AlbumId" AS "_relkey_AlbumId" + FROM + ( + SELECT + "_rel_0_Artist"."_rowset" AS "_field_Artist", + "_origin"."AlbumId" AS "_relkey_AlbumId" + FROM + "Chinook"."Album" AS "_origin" + LEFT JOIN ( + SELECT + tuple(groupArray(tuple("_row"."_field_name"))) AS "_rowset", + "_row"."_relkey_ArtistId" AS "_relkey_ArtistId" + FROM + ( + SELECT + "_origin"."Name" AS "_field_name", + "_origin"."ArtistId" AS "_relkey_ArtistId" + FROM + "Chinook"."Artist" AS "_origin" + ) AS "_row" + GROUP BY + "_row"."_relkey_ArtistId" + ) AS "_rel_0_Artist" ON "_origin"."ArtistId" = "_rel_0_Artist"."_relkey_ArtistId" + ) AS "_row" + GROUP BY + "_row"."_relkey_AlbumId" + ) AS "_rel_0_Album" ON "_origin"."AlbumId" = "_rel_0_Album"."_relkey_AlbumId" + LEFT JOIN ( + SELECT + "_order_by_0"."AlbumId" AS "_relkey_AlbumId", + "_order_by_1"."Name" AS "_order_by_value" + FROM + "Chinook"."Album" AS "_order_by_0" + JOIN "Chinook"."Artist" AS "_order_by_1" ON "_order_by_0"."ArtistId" = "_order_by_1"."ArtistId" + WHERE + TRUE + AND TRUE + LIMIT + 1 BY "_order_by_0"."AlbumId" + ) AS "_order_by_0" ON "_origin"."AlbumId" = "_order_by_0"."_relkey_AlbumId" + ORDER BY + "_order_by_0"."_order_by_value" ASC, + "_origin"."Name" ASC + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.request.json b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.request.json new file mode 100644 index 0000000..5c30d2b --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.request.json @@ -0,0 +1,116 @@ +{ + "$schema": "../../request.schema.json", + "collection": "Chinook_Track", + "query": { + "fields": { + "trackId": { + "type": "column", + "column": "TrackId", + "fields": null + }, + "name": { + "type": "column", + "column": "Name", + "fields": null + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "Name", + "path": [ + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + }, + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + } + ] + } + }, + { + "order_direction": "asc", + "target": { + "type": "star_count_aggregate", + "path": [ + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + }, + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + } + ] + } + }, + { + "order_direction": "asc", + "target": { + "type": "single_column_aggregate", + "column": "Name", + "function": "max", + "path": [ + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + }, + { + "relationship": "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + } + ] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "[{\"subgraph\":\"app\",\"name\":\"ChinookAlbum\"},\"Artist\"]": { + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Artist", + "arguments": {} + }, + "[{\"subgraph\":\"app\",\"name\":\"ChinookTrack\"},\"Album\"]": { + "column_mapping": { + "AlbumId": "AlbumId" + }, + "relationship_type": "object", + "target_collection": "Chinook_Album", + "arguments": {} + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.statement.sql b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.statement.sql new file mode 100644 index 0000000..02c023f --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/02_relationships/07_order_by_aggregate_across_relationships.statement.sql @@ -0,0 +1,73 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("trackId" Int32, "name" String)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple( + groupArray( + tuple("_row"."_field_trackId", "_row"."_field_name") + ) + ) AS "_rowset" + FROM + ( + SELECT + "_origin"."TrackId" AS "_field_trackId", + "_origin"."Name" AS "_field_name" + FROM + "Chinook"."Track" AS "_origin" + LEFT JOIN ( + SELECT + "_order_by_0"."AlbumId" AS "_relkey_AlbumId", + "_order_by_1"."Name" AS "_order_by_value" + FROM + "Chinook"."Album" AS "_order_by_0" + JOIN "Chinook"."Artist" AS "_order_by_1" ON "_order_by_0"."ArtistId" = "_order_by_1"."ArtistId" + WHERE + TRUE + AND TRUE + LIMIT + 1 BY "_order_by_0"."AlbumId" + ) AS "_order_by_0" ON "_origin"."AlbumId" = "_order_by_0"."_relkey_AlbumId" + LEFT JOIN ( + SELECT + "_order_by_0"."AlbumId" AS "_relkey_AlbumId", + COUNT(*) AS "_order_by_value" + FROM + "Chinook"."Album" AS "_order_by_0" + JOIN "Chinook"."Artist" AS "_order_by_1" ON "_order_by_0"."ArtistId" = "_order_by_1"."ArtistId" + WHERE + TRUE + AND TRUE + GROUP BY + "_order_by_0"."AlbumId" + LIMIT + 1 BY "_order_by_0"."AlbumId" + ) AS "_order_by_1" ON "_origin"."AlbumId" = "_order_by_1"."_relkey_AlbumId" + LEFT JOIN ( + SELECT + "_order_by_0"."AlbumId" AS "_relkey_AlbumId", + max("_order_by_1"."Name") AS "_order_by_value" + FROM + "Chinook"."Album" AS "_order_by_0" + JOIN "Chinook"."Artist" AS "_order_by_1" ON "_order_by_0"."ArtistId" = "_order_by_1"."ArtistId" + WHERE + TRUE + AND TRUE + GROUP BY + "_order_by_0"."AlbumId" + LIMIT + 1 BY "_order_by_0"."AlbumId" + ) AS "_order_by_2" ON "_origin"."AlbumId" = "_order_by_2"."_relkey_AlbumId" + ORDER BY + "_order_by_0"."_order_by_value" ASC, + "_order_by_1"."_order_by_value" ASC, + "_order_by_2"."_order_by_value" ASC + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/chinook/_config/configuration.json b/crates/ndc-clickhouse/tests/query_builder/chinook/_config/configuration.json new file mode 100644 index 0000000..9e67ca3 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/chinook/_config/configuration.json @@ -0,0 +1,246 @@ +{ + "$schema": "../../configuration.schema.json", + "tables": { + "Chinook_Album": { + "name": "Album", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "AlbumId", + "columns": [ + "AlbumId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "AlbumId": "Int32", + "ArtistId": "Int32", + "Title": "String" + } + } + }, + "Chinook_Artist": { + "name": "Artist", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "ArtistId", + "columns": [ + "ArtistId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "ArtistId": "Int32", + "Name": "Nullable(String)" + } + } + }, + "Chinook_Customer": { + "name": "Customer", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "CustomerId", + "columns": [ + "CustomerId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "Address": "Nullable(String)", + "City": "Nullable(String)", + "Company": "Nullable(String)", + "Country": "Nullable(String)", + "CustomerId": "Int32", + "Email": "String", + "Fax": "Nullable(String)", + "FirstName": "String", + "LastName": "String", + "Phone": "Nullable(String)", + "PostalCode": "Nullable(String)", + "State": "Nullable(String)", + "SupportRepId": "Nullable(Int32)" + } + } + }, + "Chinook_Employee": { + "name": "Employee", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "EmployeeId", + "columns": [ + "EmployeeId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "Address": "Nullable(String)", + "BirthDate": "Nullable(Date32)", + "City": "Nullable(String)", + "Country": "Nullable(String)", + "Email": "Nullable(String)", + "EmployeeId": "Int32", + "Fax": "Nullable(String)", + "FirstName": "String", + "HireDate": "Nullable(Date32)", + "LastName": "String", + "Phone": "Nullable(String)", + "PostalCode": "Nullable(String)", + "ReportsTo": "Nullable(Int32)", + "State": "Nullable(String)", + "Title": "Nullable(String)" + } + } + }, + "Chinook_Genre": { + "name": "Genre", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "GenreId", + "columns": [ + "GenreId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "GenreId": "Int32", + "Name": "Nullable(String)" + } + } + }, + "Chinook_Invoice": { + "name": "Invoice", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "InvoiceId", + "columns": [ + "InvoiceId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "BillingAddress": "Nullable(String)", + "BillingCity": "Nullable(String)", + "BillingCountry": "Nullable(String)", + "BillingPostalCode": "Nullable(String)", + "BillingState": "Nullable(String)", + "CustomerId": "Int32", + "InvoiceDate": "DateTime64(9)", + "InvoiceId": "Int32", + "Total": "Float64" + } + } + }, + "Chinook_InvoiceLine": { + "name": "InvoiceLine", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "InvoiceLineId", + "columns": [ + "InvoiceLineId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "InvoiceId": "Int32", + "InvoiceLineId": "Int32", + "Quantity": "Int32", + "TrackId": "Int32", + "UnitPrice": "Float64" + } + } + }, + "Chinook_MediaType": { + "name": "MediaType", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "MediaTypeId", + "columns": [ + "MediaTypeId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "MediaTypeId": "Int32", + "Name": "Nullable(String)" + } + } + }, + "Chinook_Playlist": { + "name": "Playlist", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "PlaylistId", + "columns": [ + "PlaylistId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "Name": "Nullable(String)", + "PlaylistId": "Int32" + } + } + }, + "Chinook_PlaylistTrack": { + "name": "PlaylistTrack", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "PlaylistId, TrackId", + "columns": [ + "PlaylistId", + "TrackId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "PlaylistId": "Int32", + "TrackId": "Int32" + } + } + }, + "Chinook_Track": { + "name": "Track", + "schema": "Chinook", + "comment": "", + "primary_key": { + "name": "TrackId", + "columns": [ + "TrackId" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "AlbumId": "Nullable(Int32)", + "Bytes": "Nullable(Int32)", + "Composer": "Nullable(String)", + "GenreId": "Nullable(Int32)", + "MediaTypeId": "Int32", + "Milliseconds": "Int32", + "Name": "String", + "TrackId": "Int32", + "UnitPrice": "Float64" + } + } + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/config/configuration.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/_config/configuration.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/config/configuration.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/_config/configuration.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/01_generate_column_accessor.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/01_generate_column_accessor.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/01_generate_column_accessor.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/01_generate_column_accessor.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/01_generate_column_accessor.statement.sql b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/01_generate_column_accessor.statement.sql similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/01_generate_column_accessor.statement.sql rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/01_generate_column_accessor.statement.sql diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/02_skip_if_not_required.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/02_skip_if_not_required.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/02_skip_if_not_required.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/02_skip_if_not_required.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/02_skip_if_not_required.statement.sql b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/02_skip_if_not_required.statement.sql similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/02_skip_if_not_required.statement.sql rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/02_skip_if_not_required.statement.sql diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/03_support_relationships_on_nested_field.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/03_support_relationships_on_nested_field.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/03_support_relationships_on_nested_field.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/03_support_relationships_on_nested_field.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/03_support_relationships_on_nested_field.statement.sql b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/03_support_relationships_on_nested_field.statement.sql similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/03_support_relationships_on_nested_field.statement.sql rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/03_support_relationships_on_nested_field.statement.sql diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/04_error_on_relationships_on_array_nested_field.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/04_error_on_relationships_on_array_nested_field.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/04_error_on_relationships_on_array_nested_field.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/04_error_on_relationships_on_array_nested_field.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/05_complex_example.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/05_complex_example.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/05_complex_example.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/05_complex_example.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/05_complex_example.statement.sql b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/05_complex_example.statement.sql similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/05_complex_example.statement.sql rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/05_complex_example.statement.sql diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/06_no_useless_nested_accessors.request.json b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/06_no_useless_nested_accessors.request.json similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/06_no_useless_nested_accessors.request.json rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/06_no_useless_nested_accessors.request.json diff --git a/crates/ndc-clickhouse/tests/query_builder/field_selector/06_no_useless_nested_accessors.statement.sql b/crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/06_no_useless_nested_accessors.statement.sql similarity index 100% rename from crates/ndc-clickhouse/tests/query_builder/field_selector/06_no_useless_nested_accessors.statement.sql rename to crates/ndc-clickhouse/tests/query_builder/complex_columns/field_selector/06_no_useless_nested_accessors.statement.sql diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.request.json b/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.request.json new file mode 100644 index 0000000..077877a --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.request.json @@ -0,0 +1,15 @@ +{ + "$schema": "../../request.schema.json", + "collection": "q11", + "query": { + "fields": { + "revenue": { + "type": "column", + "column": "revenue", + "fields": null + } + } + }, + "arguments": {}, + "collection_relationships": {} +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.statement.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.statement.sql new file mode 100644 index 0000000..2568396 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/01_native_queries/01_native_query.statement.sql @@ -0,0 +1,30 @@ +SELECT + toJSONString( + groupArray( + cast( + "_rowset"."_rowset", + 'Tuple(rows Array(Tuple("revenue" UInt64)))' + ) + ) + ) AS "rowsets" +FROM + ( + SELECT + tuple(groupArray(tuple("_row"."_field_revenue"))) AS "_rowset" + FROM + ( + SELECT + "_origin"."revenue" AS "_field_revenue" + FROM + ( + SELECT + sum(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue + FROM + star.lineorder_flat + WHERE + toYear(LO_ORDERDATE) = 1993 + AND LO_DISCOUNT BETWEEN 1 AND 3 + AND LO_QUANTITY < 25 + ) AS "_origin" + ) AS "_row" + ) AS "_rowset" FORMAT TabSeparatedRaw; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/configuration.json b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/configuration.json new file mode 100644 index 0000000..01dfa0d --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/configuration.json @@ -0,0 +1,322 @@ +{ + "$schema": "../../configuration.schema.json", + "tables": { + "star_customer": { + "name": "customer", + "schema": "star", + "comment": "", + "primary_key": { + "name": "C_CUSTKEY", + "columns": [ + "C_CUSTKEY" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "C_ADDRESS": "String", + "C_CITY": "LowCardinality(String)", + "C_CUSTKEY": "UInt32", + "C_MKTSEGMENT": "LowCardinality(String)", + "C_NAME": "String", + "C_NATION": "LowCardinality(String)", + "C_PHONE": "String", + "C_REGION": "LowCardinality(String)" + } + } + }, + "star_lineorder": { + "name": "lineorder", + "schema": "star", + "comment": "", + "primary_key": { + "name": "LO_ORDERDATE, LO_ORDERKEY", + "columns": [ + "LO_ORDERKEY", + "LO_ORDERDATE" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "LO_COMMITDATE": "Date", + "LO_CUSTKEY": "UInt32", + "LO_DISCOUNT": "UInt8", + "LO_EXTENDEDPRICE": "UInt32", + "LO_LINENUMBER": "UInt8", + "LO_ORDERDATE": "Date", + "LO_ORDERKEY": "UInt32", + "LO_ORDERPRIORITY": "LowCardinality(String)", + "LO_ORDTOTALPRICE": "UInt32", + "LO_PARTKEY": "UInt32", + "LO_QUANTITY": "UInt8", + "LO_REVENUE": "UInt32", + "LO_SHIPMODE": "LowCardinality(String)", + "LO_SHIPPRIORITY": "UInt8", + "LO_SUPPKEY": "UInt32", + "LO_SUPPLYCOST": "UInt32", + "LO_TAX": "UInt8" + } + } + }, + "star_lineorder_flat": { + "name": "lineorder_flat", + "schema": "star", + "comment": "", + "primary_key": { + "name": "LO_ORDERDATE, LO_ORDERKEY", + "columns": [ + "LO_ORDERKEY", + "LO_ORDERDATE" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "C_ADDRESS": "String", + "C_CITY": "LowCardinality(String)", + "C_MKTSEGMENT": "LowCardinality(String)", + "C_NAME": "String", + "C_NATION": "LowCardinality(String)", + "C_PHONE": "String", + "C_REGION": "LowCardinality(String)", + "LO_COMMITDATE": "Date", + "LO_CUSTKEY": "UInt32", + "LO_DISCOUNT": "UInt8", + "LO_EXTENDEDPRICE": "UInt32", + "LO_LINENUMBER": "UInt8", + "LO_ORDERDATE": "Date", + "LO_ORDERKEY": "UInt32", + "LO_ORDERPRIORITY": "LowCardinality(String)", + "LO_ORDTOTALPRICE": "UInt32", + "LO_PARTKEY": "UInt32", + "LO_QUANTITY": "UInt8", + "LO_REVENUE": "UInt32", + "LO_SHIPMODE": "LowCardinality(String)", + "LO_SHIPPRIORITY": "UInt8", + "LO_SUPPKEY": "UInt32", + "LO_SUPPLYCOST": "UInt32", + "LO_TAX": "UInt8", + "P_BRAND": "LowCardinality(String)", + "P_CATEGORY": "LowCardinality(String)", + "P_COLOR": "LowCardinality(String)", + "P_CONTAINER": "LowCardinality(String)", + "P_MFGR": "LowCardinality(String)", + "P_NAME": "String", + "P_SIZE": "UInt8", + "P_TYPE": "LowCardinality(String)", + "S_ADDRESS": "String", + "S_CITY": "LowCardinality(String)", + "S_NAME": "String", + "S_NATION": "LowCardinality(String)", + "S_PHONE": "String", + "S_REGION": "LowCardinality(String)" + } + } + }, + "star_part": { + "name": "part", + "schema": "star", + "comment": "", + "primary_key": { + "name": "P_PARTKEY", + "columns": [ + "P_PARTKEY" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "P_BRAND": "LowCardinality(String)", + "P_CATEGORY": "LowCardinality(String)", + "P_COLOR": "LowCardinality(String)", + "P_CONTAINER": "LowCardinality(String)", + "P_MFGR": "LowCardinality(String)", + "P_NAME": "String", + "P_PARTKEY": "UInt32", + "P_SIZE": "UInt8", + "P_TYPE": "LowCardinality(String)" + } + } + }, + "star_supplier": { + "name": "supplier", + "schema": "star", + "comment": "", + "primary_key": { + "name": "S_SUPPKEY", + "columns": [ + "S_SUPPKEY" + ] + }, + "return_type": { + "kind": "definition", + "columns": { + "S_ADDRESS": "String", + "S_CITY": "LowCardinality(String)", + "S_NAME": "String", + "S_NATION": "LowCardinality(String)", + "S_PHONE": "String", + "S_REGION": "LowCardinality(String)", + "S_SUPPKEY": "UInt32" + } + } + } + }, + "queries": { + "q11": { + "exposed_as": "collection", + "file": "./queries/q1.1.sql", + "return_type": { + "kind": "definition", + "columns": { + "revenue": "UInt64" + } + } + }, + "q12": { + "exposed_as": "collection", + "file": "./queries/q1.2.sql", + "return_type": { + "kind": "query_reference", + "query_name": "q11" + } + }, + "q13": { + "exposed_as": "collection", + "file": "./queries/q1.3.sql", + "return_type": { + "kind": "definition", + "columns": { + "revenue": "UInt64" + } + } + }, + "q21": { + "exposed_as": "collection", + "file": "./queries/q2.1.sql", + "return_type": { + "kind": "definition", + "columns": { + "P_BRAND": "LowCardinality(String)", + "sum(LO_REVENUE)": "UInt64", + "year": "UInt16" + } + } + }, + "q22": { + "exposed_as": "collection", + "file": "./queries/q2.2.sql", + "return_type": { + "kind": "definition", + "columns": { + "P_BRAND": "LowCardinality(String)", + "sum(LO_REVENUE)": "UInt64", + "year": "UInt16" + } + } + }, + "q23": { + "exposed_as": "collection", + "file": "./queries/q2.3.sql", + "return_type": { + "kind": "definition", + "columns": { + "P_BRAND": "LowCardinality(String)", + "sum(LO_REVENUE)": "UInt64", + "year": "UInt16" + } + } + }, + "q31": { + "exposed_as": "collection", + "file": "./queries/q3.1.sql", + "return_type": { + "kind": "definition", + "columns": { + "C_NATION": "LowCardinality(String)", + "S_NATION": "LowCardinality(String)", + "revenue": "UInt64", + "year": "UInt16" + } + } + }, + "q32": { + "exposed_as": "collection", + "file": "./queries/q3.2.sql", + "return_type": { + "kind": "definition", + "columns": { + "C_NATION": "LowCardinality(String)", + "S_NATION": "LowCardinality(String)", + "revenue": "UInt64", + "year": "UInt16" + } + } + }, + "q33": { + "exposed_as": "collection", + "file": "./queries/q3.3.sql", + "return_type": { + "kind": "definition", + "columns": { + "C_NATION": "LowCardinality(String)", + "S_NATION": "LowCardinality(String)", + "revenue": "UInt64", + "year": "UInt16" + } + } + }, + "q34": { + "exposed_as": "collection", + "file": "./queries/q3.4.sql", + "return_type": { + "kind": "definition", + "columns": { + "C_NATION": "LowCardinality(String)", + "S_NATION": "LowCardinality(String)", + "revenue": "UInt64", + "year": "UInt16" + } + } + }, + "q41": { + "exposed_as": "collection", + "file": "./queries/q4.1.sql", + "return_type": { + "kind": "definition", + "columns": { + "C_NATION": "LowCardinality(String)", + "profit": "Int64", + "year": "UInt16" + } + } + }, + "q42": { + "exposed_as": "collection", + "file": "./queries/q4.2.sql", + "return_type": { + "kind": "definition", + "columns": { + "P_CATEGORY": "LowCardinality(String)", + "S_NATION": "LowCardinality(String)", + "profit": "Int64", + "year": "UInt16" + } + } + }, + "q43": { + "exposed_as": "collection", + "file": "./queries/q4.3.sql", + "return_type": { + "kind": "definition", + "columns": { + "P_BRAND": "LowCardinality(String)", + "S_CITY": "LowCardinality(String)", + "profit": "Int64", + "year": "UInt16" + } + } + } + } +} \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.1.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.1.sql new file mode 100644 index 0000000..dcfcde3 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.1.sql @@ -0,0 +1,3 @@ +SELECT sum(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue +FROM star.lineorder_flat +WHERE toYear(LO_ORDERDATE) = 1993 AND LO_DISCOUNT BETWEEN 1 AND 3 AND LO_QUANTITY < 25; diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.2.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.2.sql new file mode 100644 index 0000000..98a12f8 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.2.sql @@ -0,0 +1,3 @@ +SELECT sum(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue +FROM star.lineorder_flat +WHERE toYYYYMM(LO_ORDERDATE) = 199401 AND LO_DISCOUNT BETWEEN 4 AND 6 AND LO_QUANTITY BETWEEN 26 AND 35; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.3.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.3.sql new file mode 100644 index 0000000..4d38223 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q1.3.sql @@ -0,0 +1,5 @@ + +SELECT sum(LO_EXTENDEDPRICE * LO_DISCOUNT) AS revenue +FROM star.lineorder_flat +WHERE toISOWeek(LO_ORDERDATE) = 6 AND toYear(LO_ORDERDATE) = 1994 + AND LO_DISCOUNT BETWEEN 5 AND 7 AND LO_QUANTITY BETWEEN 26 AND 35; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.1.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.1.sql new file mode 100644 index 0000000..71e6fb3 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.1.sql @@ -0,0 +1,12 @@ +SELECT + sum(LO_REVENUE), + toYear(LO_ORDERDATE) AS year, + P_BRAND +FROM star.lineorder_flat +WHERE P_CATEGORY = 'MFGR#12' AND S_REGION = 'AMERICA' +GROUP BY + year, + P_BRAND +ORDER BY + year, + P_BRAND; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.2.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.2.sql new file mode 100644 index 0000000..6c72561 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.2.sql @@ -0,0 +1,12 @@ +SELECT + sum(LO_REVENUE), + toYear(LO_ORDERDATE) AS year, + P_BRAND +FROM star.lineorder_flat +WHERE P_BRAND >= 'MFGR#2221' AND P_BRAND <= 'MFGR#2228' AND S_REGION = 'ASIA' +GROUP BY + year, + P_BRAND +ORDER BY + year, + P_BRAND; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.3.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.3.sql new file mode 100644 index 0000000..b024286 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q2.3.sql @@ -0,0 +1,12 @@ +SELECT + sum(LO_REVENUE), + toYear(LO_ORDERDATE) AS year, + P_BRAND +FROM star.lineorder_flat +WHERE P_BRAND = 'MFGR#2239' AND S_REGION = 'EUROPE' +GROUP BY + year, + P_BRAND +ORDER BY + year, + P_BRAND; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.1.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.1.sql new file mode 100644 index 0000000..97b9fa9 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.1.sql @@ -0,0 +1,14 @@ +SELECT + C_NATION, + S_NATION, + toYear(LO_ORDERDATE) AS year, + sum(LO_REVENUE) AS revenue +FROM star.lineorder_flat +WHERE C_REGION = 'ASIA' AND S_REGION = 'ASIA' AND year >= 1992 AND year <= 1997 +GROUP BY + C_NATION, + S_NATION, + year +ORDER BY + year ASC, + revenue DESC; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.2.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.2.sql new file mode 100644 index 0000000..7d13f58 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.2.sql @@ -0,0 +1,14 @@ +SELECT + C_CITY, + S_CITY, + toYear(LO_ORDERDATE) AS year, + sum(LO_REVENUE) AS revenue +FROM star.lineorder_flat +WHERE C_NATION = 'UNITED STATES' AND S_NATION = 'UNITED STATES' AND year >= 1992 AND year <= 1997 +GROUP BY + C_CITY, + S_CITY, + year +ORDER BY + year ASC, + revenue DESC; diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.3.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.3.sql new file mode 100644 index 0000000..f4f8ffc --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.3.sql @@ -0,0 +1,14 @@ +SELECT + C_CITY, + S_CITY, + toYear(LO_ORDERDATE) AS year, + sum(LO_REVENUE) AS revenue +FROM star.lineorder_flat +WHERE (C_CITY = 'UNITED KI1' OR C_CITY = 'UNITED KI5') AND (S_CITY = 'UNITED KI1' OR S_CITY = 'UNITED KI5') AND year >= 1992 AND year <= 1997 +GROUP BY + C_CITY, + S_CITY, + year +ORDER BY + year ASC, + revenue DESC; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.4.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.4.sql new file mode 100644 index 0000000..b4745cc --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q3.4.sql @@ -0,0 +1,15 @@ + +SELECT + C_CITY, + S_CITY, + toYear(LO_ORDERDATE) AS year, + sum(LO_REVENUE) AS revenue +FROM star.lineorder_flat +WHERE (C_CITY = 'UNITED KI1' OR C_CITY = 'UNITED KI5') AND (S_CITY = 'UNITED KI1' OR S_CITY = 'UNITED KI5') AND toYYYYMM(LO_ORDERDATE) = 199712 +GROUP BY + C_CITY, + S_CITY, + year +ORDER BY + year ASC, + revenue DESC; diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.1.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.1.sql new file mode 100644 index 0000000..8cc0068 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.1.sql @@ -0,0 +1,12 @@ +SELECT + toYear(LO_ORDERDATE) AS year, + C_NATION, + sum(LO_REVENUE - LO_SUPPLYCOST) AS profit +FROM star.lineorder_flat +WHERE C_REGION = 'AMERICA' AND S_REGION = 'AMERICA' AND (P_MFGR = 'MFGR#1' OR P_MFGR = 'MFGR#2') +GROUP BY + year, + C_NATION +ORDER BY + year ASC, + C_NATION ASC; diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.2.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.2.sql new file mode 100644 index 0000000..3c0b1ed --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.2.sql @@ -0,0 +1,15 @@ +SELECT + toYear(LO_ORDERDATE) AS year, + S_NATION, + P_CATEGORY, + sum(LO_REVENUE - LO_SUPPLYCOST) AS profit +FROM star.lineorder_flat +WHERE C_REGION = 'AMERICA' AND S_REGION = 'AMERICA' AND (year = 1997 OR year = 1998) AND (P_MFGR = 'MFGR#1' OR P_MFGR = 'MFGR#2') +GROUP BY + year, + S_NATION, + P_CATEGORY +ORDER BY + year ASC, + S_NATION ASC, + P_CATEGORY ASC; \ No newline at end of file diff --git a/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.3.sql b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.3.sql new file mode 100644 index 0000000..ae49fa4 --- /dev/null +++ b/crates/ndc-clickhouse/tests/query_builder/star_schema/_config/queries/q4.3.sql @@ -0,0 +1,16 @@ +SELECT + toYear(LO_ORDERDATE) AS year, + S_CITY, + P_BRAND, + sum(LO_REVENUE - LO_SUPPLYCOST) AS profit +FROM star.lineorder_flat +WHERE S_NATION = 'UNITED STATES' AND (year = 1997 OR year = 1998) AND P_CATEGORY = 'MFGR#14' +GROUP BY + year, + S_CITY, + P_BRAND +ORDER BY + year ASC, + S_CITY ASC, + P_BRAND ASC; +