Skip to content

Commit 322d1cd

Browse files
committed
fix: use globs instead of ls in make_concepts.sh
1 parent 4cf9855 commit 322d1cd

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

mimic-iv/concepts/make_concepts.sh

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ for table_path in demographics/icustay_times;
4444
do
4545
table=`echo $table_path | rev | cut -d/ -f1 | rev`
4646
echo "Generating ${TARGET_DATASET}.${table}"
47-
bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
47+
bq query ${BQ_OPTIONS} --destination_table="${TARGET_DATASET}.${table}" < "${table_path}.sql"
4848
done
4949

5050
# generate tables in subfolders
@@ -54,30 +54,29 @@ done
5454
# * organfailure depends on measurement
5555
for d in demographics comorbidity measurement medication organfailure treatment firstday score sepsis;
5656
do
57-
for fn in `ls $d`;
57+
for fn_path in "$d"/*.sql;
5858
do
59-
# only run SQL queries
60-
if [[ "${fn: -4}" == ".sql" ]]; then
61-
# table name is file name minus extension
62-
tbl=`echo $fn | rev | cut -d. -f2- | rev`
59+
[ -f "$fn_path" ] || continue
60+
fn=$(basename "$fn_path")
61+
# table name is file name minus extension
62+
tbl="${fn%.sql}"
6363

64-
# skip certain tables where order matters
65-
skip=0
66-
for skip_table in meld icustay_times first_day_sofa kdigo_stages vasoactive_agent norepinephrine_equivalent_dose sepsis3
67-
do
68-
if [[ "${tbl}" == "${skip_table}" ]]; then
69-
skip=1
70-
break
71-
fi
72-
done;
73-
if [[ "${skip}" == "1" ]]; then
74-
continue
75-
fi
76-
77-
# not skipping - so generate the table on bigquery
78-
echo "Generating ${TARGET_DATASET}.${tbl}"
79-
bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET}.${tbl} < ${d}/${fn}
64+
# skip certain tables where order matters
65+
skip=0
66+
for skip_table in meld icustay_times first_day_sofa kdigo_stages vasoactive_agent norepinephrine_equivalent_dose sepsis3
67+
do
68+
if [[ "${tbl}" == "${skip_table}" ]]; then
69+
skip=1
70+
break
71+
fi
72+
done;
73+
if [[ "${skip}" == "1" ]]; then
74+
continue
8075
fi
76+
77+
# not skipping - so generate the table on bigquery
78+
echo "Generating ${TARGET_DATASET}.${tbl}"
79+
bq query ${BQ_OPTIONS} --destination_table="${TARGET_DATASET}.${tbl}" < "${fn_path}"
8180
done
8281
done
8382

@@ -88,5 +87,5 @@ do
8887
table=`echo $table_path | rev | cut -d/ -f1 | rev`
8988

9089
echo "Generating ${TARGET_DATASET}.${table}"
91-
bq query ${BQ_OPTIONS} --destination_table=${TARGET_DATASET}.${table} < ${table_path}.sql
90+
bq query ${BQ_OPTIONS} --destination_table="${TARGET_DATASET}.${table}" < "${table_path}.sql"
9291
done

0 commit comments

Comments
 (0)