File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ """Validate that every BigQuery concept SQL file parses with sqlglot.
3+
4+ Usage: ``python .github/scripts/check_sql_syntax.py [ROOT ...]``
5+ (defaults to ``mimic-iv/concepts``). Exits non-zero if any file fails to parse.
6+ """
7+ from __future__ import annotations
8+
9+ import sys
10+ from pathlib import Path
11+
12+ import sqlglot
13+ from sqlglot .errors import ParseError
14+
15+
16+ def main (argv : list [str ]) -> int :
17+ roots = [Path (p ) for p in argv [1 :]] or [Path ("mimic-iv/concepts" )]
18+ files = sorted ({f for root in roots for f in root .rglob ("*.sql" )})
19+ if not files :
20+ print (f"::error::No .sql files found under: { ', ' .join (map (str , roots ))} " )
21+ return 1
22+
23+ failures = 0
24+ for f in files :
25+ try :
26+ sqlglot .parse_one (f .read_text (), read = "bigquery" )
27+ except ParseError as exc :
28+ failures += 1
29+ # Keep the GitHub annotation to a single line so it anchors to the
30+ # file; the full multi-line message follows in the log.
31+ first_line = str (exc ).splitlines ()[0 ]
32+ print (f"::error file={ f } ::sqlglot failed to parse: { first_line } " )
33+ print (str (exc ))
34+ else :
35+ print (f"OK { f } " )
36+
37+ print ()
38+ if failures :
39+ print (f"{ failures } of { len (files )} concept file(s) failed to parse." )
40+ return 1
41+ print (f"All { len (files )} concept file(s) parsed successfully." )
42+ return 0
43+
44+
45+ if __name__ == "__main__" :
46+ raise SystemExit (main (sys .argv ))
Original file line number Diff line number Diff line change 1- name : BigQuery syntax check ( dry run)
1+ name : BigQuery dry run
22
3- # Verify syntax of bq through `bq query --dry_run`
4- # Note: dry-run resolves inter-concept references against mimiciv_derived dataset,
5- # so a brand-new concept that depends on another brand-new concept (not yet published)
6- # will report the dependency as missing until the first is released.
3+ # Semantic validation of the BigQuery concept sources via `bq query --dry_run`,
4+ # which resolves table/column references against the live mimiciv_derived
5+ # dataset. This requires cloud credentials (OIDC), so it is only run on main.
6+ #
7+ # Note: dry-run resolves inter-concept references against mimiciv_derived, so a
8+ # brand-new concept that depends on another brand-new concept (not yet
9+ # published) will report the dependency as missing until the first is released.
710on :
8- pull_request_review :
9- types : [submitted]
11+ push :
12+ branches :
13+ - main
14+ paths :
15+ - ' mimic-iv/concepts/**'
16+ - ' .github/workflows/bigquery_dry_run.yml'
1017
1118jobs :
1219 dry-run :
13- if : github.event.review.state == 'approved'
1420 runs-on : ubuntu-latest
1521 permissions :
1622 contents : ' read'
Original file line number Diff line number Diff line change 1+ name : BigQuery SQL syntax check via sqlglot
2+
3+ on :
4+ pull_request :
5+ paths :
6+ - ' mimic-iv/concepts/**'
7+ - ' src/mimic_utils/**'
8+ - ' .github/scripts/check_sql_syntax.py'
9+ - ' .github/workflows/sql_syntax_check.yml'
10+
11+ permissions :
12+ contents : read
13+
14+ jobs :
15+ syntax-check :
16+ runs-on : ubuntu-latest
17+ steps :
18+ - uses : actions/checkout@v4
19+ - uses : actions/setup-python@v5
20+ with :
21+ python-version : " 3.12"
22+ - name : Install locked dependencies
23+ run : pip install -r requirements-lock.txt
24+ - name : Install package
25+ run : pip install -e . --no-deps
26+ - name : Parse concept SQL with sqlglot
27+ run : python .github/scripts/check_sql_syntax.py mimic-iv/concepts
Original file line number Diff line number Diff line change 6262.read medication/ acei .sql
6363.print ' medication/antibiotic.sql'
6464.read medication/ antibiotic .sql
65+ .print ' medication/arb.sql'
66+ .read medication/ arb .sql
6567.print ' medication/dobutamine.sql'
6668.read medication/ dobutamine .sql
6769.print ' medication/dopamine.sql'
8284.read medication/ vasopressin .sql
8385
8486-- treatment
87+ .print ' treatment/code_status.sql'
88+ .read treatment/ code_status .sql
8589.print ' treatment/crrt.sql'
8690.read treatment/ crrt .sql
8791.print ' treatment/invasive_line.sql'
You can’t perform that action at this time.
0 commit comments