Skip to content

Commit bccbdea

Browse files
pieternadamcain-db
andauthored
Add Unity Catalog support (#471)
This is a continuation of #414. This commit introduces Unity Catalog support through a new top level command "unity-catalog". Co-authored-by: Adam Cain <[email protected]>
1 parent f403bb1 commit bccbdea

27 files changed

+2912
-6
lines changed

databricks_cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from databricks_cli.instance_pools.cli import instance_pools_group
4242
from databricks_cli.pipelines.cli import pipelines_group
4343
from databricks_cli.repos.cli import repos_group
44+
from databricks_cli.unity_catalog.cli import unity_catalog_group
4445

4546

4647
@click.group(context_settings=CONTEXT_SETTINGS)
@@ -67,6 +68,7 @@ def cli():
6768
cli.add_command(instance_pools_group, name="instance-pools")
6869
cli.add_command(pipelines_group, name='pipelines')
6970
cli.add_command(repos_group, name='repos')
71+
cli.add_command(unity_catalog_group, name='unity-catalog')
7072

7173
if __name__ == "__main__":
7274
cli()

databricks_cli/click_types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ class PipelineIdClickType(ParamType):
112112
help = 'The pipeline ID.'
113113

114114

115+
class MetastoreIdClickType(ParamType):
116+
name = 'METASTORE_ID'
117+
help = 'ID of the Metastore'
118+
119+
120+
class WorkspaceIdClickType(ParamType):
121+
name = 'WORKSPACE_ID'
122+
help = 'ID of the Workspace'
123+
124+
115125
class OneOfOption(Option):
116126
def __init__(self, *args, **kwargs):
117127
self.one_of = kwargs.pop('one_of')

databricks_cli/unity_catalog/__init__.py

Whitespace-only changes.
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
# Databricks CLI
2+
# Copyright 2022 Databricks, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"), except
5+
# that the use of services to which certain application programming
6+
# interfaces (each, an "API") connect requires that the user first obtain
7+
# a license for the use of the APIs from Databricks, Inc. ("Databricks"),
8+
# by creating an account at www.databricks.com and agreeing to either (a)
9+
# the Community Edition Terms of Service, (b) the Databricks Terms of
10+
# Service, or (c) another written agreement between Licensee and Databricks
11+
# for the use of the APIs.
12+
#
13+
# You may not use this file except in compliance with the License.
14+
# You may obtain a copy of the License at
15+
#
16+
# http://www.apache.org/licenses/LICENSE-2.0
17+
#
18+
# Unless required by applicable law or agreed to in writing, software
19+
# distributed under the License is distributed on an "AS IS" BASIS,
20+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
# See the License for the specific language governing permissions and
22+
# limitations under the License.
23+
24+
from databricks_cli.unity_catalog.uc_service import UnityCatalogService
25+
26+
27+
class UnityCatalogApi(object):
28+
def __init__(self, api_client):
29+
self.client = UnityCatalogService(api_client)
30+
31+
# Metastore APIs
32+
33+
def create_metastore(self, name, storage_root):
34+
return self.client.create_metastore(name, storage_root)
35+
36+
def list_metastores(self):
37+
return self.client.list_metastores()
38+
39+
def get_metastore(self, metastore_id):
40+
return self.client.get_metastore(metastore_id)
41+
42+
def update_metastore(self, metastore_id, metastore_spec):
43+
return self.client.update_metastore(metastore_id, metastore_spec)
44+
45+
def delete_metastore(self, metastore_id, force):
46+
return self.client.delete_metastore(metastore_id, force)
47+
48+
def get_metastore_summary(self):
49+
return self.client.get_metastore_summary()
50+
51+
def create_metastore_assignment(self, workspace_id, metastore_id, default_catalog_name):
52+
return self.client.create_metastore_assignment(workspace_id, metastore_id,
53+
default_catalog_name)
54+
55+
def update_metastore_assignment(self, workspace_id, metastore_id, default_catalog_name):
56+
return self.client.update_metastore_assignment(workspace_id, metastore_id,
57+
default_catalog_name)
58+
59+
def delete_metastore_assignment(self, workspace_id, metastore_id):
60+
return self.client.delete_metastore_assignment(workspace_id, metastore_id)
61+
62+
# External Location APIs
63+
64+
def create_external_location(self, loc_spec, skip_validation):
65+
return self.client.create_external_location(loc_spec, skip_validation)
66+
67+
def list_external_locations(self):
68+
return self.client.list_external_locations()
69+
70+
def get_external_location(self, name):
71+
return self.client.get_external_location(name)
72+
73+
def update_external_location(self, name, loc_spec, force, skip_validation):
74+
return self.client.update_external_location(name, loc_spec, force, skip_validation)
75+
76+
def delete_external_location(self, name, force):
77+
return self.client.delete_external_location(name, force)
78+
79+
def validate_external_location(self, validation_spec):
80+
return self.client.validate_external_location(validation_spec)
81+
82+
# Data Access Configuration APIs
83+
84+
def create_dac(self, metastore_id, dac_spec, skip_validation):
85+
return self.client.create_dac(metastore_id, dac_spec, skip_validation)
86+
87+
def list_dacs(self, metastore_id):
88+
return self.client.list_dacs(metastore_id)
89+
90+
def get_dac(self, metastore_id, dac_id):
91+
return self.client.get_dac(metastore_id, dac_id)
92+
93+
def delete_dac(self, metastore_id, dac_id):
94+
return self.client.delete_dac(metastore_id, dac_id)
95+
96+
# Storage Credentials
97+
98+
def create_storage_credential(self, cred_spec, skip_validation):
99+
return self.client.create_storage_credential(cred_spec, skip_validation)
100+
101+
def list_storage_credentials(self, name_pattern):
102+
return self.client.list_storage_credentials(name_pattern)
103+
104+
def get_storage_credential(self, name):
105+
return self.client.get_storage_credential(name)
106+
107+
def update_storage_credential(self, name, cred_spec, skip_validation):
108+
return self.client.update_storage_credential(name, cred_spec, skip_validation)
109+
110+
def delete_storage_credential(self, name, force):
111+
return self.client.delete_storage_credential(name, force)
112+
113+
# Catalog APIs
114+
115+
def create_catalog(self, catalog_name, comment, provider, share):
116+
return self.client.create_catalog(catalog_name, comment, provider, share)
117+
118+
def list_catalogs(self):
119+
return self.client.list_catalogs()
120+
121+
def get_catalog(self, name):
122+
return self.client.get_catalog(name)
123+
124+
def update_catalog(self, name, catalog_spec):
125+
return self.client.update_catalog(name, catalog_spec)
126+
127+
def delete_catalog(self, catalog_name):
128+
return self.client.delete_catalog(catalog_name)
129+
130+
# Schema APIs
131+
132+
def create_schema(self, catalog_name, schema_name, comment):
133+
return self.client.create_schema(catalog_name, schema_name, comment)
134+
135+
def list_schemas(self, catalog_name, name_pattern):
136+
return self.client.list_schemas(catalog_name, name_pattern)
137+
138+
def get_schema(self, full_name):
139+
return self.client.get_schema(full_name)
140+
141+
def update_schema(self, full_name, schema_spec):
142+
return self.client.update_schema(full_name, schema_spec)
143+
144+
def delete_schema(self, schema_full_name):
145+
return self.client.delete_schema(schema_full_name)
146+
147+
# Table APIs
148+
149+
def create_table(self, table_spec):
150+
return self.client.create_table(table_spec)
151+
152+
def list_tables(self, catalog_name, schema_name, name_pattern):
153+
return self.client.list_tables(catalog_name, schema_name, name_pattern)
154+
155+
def list_table_summaries(self, catalog_name):
156+
return self.client.list_table_summaries(catalog_name)
157+
158+
def get_table(self, full_name):
159+
return self.client.get_table(full_name)
160+
161+
def update_table(self, full_name, table_spec):
162+
return self.client.update_table(full_name, table_spec)
163+
164+
def delete_table(self, table_full_name):
165+
return self.client.delete_table(table_full_name)
166+
167+
# Share APIs
168+
169+
def create_share(self, name):
170+
return self.client.create_share(name)
171+
172+
def list_shares(self):
173+
return self.client.list_shares()
174+
175+
def get_share(self, name, include_shared_data):
176+
return self.client.get_share(name, include_shared_data)
177+
178+
def update_share(self, name, share_spec):
179+
return self.client.update_share(name, share_spec)
180+
181+
def delete_share(self, name):
182+
return self.client.delete_share(name)
183+
184+
def list_share_permissions(self, name):
185+
return self.client.list_share_permissions(name)
186+
187+
def update_share_permissions(self, name, perm_spec):
188+
return self.client.update_share_permissions(name, perm_spec)
189+
190+
# Recipient APIs
191+
192+
def create_recipient(self, name, comment, sharing_code, allowed_ip_addresses):
193+
return self.client.create_recipient(name, comment, sharing_code, allowed_ip_addresses)
194+
195+
def list_recipients(self):
196+
return self.client.list_recipients()
197+
198+
def get_recipient(self, name):
199+
return self.client.get_recipient(name)
200+
201+
def update_recipient(self, name, recipient_spec):
202+
return self.client.update_recipient(name, recipient_spec)
203+
204+
def rotate_recipient_token(self, name, existing_token_expire_in_seconds):
205+
return self.client.rotate_recipient_token(name, existing_token_expire_in_seconds)
206+
207+
def get_recipient_share_permissions(self, name):
208+
return self.client.get_recipient_share_permissions(name)
209+
210+
def delete_recipient(self, name):
211+
return self.client.delete_recipient(name)
212+
213+
# Provider APIs
214+
215+
def create_provider(self, name, comment, recipient_profile):
216+
return self.client.create_provider(name, comment, recipient_profile)
217+
218+
def list_providers(self):
219+
return self.client.list_providers()
220+
221+
def get_provider(self, name):
222+
return self.client.get_provider(name)
223+
224+
def update_provider(self, name, new_name=None, comment=None, recipient_profile=None):
225+
return self.client.update_provider(name, new_name, comment, recipient_profile)
226+
227+
def delete_provider(self, name):
228+
return self.client.delete_provider(name)
229+
230+
def list_provider_shares(self, name):
231+
return self.client.list_provider_shares(name)
232+
233+
# Permissions APIs
234+
235+
def get_permissions(self, sec_type, sec_name):
236+
return self.client.get_permissions(sec_type, sec_name)
237+
238+
def update_permissions(self, sec_type, sec_name, diff_spec):
239+
return self.client.update_permissions(sec_type, sec_name, diff_spec)
240+
241+
def replace_permissions(self, sec_type, sec_name, perm_spec):
242+
return self.client.replace_permissions(sec_type, sec_name, perm_spec)
243+
244+
# Lineage APIs
245+
246+
def list_lineages_by_table(self, table_name):
247+
return self.client.list_lineages_by_table(table_name)
248+
249+
def list_lineages_by_column(self, table_name, column_name):
250+
return self.client.list_lineages_by_column(table_name, column_name)

0 commit comments

Comments
 (0)