Skip to content

Warehouses

export_all_warehouses(workspace, path)

Exports all warehouses from the workspace to path.

Parameters:

Name Type Description Default
workspace str

The ID or name of the workspace.

required
path Union[str, Path]

The path to export to.

required
Source code in src/pyfabricops/helpers/warehouses.py
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
def export_all_warehouses(workspace: str, path: Union[str, Path]) -> None:
    """
    Exports all warehouses from the workspace to path.

    Args:
        workspace (str): The ID or name of the workspace.
        path (Union[str, Path]): The path to export to.
    """
    workspace_id = resolve_workspace(workspace)
    if workspace_id is None:
        return None

    items = list_valid_warehouses(workspace_id, df=False)
    if items is None:
        return None

    for item in items:
        try:
            folder_path = resolve_folder_from_id_to_path(
                workspace_id, item['folderId']
            )
        except:
            logger.info(
                f'{item["displayName"]}.Warehouse is not inside a folder.'
            )
            folder_path = None

        if folder_path is None:
            item_path = Path(path) / (item['displayName'] + '.Warehouse')
        else:
            item_path = (
                Path(path) / folder_path / (item['displayName'] + '.Warehouse')
            )
        os.makedirs(item_path, exist_ok=True)

        platform = _generate_warehouse_platform(
            display_name=item['displayName'],
            description=item['description'],
        )

        _save_warehouse_platform(platform, item_path)

        _save_warehouse_defaultsemanticmodel_txt(item_path)

        _save_warehouse_sqlproj(item['displayName'], item_path)

        _save_warehouse_xmla_json(item_path)

    logger.success(f'All warehouses exported to {path} successfully.')
    return None

export_warehouse(workspace, warehouse, path)

Export a warehouse to path

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace.

required
warehouse str

The name or ID of the warehouse.

required
path Union[str, Path]

The path to export to.

required
Source code in src/pyfabricops/helpers/warehouses.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
def export_warehouse(
    workspace: str,
    warehouse: str,
    path: Union[str, Path],
) -> None:
    """
    Export a warehouse to path

    Args:
        workspace (str): The name or ID of the workspace.
        warehouse (str): The name or ID of the warehouse.
        path (Union[str, Path]): The path to export to.
    """
    workspace_id = resolve_workspace(workspace)
    if workspace_id is None:
        return None

    item = get_warehouse(workspace_id, warehouse, df=True)
    try:
        folder_path = resolve_folder_from_id_to_path(
            workspace_id, item['folderId']
        )
    except:
        logger.info(f'{item["displayName"]}.Warehouse is not inside a folder.')
        folder_path = None

    if folder_path is None:
        item_path = Path(path) / (item['displayName'] + '.Warehouse')
    else:
        item_path = (
            Path(path) / folder_path / (item['displayName'] + '.Warehouse')
        )
    os.makedirs(item_path, exist_ok=True)

    platform = _generate_warehouse_platform(
        display_name=item['displayName'],
        description=item['description'],
    )

    _save_warehouse_platform(platform, item_path)

    _save_warehouse_defaultsemanticmodel_txt(item_path)

    _save_warehouse_sqlproj(item['displayName'], item_path)

    _save_warehouse_xmla_json(item_path)

    logger.success(f'All warehouses exported to {path} successfully.')
    return None

get_all_warehouses_config(workspace)

Generate warehouses 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 warehouses of the workspace

Source code in src/pyfabricops/helpers/warehouses.py
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
def get_all_warehouses_config(workspace: str) -> Union[Dict[str, Any], None]:
    """
    Generate warehouses 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 warehouses of the workspace
    """
    items = list_valid_warehouses(workspace, df=False)

    if items is None:
        return None

    config = {}

    for item in items:

        item_data = get_warehouse(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'],
            'connection_string': item_data['properties']['connectionString'],
        }

    return config

get_warehouse_config(workspace, warehouse)

Get a specific warehouse config from a workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID from the workspace.

required
warehouse str

The name or ID from the warehouse.

required

Returns:

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

The dict config from the warehouse

Source code in src/pyfabricops/helpers/warehouses.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def get_warehouse_config(
    workspace: str, warehouse: str
) -> Union[Dict[str, Any], None]:
    """
    Get a specific warehouse config from a workspace.

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

    Returns:
        (Union[Dict[str, Any], None]): The dict config from the warehouse
    """
    item = warehouse
    item_data = get_warehouse(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'],
            'connection_string': item_data['properties']['connectionString'],
        }

        return config

list_valid_warehouses(workspace, df=True)

Generate a list of valid warehouses 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 warehouses of the workspace

Source code in src/pyfabricops/helpers/warehouses.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
@df
def list_valid_warehouses(
    workspace: str,
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Generate a list of valid warehouses from a workspace.

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

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

    if items is None:
        return None

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