Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix capabilities version, upgrade SDK to v0.1.4, fix Clippy lints #21

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions crates/common/src/clickhouse_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ 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");
}

#[test]
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");
}

Expand All @@ -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");
}
14 changes: 7 additions & 7 deletions crates/ndc-clickhouse-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async fn read_config_file(file_path: &PathBuf) -> Result<Option<ServerConfigFile

async fn update_tables_config(
configuration_dir: impl AsRef<Path> + Send,
introspection: &Vec<TableInfo>,
introspection: &[TableInfo],
) -> Result<ServerConfigFile, Box<dyn Error>> {
let file_path = configuration_dir.as_ref().join(CONFIG_FILE_NAME);
let schema_file_path = configuration_dir.as_ref().join(CONFIG_SCHEMA_FILE_NAME);
Expand Down Expand Up @@ -206,7 +206,7 @@ async fn update_tables_config(
table,
&old_table_config,
&old_config,
&introspection,
introspection,
),
};

Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -435,7 +435,7 @@ fn get_table_return_type(
table: &TableInfo,
old_table: &Option<(&String, &TableConfigFile)>,
old_config: &Option<ServerConfigFile>,
introspection: &Vec<TableInfo>,
introspection: &[TableInfo],
) -> ReturnType {
let new_columns = get_return_type_columns(table);

Expand Down Expand Up @@ -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,
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-clickhouse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 17 additions & 22 deletions crates/ndc-clickhouse/src/connector.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -318,7 +313,7 @@ fn get_connection_config() -> Result<ConnectionConfig, ParseError> {
fn validate_and_parse_return_type(
return_type: &ReturnType,
config: &ServerConfigFile,
file_path: &PathBuf,
file_path: &Path,
node_path: &[&str],
) -> Result<Option<BTreeMap<String, ClickHouseDataType>>, ParseError> {
let get_node_path = |extra_segments: &[&str]| {
Expand All @@ -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",
Expand All @@ -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,
),
},
])));
])))
}
}
}
Expand All @@ -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",
Expand All @@ -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 {}",
Expand All @@ -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 \"{}\": {}",
Expand Down
9 changes: 7 additions & 2 deletions crates/ndc-clickhouse/src/connector/handler/capabilities.rs
Original file line number Diff line number Diff line change
@@ -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(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the boo boo. 😭

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,
Expand Down
2 changes: 1 addition & 1 deletion crates/ndc-clickhouse/src/connector/handler/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
{
Expand Down
Loading
Loading