Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add support for Primary and Foreign Key Constraints in databricks_sql_table #4155

Conversation

hshahconsulting
Copy link

@hshahconsulting hshahconsulting commented Oct 25, 2024

Changes

This pull request aims to enable support for Primary Key and Foreign Key constraints that are generally available in Databricks.

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

Closes #4157

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@hshahconsulting hshahconsulting marked this pull request as ready for review October 25, 2024 10:06
@hshahconsulting hshahconsulting requested review from a team as code owners October 25, 2024 10:06
@hshahconsulting hshahconsulting requested review from hectorcast-db and removed request for a team October 25, 2024 10:06
@hshahconsulting hshahconsulting marked this pull request as draft October 25, 2024 12:29
@hshahconsulting hshahconsulting marked this pull request as ready for review October 25, 2024 14:08
@hshahconsulting hshahconsulting marked this pull request as draft October 28, 2024 10:39
@hshahconsulting
Copy link
Author

Set to draft to add "name" parameter to constraint

@hshahconsulting
Copy link
Author

There is now added code for adding and removing constraints to an existing table. However, the tests are not running. Assistance will be needed to complete this.

@tanmay-db tanmay-db marked this pull request as ready for review November 7, 2024 00:04
Copy link

github-actions bot commented Nov 7, 2024

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:

  • PR number: 4155
  • Commit SHA: 11c26ef63a9f7d898214bd75b917878f6f8a6a72

Checks will be approved automatically on success.

@eng-dev-ecosystem-bot
Copy link
Collaborator

Test Details: go/deco-tests/11713988746

@tanmay-db
Copy link
Contributor

Hi @hshahconsulting, thanks for the PR. The tests are running. I see the pull request was in draft state -- I have marked it for review.

Some unit tests are failing, can you please take a look? You can run the unit test locally by running make test from the root of repository.

=== Failed
=== FAIL: catalog TestResourceSqlTableUpdateTable_KeyConstraints (0.00s)
    resource_sql_table_test.go:1149: 
        	Error Trace:	/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/catalog/resource_sql_table_test.go:1149
        	            				/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/catalog/resource_sql_table_test.go:1225
exit status 1
        	Error:      	Received unexpected error:
        	            	At 11:4: expected: IDENT | STRING got: LBRACE
        	Test:       	TestResourceSqlTableUpdateTable_KeyConstraints

@hshahconsulting
Copy link
Author

Hi @hshahconsulting, thanks for the PR. The tests are running. I see the pull request was in draft state -- I have marked it for review.

Some unit tests are failing, can you please take a look? You can run the unit test locally by running make test from the root of repository.

=== Failed
=== FAIL: catalog TestResourceSqlTableUpdateTable_KeyConstraints (0.00s)
    resource_sql_table_test.go:1149: 
        	Error Trace:	/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/catalog/resource_sql_table_test.go:1149
        	            				/home/runner/work/terraform-provider-databricks/terraform-provider-databricks/catalog/resource_sql_table_test.go:1225
exit status 1
        	Error:      	Received unexpected error:
        	            	At 11:4: expected: IDENT | STRING got: LBRACE
        	Test:       	TestResourceSqlTableUpdateTable_KeyConstraints

Hi Tanmay, thank you for taking the time to having a look. The issue here is that I am not a Go programmer and I will need help from you guys to make the tests pass. I have tried to make them work but I lack the knowledge to find the issue.

@wiatrak2
Copy link

Hi!
It seems that we both are working on introducing the CONSTRAINTs to the resource - I've also created a PR #4205 with these possibilities.
I'm looking into your code and it seems that you try to use incorrect syntax when defining a CONSTRAINT during table creation - according to CREATE TABLE documentation the constraint part should be included in the same parentheses as columns definitions. I wonder how should we proceed to introduce the feature to the resource - I'm not fully convinced with the approach you took (different blocks for primary/foreign key, support for one key column only, also CHECK constraint could be difficult to support with this structure), what are your plans for supporting these options? It would be silly to develop both branches if we'd introduce the same changes, we could coordinate to avoid duplication :)

@hshahconsulting
Copy link
Author

Hi! It seems that we both are working on introducing the CONSTRAINTs to the resource - I've also created a PR #4205 with these possibilities. I'm looking into your code and it seems that you try to use incorrect syntax when defining a CONSTRAINT during table creation - according to CREATE TABLE documentation the constraint part should be included in the same parentheses as columns definitions. I wonder how should we proceed to introduce the feature to the resource - I'm not fully convinced with the approach you took (different blocks for primary/foreign key, support for one key column only, also CHECK constraint could be difficult to support with this structure), what are your plans for supporting these options? It would be silly to develop both branches if we'd introduce the same changes, we could coordinate to avoid duplication :)

Hello, thank you for adding your comment :) I am not a Go programmer and struggling to make the tests work, so I have asked to open a support ticket on my client's behalf.

If your PR can

  1. add support for primary and foreign key constraints
  2. Add support for creating constraints in alter table statements
  3. Adding support for dropping constraints in alter table statements

I suggest that we drop my PR and that you merge yours instead.

Best regards
Hassan Shah

@hshahconsulting
Copy link
Author

As this feature is being developed in #4205, I am closing this issue. If something changes, it will be reopened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for Primary and Foreign Key Constraints in databricks_sql_table
4 participants