diff --git a/website/docs/docs/core/connect-data-platform/singlestore-setup.md b/website/docs/docs/core/connect-data-platform/singlestore-setup.md index a63466542a9..6fa7ed4d5c2 100644 --- a/website/docs/docs/core/connect-data-platform/singlestore-setup.md +++ b/website/docs/docs/core/connect-data-platform/singlestore-setup.md @@ -13,7 +13,7 @@ meta: slack_channel_name: 'db-singlestore' slack_channel_link: 'https://getdbt.slack.com/archives/C02V2QHFF7U' platform_name: 'SingleStore' - config_page: '/reference/resource-configs/no-configs' + config_page: '/reference/resource-configs/singlestore-configs' --- :::info Vendor-supported plugin diff --git a/website/docs/reference/resource-configs/singlestore-configs.md b/website/docs/reference/resource-configs/singlestore-configs.md index 0c93d557a8b..c1a1c6869f1 100644 --- a/website/docs/reference/resource-configs/singlestore-configs.md +++ b/website/docs/reference/resource-configs/singlestore-configs.md @@ -3,10 +3,14 @@ title: "SingleStore configurations" id: "singlestore-configs" --- +## Incremental materialization strategies +The [`incremental_strategy` config](/docs/build/incremental-models#about-incremental_strategy) controls how dbt builds incremental models. Currently, SingleStoreDB supports only the `delete+insert` configuration. + +The `delete+insert` incremental strategy directs dbt to follow a two-step incremental approach. Initially, it identifies and removes the records flagged by the configured `is_incremental()` block. Subsequently, it re-inserts these records. + ## Performance Optimizations [SingleStore Physical Database Schema Design documentation](https://docs.singlestore.com/managed-service/en/create-a-database/physical-database-schema-design/concepts-of-physical-database-schema-design.html) is helpful if you want to use specific options (that are described below) in your dbt project. - ### Storage type SingleStore supports two storage types: **In-Memory Rowstore** and **Disk-based Columnstore** (the latter is default). See [the docs](https://docs.singlestore.com/managed-service/en/create-a-database/physical-database-schema-design/concepts-of-physical-database-schema-design/choosing-a-table-storage-type.html) for details. The dbt-singlestore adapter allows you to specify which storage type your table materialization would rely on using `storage_type` config parameter. @@ -101,4 +105,113 @@ You can specify the character set and collation for the table using `charset` an select ... ``` - \ No newline at end of file + + +## Model contracts + +Starting from 1.5, the `dbt-singlestore` adapter supports model contracts. + +| Constraint type | Support | Platform enforcement | +|:----------------|:----------------|:------------------| +| not_null | ✅ Supported | ✅ Enforced | +| primary_key | ✅ Supported | ❌ Not enforced | +| foreign_key | ❌ Not supported | ❌ Not enforced | +| unique | ✅ Supported | ❌ Not enforced | +| check | ❌ Not supported | ❌ Not enforced | + + +Consider the following restrictions while using contracts with the `dbt-singlestore` adapter: + +### Model and Column Definitions: + - The `unique` constraint can only be set at the model level. Hence, do not set it at the column level. + - Repeating constraints will return an error. For example, setting `primary_key` in both column and model settings returns an error. + +### Overwriting Settings: + +The contract setting overrides the configuration setting. For example, if you define a `primary_key` or `unique_table_key` in the config and then also set it in the contract, the contract setting replaces the configuration setting. + +### Working with constants: + + + +```sql +models: + - name: dim_customers + config: + materialized: table + contract: + enforced: true + columns: + - name: customer_id + data_type: int + constraints: + - type: not_null + - name: customer_name + data_type: text +``` + + + +Let's say your model is defined as: + + + +```sql +select + 'abc123' as customer_id, + 'My Best Customer' as customer_name +``` + + + +When using constants, you must specify the data types directly. If not, SingleStoreDB will automatically choose what it thinks is the most appropriate data type. + + + +```sql +select + ('abc123' :> int) as customer_id, + ('My Best Customer' :> text) as customer_name +``` + + + +### Misleading datatypes + +Using `model contracts` ensures that you don't accidentally add the wrong type of data into a column. For instance, if you expect a number in a column, but accidentally specify text to be added, the model contract catches it and returns an error. + +The error message may occasionally show a different data type name than expected, because of how the `singlestoredb-python` connector works. For instance, + + + +```sql +select + 'abc123' as customer_id, + ('My Best Customer' :> text) as customer_name +``` + + + +will result in + +```sql +Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition. +| column_name | definition_type | contract_type | mismatch_reason | +| customer_id | LONGBLOB | LONG | data type mismatch | +``` + +It's important to note that certain data type mappings might show up differently in error messages, but this doesn't affect how they work. Here's a quick list of what you might see: + +| Data type | Data type returned by
singlestoredb-python | +|:-----------|:-----------------------------------------------| +| BOOL | TINY | +| INT | LONG | +| CHAR | BINARY | +| VARCHAR | VARBINARY | +| TEXT | BLOB | +| TINYTEXT | TINYBLOB | +| MEDIUMTEXT | MEDIUMBLOB | +| LONGTEXT | LONGBLOB | + + +Just keep these points in mind when setting up and using your `dbt-singlestore` adapter, and you'll avoid common pitfalls!