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

SQL-2288: Create mongosqltranslate integration tests #251

Open
wants to merge 25 commits into
base: on-prem-eap
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
91e709e
cargo.lock
EthanHardyMongo Mar 6, 2024
f9039e0
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Mar 6, 2024
2997ffd
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Mar 12, 2024
71e5ec3
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Mar 12, 2024
6519307
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Mar 26, 2024
914ca8f
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Apr 3, 2024
59a37de
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Apr 15, 2024
74b8d02
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Apr 19, 2024
e7ce323
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Jun 3, 2024
401713b
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Jun 6, 2024
65ff048
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Jun 27, 2024
5bc7a32
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Jul 31, 2024
f5541e3
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Aug 22, 2024
9125f5c
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Sep 19, 2024
8050d4f
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Sep 26, 2024
4e45044
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Oct 4, 2024
52be409
SQL-2374: Implement columns metadata logic for Direct cluster (#245)
EthanHardyMongo Oct 7, 2024
558358d
Merge remote-tracking branch 'upstream/master'
EthanHardyMongo Oct 7, 2024
e7e8234
create mongosqltranslate tests and fix logic
EthanHardyMongo Oct 14, 2024
ac45b5d
fix evergreen names
EthanHardyMongo Oct 15, 2024
2ca83d0
remove test flag
EthanHardyMongo Oct 15, 2024
d3645cf
rename evergreen mongosqltranslate task
EthanHardyMongo Oct 15, 2024
2f9c330
change version back to 0.0.0
EthanHardyMongo Oct 15, 2024
faba35f
change mongosqltranslate library used in evergreen
EthanHardyMongo Oct 15, 2024
b17ce9e
respond to some feedback
EthanHardyMongo Oct 17, 2024
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
5 changes: 4 additions & 1 deletion core/src/col_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,12 @@ pub struct VersionedJsonSchema {
}

// Struct representing the ResultSetSchema.
// The `schema` field needs the alias `result_set_schema` because this struct is used to get the schema
// from the __sql_schemas collection, which stores the schema in it's `schema` field, and the libmongosqltranslate
// `translate` command, which stores the schema in it's `result_set_schema` field.
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone, Default)]
pub struct ResultSetSchema {
#[serde(rename = "result_set_schema")]
#[serde(alias = "result_set_schema")]
pub schema: crate::json_schema::Schema,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why this wasn't failing earlier, but I fixed it and added a comment explaining what's going on.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh actually I think it's because the error it would cause gets pushed into a warnings vector instead of causing a crash. This is probably why my tests weren't failing.

let result_set_schema: Result<ResultSetSchema> =
                                ResultSetSchema::from_sql_schemas_document(&schema_doc).map_err(
                                    |e| {
                                        Error::CollectionDeserialization(collection_name.clone(), e)
                                    },
                                );

                            match result_set_schema {
                                Ok(result_set_schema) => result_set_schema,
                                Err(error) => {
                                    // If there is an Error while deserializing the schema, we won't show any columns for it
                                    warnings.push(error);
                                    continue;
                                }
                            }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh wait never mind. The part of the code that would fail was never called by my tests. That's why this wasn't causing any failures.

#[serde(skip_serializing_if = "Option::is_none")]
pub select_order: Option<Vec<Vec<String>>>,
Expand Down
10 changes: 2 additions & 8 deletions core/src/collections.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stmt::EmptyStatement;
use crate::util::{is_match, table_type_filter_to_vec, to_name_regex};
use crate::util::{databases_filter, is_match, table_type_filter_to_vec, to_name_regex};
use crate::{
col_metadata::MongoColMetadata,
conn::MongoConnection,
Expand Down Expand Up @@ -123,13 +123,7 @@ impl MongoCollections {
.unwrap()
.iter()
// MHOUSE-7119 - admin database and empty strings are showing in list_database_names
.filter(|&db_name| {
!db_name.is_empty()
&& !db_name.eq("admin")
&& !db_name.eq("config")
&& !db_name.eq("local")
&& !db_name.eq("system")
})
.filter(|&db_name| databases_filter(db_name))
.filter(|&db_name| is_match(db_name, db_name_filter, accept_search_patterns))
.map(|val| async move {
CollectionsForDb {
Expand Down
2 changes: 2 additions & 0 deletions core/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ impl MongoConnection {

let compatibility = Self::is_libmongosqltranslate_compatible_with_driver_version()?;

log::info!("libmongosqltranslate version: `{0}`. ODBC driver version: `{1}`. The ODBC driver and libmongosqltranslate library is compatible: `{2}`.", libmongosqltranslate_version, *DRIVER_METRICS_VERSION, compatibility);

(Some(compatibility), Some(libmongosqltranslate_version))
} else {
(None, None)
Expand Down
10 changes: 2 additions & 8 deletions core/src/databases.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
col_metadata::MongoColMetadata, conn::MongoConnection, err::Result, stmt::MongoStatement,
BsonTypeInfo, Error,
util::databases_filter, BsonTypeInfo, Error,
};
use definitions::Nullability;
use mongodb::bson::Bson;
Expand Down Expand Up @@ -221,13 +221,7 @@ impl MongoDatabases {
})
.unwrap()
.iter()
.filter(|&db_name| {
!db_name.is_empty()
&& !db_name.eq("admin")
&& !db_name.eq("config")
&& !db_name.eq("local")
&& !db_name.eq("system")
})
.filter(|&db_name| databases_filter(db_name))
.map(|s| s.to_string())
.collect();

Expand Down
39 changes: 19 additions & 20 deletions core/src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
conn::MongoConnection,
err::{Error, Result},
stmt::MongoStatement,
util::to_name_regex,
util::{databases_filter, to_name_regex},
BsonTypeInfo, TypeMode,
};
use constants::SQL_SCHEMAS_COLLECTION;
Expand Down Expand Up @@ -486,13 +486,7 @@ impl MongoFields {
.unwrap()
// MHOUSE-7119 - admin database and empty strings are showing in list_database_names
.iter()
.filter(|&db_name| {
!db_name.is_empty()
&& !db_name.eq("admin")
&& !db_name.eq("config")
&& !db_name.eq("local")
&& !db_name.eq("system")
})
.filter(|&db_name| databases_filter(db_name))
.map(|s| s.to_string())
.collect()
},
Expand Down Expand Up @@ -567,13 +561,17 @@ impl MongoFields {
Error::CollectionDeserialization(collection_name.clone(), e)
Copy link
Member

Choose a reason for hiding this comment

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

How about an integration test that confirms we get this on a deserialization error?

});

if let Err(error) = sql_get_schema_response {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
}
let error_checked_sql_get_schema_response =
match sql_get_schema_response {
Ok(sql_get_schema_response) => sql_get_schema_response,
Err(error) => {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
}
};

sql_get_schema_response.unwrap().into()
error_checked_sql_get_schema_response.into()
} else if mongo_connection.cluster_type == MongoClusterType::Enterprise {
let schema_collection =
db.collection::<Document>(SQL_SCHEMAS_COLLECTION);
Expand All @@ -599,13 +597,14 @@ impl MongoFields {
},
);

if let Err(error) = result_set_schema {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
match result_set_schema {
Ok(result_set_schema) => result_set_schema,
Err(error) => {
// If there is an Error while deserializing the schema, we won't show any columns for it
warnings.push(error);
continue;
}
}

result_set_schema.unwrap()
} else {
unreachable!()
};
Expand Down
5 changes: 5 additions & 0 deletions core/src/mongosqltranslate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ pub(crate) fn libmongosqltranslate_run_command<T: CommandName + Serialize>(
capacity: command_bytes_capacity,
};

log::info!(
"Calling `{}` libmongosqltranslate runCommand.",
T::command_name()
);

let decomposed_returned_doc = unsafe { run_command_function(libmongosqltranslate_command) };

let mut command_response_doc: Document = unsafe {
Expand Down
8 changes: 8 additions & 0 deletions core/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ pub(crate) fn table_type_filter_to_vec(table_type: &str) -> Option<Vec<Collectio
};
}

pub(crate) fn databases_filter(db_name: &str) -> bool {
!db_name.is_empty()
&& !db_name.eq("admin")
&& !db_name.eq("config")
&& !db_name.eq("local")
&& !db_name.eq("system")
}

#[macro_export]
macro_rules! map {
($($key:expr => $val:expr),* $(,)?) => {
Expand Down
14 changes: 14 additions & 0 deletions integration_test/tests/mongosqltranslate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ mod mongosqltranslate {
get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle)
);

let error_message = get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle);
assert!(
error_message.contains("No schema information returned for the requested collections."),
"Expected error message: `No schema information returned for the requested collections.`; actual error message: {}",
error_message
);

disconnect_and_close_handles(dbc, stmt);
}
let _ = unsafe { Box::from_raw(env_handle) };
Expand All @@ -150,6 +157,13 @@ mod mongosqltranslate {
get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle)
);

let error_message = get_sql_diagnostics(HandleType::SQL_HANDLE_STMT, stmt as Handle);
assert!(
error_message.contains("The libmongosqltranslate command `translate` failed. Error message: `algebrize error: Error 1016: unknown collection 'foo' in database 'test'`. Error is internal: false"),
"Expected error message: `The libmongosqltranslate command `translate` failed. Error message: `algebrize error: Error 1016: unknown collection 'foo' in database 'test'`. Error is internal: false`; actual error message: {}",
error_message
);

disconnect_and_close_handles(dbc, stmt);
}
let _ = unsafe { Box::from_raw(env_handle) };
Expand Down