Skip to content

Commit 3c9b2f6

Browse files
committed
update ndc-spec version
1 parent 00e8f5e commit 3c9b2f6

File tree

9 files changed

+49
-141
lines changed

9 files changed

+49
-141
lines changed

Cargo.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ similar_names = "allow"
3333
too_many_lines = "allow"
3434

3535
[workspace.dependencies]
36-
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.5" }
37-
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.2.1" }
38-
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.5" }
36+
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.6" }
37+
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.4.0" }
38+
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.6" }
3939

4040
anyhow = "1"
4141
async-trait = "0.1"

crates/connectors/ndc-bigquery/src/capabilities.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub fn get_capabilities() -> models::Capabilities {
1212
aggregates: Some(models::LeafCapability {}),
1313
variables: Some(models::LeafCapability {}),
1414
explain: Some(models::LeafCapability {}),
15+
exists: models::ExistsCapabilities {
16+
nested_collections: Some(models::LeafCapability {}),
17+
},
1518
nested_fields: models::NestedFieldCapabilities {
1619
filter_by: Some(models::LeafCapability {}),
1720
order_by: Some(models::LeafCapability {}),

crates/connectors/ndc-bigquery/src/connector.rs

+16-37
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use async_trait::async_trait;
99
use tracing::{info_span, Instrument};
1010

1111
use ndc_sdk::connector;
12-
use ndc_sdk::connector::{Connector, ConnectorSetup};
12+
use ndc_sdk::connector::{Connector, ConnectorSetup, Result};
1313
use ndc_sdk::json_response::JsonResponse;
1414
use ndc_sdk::models;
1515

@@ -45,33 +45,10 @@ impl Connector for BigQuery {
4545
fn fetch_metrics(
4646
_configuration: &Arc<ndc_bigquery_configuration::Configuration>,
4747
_state: &Self::State,
48-
) -> Result<(), connector::FetchMetricsError> {
48+
) -> Result<()> {
4949
Ok(())
5050
}
5151

52-
/// Check the health of the connector.
53-
///
54-
/// For example, this function should check that the connector
55-
/// is able to reach its data source over the network.
56-
async fn health_check(
57-
_configuration: &Self::Configuration,
58-
state: &Self::State,
59-
) -> Result<(), connector::HealthError> {
60-
health::health_check(&state.bigquery_client)
61-
.await
62-
.map_err(|err| {
63-
tracing::error!(
64-
meta.signal_type = "log",
65-
event.domain = "ndc",
66-
event.name = "Health check error",
67-
name = "Health check error",
68-
body = %err,
69-
error = true,
70-
);
71-
err
72-
})
73-
}
74-
7552
/// Get the connector's capabilities.
7653
///
7754
/// This function implements the [capabilities endpoint](https://hasura.github.io/ndc-spec/specification/capabilities.html)
@@ -86,7 +63,7 @@ impl Connector for BigQuery {
8663
/// from the NDC specification.
8764
async fn get_schema(
8865
configuration: &Self::Configuration,
89-
) -> Result<JsonResponse<models::SchemaResponse>, connector::SchemaError> {
66+
) -> Result<JsonResponse<models::SchemaResponse>> {
9067
schema::get_schema(configuration)
9168
.await
9269
.map_err(|err| {
@@ -112,7 +89,7 @@ impl Connector for BigQuery {
11289
configuration: &Self::Configuration,
11390
state: &Self::State,
11491
request: models::QueryRequest,
115-
) -> Result<JsonResponse<models::ExplainResponse>, connector::ExplainError> {
92+
) -> Result<JsonResponse<models::ExplainResponse>> {
11693
todo!("query explain is currently not implemented")
11794
// query::explain(configuration, state, request)
11895
// .await
@@ -138,7 +115,7 @@ impl Connector for BigQuery {
138115
configuration: &Self::Configuration,
139116
state: &Self::State,
140117
request: models::MutationRequest,
141-
) -> Result<JsonResponse<models::ExplainResponse>, connector::ExplainError> {
118+
) -> Result<JsonResponse<models::ExplainResponse>> {
142119
todo!("mutation explain is currently not implemented")
143120
// mutation::explain(configuration, state, request)
144121
// .await
@@ -164,7 +141,7 @@ impl Connector for BigQuery {
164141
configuration: &Self::Configuration,
165142
state: &Self::State,
166143
request: models::MutationRequest,
167-
) -> Result<JsonResponse<models::MutationResponse>, connector::MutationError> {
144+
) -> Result<JsonResponse<models::MutationResponse>> {
168145
todo!("mutation is currently not implemented")
169146
// mutation::mutation(configuration, state, request)
170147
// .await
@@ -189,7 +166,7 @@ impl Connector for BigQuery {
189166
configuration: &Self::Configuration,
190167
state: &Self::State,
191168
query_request: models::QueryRequest,
192-
) -> Result<JsonResponse<models::QueryResponse>, connector::QueryError> {
169+
) -> Result<JsonResponse<models::QueryResponse>> {
193170
query::query(configuration, state, query_request)
194171
.await
195172
.map_err(|err| {
@@ -225,7 +202,7 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for BigQuerySetup<Env> {
225202
async fn parse_configuration(
226203
&self,
227204
configuration_dir: impl AsRef<Path> + Send,
228-
) -> Result<<Self::Connector as Connector>::Configuration, connector::ParseError> {
205+
) -> Result<<Self::Connector as Connector>::Configuration> {
229206
// Note that we don't log validation errors, because they are part of the normal business
230207
// operation of configuration validation, i.e. they don't represent an error condition that
231208
// signifies that anything has gone wrong with the ndc process or infrastructure.
@@ -243,7 +220,8 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for BigQuerySetup<Env> {
243220
line,
244221
column,
245222
message,
246-
}),
223+
})
224+
.into(),
247225
configuration::error::ParseConfigurationError::EmptyConnectionUri { file_path } => {
248226
connector::ParseError::ValidateError(connector::InvalidNodes(vec![
249227
connector::InvalidNode {
@@ -252,16 +230,17 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for BigQuerySetup<Env> {
252230
message: "database connection URI must be specified".to_string(),
253231
},
254232
]))
233+
.into()
255234
}
256235
configuration::error::ParseConfigurationError::IoError(inner) => {
257-
connector::ParseError::IoError(inner)
236+
connector::ParseError::IoError(inner).into()
258237
}
259238
configuration::error::ParseConfigurationError::IoErrorButStringified(inner) => {
260-
connector::ParseError::Other(inner.into())
239+
inner.into()
261240
}
262241
configuration::error::ParseConfigurationError::DidNotFindExpectedVersionTag(_)
263242
| configuration::error::ParseConfigurationError::UnableToParseAnyVersions(_) => {
264-
connector::ParseError::Other(Box::new(error))
243+
connector::ErrorResponse::from_error(error)
265244
}
266245
})?;
267246

@@ -296,7 +275,7 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for BigQuerySetup<Env> {
296275
&self,
297276
_configuration: &<Self::Connector as Connector>::Configuration,
298277
metrics: &mut prometheus::Registry,
299-
) -> Result<<Self::Connector as Connector>::State, connector::InitializationError> {
278+
) -> Result<<Self::Connector as Connector>::State> {
300279
state::create_state(
301280
// &configuration.connection_uri,
302281
// &configuration.pool_settings,
@@ -306,7 +285,7 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for BigQuerySetup<Env> {
306285
.instrument(info_span!("Initialise state"))
307286
.await
308287
.map(Arc::new)
309-
.map_err(|err| connector::InitializationError::Other(err.into()))
288+
.map_err(|err| connector::ErrorResponse::from_error(err))
310289
.map_err(|err| {
311290
tracing::error!(
312291
meta.signal_type = "log",
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,40 @@
11
//! Functions to convert between internal error types and the error types exposed by ndc-sdk.
22
3-
use ndc_sdk::connector;
3+
use ndc_sdk::connector::{self, ErrorResponse};
44

5-
/// Convert an error from [query_engine_execution] to [connector::QueryError].
6-
pub fn execution_error_to_query_error(
7-
error: query_engine_execution::error::Error,
8-
) -> connector::QueryError {
5+
/// Convert an error from [query_engine_execution] to [ErrorResponse].
6+
pub fn execution_error_to_response(error: query_engine_execution::error::Error) -> ErrorResponse {
97
use query_engine_execution::error::*;
108
match error {
119
Error::Query(query_error) => match &query_error {
1210
QueryError::VariableNotFound(_) => {
13-
connector::QueryError::new_invalid_request(&query_error.to_string())
11+
connector::QueryError::new_invalid_request(&query_error.to_string()).into()
1412
}
1513
QueryError::NotSupported(_) => {
16-
connector::QueryError::new_unsupported_operation(&query_error.to_string())
17-
}
18-
QueryError::DBError(_) | QueryError::DBConstraintError(_) => {
19-
connector::QueryError::new_unprocessable_content(&query_error.to_string())
20-
}
21-
QueryError::MutationConstraintFailed => connector::QueryError::new("Internal error")
22-
.with_details(serde_json::Value::String(query_error.to_string())),
23-
},
24-
Error::DB(_) => connector::QueryError::new("Internal error")
25-
.with_details(serde_json::Value::String(error.to_string())),
26-
}
27-
}
28-
29-
/// Convert an error from [query_engine_execution] to [connector::MutationError].
30-
pub fn execution_error_to_mutation_error(
31-
error: query_engine_execution::error::Error,
32-
) -> connector::MutationError {
33-
use query_engine_execution::error::*;
34-
match error {
35-
Error::Query(query_error) => match &query_error {
36-
QueryError::VariableNotFound(_) => {
37-
connector::MutationError::new_invalid_request(&query_error.to_string())
38-
}
39-
QueryError::NotSupported(_) => {
40-
connector::MutationError::new_unsupported_operation(&query_error.to_string())
14+
connector::QueryError::new_unsupported_operation(&query_error.to_string()).into()
4115
}
4216
QueryError::DBError(_) => {
43-
connector::MutationError::new_unprocessable_content(&query_error.to_string())
17+
connector::QueryError::new_unprocessable_content(&query_error.to_string()).into()
4418
}
4519
QueryError::DBConstraintError(_) | QueryError::MutationConstraintFailed => {
46-
connector::MutationError::new_constraint_not_met(&query_error.to_string())
20+
connector::MutationError::new_constraint_not_met(&query_error.to_string()).into()
4721
}
4822
},
49-
Error::DB(_) => connector::MutationError::new("Internal error")
50-
.with_details(serde_json::Value::String(error.to_string())),
51-
}
52-
}
53-
54-
/// Convert an error from [query_engine_execution] to [connector::ExplainError].
55-
pub fn execution_error_to_explain_error(
56-
error: query_engine_execution::error::Error,
57-
) -> connector::ExplainError {
58-
use query_engine_execution::error::*;
59-
match error {
60-
Error::Query(query_error) => match &query_error {
61-
QueryError::VariableNotFound(_) => {
62-
connector::ExplainError::new_invalid_request(&query_error.to_string())
63-
}
64-
QueryError::NotSupported(_) => {
65-
connector::ExplainError::new_unsupported_operation(&query_error.to_string())
66-
}
67-
QueryError::DBError(_) | QueryError::DBConstraintError(_) => {
68-
connector::ExplainError::new_unprocessable_content(&query_error.to_string())
69-
}
70-
QueryError::MutationConstraintFailed => connector::ExplainError::new("Internal error")
71-
.with_details(serde_json::Value::String(query_error.to_string())),
72-
},
73-
Error::DB(_) => connector::ExplainError::new("Internal error")
74-
.with_details(serde_json::Value::String(error.to_string())),
75-
}
76-
}
77-
78-
/// Convert an error from [query_engine_translation] to [connector::QueryError].
79-
pub fn translation_error_to_query_error(
80-
error: &query_engine_translation::translation::error::Error,
81-
) -> connector::QueryError {
82-
use query_engine_translation::translation::error::*;
83-
match error {
84-
Error::CapabilityNotSupported(_) | Error::NotImplementedYet(_) => {
85-
connector::QueryError::new_unsupported_operation(&error.to_string())
86-
}
87-
_ => connector::QueryError::new_invalid_request(&error.to_string()),
88-
}
89-
}
90-
91-
/// Convert an error from [query_engine_translation] to [connector::MutationError].
92-
pub fn translation_error_to_mutation_error(
93-
error: &query_engine_translation::translation::error::Error,
94-
) -> connector::MutationError {
95-
use query_engine_translation::translation::error::*;
96-
match error {
97-
Error::CapabilityNotSupported(_) | Error::NotImplementedYet(_) => {
98-
connector::MutationError::new_unsupported_operation(&error.to_string())
23+
Error::DB(_) => {
24+
ErrorResponse::new_internal_with_details(serde_json::Value::String(error.to_string()))
9925
}
100-
_ => connector::MutationError::new_invalid_request(&error.to_string()),
10126
}
10227
}
10328

104-
/// Convert an error from [query_engine_translation] to [connector::ExplainError].
105-
pub fn translation_error_to_explain_error(
29+
/// Convert an error from [query_engine_translation] to [connector::QueryError].
30+
pub fn translation_error_to_response(
10631
error: &query_engine_translation::translation::error::Error,
107-
) -> connector::ExplainError {
32+
) -> ErrorResponse {
10833
use query_engine_translation::translation::error::*;
10934
match error {
11035
Error::CapabilityNotSupported(_) | Error::NotImplementedYet(_) => {
111-
connector::ExplainError::new_unsupported_operation(&error.to_string())
36+
connector::QueryError::new_unsupported_operation(&error.to_string()).into()
11237
}
113-
_ => connector::ExplainError::new_invalid_request(&error.to_string()),
38+
_ => connector::QueryError::new_invalid_request(&error.to_string()).into(),
11439
}
11540
}

crates/connectors/ndc-bigquery/src/health.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Health check endpoint for the connector.
22
3-
use ndc_sdk::connector;
3+
use ndc_sdk::connector::ErrorResponse;
44

55
use gcp_bigquery_client::model::query_request::QueryRequest;
66

@@ -10,7 +10,7 @@ use gcp_bigquery_client::model::query_request::QueryRequest;
1010
/// is able to reach its data source over the network.
1111
pub async fn health_check(
1212
bigquery_client: &gcp_bigquery_client::Client,
13-
) -> Result<(), connector::HealthError> {
13+
) -> Result<(), ErrorResponse> {
1414
// TODO: need to parse this from service account key or allow user to provide it
1515
let project_id = "hasura-development";
1616

crates/connectors/ndc-bigquery/src/query.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub async fn query(
2929
configuration: &configuration::Configuration,
3030
state: &state::State,
3131
query_request: models::QueryRequest,
32-
) -> Result<JsonResponse<models::QueryResponse>, connector::QueryError> {
32+
) -> Result<JsonResponse<models::QueryResponse>, connector::ErrorResponse> {
3333
// let timer = state.query_metrics.time_query_total();
3434

3535
// See https://docs.rs/tracing/0.1.29/tracing/span/struct.Span.html#in-asynchronous-code
@@ -42,7 +42,7 @@ pub async fn query(
4242
let plan = async {
4343
plan_query(configuration, state, query_request).map_err(|err| {
4444
record::translation_error(&err, &state.metrics);
45-
convert::translation_error_to_query_error(&err)
45+
convert::translation_error_to_response(&err)
4646
})
4747
}
4848
.instrument(info_span!("Plan query"))
@@ -51,7 +51,7 @@ pub async fn query(
5151
let result = async {
5252
execute_query(state, plan).await.map_err(|err| {
5353
record::execution_error(&err, &state.metrics);
54-
convert::execution_error_to_query_error(err)
54+
convert::execution_error_to_response(err)
5555
})
5656
}
5757
.instrument(info_span!("Execute query"))

crates/connectors/ndc-bigquery/src/schema.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use ndc_bigquery_configuration::configuration;
4040
/// from the NDC specification.
4141
pub async fn get_schema(
4242
configuration: &configuration::Configuration,
43-
) -> Result<models::SchemaResponse, connector::SchemaError> {
43+
) -> Result<models::SchemaResponse, connector::ErrorResponse> {
4444
// let RawConfiguration {
4545
// metadata,
4646
// aggregate_functions,

crates/query-engine/translation/src/translation/query/filtering.rs

+1
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ pub fn translate_exists_in_collection(
635635
select: Box::new(select),
636636
})
637637
}
638+
models::ExistsInCollection::NestedCollection { column_name, arguments, field_path } => todo!("Filter by nested collection is not implemented yet"),
638639
}
639640
}
640641

0 commit comments

Comments
 (0)