Merge pull request #3 from buster-so/dal/buster-cli

Refactor buster-cli model structures and update YAML templates
This commit is contained in:
dal 2025-01-02 15:49:02 -08:00 committed by GitHub
commit bc4fd6c8b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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:
@ -23,7 +23,7 @@ semantic_models:
"#;
let dbt_yaml = convert_buster_to_dbt_model(buster_yaml).unwrap();
// The converted YAML shouldn't contain Buster-specific fields
assert!(!dbt_yaml.contains("aliases"));
assert!(!dbt_yaml.contains("join_type"));