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

Add a databricks_table data source #3170

Closed
wants to merge 19 commits into from

Conversation

jdavidheiser
Copy link

Changes

This adds a new data source to describe a Databricks table, to address the request in #3148. I am not particularly familiar with the Databricks Terraform Provider repo, and not sure which styles are best to mimic. I opted to re-use the struct from the Databricks SDK, rather than implementing a new one. I don't see this pattern a lot in the repo, but it seems like recent changes to the SQL data source may have taken this approach.

Tests

I wanted to see if this approach of using the SDK structs is acceptable before writing tests. Go is not a language I normally work in, so it might take a bit of doing for me to figure out that part.

I did manually test it against a real Databricks workspace and confirm the return data shows up in my terraform.tfstate

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

@jdavidheiser jdavidheiser requested review from a team as code owners January 26, 2024 21:34
@jdavidheiser jdavidheiser requested review from hectorcast-db and removed request for a team January 26, 2024 21:34
@jdavidheiser
Copy link
Author

jdavidheiser commented Jan 31, 2024

I fixed a formatting error and added some basic unit testing. I am not really set up for running integration tests yet. Setting that up seems like a lot of overhead to commit a change that just passes an SDK result through unmodified, so if someone already set up for integration tests could help me out that would be appreciated.

@alexott
Copy link
Contributor

alexott commented Jan 31, 2024

Please add at least a unit test...

@jdavidheiser
Copy link
Author

Sorry, I did and forgot to commit it.. Should be there now.

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.47%. Comparing base (edbda2a) to head (c9055a1).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3170      +/-   ##
==========================================
+ Coverage   83.43%   83.47%   +0.04%     
==========================================
  Files         176      177       +1     
  Lines       16223    16258      +35     
==========================================
+ Hits        13536    13572      +36     
+ Misses       1865     1864       -1     
  Partials      822      822              
Files Coverage Δ
catalog/data_table.go 100.00% <100.00%> (ø)
provider/provider.go 94.68% <100.00%> (+0.02%) ⬆️

... and 5 files with indirect coverage changes

Copy link
Contributor

@alexott alexott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a

catalog/data_table.go Outdated Show resolved Hide resolved
catalog/data_table.go Show resolved Hide resolved
@alexott
Copy link
Contributor

alexott commented Feb 1, 2024

Please rebase to the latest main branch to fix the conflict. The changes should be like this: e221fe7

@jdavidheiser
Copy link
Author

conflict should be fixed and switched to common.resource

@alexott
Copy link
Contributor

alexott commented Feb 1, 2024

you can always run make fmt && make lint before committing...

@alexott
Copy link
Contributor

alexott commented Feb 1, 2024

Oh, I missed that documentation isn't a part of PR - please add the documentation as doc/data-sources/table.md file.

@jdavidheiser
Copy link
Author

I added a doc file - mostly copy/pasted from the Databricks SDK for Go docs.

@alexott
Copy link
Contributor

alexott commented Feb 21, 2024

@jdavidheiser can you please resolve conflicts in the provider?

@jdavidheiser
Copy link
Author

fixed

@jdavidheiser
Copy link
Author

Hi - just circling back on this, hoping it could get merged soon to prevent more conflicts.

Read: true,
NonWritable: true,
ID: "_",
}.Apply(t)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could rewrite this as

ApplyAndExpectData(t, map[string]any{
"catalog_name": "a",
...
})


func TestTableData(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use MockWorkspaceClientFunc instead of Fixtures

MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
    e:= w.GetMockTablesAPI().EXPECT()
    e.GetByFullName(mock.Anything, "a.b.c").Return(&catalog.TableInfo{})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pretty much copy pasted patterns I saw elsewhere in this repo - I don't really work in golang so things like this are outside of my comfort zone. I wonder if it might be a lot faster for someone with more familiarity to clean up the test style in a separate pass?

docs/data-sources/table.md Outdated Show resolved Hide resolved
* `storage_location` - Storage root URL for table (for **MANAGED**, **EXTERNAL** tables)
* `table_constraints` - List of table constraints
* `table_id` - Name of table, relative to parent schema
* `table_type` - Table or View
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@nkvuong nkvuong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for this PR. a couple more changes suggested

@nkvuong nkvuong requested review from mgyucht and alexott April 5, 2024 18:40
@alexott
Copy link
Contributor

alexott commented May 14, 2024

Supersed by #3571

@alexott alexott closed this May 14, 2024
@jdavidheiser jdavidheiser deleted the table-data-source branch May 14, 2024 13:32
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.

4 participants