Refactor buster-cli model structures and update YAML templates

- Renamed `semantic_models` to `models` in YAML template and related structures for consistency.
- Changed `expr` field type in `PostDatasetsEntityRelationshipsRequest` from `Vec<String>` to `String` to simplify data handling.
- Updated `BusterModel` struct to reflect the new `models` naming and removed unused `ModelDefaults` struct.
- Adjusted tests to align with the updated model structure.

These changes enhance clarity and maintainability in the model representation and data handling within the buster-cli.
This commit is contained in:
dal 2025-01-02 16:48:10 -07:00
parent 26198ab926
commit 1cff6c01e4
4 changed files with 8 additions and 14 deletions

View File

@ -1,6 +1,6 @@
version: 2
semantic_models:
models:
- name: the_name_of_the_semantic_model ## Required
description: same as always ## Optional
model: ref('some_model') ## Required: the database identifier of the table/view/mv that this semantic model relates to.

View File

@ -47,7 +47,7 @@ pub struct PostDatasetsColumnsRequest {
#[derive(Debug, Serialize)]
pub struct PostDatasetsEntityRelationshipsRequest {
pub name: String,
pub expr: Vec<String>,
pub expr: String,
#[serde(rename = "type")]
pub type_: String,
}

View File

@ -22,13 +22,12 @@ pub struct BusterModelObject {
#[derive(Debug, Serialize, Deserialize)]
pub struct BusterModel {
pub version: i32,
pub semantic_models: Vec<SemanticModel>,
pub models: Vec<Model>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SemanticModel {
pub struct Model {
pub name: String,
pub defaults: ModelDefaults,
pub description: String,
pub model: Option<String>,
pub entities: Vec<Entity>,
@ -36,11 +35,6 @@ pub struct SemanticModel {
pub measures: Vec<Measure>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ModelDefaults {
pub agg_time_dimension: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Entity {
pub name: String,
@ -121,7 +115,7 @@ pub async fn upload_model_files(
// Iterate through each model object and the semantic models within. These are the datasets we want to create.
for model in model_objects {
for semantic_model in model.model_file.semantic_models {
for semantic_model in model.model_file.models {
let mut columns = Vec::new();
for column in semantic_model.dimensions {
@ -151,7 +145,7 @@ pub async fn upload_model_files(
for entity in semantic_model.entities {
entity_relationships.push(PostDatasetsEntityRelationshipsRequest {
name: entity.name,
expr: vec![entity.expr],
expr: entity.expr,
type_: entity.entity_type,
});
}

View File

@ -2,7 +2,7 @@
fn test_convert_buster_to_dbt_model() {
let buster_yaml = r#"
version: 2
semantic_models:
models:
- name: test_model
aliases: ["alias1"]
entities: