All projects
Big dataMSc Data Science · University of Salford

Clinical Trials Analytics at Scale

Apache SparkSpark SQLPySparkDatabricksData qualityHealthcare

Four business questions answered with Spark SQL on a January 2025 extract of more than 520,000 registered clinical trials, framed around long-term planning and market evaluation for the pharmaceutical sector. The work combines typed schema design, defensive parsing of messy fields and clearly commented, reproducible SQL.

521KTrials analysed
36.5 moMean trial length
76.6%Interventional studies
755Diabetes trials completed in 2019 (peak)

The problem

Strategy teams in pharma need to know what is being studied, how often and for how long. The registry extract is large, multi-valued (conditions are stored as delimited lists) and inconsistent (mixed date formats and shifted records), so each question starts with data engineering.

The data

  • Loaded with an explicit StructType schema instead of inferred types, then exposed as a temporary SQL view so every query is repeatable.
  • A frequency check on Study Type exposed malformed rows (numbers and free text shifted into the column). The analysis whitelists the three valid study types.
  • Start and completion dates mix yyyy-MM and MM/dd/yyyy formats. They are parsed with CASE logic and regex guards, and negative durations are excluded.

Approach

  1. Study typesCount trials per study type, excluding null and malformed values.
  2. Most common conditionsNormalise the multi-valued Conditions field with regexp_replace, split and LATERAL VIEW explode, lower-case and trim, then rank the top ten.
  3. Average trial lengthA CTE parses both date formats; MONTHS_BETWEEN gives the duration in months, averaged over trials with valid start and completion dates.
  4. Diabetes research over timeCompleted studies that mention diabetes, grouped by completion year (1989 to 2025) and charted in Databricks.

Results

Trials by study type

View as table
Interventional399,654
Observational120,816
Expanded access966

Ten most-studied conditions (number of trials)

View as table
Healthy10,786
Obesity8,616
Breast cancer8,031
Diabetes mellitus6,759
Pain6,657
Stroke5,328
Depression4,728
Hypertension4,719
Prostate cancer4,084
Cancer3,866

Completed diabetes studies by completion year

020040060080019891994199920042009201420192024
View as table
Completed studies
19892
19901
19911
19923
19933
19942
19952
19962
19973
199810
199911
200020
200126
200251
200376
2004124
2005190
2006244
2007316
2008415
2009459
2010531
2011514
2012589
2013583
2014595
2015665
2016633
2017716
2018685
2019755
2020559
2021577
2022654
2023616
2024427

Key findings

  • Interventional studies make up about three quarters of the registry (399,654 of 521,436), observational studies a further 23%, and expanded-access programmes under 0.2%.
  • Healthy volunteers are the most common category (10,786 trials), followed by obesity (8,616), breast cancer (8,031), diabetes mellitus (6,759) and pain (6,657).
  • Cleaning changed the answer. A naive split on the pipe character leaves diabetes mellitus (6,759 trials once normalised, fourth overall) out of the top ten altogether, and case and delimiter normalisation lifts obesity from 6,949 to 8,616.
  • The average trial runs 36.5 months, just over three years from start to completion.
  • Completed diabetes studies grew from 51 in 2002 to a peak of 755 in 2019, then settled between roughly 430 and 660 a year. The most recent years may be understated, and 2025 is left out of the chart, because the extract dates from January 2025.

Next steps

  • Replace the delimiter heuristic with a controlled vocabulary such as MeSH so compound condition names stay intact.
  • Cache the cleaned DataFrame and partition it by year to speed up repeated queries.
  • Extend the analysis to sponsors and funder types.