Skip to content

Commit 5706978

Browse files
authored
Merge pull request #1947 from MIT-LCP/alistair/fix_derived_build
Fix SQLFluff test and derived tables copying
2 parents e849006 + 55d3f95 commit 5706978

File tree

5 files changed

+43
-46
lines changed

5 files changed

+43
-46
lines changed

.github/workflows/lint_sqlfluff.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,37 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: checkout
11-
uses: actions/checkout@v3
11+
uses: actions/checkout@v4
1212
- name: Install Python
13-
uses: "actions/setup-python@v2"
13+
uses: actions/setup-python@v5
1414
with:
15-
python-version: "3.7"
15+
python-version: "3.12"
1616
- name: install sqlfluff
17-
run: "pip install sqlfluff==1.4.5"
17+
run: "pip install sqlfluff==3.5.0"
1818
- name: Get changed files
1919
id: get_file_changes
2020
uses: trilom/[email protected]
2121
with:
2222
output: ' '
2323
- name: Get changed .sql files in mimic-iv concepts folder
2424
id: get_files_to_lint
25-
shell: bash -l {0}
25+
shell: bash
2626
run: |
27-
# Set the command in the $() brackets as an output to use in later steps
28-
echo "lintees=$(
29-
echo \
30-
$(echo ${{ steps.get_file_changes.outputs.files_modified }} |
31-
tr -s ' ' '\n' |
32-
grep -E '^mimic-iv/concepts/.*[.]sql$' |
33-
tr -s '\n' ' ') \
34-
$(echo ${{ steps.get_file_changes.outputs.files_added }} |
35-
tr -s ' ' '\n' |
36-
grep -E '^mimic-iv/concepts/.*[.]sql$' |
37-
tr -s '\n' ' ')
38-
) >> $GITHUB_OUTPUT"
27+
# Compose list of changed SQL files under mimic-iv/concepts and export to step output
28+
raw="${{ steps.get_file_changes.outputs.files_modified }} ${{ steps.get_file_changes.outputs.files_added }}"
29+
# Check for mimic-iv SQL files which may have changed
30+
filtered="$(printf '%s' "$raw" | tr -s ' ' '\n' | grep -E '^mimic-iv/concepts/.*[.]sql$' || true)"
31+
# Turn this into a space separated list for the next step
32+
files="$(printf '%s' "$filtered" | tr -s '\n' ' ')"
33+
echo "lintees=${files}" >> "$GITHUB_OUTPUT"
3934
4035
- name: Lint SQL files
4136
id: sqlfluff_json
4237
if: steps.get_files_to_lint.outputs.lintees != ''
43-
shell: bash -l {0}
38+
shell: bash
4439
run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json
4540
- name: Annotate
46-
uses: yuzutech/annotations-action@v0.3.0
41+
uses: yuzutech/annotations-action@v0.5.0
4742
with:
4843
repo-token: "${{ secrets.GITHUB_TOKEN }}"
4944
title: "SQLFluff Lint"

.sqlfluff

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
[sqlfluff:core]
2-
rules = core,L019
3-
large_file_skip_byte_limit = 40000
1+
[sqlfluff]
42
dialect = bigquery
3+
large_file_skip_byte_limit = 40000
4+
exclude_rules = LT02
5+
6+
# Enable core rules plus explicit layout.commas (leading commas)
7+
[sqlfluff:core]
8+
rules = core,layout.commas
59

610
[sqlfluff:layout:type:comma]
711
line_position = leading
812

9-
[sqlfluff:indentation]
10-
indented_joins = false
11-
indented_using_on = true
12-
template_blocks_indent = false
13-
14-
[sqlfluff:rules:L010]
15-
# Keywords should be upper case
13+
# Capitalisation rules
14+
[sqlfluff:rules:capitalisation.keywords]
1615
capitalisation_policy = upper
1716

18-
[sqlfluff:rules:L030]
19-
# Functions should be upper case
20-
extended_capitalisation_policy = upper
17+
[sqlfluff:rules:capitalisation.functions]
18+
extended_capitalisation_policy = upper
19+
20+
[sqlfluff:rules:capitalisation.identifiers]
21+
extended_capitalisation_policy = lower

mimic-iv/concepts/copy_concepts_to_versioned_schema.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ else
2727
fi
2828

2929
echo "Copying tables from ${SOURCE_DATASET} to ${TARGET_DATASET}."
30-
for TABLE in `bq ls ${PROJECT_ID}:${SOURCE_DATASET} | cut -d' ' -f3`;
30+
for TABLE in `bq ls -n 500 ${PROJECT_ID}:${SOURCE_DATASET} | cut -d' ' -f3`;
3131
do
3232
# skip the first line of dashes
3333
if [[ "${TABLE:0:2}" == '--' ]]; then

mimic-iv/concepts/firstday/first_day_bg_art.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ SELECT
2828
, MIN(sodium) AS sodium_min, MAX(sodium) AS sodium_max
2929
FROM `physionet-data.mimiciv_icu.icustays` ie
3030
LEFT JOIN `physionet-data.mimiciv_derived.bg` bg
31-
ON ie.subject_id = bg.subject_id
31+
ON
32+
ie.subject_id = bg.subject_id
3233
AND bg.specimen = 'ART.'
3334
AND bg.charttime >= DATETIME_SUB(ie.intime, INTERVAL '6' HOUR)
3435
AND bg.charttime <= DATETIME_ADD(ie.intime, INTERVAL '1' DAY)
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
WITH arb_drug AS (
1+
WITH arb_drug AS (
22
SELECT DISTINCT
33
drug
44
, CASE
5-
WHEN UPPER(drug) LIKE '%AZILSARTAN%' OR UPPER(drug) LIKE '%EDARBI%' THEN 1
6-
WHEN UPPER(drug) LIKE '%CANDESARTAN%' OR UPPER(drug) LIKE '%ATACAND%' THEN 1
7-
WHEN UPPER(drug) LIKE '%IRBESARTAN%' OR UPPER(drug) LIKE '%AVAPRO%' THEN 1
8-
WHEN UPPER(drug) LIKE '%LOSARTAN%' OR UPPER(drug) LIKE '%COZAAR%' THEN 1
9-
WHEN UPPER(drug) LIKE '%OLMESARTAN%' OR UPPER(drug) LIKE '%BENICAR%' THEN 1
10-
WHEN UPPER(drug) LIKE '%TELMISARTAN%' OR UPPER(drug) LIKE '%MICARDIS%' THEN 1
11-
WHEN UPPER(drug) LIKE '%VALSARTAN%' OR UPPER(drug) LIKE '%DIOVAN%' THEN 1
12-
WHEN UPPER(drug) LIKE '%SACUBITRIL%' OR UPPER(drug) LIKE '%ENTRESTO%' THEN 1
13-
ELSE 0
5+
WHEN UPPER(drug) LIKE '%AZILSARTAN%' OR UPPER(drug) LIKE '%EDARBI%'
6+
OR UPPER(drug) LIKE '%CANDESARTAN%' OR UPPER(drug) LIKE '%ATACAND%'
7+
OR UPPER(drug) LIKE '%IRBESARTAN%' OR UPPER(drug) LIKE '%AVAPRO%'
8+
OR UPPER(drug) LIKE '%LOSARTAN%' OR UPPER(drug) LIKE '%COZAAR%'
9+
OR UPPER(drug) LIKE '%OLMESARTAN%' OR UPPER(drug) LIKE '%BENICAR%'
10+
OR UPPER(drug) LIKE '%TELMISARTAN%' OR UPPER(drug) LIKE '%MICARDIS%'
11+
OR UPPER(drug) LIKE '%VALSARTAN%' OR UPPER(drug) LIKE '%DIOVAN%'
12+
OR UPPER(drug) LIKE '%SACUBITRIL%' OR UPPER(drug) LIKE '%ENTRESTO%'
13+
THEN 1
14+
ELSE 0
1415
END AS arb
1516
FROM `physionet-data.mimiciv_hosp.prescriptions`
1617
)
@@ -24,8 +25,7 @@ SELECT
2425
FROM
2526
`physionet-data.mimiciv_hosp.prescriptions` pr
2627
INNER JOIN arb_drug
27-
ON
28-
pr.drug = arb_drug.drug
28+
ON pr.drug = arb_drug.drug
2929
WHERE
3030
arb_drug.arb = 1
3131
;

0 commit comments

Comments
 (0)