Skip to content

Commit bb80198

Browse files
committed
translation tests
1 parent e59519b commit bb80198

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1136
-542
lines changed

Cargo.lock

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

crates/configuration/src/config2.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ WITH column_data AS (
66
c.column_name,
77
TO_JSON_STRING(STRUCT(
88
c.column_name AS name,
9-
JSON_OBJECT('ScalarType',
9+
JSON_OBJECT('scalarType',
1010
case LOWER(c.data_type)
1111
when 'bool' then 'boolean'
1212
when 'boolean' then 'boolean'

crates/configuration/src/version1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const NOT_APPROX_COUNTABLE: [&str; 4] = ["image", "sql_variant", "ntext", "text"
5151
/// Initial configuration, just enough to connect to a database and elaborate a full
5252
/// 'Configuration'.
5353
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
54+
#[serde(rename_all = "camelCase")]
5455
pub struct ParsedConfiguration {
5556
// Which version of the configuration format are we using
5657
pub version: u32,
@@ -238,7 +239,7 @@ pub async fn configure(
238239

239240
/// Parse the configuration format from a directory.
240241
pub async fn parse_configuration(
241-
configuration_dir: impl AsRef<Path>,
242+
configuration_dir: impl AsRef<Path> + Send,
242243
) -> Result<ParsedConfiguration, ParseConfigurationError> {
243244
let configuration_file = configuration_dir.as_ref().join(CONFIGURATION_FILENAME);
244245

crates/query-engine/metadata/src/metadata/database.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct ScalarTypeTypeName(pub String);
1313

1414
/// The type of values that a column, field, or argument may take.
1515
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
16+
#[serde(rename_all = "camelCase")]
1617
pub enum Type {
1718
ScalarType(models::ScalarTypeName),
1819
CompositeType(models::TypeName),

crates/query-engine/metadata/src/metadata/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
1212

1313
/// Metadata information.
1414
#[derive(Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize, JsonSchema)]
15+
#[serde(rename_all = "camelCase")]
1516
pub struct Metadata {
1617
pub tables: TablesInfo,
1718
// pub composite_types: CompositeTypes,

crates/query-engine/translation/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ndc-models = { workspace = true }
99

1010
query-engine-metadata = { path = "../metadata" }
1111
query-engine-sql = { path = "../sql" }
12+
ndc-bigquery-configuration = { path = "../../../crates/configuration" }
1213

1314
enum-iterator = { workspace = true }
1415
indexmap = { workspace = true }
@@ -18,6 +19,7 @@ serde_json = { workspace = true }
1819
thiserror = { workspace = true }
1920
tracing = { workspace = true }
2021
anyhow = { workspace = true }
22+
tokio = { workspace = true }
2123

2224
[dev-dependencies]
2325
insta = { workspace = true, features = ["json"] }

crates/query-engine/translation/tests/common/mod.rs

+37-15
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,58 @@ use std::fs;
22

33
use query_engine_sql::sql;
44
use query_engine_translation::translation;
5+
use std::path::PathBuf;
56

67
/// Run a query against the server, get the result, and compare against the snapshot.
7-
pub fn test_translation(testname: &str) -> anyhow::Result<String> {
8-
let tables = serde_json::from_str(
9-
fs::read_to_string(format!("tests/goldenfiles/{}/tables.json", testname))
10-
.unwrap()
11-
.as_str(),
12-
)
13-
.unwrap();
14-
let request = serde_json::from_str(
15-
fs::read_to_string(format!("tests/goldenfiles/{}/request.json", testname))
16-
.unwrap()
17-
.as_str(),
18-
)
19-
.unwrap();
20-
21-
let plan = translation::query::translate(&tables, request)?;
8+
pub async fn test_translation(testname: &str) -> anyhow::Result<String> {
9+
// let tables = serde_json::from_str(
10+
// fs::read_to_string(format!("tests/goldenfiles/{}/tables.json", testname))
11+
// .unwrap()
12+
// .as_str(),
13+
// )
14+
// .unwrap();
15+
16+
let directory = PathBuf::from("tests/goldenfiles").join(testname);
17+
18+
let parsed_configuration = ndc_bigquery_configuration::parse_configuration(&directory).await?;
19+
let configuration = ndc_bigquery_configuration::make_runtime_configuration(
20+
parsed_configuration,
21+
ndc_bigquery_configuration::environment::FixedEnvironment::from([
22+
(
23+
"HASURA_BIGQUERY_SERVICE_KEY".into(),
24+
"the translation tests do not rely on a database connection".into(),
25+
),
26+
(
27+
"HASURA_BIGQUERY_PROJECT_ID".into(),
28+
"the translation tests do not rely on a database connection".into(),
29+
),
30+
(
31+
"HASURA_BIGQUERY_DATASET_ID".into(),
32+
"the translation tests do not rely on a database connection".into(),
33+
),
34+
]),
35+
)?;
36+
let metadata = configuration.metadata;
37+
38+
let request =
39+
serde_json::from_str(&fs::read_to_string(directory.join("request.json")).unwrap()).unwrap();
40+
41+
let plan = translation::query::translate(&metadata, request)?;
2242
let query = plan.query.query_sql();
2343
let params: Vec<(usize, &sql::string::Param)> = query
2444
.params
2545
.iter()
2646
.enumerate()
2747
.map(|(i, p)| (i + 1, p))
2848
.collect();
49+
dbg!(&query);
2950

3051
let pretty = sqlformat::format(
3152
&query.sql,
3253
&sqlformat::QueryParams::None,
3354
sqlformat::FormatOptions::default(),
3455
);
56+
dbg!(&pretty);
3557

3658
Ok(format!("{}\n\n{:?}", pretty, params))
3759
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"version": 1,
3+
"connectionSettings": {
4+
"serviceKey": {
5+
"variable": "HASURA_BIGQUERY_SERVICE_KEY"
6+
},
7+
"projectId": {
8+
"variable": "HASURA_BIGQUERY_PROJECT_ID"
9+
},
10+
"datasetId": {
11+
"variable": "HASURA_BIGQUERY_DATASET_ID"
12+
}
13+
},
14+
"metadata": {
15+
"tables": {
16+
"albums": {
17+
"schemaName": "test_project.test_dataset",
18+
"tableName": "albums",
19+
"columns": {
20+
"AlbumId": {
21+
"name": "AlbumId",
22+
"type": {
23+
"scalarType": "bigint"
24+
},
25+
"nullable": "nullable",
26+
"description": null
27+
},
28+
"Title": {
29+
"name": "Title",
30+
"type": {
31+
"scalarType": "string"
32+
},
33+
"nullable": "nullable",
34+
"description": null
35+
},
36+
"ArtistId": {
37+
"name": "ArtistId",
38+
"type": {
39+
"scalarType": "bigint"
40+
},
41+
"nullable": "nullable",
42+
"description": null
43+
}
44+
},
45+
"uniquenessConstraints": {},
46+
"foreignRelations": {},
47+
"description": null
48+
}
49+
},
50+
"scalarTypes": {
51+
"bigint": {
52+
"typeName": "bigint",
53+
"schemaName": "test_project.test_dataset",
54+
"description": null,
55+
"aggregateFunctions": {},
56+
"comparisonOperators": {},
57+
"typeRepresentation": null
58+
},
59+
"string": {
60+
"typeName": "string",
61+
"schemaName": "test_project.test_dataset",
62+
"description": null,
63+
"aggregateFunctions": {},
64+
"comparisonOperators": {},
65+
"typeRepresentation": null
66+
}
67+
},
68+
"nativeOperations": {
69+
"queries": {},
70+
"mutations": {}
71+
}
72+
}
73+
}

crates/query-engine/translation/tests/goldenfiles/aggregate_count_albums/request.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"collection": "Album",
2+
"collection": "albums",
33
"query": {
44
"fields": {
55
"Title": {

crates/query-engine/translation/tests/goldenfiles/aggregate_count_albums/tables.json

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"version": 1,
3+
"connectionSettings": {
4+
"serviceKey": {
5+
"variable": "HASURA_BIGQUERY_SERVICE_KEY"
6+
},
7+
"projectId": {
8+
"variable": "HASURA_BIGQUERY_PROJECT_ID"
9+
},
10+
"datasetId": {
11+
"variable": "HASURA_BIGQUERY_DATASET_ID"
12+
}
13+
},
14+
"metadata": {
15+
"tables": {
16+
"albums": {
17+
"schemaName": "test_project.test_dataset",
18+
"tableName": "albums",
19+
"columns": {
20+
"AlbumId": {
21+
"name": "AlbumId",
22+
"type": {
23+
"scalarType": "bigint"
24+
},
25+
"nullable": "nullable",
26+
"description": null
27+
},
28+
"Title": {
29+
"name": "Title",
30+
"type": {
31+
"scalarType": "string"
32+
},
33+
"nullable": "nullable",
34+
"description": null
35+
},
36+
"ArtistId": {
37+
"name": "ArtistId",
38+
"type": {
39+
"scalarType": "bigint"
40+
},
41+
"nullable": "nullable",
42+
"description": null
43+
}
44+
},
45+
"uniquenessConstraints": {},
46+
"foreignRelations": {},
47+
"description": null
48+
}
49+
},
50+
"scalarTypes": {
51+
"bigint": {
52+
"typeName": "bigint",
53+
"schemaName": "test_project.test_dataset",
54+
"description": null,
55+
"aggregateFunctions": {},
56+
"comparisonOperators": {},
57+
"typeRepresentation": null
58+
},
59+
"string": {
60+
"typeName": "string",
61+
"schemaName": "test_project.test_dataset",
62+
"description": null,
63+
"aggregateFunctions": {},
64+
"comparisonOperators": {},
65+
"typeRepresentation": null
66+
}
67+
},
68+
"nativeOperations": {
69+
"queries": {},
70+
"mutations": {}
71+
}
72+
}
73+
}

crates/query-engine/translation/tests/goldenfiles/aggregate_distinct_albums/request.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"collection": "Album",
2+
"collection": "albums",
33
"query": {
44
"aggregates": {
55
"how_many_distinct_artist_ids": {

crates/query-engine/translation/tests/goldenfiles/aggregate_distinct_albums/tables.json

-22
This file was deleted.

0 commit comments

Comments
 (0)