Skip to content

Lakehouses

generate_lakehouse_shortcuts_metadata(workspace, lakehouse)

Source code in src/pyfabricops/helpers/lakehouses.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def generate_lakehouse_shortcuts_metadata(
    workspace: str, lakehouse: str
) -> Union[Dict[str, Any], None]:
    """ """
    # Create shortcuts.metadata.json
    shortcuts_list = list_shortcuts(workspace, lakehouse, df=False)

    if len(shortcuts_list) == 0:
        return None

    # Init a empty list for shortcuts
    shortcuts_list_new = []

    for shortcut_dict in shortcuts_list:
        shortcut_target = shortcut_dict['target']
        shortcut_target_type = (
            shortcut_target['type'][0].lower() + shortcut_target['type'][1:]
        )
        shortcut_target_workspace_id = shortcut_target[shortcut_target_type][
            'workspaceId'
        ]
        shortcut_target_item_id = shortcut_target[shortcut_target_type][
            'itemId'
        ]

        workspace_items = list_items(shortcut_target_workspace_id, df=False)
        for item in workspace_items:
            if item['id'] == shortcut_target_item_id:
                shortcut_target_item_type = item['type']
                break

    # Check if the workspace_id is equal shortcut_target_workspace_id then uuid zero
    if shortcut_target_workspace_id == resolve_workspace(workspace):
        shortcut_target_workspace_id = '00000000-0000-0000-0000-000000000000'

    # Create item type if not exists
    if 'artifactType' not in shortcut_dict['target'][shortcut_target_type]:
        shortcut_dict['target'][shortcut_target_type]['artifactType'] = ''
    if 'workspaceId' not in shortcut_dict['target'][shortcut_target_type]:
        shortcut_dict['target'][shortcut_target_type]['workspaceId'] = ''

    # Update if exists
    shortcut_dict['target']['oneLake'][
        'artifactType'
    ] = shortcut_target_item_type
    shortcut_dict['target']['oneLake'][
        'workspaceId'
    ] = shortcut_target_workspace_id

    shortcuts_list_new.append(shortcut_dict)

    return shortcuts_list_new

get_all_lakehouses_config(workspace)

Generate lakehouses config from a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID from the workspace.

required

Returns:

Type Description
Union[Dict[str, Any], None]

The dict config from the lakehouses of the workspace

Source code in src/pyfabricops/helpers/lakehouses.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def get_all_lakehouses_config(workspace: str) -> Union[Dict[str, Any], None]:
    """
    Generate lakehouses config from a workspace.

    Args:
        workspace (str): The name or ID from the workspace.

    Returns:
        (Union[Dict[str, Any], None]): The dict config from the lakehouses of the workspace
    """
    items = list_valid_lakehouses(workspace, df=False)

    if items is None:
        return None

    config = {}

    for item in items:

        item_data = get_lakehouse(workspace, item['id'], df=False)

        config[item['displayName']] = {
            'id': item['id'],
            'description': item.get('description', None),
            'folder_id': ''
            if item.get('folderId') is None or pd.isna(item.get('folderId'))
            else item['folderId'],
            'sql_endpoint_connection_string': item_data['properties'][
                'sqlEndpointProperties'
            ]['connectionString'],
            'sql_endpoint_id': item_data['properties'][
                'sqlEndpointProperties'
            ]['id'],
        }

    return config

get_lakehouse_config(workspace, lakehouse)

Get a specific lakehouse config from a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID from the workspace.

required
lakehouse str

The name or ID from the lakehouse.

required

Returns:

Type Description
Union[Dict[str, Any], None]

The dict config from the lakehouse

Source code in src/pyfabricops/helpers/lakehouses.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
def get_lakehouse_config(
    workspace: str, lakehouse: str
) -> Union[Dict[str, Any], None]:
    """
    Get a specific lakehouse config from a workspace.

    Args:
        workspace (str): The name or ID from the workspace.
        lakehouse (str): The name or ID from the lakehouse.

    Returns:
        (Union[Dict[str, Any], None]): The dict config from the lakehouse
    """
    item = lakehouse
    item_data = get_lakehouse(workspace, item, df=False)

    if item_data is None:
        return None

    else:
        config = {}
        config = config[item_data.get('displayName')] = {}

        config = {
            'id': item_data['id'],
            'description': item_data.get('description', None),
            'folder_id': ''
            if item_data.get('folderId') is None
            or pd.isna(item_data.get('folderId'))
            else item_data['folderId'],
            'sql_endpoint_connection_string': item_data.get(
                'properties_sqlEndpointProperties_connectionString'
            ),
            'sql_endpoint_id': item_data.get(
                'properties_sqlEndpointProperties_id'
            ),
        }

        return config

list_valid_lakehouses(workspace, df=True)

Generate a list of valid lakehouses from a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID from the workspace.

required

Returns:

Type Description
Union[Dict[str, Any], None]

The list of valids lakehouses of the workspace

Source code in src/pyfabricops/helpers/lakehouses.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@df
def list_valid_lakehouses(
    workspace: str,
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Generate a list of valid lakehouses from a workspace.

    Args:
        workspace (str): The name or ID from the workspace.

    Returns:
        (Union[Dict[str, Any], None]): The list of valids lakehouses of the workspace
    """
    items = list_lakehouses(workspace)

    if items is None:
        return None

    return items[
        ~items['displayName'].str.contains('staging', case=False, na=False)
    ].to_dict(orient='records')

save_lakehouse_shortcuts_metadata(shortcuts_metadata, path)

Source code in src/pyfabricops/helpers/lakehouses.py
233
234
235
236
237
238
def save_lakehouse_shortcuts_metadata(
    shortcuts_metadata: Dict[str, Any], path: str
) -> None:
    """ """
    with open(Path(path) / 'shortcuts.metadata.json', 'w') as f:
        json.dump(shortcuts_metadata, f, indent=2)