Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support `ArrowJson` schema output format in QGL API and CLI commands
- New `kamu system compact <dataset>` command that compacts dataslices for the given dataset
### Changed
- Next batch of optimizations of metadata chain traversal through API using Visitors
- Case insensitive comparisons of `dataset`s, `account`s and `repo`s

## [0.170.0] - 2024-03-29
### Added
Expand Down
5 changes: 2 additions & 3 deletions src/adapter/graphql/src/queries/datasets/datasets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ impl Datasets {
account_name: AccountName,
dataset_name: DatasetName,
) -> Result<Option<Dataset>> {
let account = Account::from_account_name(account_name.clone().into());

let dataset_alias = odf::DatasetAlias::new(Some(account_name.into()), dataset_name.into());

let dataset_repo = from_catalog::<dyn domain::DatasetRepository>(ctx).unwrap();
let hdl = dataset_repo
.try_resolve_dataset_ref(&dataset_alias.into_local_ref())
.await?;
Ok(hdl.map(|h| Dataset::new(account, h)))

Ok(hdl.map(|h| Dataset::new(Account::from_dataset_alias(ctx, &h.alias), h)))
}

#[graphql(skip)]
Expand Down
73 changes: 57 additions & 16 deletions src/adapter/graphql/tests/tests/test_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@ use opendatafabric::AccountName;

#[test_log::test(tokio::test)]
async fn test_account_by_name() {
let mut mock_authentication_service = MockAuthenticationService::new();
mock_authentication_service
.expect_find_account_info_by_name()
.with(eq(AccountName::new_unchecked(DEFAULT_ACCOUNT_NAME)))
.returning(|_| Ok(Some(AccountInfo::dummy())));
mock_authentication_service
.expect_find_account_info_by_name()
.with(eq(AccountName::new_unchecked("unknown")))
.returning(|_| Ok(None));

let cat = dill::CatalogBuilder::new()
.add_value(mock_authentication_service)
.bind::<dyn kamu_core::auth::AuthenticationService, MockAuthenticationService>()
.build();
let harness = GraphQLAccountsHarness::new();

let schema = kamu_adapter_graphql::schema_quiet();
let res = schema
Expand All @@ -46,7 +33,7 @@ async fn test_account_by_name() {
}}
"#,
))
.data(cat.clone()),
.data(harness.catalog.clone()),
)
.await;

Expand Down Expand Up @@ -76,7 +63,7 @@ async fn test_account_by_name() {
"#,
"unknown",
))
.data(cat),
.data(harness.catalog.clone()),
)
.await;

Expand All @@ -89,6 +76,60 @@ async fn test_account_by_name() {
}
})
);

let res = schema
.execute(
async_graphql::Request::new(format!(
r#"
query {{
accounts {{
byName (name: "{}") {{
accountName
}}
}}
}}
"#,
DEFAULT_ACCOUNT_NAME.to_ascii_uppercase(),
))
.data(harness.catalog),
)
.await;

assert!(res.is_ok(), "{res:?}");
assert_eq!(
res.data,
value!({
"accounts": {
"byName": {
"accountName": DEFAULT_ACCOUNT_NAME
}
}
})
);
}

////////////////////////////////////////////////////////////////////////////////////////

struct GraphQLAccountsHarness {
catalog: dill::Catalog,
}

impl GraphQLAccountsHarness {
pub fn new() -> Self {
let mut mock_authentication_service = MockAuthenticationService::new();
mock_authentication_service
.expect_find_account_info_by_name()
.with(eq(AccountName::new_unchecked(DEFAULT_ACCOUNT_NAME)))
.returning(|_| Ok(Some(AccountInfo::dummy())));
mock_authentication_service
.expect_find_account_info_by_name()
.with(eq(AccountName::new_unchecked("unknown")))
.returning(|_| Ok(None));
let catalog = dill::CatalogBuilder::new()
.add_value(mock_authentication_service)
.bind::<dyn kamu_core::auth::AuthenticationService, MockAuthenticationService>()
.build();

Self { catalog }
}
}
29 changes: 18 additions & 11 deletions src/adapter/graphql/tests/tests/test_gql_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ use opendatafabric::*;

/////////////////////////////////////////////////////////////////////////////////////////

fn create_catalog_with_local_workspace(tempdir: &Path) -> dill::Catalog {
fn create_catalog_with_local_workspace(tempdir: &Path, is_multitenant: bool) -> dill::Catalog {
let datasets_dir = tempdir.join("datasets");
std::fs::create_dir(&datasets_dir).unwrap();

dill::CatalogBuilder::new()
.add::<EventBus>()
.add::<DependencyGraphServiceInMemory>()
.add_builder(
DatasetRepositoryLocalFs::builder()
.with_root(tempdir.join("datasets"))
.with_root(datasets_dir)
.with_current_account_subject(Arc::new(CurrentAccountSubject::new_test()))
.with_multi_tenant(false),
.with_multi_tenant(is_multitenant),
)
.bind::<dyn DatasetRepository, DatasetRepositoryLocalFs>()
.add::<QueryServiceImpl>()
Expand All @@ -42,12 +45,16 @@ fn create_catalog_with_local_workspace(tempdir: &Path) -> dill::Catalog {

/////////////////////////////////////////////////////////////////////////////////////////

async fn create_test_dataset(catalog: &dill::Catalog, tempdir: &Path) {
async fn create_test_dataset(
catalog: &dill::Catalog,
tempdir: &Path,
account_name: Option<AccountName>,
) {
let dataset_repo = catalog.get_one::<dyn DatasetRepository>().unwrap();

let dataset = dataset_repo
.create_dataset(
&DatasetAlias::new(None, DatasetName::new_unchecked("foo")),
&DatasetAlias::new(account_name, DatasetName::new_unchecked("foo")),
MetadataFactory::metadata_block(MetadataFactory::seed(DatasetKind::Root).build())
.build_typed(),
)
Expand Down Expand Up @@ -103,8 +110,8 @@ async fn create_test_dataset(catalog: &dill::Catalog, tempdir: &Path) {
#[test_log::test(tokio::test)]
async fn test_dataset_schema_local_fs() {
let tempdir = tempfile::tempdir().unwrap();
let catalog = create_catalog_with_local_workspace(tempdir.path());
create_test_dataset(&catalog, tempdir.path()).await;
let catalog = create_catalog_with_local_workspace(tempdir.path(), true);
create_test_dataset(&catalog, tempdir.path(), None).await;

let schema = kamu_adapter_graphql::schema_quiet();
let res = schema
Expand Down Expand Up @@ -162,8 +169,8 @@ async fn test_dataset_schema_local_fs() {
#[test_log::test(tokio::test)]
async fn test_dataset_tail_local_fs() {
let tempdir = tempfile::tempdir().unwrap();
let catalog = create_catalog_with_local_workspace(tempdir.path());
create_test_dataset(&catalog, tempdir.path()).await;
let catalog = create_catalog_with_local_workspace(tempdir.path(), true);
create_test_dataset(&catalog, tempdir.path(), None).await;

let schema = kamu_adapter_graphql::schema_quiet();
let res = schema
Expand Down Expand Up @@ -203,8 +210,8 @@ async fn test_dataset_tail_local_fs() {
#[test_log::test(tokio::test)]
async fn test_dataset_tail_empty_local_fs() {
let tempdir = tempfile::tempdir().unwrap();
let catalog = create_catalog_with_local_workspace(tempdir.path());
create_test_dataset(&catalog, tempdir.path()).await;
let catalog = create_catalog_with_local_workspace(tempdir.path(), true);
create_test_dataset(&catalog, tempdir.path(), None).await;

let schema = kamu_adapter_graphql::schema_quiet();
let res = schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1099,12 +1099,14 @@ struct FlowConfigHarness {
impl FlowConfigHarness {
fn new() -> Self {
let tempdir = tempfile::tempdir().unwrap();
let datasets_dir = tempdir.path().join("datasets");
std::fs::create_dir(&datasets_dir).unwrap();

let catalog_base = dill::CatalogBuilder::new()
.add::<EventBus>()
.add_builder(
DatasetRepositoryLocalFs::builder()
.with_root(tempdir.path().join("datasets"))
.with_root(datasets_dir)
.with_multi_tenant(false),
)
.bind::<dyn DatasetRepository, DatasetRepositoryLocalFs>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,8 @@ impl FlowRunsHarness {
let tempdir = tempfile::tempdir().unwrap();
let run_info_dir = tempdir.path().join("run");
let cache_dir = tempdir.path().join("cache");
let datasets_dir = tempdir.path().join("datasets");
std::fs::create_dir(&datasets_dir).unwrap();
std::fs::create_dir(&run_info_dir).unwrap();
std::fs::create_dir(&cache_dir).unwrap();

Expand All @@ -1711,7 +1713,7 @@ impl FlowRunsHarness {
.add::<EventBus>()
.add_builder(
DatasetRepositoryLocalFs::builder()
.with_root(tempdir.path().join("datasets"))
.with_root(datasets_dir)
.with_multi_tenant(false),
)
.bind::<dyn DatasetRepository, DatasetRepositoryLocalFs>()
Expand Down
Loading