Skip to content

Commit 6dfb650

Browse files
jgarciaf106Andres Garcia
andauthored
Fixed Assessment Exporter Notebook (#3829)
<!-- REMOVE IRRELEVANT COMMENTS BEFORE CREATING A PULL REQUEST --> ## Changes <!-- Summary of your changes that are easy to understand. Add screenshots when necessary --> Adjusted the Lakeview dashboard Assessment Main dashboard path to the new naming format (Now looks for the dashboard name dynamically to avoid hardcoded values) in the EXPORT_ASSESSMENT_TO_EXCEL Notebook. ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [X] manually tested https://github.com/user-attachments/assets/dcbf6df4-a6f0-4fae-836a-0fcec861d86c --------- Co-authored-by: Andres Garcia <andres.garcia+data@databricks.com>
1 parent fd9349e commit 6dfb650

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/databricks/labs/ucx/installer/workflows.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,29 +173,37 @@
173173
174174
# DBTITLE 1,Assessment Export
175175
FILE_NAME = "ucx_assessment_main.xlsx"
176-
TMP_PATH = f"/Workspace{{ctx.installation.install_folder()}}/tmp/"
177-
DOWNLOAD_PATH = "/dbfs/FileStore/excel-export"
176+
UCX_PATH = Path(f"/Workspace{{ctx.installation.install_folder()}}")
177+
DOWNLOAD_PATH = Path("/dbfs/FileStore/excel-export/")
178178
179179
180180
def _cleanup() -> None:
181181
'''Move the temporary results file to the download path and clean up the temp directory.'''
182182
shutil.move(
183-
os.path.join(TMP_PATH, FILE_NAME),
184-
os.path.join(DOWNLOAD_PATH, FILE_NAME),
183+
UCX_PATH / "tmp" / FILE_NAME,
184+
DOWNLOAD_PATH / FILE_NAME,
185185
)
186-
shutil.rmtree(TMP_PATH)
186+
shutil.rmtree(UCX_PATH / "tmp/")
187187
188188
189189
def _prepare_directories() -> None:
190190
'''Ensure that the necessary directories exist.'''
191-
os.makedirs(TMP_PATH, exist_ok=True)
191+
os.makedirs(UCX_PATH / "tmp/", exist_ok=True)
192192
os.makedirs(DOWNLOAD_PATH, exist_ok=True)
193193
194+
def _process_id_columns(df):
195+
id_columns = [col for col in df.columns if 'id' in col.lower()]
196+
197+
if id_columns:
198+
for col in id_columns:
199+
df[col] = "'" + df[col].astype(str)
200+
return df
194201
195202
def _to_excel(dataset: Dataset, writer: ...) -> None:
196203
'''Execute a SQL query and write the result to an Excel sheet.'''
197204
worksheet_name = dataset.display_name[:31]
198205
df = spark.sql(dataset.query).toPandas()
206+
df = _process_id_columns(df)
199207
with lock:
200208
df.to_excel(writer, sheet_name=worksheet_name, index=False)
201209
@@ -214,14 +222,11 @@ def export_results() -> None:
214222
'''Main method to export results to an Excel file.'''
215223
_prepare_directories()
216224
217-
dashboard_path = (
218-
Path(ctx.installation.install_folder())
219-
/ "dashboards/[UCX] UCX Assessment (Main).lvdash.json"
220-
)
221-
dashboard = Dashboards(ctx.workspace_client)
222-
dashboard_datasets = dashboard.get_dashboard(dashboard_path).datasets
225+
assessment_dashboard = next(UCX_PATH.glob("dashboards/*Assessment (Main)*"))
226+
dashboard_datasets = Dashboards(ctx.workspace_client).get_dashboard(assessment_dashboard).datasets
227+
223228
try:
224-
target = TMP_PATH + "/ucx_assessment_main.xlsx"
229+
target = UCX_PATH / "tmp/ucx_assessment_main.xlsx"
225230
with pd.ExcelWriter(target, engine="xlsxwriter") as writer:
226231
tasks = []
227232
for dataset in dashboard_datasets:

0 commit comments

Comments
 (0)