databricks / terraform-provider-databricks

Databricks Terraform Provider
https://registry.terraform.io/providers/databricks/databricks/latest
Other
456 stars 393 forks source link

[Feature] Add support for constraints in databricks_sql_table resource #4205

Open wiatrak2 opened 1 week ago

wiatrak2 commented 1 week ago

Changes

Hi!

I'd like to extend the databricks_sql_table resource with constraints feature.

Within this pull request I extend the table's resource by allowing user to specify PRIMARY KEY and FOREIGN KEY constraints. I haven't implemented the CHECK constraint, as this one is more tricky and is not allowed during table creation - it can only be added later in the table's lifecycle. If the proposed changed are accepted, I can try to add the implementation for CHECK, as well as cover other constraint options.

I'm aware that the amount of implemented tests may not be satisfying. If this is the case - please let me know and guide my, what kind of tests should be added.

Tests

alexott commented 1 week ago

there is a #4155 in progress - can you coordinate with that user to avoid duplications?

wiatrak2 commented 1 week ago

oh, indeed! I see the other user decided on slightly different approach to configuration of the constraint. And seems that the syntax is not compliant with Databricks SQL, maybe that's why there are some test failures. I will ask in that PR if we can somehow cooperate :)

otherwise, is there something I could do to proceed with the feature?

wiatrak2 commented 1 week ago

there is a #4155 in progress - can you coordinate with that user to avoid duplications?

seems the feature should be developed within this PR - I'm open to review and suggestions

hshahconsulting commented 1 week ago

Could you add functionality for the "RELY" optimization of Primary Keys?

ALTER TABLE customer ADD PRIMARY KEY (c_customer_sk) RELY

Source: https://www.databricks.com/blog/primary-key-and-foreign-key-constraints-are-ga-and-now-enable-faster-queries

wiatrak2 commented 1 week ago

Sure, optional configuration of a constraint with RELY added

github-actions[bot] commented 1 week ago

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger: go/deco-tests-run/terraform

Inputs:

Checks will be approved automatically on success.

wiatrak2 commented 1 week ago

Hi @tanmay-db

Thank you for your review. I adjusted the implementation to your comments:

Please let me know what you think about these recent changes

nkvuong commented 1 day ago

@wiatrak2 there are CRUD APIs for PK/FK Table Constraints - https://docs.databricks.com/api/workspace/tableconstraints/create, does it make sense to have them as separate resources?

wdyt @tanmay-db ?