-
Notifications
You must be signed in to change notification settings - Fork 154
Add support for Lakebase synced database tables #3467
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
71087d4
Add support for Lakebase synced database table
anton-107 4af715f
add an acceptance test
anton-107 ff28434
add a converter for synced tables
anton-107 cad65d7
fix local test
anton-107 812970d
make schema
anton-107 a26b150
fix state_load_test.go
anton-107 8382206
fix run_as_test.go
anton-107 c47baee
fix apply_target_mode_test.go
anton-107 cd53d23
fix apply_bundle_permissions.go
anton-107 418fa59
update NEXT_CHANGELOG.md
anton-107 bd2f974
fix walktype_test.go
anton-107 4d75beb
fix resources_test.go
anton-107 8d7cc42
Merge branch 'main' into anton-107/lakebase-syncedtable
anton-107 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
acceptance/bundle/deploy/lakebase/synced-database-table/databricks.yml.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| bundle: | ||
| name: deploy-lakebase-synced-table-$UNIQUE_NAME | ||
|
|
||
| resources: | ||
| database_instances: | ||
| my_instance: | ||
| name: test-database-instance-$UNIQUE_NAME | ||
| capacity: CU_1 | ||
| database_catalogs: | ||
| my_catalog: | ||
| database_instance_name: ${resources.database_instances.my_instance.name} | ||
| database_name: my_database | ||
| name: my_catalog_$UNIQUE_NAME | ||
| create_database_if_not_exists: true | ||
| synced_database_tables: | ||
| my_synced_table: | ||
| name: ${resources.database_catalogs.my_catalog.name}.${resources.database_catalogs.my_catalog.database_name}.my_synced_table | ||
| database_instance_name: ${resources.database_instances.my_instance.name} | ||
| logical_database_name: ${resources.database_catalogs.my_catalog.database_name} | ||
| spec: | ||
| source_table_full_name: "samples.nyctaxi.trips" | ||
| scheduling_policy: SNAPSHOT | ||
| primary_key_columns: | ||
| - tpep_pickup_datetime |
9 changes: 9 additions & 0 deletions
9
acceptance/bundle/deploy/lakebase/synced-database-table/out.test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Local = true | ||
| Cloud = true | ||
| RequiresUnityCatalog = true | ||
|
|
||
| [CloudEnvs] | ||
| gcp = false | ||
|
|
||
| [EnvMatrix] | ||
| DATABRICKS_CLI_DEPLOYMENT = ["terraform"] |
66 changes: 66 additions & 0 deletions
66
acceptance/bundle/deploy/lakebase/synced-database-table/output.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
|
|
||
| >>> [CLI] bundle validate | ||
| Name: deploy-lakebase-synced-table-[UNIQUE_NAME] | ||
| Target: default | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default | ||
|
|
||
| Validation OK! | ||
|
|
||
| >>> [CLI] bundle summary | ||
| Name: deploy-lakebase-synced-table-[UNIQUE_NAME] | ||
| Target: default | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default | ||
| Resources: | ||
| Database catalogs: | ||
| my_catalog: | ||
| Name: my_catalog_[UNIQUE_NAME] | ||
| URL: [DATABRICKS_URL]/explore/data/my_catalog_[UNIQUE_NAME] | ||
| Database instances: | ||
| my_instance: | ||
| Name: test-database-instance-[UNIQUE_NAME] | ||
| URL: (not deployed) | ||
| Synced database tables: | ||
| my_synced_table: | ||
| Name: ${databricks_database_database_catalog.my_catalog.name}.${databricks_database_database_catalog.my_catalog.database_name}.my_synced_table | ||
| URL: [DATABRICKS_URL]/explore/data/$%7Bdatabricks_database_database_catalog.my_catalog.name%7D.$%7Bdatabricks_database_database_catalog.my_catalog.database_name%7D.my_synced_table | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] bundle summary | ||
| Name: deploy-lakebase-synced-table-[UNIQUE_NAME] | ||
| Target: default | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default | ||
| Resources: | ||
| Database catalogs: | ||
| my_catalog: | ||
| Name: my_catalog_[UNIQUE_NAME] | ||
| URL: [DATABRICKS_URL]/explore/data/my_catalog_[UNIQUE_NAME] | ||
| Database instances: | ||
| my_instance: | ||
| Name: test-database-instance-[UNIQUE_NAME] | ||
| URL: [DATABRICKS_URL]/compute/database-instances/test-database-instance-[UNIQUE_NAME] | ||
| Synced database tables: | ||
| my_synced_table: | ||
| Name: ${resources.database_catalogs.my_catalog.name}.${resources.database_catalogs.my_catalog.database_name}.my_synced_table | ||
| URL: [DATABRICKS_URL]/explore/data/$%7Bresources.database_catalogs.my_catalog.name%7D.$%7Bresources.database_catalogs.my_catalog.database_name%7D.my_synced_table | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete database_catalog my_catalog | ||
| delete database_instance my_instance | ||
| delete synced_database_table my_synced_table | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-lakebase-synced-table-[UNIQUE_NAME]/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! | ||
11 changes: 11 additions & 0 deletions
11
acceptance/bundle/deploy/lakebase/synced-database-table/script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| envsubst < databricks.yml.tmpl > databricks.yml | ||
|
|
||
| cleanup() { | ||
| trace $CLI bundle destroy --auto-approve | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| trace $CLI bundle validate | ||
| trace $CLI bundle summary | ||
| trace $CLI bundle deploy | ||
| trace $CLI bundle summary |
13 changes: 13 additions & 0 deletions
13
acceptance/bundle/deploy/lakebase/synced-database-table/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| Local = true | ||
| Cloud = true | ||
|
|
||
| RecordRequests = false | ||
|
|
||
| [EnvMatrix] | ||
| DATABRICKS_CLI_DEPLOYMENT = ["terraform"] | ||
|
|
||
| [[Repls]] | ||
| # clean up ?o=<num> suffix after URL since not all workspaces have that | ||
| Old = '\?o=\[(NUMID|ALPHANUMID)\]' | ||
| New = '' | ||
| Order = 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package resources | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/url" | ||
|
|
||
| "github.com/databricks/cli/libs/log" | ||
|
|
||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/service/database" | ||
| ) | ||
|
|
||
| type SyncedDatabaseTable struct { | ||
| ID string `json:"id,omitempty" bundle:"readonly"` | ||
| URL string `json:"url,omitempty" bundle:"internal"` | ||
| ModifiedStatus ModifiedStatus `json:"modified_status,omitempty" bundle:"internal"` | ||
|
|
||
| database.SyncedDatabaseTable | ||
| } | ||
|
|
||
| func (s *SyncedDatabaseTable) Exists(ctx context.Context, w *databricks.WorkspaceClient, name string) (bool, error) { | ||
| _, err := w.Database.GetSyncedDatabaseTable(ctx, database.GetSyncedDatabaseTableRequest{Name: name}) | ||
| if err != nil { | ||
| log.Debugf(ctx, "synced database table %s does not exist", name) | ||
| return false, err | ||
| } | ||
| return true, nil | ||
| } | ||
|
|
||
| func (s *SyncedDatabaseTable) ResourceDescription() ResourceDescription { | ||
| return ResourceDescription{ | ||
| SingularName: "synced_database_table", | ||
| PluralName: "synced_database_tables", | ||
| SingularTitle: "Synced database table", | ||
| PluralTitle: "Synced database tables", | ||
| } | ||
| } | ||
|
|
||
| func (s *SyncedDatabaseTable) GetName() string { | ||
| return s.Name | ||
| } | ||
|
|
||
| func (s *SyncedDatabaseTable) GetURL() string { | ||
| return s.URL | ||
| } | ||
|
|
||
| func (s *SyncedDatabaseTable) InitializeURL(baseURL url.URL) { | ||
| if s.Name == "" { | ||
| return | ||
| } | ||
| baseURL.Path = "explore/data/" + s.Name | ||
| s.URL = baseURL.String() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
bundle/deploy/terraform/tfdyn/convert_synced_database_table.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package tfdyn | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/databricks/cli/bundle/internal/tf/schema" | ||
| "github.com/databricks/cli/libs/dyn" | ||
| "github.com/databricks/cli/libs/dyn/convert" | ||
| "github.com/databricks/cli/libs/log" | ||
| "github.com/databricks/databricks-sdk-go/service/database" | ||
| ) | ||
|
|
||
| type syncedDatabaseTableConverter struct{} | ||
|
|
||
| func (s syncedDatabaseTableConverter) Convert(ctx context.Context, key string, vin dyn.Value, out *schema.Resources) error { | ||
| // Normalize the output value to the target schema. | ||
| vout, diags := convert.Normalize(database.SyncedDatabaseTable{}, vin) | ||
| for _, diag := range diags { | ||
| log.Debugf(ctx, "synced database table normalization diagnostic: %s", diag.Summary) | ||
| } | ||
| out.DatabaseSyncedDatabaseTable[key] = vout.AsAny() | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func init() { | ||
| registerConverter("synced_database_tables", syncedDatabaseTableConverter{}) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having references here is not something we want, right? Should we add Badness note to test.toml to track this?