Skip to content

Commit

Permalink
ndc-test
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Jan 28, 2025
1 parent 2a5a577 commit 847015b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ndc-models/tests/json_schema/schema_response.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,6 @@
"required": [
"aggregate_functions",
"comparison_operators",
"extraction_functions",
"representation"
],
"properties": {
Expand Down Expand Up @@ -869,6 +868,7 @@
},
"extraction_functions": {
"description": "A map from extraction function names to their defginitions.",
"default": {},
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/ExtractionFunctionDefinition"
Expand Down
78 changes: 45 additions & 33 deletions ndc-test/src/test_cases/query/grouping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::reporter::Reporter;
use crate::test;

use indexmap::IndexMap;
use ndc_models as models;
use ndc_models::{self as models};
use rand::rngs::SmallRng;
use rand::seq::IteratorRandom;
use std::collections::BTreeMap;
Expand All @@ -29,42 +29,54 @@ pub async fn test_grouping<C: Connector, R: Reporter>(
))?;

for _ in 0..gen_config.test_cases.max(1) {
if let Some((dimension_column_name, _)) =
common::select_all_columns_without_arguments(collection_type).choose(rng)
if let Some((dimension_column_name, scalar_type)) =
common::select_all_columns_without_arguments(collection_type)
.filter_map(|(column_name, object_field)| match &object_field.r#type {
ndc_models::Type::Named { name } => {
Some((column_name, schema.scalar_types.get(name)?))
}
_ => None,
})
.choose(rng)
{
let query_request = models::QueryRequest {
collection: collection_info.name.clone(),
query: models::Query {
aggregates: None,
fields: None,
limit: None,
offset: None,
order_by: None,
predicate: None,
groups: Some(models::Grouping {
aggregates: IndexMap::from_iter([(
"count".into(),
models::Aggregate::StarCount {},
)]),
dimensions: vec![models::Dimension::Column {
column_name: dimension_column_name.clone(),
arguments: BTreeMap::new(),
field_path: None,
path: vec![],
extraction: None,
}],
predicate: None,
order_by: None,
let mut extraction_functions = vec![None];
extraction_functions
.extend(scalar_type.extraction_functions.keys().map(Option::Some));
if let Some(extraction) = extraction_functions.into_iter().choose(rng) {
let query_request = models::QueryRequest {
collection: collection_info.name.clone(),
query: models::Query {
aggregates: None,
fields: None,
limit: None,
offset: None,
}),
},
arguments: BTreeMap::new(),
collection_relationships: BTreeMap::new(),
variables: None,
};
order_by: None,
predicate: None,
groups: Some(models::Grouping {
aggregates: IndexMap::from_iter([(
"count".into(),
models::Aggregate::StarCount {},
)]),
dimensions: vec![models::Dimension::Column {
column_name: dimension_column_name.clone(),
arguments: BTreeMap::new(),
field_path: None,
path: vec![],
extraction: extraction.cloned(),
}],
predicate: None,
order_by: None,
limit: None,
offset: None,
}),
},
arguments: BTreeMap::new(),
collection_relationships: BTreeMap::new(),
variables: None,
};

connector.query(query_request.clone()).await?;
connector.query(query_request.clone()).await?;
}
}
}

Expand Down

0 comments on commit 847015b

Please sign in to comment.