mirror of https://github.com/buster-so/buster.git
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:
parent
26198ab926
commit
1cff6c01e4
|
@ -1,6 +1,6 @@
|
||||||
version: 2
|
version: 2
|
||||||
|
|
||||||
semantic_models:
|
models:
|
||||||
- name: the_name_of_the_semantic_model ## Required
|
- name: the_name_of_the_semantic_model ## Required
|
||||||
description: same as always ## Optional
|
description: same as always ## Optional
|
||||||
model: ref('some_model') ## Required: the database identifier of the table/view/mv that this semantic model relates to.
|
model: ref('some_model') ## Required: the database identifier of the table/view/mv that this semantic model relates to.
|
||||||
|
|
|
@ -47,7 +47,7 @@ pub struct PostDatasetsColumnsRequest {
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct PostDatasetsEntityRelationshipsRequest {
|
pub struct PostDatasetsEntityRelationshipsRequest {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub expr: Vec<String>,
|
pub expr: String,
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub type_: String,
|
pub type_: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,12 @@ pub struct BusterModelObject {
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct BusterModel {
|
pub struct BusterModel {
|
||||||
pub version: i32,
|
pub version: i32,
|
||||||
pub semantic_models: Vec<SemanticModel>,
|
pub models: Vec<Model>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct SemanticModel {
|
pub struct Model {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub defaults: ModelDefaults,
|
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub model: Option<String>,
|
pub model: Option<String>,
|
||||||
pub entities: Vec<Entity>,
|
pub entities: Vec<Entity>,
|
||||||
|
@ -36,11 +35,6 @@ pub struct SemanticModel {
|
||||||
pub measures: Vec<Measure>,
|
pub measures: Vec<Measure>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
pub struct ModelDefaults {
|
|
||||||
pub agg_time_dimension: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Entity {
|
pub struct Entity {
|
||||||
pub name: String,
|
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.
|
// Iterate through each model object and the semantic models within. These are the datasets we want to create.
|
||||||
for model in model_objects {
|
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();
|
let mut columns = Vec::new();
|
||||||
|
|
||||||
for column in semantic_model.dimensions {
|
for column in semantic_model.dimensions {
|
||||||
|
@ -151,7 +145,7 @@ pub async fn upload_model_files(
|
||||||
for entity in semantic_model.entities {
|
for entity in semantic_model.entities {
|
||||||
entity_relationships.push(PostDatasetsEntityRelationshipsRequest {
|
entity_relationships.push(PostDatasetsEntityRelationshipsRequest {
|
||||||
name: entity.name,
|
name: entity.name,
|
||||||
expr: vec![entity.expr],
|
expr: entity.expr,
|
||||||
type_: entity.entity_type,
|
type_: entity.entity_type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
fn test_convert_buster_to_dbt_model() {
|
fn test_convert_buster_to_dbt_model() {
|
||||||
let buster_yaml = r#"
|
let buster_yaml = r#"
|
||||||
version: 2
|
version: 2
|
||||||
semantic_models:
|
models:
|
||||||
- name: test_model
|
- name: test_model
|
||||||
aliases: ["alias1"]
|
aliases: ["alias1"]
|
||||||
entities:
|
entities:
|
||||||
|
|
Loading…
Reference in New Issue