From 0e323bd3c36df9cdbfe53133d6d19607b2db3b25 Mon Sep 17 00:00:00 2001 From: Boris Ershov Date: Thu, 5 Dec 2024 12:56:22 +0400 Subject: [PATCH] feat(indexes): indexes feature --- README.md | 12 ++++++++++++ .../application/templates/scaffold.tar.gz | Bin 3929704 -> 3929704 bytes .../templates/dwh_sql_model_asset.tmpl | 11 +++++++++++ .../domain/internal_models/model_config.go | 7 +++++++ .../domain/services/sql_model_profiles.go | 3 +++ .../domain/services/sql_models_factory.go | 11 +++++++++++ pkg/configs/config_service.go | 2 +- pkg/configs/profile.go | 7 +++++++ 8 files changed, 52 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7695e1..531c992 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,13 @@ The asset profile can be specified via the `profile.yaml` file or via a GO templ connection: 'default' materialization: 'table' is_data_framed: true + primary_key_fields: + - "id" + indexes: + - name: "wallet" + unique: false + fields: + - "wallet_id" {{ end }} select @@ -325,6 +332,11 @@ select |materialization|String|table|See [Materializations](#materializations).| |is_data_framed|boolean|false|See [Cross-database references](#cross-database-references).| |persist_inputs|boolean|false|See [Cross-database references](#cross-database-references).| +|primary_key_fields|Array of string||List of fields for the primary unique index| +|indexes|Array of Indexes||List of indexes for the asset (only for the table and incremental materializations)| +|indexes.``|String||Name of the index| +|indexes.``.Unique|boolean|false|flag of the uniqueness of the Index| +|indexes.``.fields|Array of string||List of fields for the index| ## Materializations diff --git a/internal/application/templates/scaffold.tar.gz b/internal/application/templates/scaffold.tar.gz index 9b011a4977fc26ea267c5ef0d55e73033404da84..04411cdc17c4e266e18ace1abcc134041595d52e 100644 GIT binary patch delta 197 zcmWN_Nm>B_0Dw^xKM~11WC&%R%XEs4(AF(1{*}|Ta3_nt&(4~~+r0DtC3wE0evAhG z_CE(CC?R=}M+r+r?irPsJV{&<@+?V7$%~}rRWg#5oaCh-MJY*HDpHjfQ3(Qq 0 { profile.PrimaryKeyFields = newModelProfile.PrimaryKeyFields } + if len(newModelProfile.Indexes) > 0 { + profile.Indexes = newModelProfile.Indexes + } if len(newModelProfile.Tests) > 0 { profile.Tests = newModelProfile.Tests diff --git a/internal/domain/services/sql_models_factory.go b/internal/domain/services/sql_models_factory.go index f8d78ea..d1f8e87 100644 --- a/internal/domain/services/sql_models_factory.go +++ b/internal/domain/services/sql_models_factory.go @@ -91,6 +91,17 @@ func InitSQLModelConfigs(config *configs.Config, profiles *configs.ProjectProfil if len(modelProfile.PrimaryKeyFields) > 0 { data.PrimaryKeyExpression = strings.Join(defaultModelProfile.PrimaryKeyFields, ", ") } + + if len(modelProfile.Indexes) > 0 { + for _, index := range modelProfile.Indexes { + data.Indexes = append(data.Indexes, &internalmodels.IndexConfig{ + IndexName: index.Name, + Unique: index.Unique, + IndexFields: strings.Join(index.Fields, ", "), + }) + } + + } modelsConfigs = append(modelsConfigs, data) } } diff --git a/pkg/configs/config_service.go b/pkg/configs/config_service.go index 9dca56b..e5d9bf0 100644 --- a/pkg/configs/config_service.go +++ b/pkg/configs/config_service.go @@ -7,7 +7,7 @@ import ( "gopkg.in/yaml.v2" ) -const TEAL_VERSION = "v0.1.6" +const TEAL_VERSION = "v0.1.10" type ConfigService struct { } diff --git a/pkg/configs/profile.go b/pkg/configs/profile.go index 919550c..bd7a2d5 100644 --- a/pkg/configs/profile.go +++ b/pkg/configs/profile.go @@ -40,6 +40,7 @@ type ModelProfile struct { Connection string `yaml:"connection"` Materialization MatType `yaml:"materialization"` PrimaryKeyFields []string `yaml:"primary_key_fields"` + Indexes []*DBIndex `yaml:"indexes"` IsDataFramed bool `yaml:"is_data_framed"` PersistInputs bool `yaml:"persist_inputs"` Stage string `yaml:"-"` @@ -47,6 +48,12 @@ type ModelProfile struct { RawUpstreams []string `yaml:"raw_upstreams"` } +type DBIndex struct { + Name string `yaml:"name"` + Unique bool `yaml:"unique"` + Fields []string `yaml:"fields"` +} + type TestProfile struct { Name string `yaml:"name"` Connection string `yaml:"connection"`