Coverage for src/catalogs.py: 93%

14 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-06-05 22:56 -0700

1""" 

2Module for interacting with Databricks Unity Catalog catalogs, schemas, and tables. 

3""" 

4 

5 

6def list_catalogs(client, include_browse=False, max_results=None, page_token=None): 

7 """ 

8 Gets an array of catalogs in the metastore. 

9 

10 Args: 

11 client: DatabricksAPIClient instance 

12 include_browse: Whether to include catalogs for which the principal can only access selective metadata 

13 max_results: Maximum number of catalogs to return (optional) 

14 page_token: Opaque pagination token to go to next page (optional) 

15 

16 Returns: 

17 Dictionary containing: 

18 - catalogs: List of catalogs 

19 - next_page_token: Token for retrieving the next page (if available) 

20 """ 

21 return client.list_catalogs(include_browse, max_results, page_token) 

22 

23 

24def get_catalog(client, catalog_name): 

25 """ 

26 Gets a catalog from Unity Catalog. 

27 

28 Args: 

29 client: DatabricksAPIClient instance 

30 catalog_name: Name of the catalog 

31 

32 Returns: 

33 Catalog information 

34 """ 

35 return client.get_catalog(catalog_name) 

36 

37 

38def list_schemas( 

39 client, catalog_name, include_browse=False, max_results=None, page_token=None 

40): 

41 """ 

42 Gets an array of schemas for a catalog in the metastore. 

43 

44 Args: 

45 client: DatabricksAPIClient instance 

46 catalog_name: Parent catalog for schemas of interest (required) 

47 include_browse: Whether to include schemas for which the principal can only access selective metadata 

48 max_results: Maximum number of schemas to return (optional) 

49 page_token: Opaque pagination token to go to next page (optional) 

50 

51 Returns: 

52 Dictionary containing: 

53 - schemas: List of schemas 

54 - next_page_token: Token for retrieving the next page (if available) 

55 """ 

56 return client.list_schemas(catalog_name, include_browse, max_results, page_token) 

57 

58 

59def get_schema(client, full_name): 

60 """ 

61 Gets a schema from Unity Catalog. 

62 

63 Args: 

64 client: DatabricksAPIClient instance 

65 full_name: Full name of the schema in the format 'catalog_name.schema_name' 

66 

67 Returns: 

68 Schema information 

69 """ 

70 return client.get_schema(full_name) 

71 

72 

73def list_volumes( 

74 client, 

75 catalog_name, 

76 schema_name, 

77 max_results=None, 

78 page_token=None, 

79 include_browse=False, 

80): 

81 """ 

82 Gets an array of volumes for the current metastore under the parent catalog and schema. 

83 Args: 

84 client: DatabricksAPIClient instance 

85 catalog_name: Name of parent catalog (required) 

86 schema_name: Name of parent schema (required) 

87 max_results: Maximum number of volumes to return (optional) 

88 page_token: Opaque token for pagination (optional) 

89 include_browse: Whether to include volumes with selective metadata access (optional) 

90 Returns: 

91 Dictionary containing: 

92 - volumes: List of volumes 

93 - next_page_token: Token for retrieving the next page (if available) 

94 """ 

95 return client.list_volumes( 

96 catalog_name, schema_name, max_results, page_token, include_browse 

97 ) 

98 

99 

100def list_tables( 

101 client, 

102 catalog_name, 

103 schema_name, 

104 max_results=None, 

105 page_token=None, 

106 include_delta_metadata=False, 

107 omit_columns=False, 

108 omit_properties=False, 

109 omit_username=False, 

110 include_browse=False, 

111 include_manifest_capabilities=False, 

112): 

113 """ 

114 Gets an array of all tables for the current metastore under the parent catalog and schema. 

115 

116 Args: 

117 client: DatabricksAPIClient instance 

118 catalog_name: Name of parent catalog for tables of interest (required) 

119 schema_name: Parent schema of tables (required) 

120 max_results: Maximum number of tables to return (optional) 

121 page_token: Opaque token to send for the next page of results (optional) 

122 include_delta_metadata: Whether delta metadata should be included (optional) 

123 omit_columns: Whether to omit columns from the response (optional) 

124 omit_properties: Whether to omit properties from the response (optional) 

125 omit_username: Whether to omit username from the response (optional) 

126 include_browse: Whether to include tables with selective metadata access (optional) 

127 include_manifest_capabilities: Whether to include table capabilities (optional) 

128 

129 Returns: 

130 Dictionary containing: 

131 - tables: List of tables 

132 - next_page_token: Token for retrieving the next page (if available) 

133 """ 

134 return client.list_tables( 

135 catalog_name, 

136 schema_name, 

137 max_results, 

138 page_token, 

139 include_delta_metadata, 

140 omit_columns, 

141 omit_properties, 

142 omit_username, 

143 include_browse, 

144 include_manifest_capabilities, 

145 ) 

146 

147 

148def get_table( 

149 client, 

150 full_name, 

151 include_delta_metadata=False, 

152 include_browse=False, 

153 include_manifest_capabilities=False, 

154): 

155 """ 

156 Gets a table from the metastore for a specific catalog and schema. 

157 

158 Args: 

159 client: DatabricksAPIClient instance 

160 full_name: Full name of the table in format 'catalog_name.schema_name.table_name' 

161 include_delta_metadata: Whether delta metadata should be included (optional) 

162 include_browse: Whether to include tables with selective metadata access (optional) 

163 include_manifest_capabilities: Whether to include table capabilities (optional) 

164 

165 Returns: 

166 Table information 

167 """ 

168 return client.get_table( 

169 full_name, include_delta_metadata, include_browse, include_manifest_capabilities 

170 )