diff --git a/Cargo.lock b/Cargo.lock index e895418..29bc87b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -219,12 +219,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -1097,8 +1091,8 @@ dependencies = [ [[package]] name = "ndc-models" -version = "0.1.2" -source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.2#6e7d12a31787d5f618099a42ddc0bea786438c00" +version = "0.1.4" +source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.4#20172e3b2552b78d16dbafcd047f559ced420309" dependencies = [ "indexmap 2.2.5", "schemars", @@ -1109,8 +1103,8 @@ dependencies = [ [[package]] name = "ndc-sdk" -version = "0.1.0" -source = "git+https://github.com/hasura/ndc-sdk-rs?rev=972dba6#972dba6e270ad54f4748487f75018c24229c1e5e" +version = "0.1.4" +source = "git+https://github.com/hasura/ndc-sdk-rs?tag=v0.1.4#29adcb5983c1237e8a5f4732d5230c2ba8ab75d3" dependencies = [ "async-trait", "axum", @@ -1142,8 +1136,8 @@ dependencies = [ [[package]] name = "ndc-test" -version = "0.1.2" -source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.2#6e7d12a31787d5f618099a42ddc0bea786438c00" +version = "0.1.4" +source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.4#20172e3b2552b78d16dbafcd047f559ced420309" dependencies = [ "async-trait", "clap", @@ -1969,15 +1963,17 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.3.3" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" dependencies = [ - "base64 0.13.1", + "base64 0.22.0", "chrono", "hex", "indexmap 1.9.3", + "indexmap 2.2.5", "serde", + "serde_derive", "serde_json", "serde_with_macros", "time", @@ -1985,9 +1981,9 @@ dependencies = [ [[package]] name = "serde_with_macros" -version = "2.3.3" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" +checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" dependencies = [ "darling", "proc-macro2", diff --git a/crates/common/src/clickhouse_parser.rs b/crates/common/src/clickhouse_parser.rs index 15e0e4c..fe69a60 100644 --- a/crates/common/src/clickhouse_parser.rs +++ b/crates/common/src/clickhouse_parser.rs @@ -226,7 +226,7 @@ fn can_parse_parameterized_query() { }), ], }; - let parsed = clickhouse_parser::parameterized_query(&query); + let parsed = clickhouse_parser::parameterized_query(query); assert_eq!(parsed, Ok(expected), "can parse parameterized query"); } @@ -234,7 +234,7 @@ fn can_parse_parameterized_query() { fn can_parse_empty_parameterized_query() { let query = r#""#; let expected = ParameterizedQuery { elements: vec![] }; - let parsed = clickhouse_parser::parameterized_query(&query); + let parsed = clickhouse_parser::parameterized_query(query); assert_eq!(parsed, Ok(expected), "can parse parameterized query"); } @@ -259,6 +259,6 @@ fn does_not_parse_parameters_insides_quoted_strings() { ParameterizedQueryElement::String(" AND Name = '{ArtistName: String}'".to_string()), ], }; - let parsed = clickhouse_parser::parameterized_query(&query); + let parsed = clickhouse_parser::parameterized_query(query); assert_eq!(parsed, Ok(expected), "can parse parameterized query"); } diff --git a/crates/ndc-clickhouse-cli/src/main.rs b/crates/ndc-clickhouse-cli/src/main.rs index 5c88243..157daac 100644 --- a/crates/ndc-clickhouse-cli/src/main.rs +++ b/crates/ndc-clickhouse-cli/src/main.rs @@ -157,7 +157,7 @@ async fn read_config_file(file_path: &PathBuf) -> Result + Send, - introspection: &Vec, + introspection: &[TableInfo], ) -> Result> { let file_path = configuration_dir.as_ref().join(CONFIG_FILE_NAME); let schema_file_path = configuration_dir.as_ref().join(CONFIG_SCHEMA_FILE_NAME); @@ -206,7 +206,7 @@ async fn update_tables_config( table, &old_table_config, &old_config, - &introspection, + introspection, ), }; @@ -216,7 +216,7 @@ async fn update_tables_config( let config = ServerConfigFile { schema: CONFIG_SCHEMA_FILE_NAME.to_owned(), - tables: tables, + tables, queries: old_config .as_ref() .map(|old_config| old_config.queries.to_owned()) @@ -295,7 +295,7 @@ async fn validate_table_config( ReturnType::Definition { columns } => { for (column_alias, column_data_type) in columns { let _data_type = - ClickHouseDataType::from_str(&column_data_type).map_err(|err| { + ClickHouseDataType::from_str(column_data_type).map_err(|err| { format!( "Unable to parse data type \"{}\" for column {} in table {}: {}", column_data_type, column_alias, table_alias, err @@ -368,7 +368,7 @@ async fn validate_table_config( ReturnType::Definition { columns } => { for (column_name, column_data_type) in columns { let _data_type = - ClickHouseDataType::from_str(&column_data_type).map_err(|err| { + ClickHouseDataType::from_str(column_data_type).map_err(|err| { format!( "Unable to parse data type \"{}\" for field {} in query {}: {}", column_data_type, column_name, query_alias, err @@ -435,7 +435,7 @@ fn get_table_return_type( table: &TableInfo, old_table: &Option<(&String, &TableConfigFile)>, old_config: &Option, - introspection: &Vec, + introspection: &[TableInfo], ) -> ReturnType { let new_columns = get_return_type_columns(table); @@ -495,7 +495,7 @@ fn get_table_return_type( }, ); - old_return_type.unwrap_or_else(|| ReturnType::Definition { + old_return_type.unwrap_or(ReturnType::Definition { columns: new_columns, }) } diff --git a/crates/ndc-clickhouse/Cargo.toml b/crates/ndc-clickhouse/Cargo.toml index 73a2a53..95d0c8c 100644 --- a/crates/ndc-clickhouse/Cargo.toml +++ b/crates/ndc-clickhouse/Cargo.toml @@ -8,7 +8,7 @@ async-trait = "0.1.78" bytes = "1.6.0" common = { path = "../common" } indexmap = "2.1.0" -ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs", rev = "972dba6", package = "ndc-sdk" } +ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs", tag = "v0.1.4", package = "ndc-sdk" } prometheus = "0.13.3" reqwest = { version = "0.12.3", features = [ "json", diff --git a/crates/ndc-clickhouse/src/connector.rs b/crates/ndc-clickhouse/src/connector.rs index daa5f01..81ec2fd 100644 --- a/crates/ndc-clickhouse/src/connector.rs +++ b/crates/ndc-clickhouse/src/connector.rs @@ -1,12 +1,7 @@ pub mod handler; pub mod state; -use std::{ - collections::BTreeMap, - env, - path::{Path, PathBuf}, - str::FromStr, -}; +use std::{collections::BTreeMap, env, path::Path, str::FromStr}; use tokio::fs; use async_trait::async_trait; @@ -164,14 +159,14 @@ pub async fn read_server_config( &file_path, &["tables", &table_alias, "return_type"], )? - .and_then(|columns| { - Some(( + .map(|columns| { + ( table_alias.to_owned(), TableType { comment: table_config.comment.to_owned(), columns, }, - )) + ) }); Ok(table_type) @@ -183,14 +178,14 @@ pub async fn read_server_config( &file_path, &["query", &query_alias, "return_type"], )? - .and_then(|columns| { - Some(( + .map(|columns| { + ( query_alias.to_owned(), TableType { comment: query_config.comment.to_owned(), columns, }, - )) + ) }); Ok(table_type) @@ -223,7 +218,7 @@ pub async fn read_server_config( .iter() .map(|(name, r#type)| { let data_type = - ClickHouseDataType::from_str(&r#type).map_err(|_err| { + ClickHouseDataType::from_str(r#type).map_err(|_err| { ParseError::ValidateError(InvalidNodes(vec![InvalidNode { file_path: file_path.to_owned(), node_path: vec![ @@ -318,7 +313,7 @@ fn get_connection_config() -> Result { fn validate_and_parse_return_type( return_type: &ReturnType, config: &ServerConfigFile, - file_path: &PathBuf, + file_path: &Path, node_path: &[&str], ) -> Result>, ParseError> { let get_node_path = |extra_segments: &[&str]| { @@ -338,7 +333,7 @@ fn validate_and_parse_return_type( Some(_) => { Err(ParseError::ValidateError(InvalidNodes(vec![ InvalidNode { - file_path: file_path.clone(), + file_path: file_path.to_path_buf(), node_path: get_node_path(&["table_name"]), message: format!( "Invalid reference: referenced table {} which does not have a return type definition", @@ -348,16 +343,16 @@ fn validate_and_parse_return_type( ]))) } None => { - return Err(ParseError::ValidateError(InvalidNodes(vec![ + Err(ParseError::ValidateError(InvalidNodes(vec![ InvalidNode { - file_path: file_path.clone(), + file_path: file_path.to_path_buf(), node_path: get_node_path(&["table_name"]), message: format!( "Orphan reference: cannot find referenced table {}", table_name, ), }, - ]))); + ]))) } } } @@ -370,7 +365,7 @@ fn validate_and_parse_return_type( Some(_) => { Err(ParseError::ValidateError(InvalidNodes(vec![ InvalidNode { - file_path: file_path.clone(), + file_path: file_path.to_path_buf(), node_path: get_node_path(&["query_name"]), message: format!( "Invalid reference: referenced query {} which does not have a return type definition", @@ -382,7 +377,7 @@ fn validate_and_parse_return_type( None => { Err(ParseError::ValidateError(InvalidNodes(vec![ InvalidNode { - file_path: file_path.clone(), + file_path: file_path.to_path_buf(), node_path: get_node_path(&["query_name"]), message: format!( "Orphan reference: cannot find referenced query {}", @@ -398,9 +393,9 @@ fn validate_and_parse_return_type( columns .iter() .map(|(field_alias, field_type)| { - let data_type = ClickHouseDataType::from_str(&field_type).map_err(|err| { + let data_type = ClickHouseDataType::from_str(field_type).map_err(|err| { ParseError::ValidateError(InvalidNodes(vec![InvalidNode { - file_path: file_path.clone(), + file_path: file_path.to_path_buf(), node_path: get_node_path(&["columns", field_alias]), message: format!( "Unable to parse data type \"{}\": {}", diff --git a/crates/ndc-clickhouse/src/connector/handler/capabilities.rs b/crates/ndc-clickhouse/src/connector/handler/capabilities.rs index 311aa79..72b524f 100644 --- a/crates/ndc-clickhouse/src/connector/handler/capabilities.rs +++ b/crates/ndc-clickhouse/src/connector/handler/capabilities.rs @@ -1,13 +1,18 @@ -use ndc_sdk::models::{self, LeafCapability, RelationshipCapabilities}; +use ndc_sdk::models::{self, LeafCapability, NestedFieldCapabilities, RelationshipCapabilities}; pub fn capabilities() -> models::CapabilitiesResponse { models::CapabilitiesResponse { - version: "^0.1.1".to_string(), + version: "0.1.4".to_owned(), capabilities: models::Capabilities { query: models::QueryCapabilities { aggregates: Some(LeafCapability {}), variables: Some(LeafCapability {}), explain: Some(LeafCapability {}), + nested_fields: NestedFieldCapabilities { + filter_by: None, + order_by: None, + aggregates: None, + }, }, mutation: models::MutationCapabilities { transactional: None, diff --git a/crates/ndc-clickhouse/src/connector/handler/query.rs b/crates/ndc-clickhouse/src/connector/handler/query.rs index fb1e642..e82461b 100644 --- a/crates/ndc-clickhouse/src/connector/handler/query.rs +++ b/crates/ndc-clickhouse/src/connector/handler/query.rs @@ -60,7 +60,7 @@ pub async fn query( ) .instrument(execution_span) .await - .map_err(|err| QueryError::UnprocessableContent(err.to_string().into()))?; + .map_err(|err| QueryError::UnprocessableContent(err.to_string()))?; #[cfg(debug_assertions)] { diff --git a/crates/ndc-clickhouse/src/connector/handler/schema.rs b/crates/ndc-clickhouse/src/connector/handler/schema.rs index 379204f..525665f 100644 --- a/crates/ndc-clickhouse/src/connector/handler/schema.rs +++ b/crates/ndc-clickhouse/src/connector/handler/schema.rs @@ -1,4 +1,4 @@ -use crate::schema::ClickHouseTypeDefinition; +use crate::schema::{ClickHouseTypeDefinition, SchemaTypeDefinitions}; use common::{ clickhouse_parser::{ datatype::ClickHouseDataType, @@ -20,13 +20,13 @@ pub async fn schema( let mut fields = vec![]; for (column_alias, column_type) in &table_type.columns { let type_definition = ClickHouseTypeDefinition::from_table_column( - &column_type, - &column_alias, - &type_name, + column_type, + column_alias, + type_name, &configuration.namespace_separator, ); - let (scalars, objects) = type_definition.type_definitions(); + let SchemaTypeDefinitions { scalars, objects } = type_definition.type_definitions(); for (name, definition) in objects { object_type_definitions.push((name, definition)); @@ -43,6 +43,7 @@ pub async fn schema( models::ObjectField { description: None, r#type: type_definition.type_identifier(), + arguments: BTreeMap::new(), }, )); } @@ -59,12 +60,12 @@ pub async fn schema( for (table_alias, table_config) in &configuration.tables { for (argument_name, argument_type) in &table_config.arguments { let type_definition = ClickHouseTypeDefinition::from_query_argument( - &argument_type, - &argument_name, + argument_type, + argument_name, table_alias, &configuration.namespace_separator, ); - let (scalars, objects) = type_definition.type_definitions(); + let SchemaTypeDefinitions { scalars, objects } = type_definition.type_definitions(); for (name, definition) in objects { object_type_definitions.push((name, definition)); @@ -92,7 +93,7 @@ pub async fn schema( &configuration.namespace_separator, ); - let (scalars, objects) = type_definition.type_definitions(); + let SchemaTypeDefinitions { scalars, objects } = type_definition.type_definitions(); for (name, definition) in objects { object_type_definitions.push((name, definition)); @@ -118,8 +119,8 @@ pub async fn schema( .iter() .map(|(argument_name, argument_type)| { let type_definition = ClickHouseTypeDefinition::from_query_argument( - &argument_type, - &argument_name, + argument_type, + argument_name, table_alias, &configuration.namespace_separator, ); @@ -165,7 +166,7 @@ pub async fn schema( ParameterizedQueryElement::Parameter(Parameter { name, r#type }) => { let data_type = match r#type { ParameterType::Identifier => &ClickHouseDataType::String, - ParameterType::DataType(t) => &t, + ParameterType::DataType(t) => t, }; let type_definition = ClickHouseTypeDefinition::from_query_argument( data_type, diff --git a/crates/ndc-clickhouse/src/schema/type_definition.rs b/crates/ndc-clickhouse/src/schema/type_definition.rs index c39ff38..c231c02 100644 --- a/crates/ndc-clickhouse/src/schema/type_definition.rs +++ b/crates/ndc-clickhouse/src/schema/type_definition.rs @@ -1,7 +1,7 @@ use common::clickhouse_parser::datatype::{ClickHouseDataType, Identifier, SingleQuotedString}; use indexmap::IndexMap; use ndc_sdk::models; -use std::iter; +use std::{collections::BTreeMap, iter}; use super::{ClickHouseBinaryComparisonOperator, ClickHouseSingleColumnAggregateFunction}; @@ -16,7 +16,7 @@ impl<'a> NameSpace<'a> { Self { separator, path } } pub fn value(&self) -> String { - self.path.join(&self.separator) + self.path.join(self.separator) } pub fn child(&self, path_element: &'a str) -> Self { Self { @@ -106,21 +106,21 @@ impl ClickHouseScalar { match &self.0 { ClickHouseDataType::Bool => Some(Rep::Boolean), ClickHouseDataType::String => Some(Rep::String), - ClickHouseDataType::UInt8 => Some(Rep::Integer), - ClickHouseDataType::UInt16 => Some(Rep::Integer), - ClickHouseDataType::UInt32 => Some(Rep::Integer), - ClickHouseDataType::UInt64 => Some(Rep::Integer), - ClickHouseDataType::UInt128 => Some(Rep::Integer), - ClickHouseDataType::UInt256 => Some(Rep::Integer), - ClickHouseDataType::Int8 => Some(Rep::Integer), - ClickHouseDataType::Int16 => Some(Rep::Integer), - ClickHouseDataType::Int32 => Some(Rep::Integer), - ClickHouseDataType::Int64 => Some(Rep::Integer), - ClickHouseDataType::Int128 => Some(Rep::Integer), - ClickHouseDataType::Int256 => Some(Rep::Integer), - ClickHouseDataType::Float32 => Some(Rep::Number), - ClickHouseDataType::Float64 => Some(Rep::Number), - ClickHouseDataType::Decimal { .. } => Some(Rep::Number), + ClickHouseDataType::UInt8 => Some(Rep::Int16), // Unsigned int8 fits into signed int16 + ClickHouseDataType::UInt16 => Some(Rep::Int32), // Unsigned int16 fits into signed int32 + ClickHouseDataType::UInt32 => Some(Rep::Int64), // Unsigned int32 fits into signed int64 + ClickHouseDataType::UInt64 => Some(Rep::BigInteger), // Unsigned int64 will have to go into BigInteger + ClickHouseDataType::UInt128 => Some(Rep::BigInteger), // Unsigned int128 will have to go into BigInteger + ClickHouseDataType::UInt256 => Some(Rep::BigInteger), // Unsigned int256 will have to go into BigInteger + ClickHouseDataType::Int8 => Some(Rep::Int8), + ClickHouseDataType::Int16 => Some(Rep::Int16), + ClickHouseDataType::Int32 => Some(Rep::Int32), + ClickHouseDataType::Int64 => Some(Rep::Int64), + ClickHouseDataType::Int128 => Some(Rep::BigInteger), + ClickHouseDataType::Int256 => Some(Rep::BigInteger), + ClickHouseDataType::Float32 => Some(Rep::Float32), + ClickHouseDataType::Float64 => Some(Rep::Float64), + ClickHouseDataType::Decimal { .. } => Some(Rep::BigDecimal), ClickHouseDataType::Decimal32 { .. } => Some(Rep::String), ClickHouseDataType::Decimal64 { .. } => Some(Rep::String), ClickHouseDataType::Decimal128 { .. } => Some(Rep::String), @@ -129,7 +129,7 @@ impl ClickHouseScalar { ClickHouseDataType::Date32 => Some(Rep::String), ClickHouseDataType::DateTime { .. } => Some(Rep::String), ClickHouseDataType::DateTime64 { .. } => Some(Rep::String), - ClickHouseDataType::Json => Some(Rep::String), + ClickHouseDataType::Json => Some(Rep::JSON), ClickHouseDataType::Uuid => Some(Rep::String), ClickHouseDataType::IPv4 => Some(Rep::String), ClickHouseDataType::IPv6 => Some(Rep::String), @@ -499,7 +499,7 @@ impl ClickHouseTypeDefinition { return Self::Scalar(ClickHouseScalar(data_type.to_owned())); }; - let field_namespace = namespace.child(&field_name); + let field_namespace = namespace.child(field_name); let field_definition = Self::new(field_data_type, &field_namespace); @@ -590,16 +590,12 @@ impl ClickHouseTypeDefinition { } /// returns the schema type definitions for this type /// note that ScalarType definitions may be duplicated - pub fn type_definitions( - &self, - ) -> ( - Vec<(String, models::ScalarType)>, - Vec<(String, models::ObjectType)>, - ) { + pub fn type_definitions(&self) -> SchemaTypeDefinitions { match self { - ClickHouseTypeDefinition::Scalar(scalar) => { - (vec![(scalar.type_name(), scalar.type_definition())], vec![]) - } + ClickHouseTypeDefinition::Scalar(scalar) => SchemaTypeDefinitions { + scalars: vec![(scalar.type_name(), scalar.type_definition())], + objects: vec![], + }, ClickHouseTypeDefinition::Nullable { inner } => inner.type_definitions(), ClickHouseTypeDefinition::Array { element_type } => element_type.type_definitions(), ClickHouseTypeDefinition::Object { @@ -611,7 +607,10 @@ impl ClickHouseTypeDefinition { let mut scalar_type_definitions = vec![]; for (field_name, field) in fields { - let (mut scalars, mut objects) = field.type_definitions(); + let SchemaTypeDefinitions { + mut scalars, + mut objects, + } = field.type_definitions(); scalar_type_definitions.append(&mut scalars); object_type_definitions.append(&mut objects); @@ -621,6 +620,7 @@ impl ClickHouseTypeDefinition { models::ObjectField { description: None, r#type: field.type_identifier(), + arguments: BTreeMap::new(), }, )); } @@ -633,7 +633,10 @@ impl ClickHouseTypeDefinition { }, )); - (scalar_type_definitions, object_type_definitions) + SchemaTypeDefinitions { + scalars: scalar_type_definitions, + objects: object_type_definitions, + } } } } @@ -657,3 +660,8 @@ impl ClickHouseTypeDefinition { } } } + +pub struct SchemaTypeDefinitions { + pub scalars: Vec<(String, models::ScalarType)>, + pub objects: Vec<(String, models::ObjectType)>, +} diff --git a/crates/ndc-clickhouse/src/sql/query_builder.rs b/crates/ndc-clickhouse/src/sql/query_builder.rs index 86bfbc5..ab18d55 100644 --- a/crates/ndc-clickhouse/src/sql/query_builder.rs +++ b/crates/ndc-clickhouse/src/sql/query_builder.rs @@ -54,7 +54,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { collection.alias(), query, &self.request.collection_relationships, - &self.configuration, + self.configuration, )? .into_cast_type() .to_string(), @@ -135,7 +135,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { .into_box(), op: BinaryOperator::Eq, right: Expr::CompoundIdentifier(vec![ - Ident::new_quoted(format!("_rowset")), + Ident::new_quoted("_rowset".to_owned()), Ident::new_quoted("_varset_id"), ]) .into_box(), @@ -218,6 +218,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { models::Aggregate::ColumnCount { distinct, column: _, + field_path: _, } => { let column = Expr::CompoundIdentifier(vec![ Ident::new_quoted("_row"), @@ -231,6 +232,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { models::Aggregate::SingleColumn { function, column: _, + field_path: _, } => { let column = Expr::CompoundIdentifier(vec![ Ident::new_quoted("_row"), @@ -284,7 +286,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { } let from = vec![self - .row_subquery(¤t_collection, relkeys, query)? + .row_subquery(current_collection, relkeys, query)? .into_table_factor() .alias("_row") .into_table_with_joins(vec![])]; @@ -318,11 +320,15 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { let mut rel_index = 0; for (alias, field) in fields { match field { - models::Field::Column { column, fields } => { + models::Field::Column { + column, + fields, + arguments: _, + } => { let data_type = self.column_data_type(column, current_collection)?; let column_definition = ClickHouseTypeDefinition::from_table_column( &data_type, - &column, + column, current_collection.alias(), &self.configuration.namespace_separator, ); @@ -355,7 +361,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { let (expr, join) = self.field_relationship( alias, &mut rel_index, - &vec![Ident::new_quoted("_origin")], + &[Ident::new_quoted("_origin")], query, relationship, arguments, @@ -492,7 +498,11 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { for element in &order_by.elements { match &element.target { - models::OrderByTarget::Column { name, path } if path.is_empty() => { + models::OrderByTarget::Column { + name, + path, + field_path: _, + } if path.is_empty() => { let expr = Expr::CompoundIdentifier(vec![ Ident::new_quoted("_origin"), self.column_ident(name), @@ -698,7 +708,11 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { } match &element.target { - models::OrderByTarget::Column { name, path: _ } => { + models::OrderByTarget::Column { + name, + path: _, + field_path: _, + } => { let column = Expr::CompoundIdentifier(vec![ last_join_alias, self.column_ident(name), @@ -710,6 +724,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { column, function, path: _, + field_path: _, } => { let column = Expr::CompoundIdentifier(vec![ last_join_alias, @@ -825,7 +840,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { &self, field_alias: &str, name_index: &mut u32, - target_path: &Vec, + target_path: &[Ident], query: &models::Query, relationship: &str, arguments: &BTreeMap, @@ -834,8 +849,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { *name_index += 1; let relationship = self.collection_relationship(relationship)?; - let relationship_collection = - CollectionContext::from_relationship(&relationship, &arguments); + let relationship_collection = CollectionContext::from_relationship(relationship, arguments); let mut join_expr = relationship .column_mapping @@ -844,8 +858,8 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { Ok(Expr::BinaryOp { left: Expr::CompoundIdentifier( target_path - .clone() - .into_iter() + .iter() + .cloned() .chain(iter::once(Ident::new_quoted(source_col))) .collect(), ) @@ -1102,7 +1116,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { models::ExistsInCollection::Unrelated { collection, arguments, - } => CollectionContext::new_unrelated(&collection, arguments), + } => CollectionContext::new_unrelated(collection, arguments), }; let subquery_origin_alias = Ident::new_quoted(format!("_exists_{}", name_index)); @@ -1286,6 +1300,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { models::ComparisonTarget::Column { name: comparison_column_name, path, + field_path: _, } => { if let Some(first_element) = path.first() { if current_is_origin { @@ -1649,7 +1664,10 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { )) } } - models::ComparisonTarget::RootCollectionColumn { name } => { + models::ComparisonTarget::RootCollectionColumn { + name, + field_path: _, + } => { if current_is_origin { let column_ident = Expr::CompoundIdentifier(vec![ current_join_alias.clone(), @@ -1692,7 +1710,7 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { }) }; let variable_argument = |arg_name: &String, variable_name: &String| { - let argument_type = table_argument_type(&arg_name)?; + let argument_type = table_argument_type(arg_name)?; let column_ident = Expr::CompoundIdentifier(vec![ Ident::new_quoted("_vars"), Ident::new_quoted(format!("_var_{variable_name}")), @@ -1964,7 +1982,11 @@ impl<'r, 'c> QueryBuilder<'r, 'c> { let mut accessor_required = false; for (alias, field) in &inner.fields { match field { - models::Field::Column { column, fields } => { + models::Field::Column { + column, + fields, + arguments: _, + } => { required_columns.push(column); let type_definition = diff --git a/crates/ndc-clickhouse/src/sql/query_builder/collection_context.rs b/crates/ndc-clickhouse/src/sql/query_builder/collection_context.rs index c0653ef..da0c1a8 100644 --- a/crates/ndc-clickhouse/src/sql/query_builder/collection_context.rs +++ b/crates/ndc-clickhouse/src/sql/query_builder/collection_context.rs @@ -55,7 +55,7 @@ impl<'a, 'b> CollectionContext<'a, 'b> { } | CollectionContext::UnrelatedRelationship { collection_alias, .. - } => &collection_alias, + } => collection_alias, } } pub fn has_arguments(&self) -> bool { diff --git a/crates/ndc-clickhouse/src/sql/query_builder/typecasting.rs b/crates/ndc-clickhouse/src/sql/query_builder/typecasting.rs index 1c16e8e..edb7b06 100644 --- a/crates/ndc-clickhouse/src/sql/query_builder/typecasting.rs +++ b/crates/ndc-clickhouse/src/sql/query_builder/typecasting.rs @@ -100,17 +100,18 @@ impl AggregatesTypeString { models::Aggregate::SingleColumn { column: column_alias, function, + field_path: _, } => { let column_type = get_column(column_alias, table_alias, config)?; let type_definition = ClickHouseTypeDefinition::from_table_column( - &column_type, + column_type, column_alias, table_alias, &config.namespace_separator, ); let aggregate_function = - ClickHouseSingleColumnAggregateFunction::from_str(&function).map_err( + ClickHouseSingleColumnAggregateFunction::from_str(function).map_err( |_err| TypeStringError::UnknownAggregateFunction { table: table_alias.to_owned(), column: column_alias.to_owned(), @@ -172,10 +173,11 @@ impl RowTypeString { models::Field::Column { column: column_alias, fields, + arguments: _, } => { let column_type = get_column(column_alias, table_alias, config)?; let type_definition = ClickHouseTypeDefinition::from_table_column( - &column_type, + column_type, column_alias, table_alias, &config.namespace_separator, @@ -268,6 +270,7 @@ impl FieldTypeString { models::Field::Column { column, fields: subfield_selector, + arguments: _, } => { let type_definition = fields.get(column).ok_or_else(|| { TypeStringError::MissingNestedField { @@ -279,7 +282,7 @@ impl FieldTypeString { Ok(( alias.to_owned(), FieldTypeString::new( - &type_definition, + type_definition, subfield_selector.as_ref(), relationships, config, diff --git a/crates/ndc-clickhouse/tests/query_builder.rs b/crates/ndc-clickhouse/tests/query_builder.rs index 894742c..913dfeb 100644 --- a/crates/ndc-clickhouse/tests/query_builder.rs +++ b/crates/ndc-clickhouse/tests/query_builder.rs @@ -72,7 +72,7 @@ mod test_utils { ) -> Result<(), Box> { let statement_path = tests_dir_path(schema_dir, group_dir).join(format!("{test_name}.statement.sql")); - let pretty_statement = pretty_print_sql(&generated_statement); + let pretty_statement = pretty_print_sql(generated_statement); fs::write(&statement_path, &pretty_statement).await?; Ok(()) } @@ -92,7 +92,7 @@ mod test_utils { request: &models::QueryRequest, ) -> Result { let generated_statement = pretty_print_sql( - &QueryBuilder::new(&request, &configuration) + &QueryBuilder::new(request, configuration) .build()? .to_unsafe_sql_string(), );