Skip to content

Commit ae392a2

Browse files
committed
enh: improve schema column descriptions
* require that descriptions are not empty for all queries parsed * add missing descriptions * add explicit short column names whenever source column was dereferenced from a table (e.g., "dicom_all.ImageType AS ImageType") * fix incorrect baseline
1 parent fa17f8c commit ae392a2

5 files changed

Lines changed: 44 additions & 24 deletions

File tree

assets/sm_instance_index.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ WITH
5050
SELECT
5151
# description:
5252
# unique identifier of the instance
53-
dicom_all.SOPInstanceUID,
53+
dicom_all.SOPInstanceUID AS SOPInstanceUID,
5454
# description:
5555
# unique identifier of the series
56-
dicom_all.SeriesInstanceUID,
56+
dicom_all.SeriesInstanceUID AS SeriesInstanceUID,
5757
-- Embedding Medium
5858
# description:
5959
# embedding medium used for the slide preparation
@@ -119,23 +119,23 @@ SELECT
119119
SAFE_CAST(SharedFunctionalGroupsSequence[SAFE_OFFSET(0)].PixelMeasuresSequence[SAFE_OFFSET(0)]. PixelSpacing[SAFE_OFFSET(0)] AS FLOAT64) AS PixelSpacing_0,
120120
# description:
121121
# DICOM ImageType attribute
122-
dicom_all.ImageType,
122+
dicom_all.ImageType AS ImageType,
123123
# description:
124124
# DICOM TransferSyntaxUID attribute
125-
dicom_all.TransferSyntaxUID,
125+
dicom_all.TransferSyntaxUID AS TransferSyntaxUID,
126126
# description:
127127
# size of the instance file in bytes
128-
dicom_all.instance_size,
128+
dicom_all.instance_size AS instance_size,
129129
# description:
130130
# number of columns in the image
131-
dicom_all.TotalPixelMatrixColumns,
131+
dicom_all.TotalPixelMatrixColumns AS TotalPixelMatrixColumns,
132132
# description:
133133
# number of rows in the image
134-
dicom_all.TotalPixelMatrixRows,
134+
dicom_all.TotalPixelMatrixRows AS TotalPixelMatrixRows,
135135
-- attributes needed to retrieve the selected instances/files
136136
# description:
137137
# unique identifier of the instance within the IDC
138-
dicom_all.crdc_instance_uuid
138+
dicom_all.crdc_instance_uuid AS crdc_instance_uuid
139139
FROM
140140
`bigquery-public-data.idc_v22.dicom_all` AS dicom_all
141141
LEFT JOIN

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build-backend = "scikit_build_core.build"
1313

1414
[project]
1515
name = "idc-index-data"
16-
version = "22.1.3"
16+
version = "22.1.4"
1717
authors = [
1818
{ name = "Andrey Fedorov", email = "andrey.fedorov@gmail.com" },
1919
{ name = "Vamsi Thiriveedhi", email = "vthiriveedhi@mgh.harvard.edu" },

scripts/python/idc_index_data_manager.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,16 @@ def parse_column_descriptions(sql_query: str) -> dict[str, str]:
130130
logger.debug(
131131
"Parsed description for column '%s': %s",
132132
column_name,
133-
description[:50] + "..."
134-
if len(description) > 50
135-
else description,
133+
description,
136134
)
135+
# throw exception if description is empty
136+
if not description:
137+
raise ValueError(
138+
"Description for column '"
139+
+ column_name
140+
+ "' is empty, and empty descriptions are not allowed."
141+
)
142+
137143
else:
138144
i += 1
139145
else:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
SELECT
2+
# description:
3+
# unique identifier of the analysis results collection
24
ID AS analysis_result_id,
5+
# description:
6+
# name of the analysis results collection
37
Title AS analysis_result_title,
8+
# description:
9+
# Digital Object Identifier (DOI) of the analysis results collection
410
source_doi,
11+
# description:
12+
# URL for the location of additional information about the analysis results collection
513
source_url,
14+
# description:
15+
# number of subjects analyzed in the analysis results collection
616
Subjects,
17+
# description:
18+
# collections analyzed in the analysis results collection
719
Collections,
20+
# description:
21+
# analysis artifacts included in the analysis results collection
822
AnalysisArtifacts,
23+
# description:
24+
# timestamp of the last update to the analysis results collection
925
Updated,
26+
# description:
27+
# license URL for the analysis results collection
1028
license_url,
29+
# description:
30+
# license name for the analysis results collection
1131
license_long_name,
32+
# description:
33+
# short name for the license of the analysis results collection
1234
license_short_name,
35+
# description:
36+
# detailed description of the analysis results collection
1337
Description,
38+
# description:
39+
# citation for the analysis results collection that should be used for acknowledgment
1440
Citation
1541
FROM
1642
`bigquery-public-data.idc_v22.analysis_results_metadata`

tests/test_real_sql_parsing.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ def test_real_sql_files() -> None:
8484
else:
8585
print(f"✗ Missing expected column: {col}")
8686

87-
# Test analysis_results_index.sql (should have no descriptions)
88-
analysis_sql_path = sql_dir / "analysis_results_index.sql"
89-
if analysis_sql_path.exists():
90-
with analysis_sql_path.open("r") as f:
91-
sql_query = f.read()
92-
93-
descriptions = IDCIndexDataManager.parse_column_descriptions(sql_query)
94-
print("\n=== analysis_results_index.sql ===")
95-
print(f"Found {len(descriptions)} column descriptions (expected 0)")
96-
assert len(descriptions) == 0, "Expected no descriptions in this file"
97-
print("✓ Correctly found no descriptions")
98-
9987

10088
if __name__ == "__main__":
10189
test_real_sql_files()

0 commit comments

Comments
 (0)