-
Notifications
You must be signed in to change notification settings - Fork 3
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
implement read-only native queries with no arguments #5
Merged
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1ef17e1
add configuration for native queries; report queries in schema response
hallettj 029ff0f
read schema and native queries from separate files
hallettj 9ebfc75
rename metadata to schema
hallettj b6f6258
update fixture configuration
hallettj 039c840
succeed parsing configuration if no native_queries are present
hallettj 12e7b33
add mode property to NativeQuery
hallettj 5962ae5
represent native queries as functions and procedures in schema
hallettj b995bee
Merge branch 'main' into jesse/native-queries
hallettj 178695a
execute native query
hallettj c608d17
updated fixtures with a very basic native query
hallettj e9f042f
add more context to configuration read errors
hallettj f5d4f62
add objectTypes field to native queries
hallettj 5385363
update fixtures with object types
hallettj 1238cc6
Merge branch 'main' into jesse/native-queries-in-query-handler
hallettj e6b32b1
fix a typo
hallettj 0d098d3
check for duplicate names when parsing configuration
hallettj de64173
Merge branch 'main' into jesse/native-queries-in-query-handler
hallettj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
crates/mongodb-agent-common/src/query/execute_native_query_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use configuration::native_queries::NativeQuery; | ||
use dc_api::JsonResponse; | ||
use dc_api_types::{QueryResponse, ResponseFieldValue, RowSet}; | ||
use mongodb::Database; | ||
|
||
use crate::interface_types::MongoAgentError; | ||
|
||
pub async fn handle_native_query_request( | ||
native_query: NativeQuery, | ||
database: Database, | ||
) -> Result<JsonResponse<QueryResponse>, MongoAgentError> { | ||
let result = database | ||
.run_command(native_query.command, native_query.selection_criteria) | ||
.await?; | ||
let result_json = | ||
serde_json::to_value(result).map_err(|err| MongoAgentError::AdHoc(err.into()))?; | ||
|
||
// A function returs a single row with a single column called `__value` | ||
// https://hasura.github.io/ndc-spec/specification/queries/functions.html | ||
let response_row = [( | ||
"__value".to_owned(), | ||
ResponseFieldValue::Column(result_json), | ||
)] | ||
.into_iter() | ||
.collect(); | ||
|
||
Ok(JsonResponse::Value(QueryResponse::Single(RowSet { | ||
aggregates: None, | ||
rows: Some(vec![response_row]), | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine for now, but linear search (i.e.
find
) could lead to performance problems for users who have a lot of native queries. These should eventually be stored in some sort of hashmap.