Skip to content

Commit 3afbf29

Browse files
author
Alistair Johnson
committed
fix: adds call to dependency tables to top of postgres-make-concepts.sql
1 parent 362f3c5 commit 3afbf29

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mimic-iv/concepts/convert_bigquery_to_postgres.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,29 @@ echo "\echo 'The scripts drop views before creating them, and these notices indi
2828
echo "\echo '==='" >> postgres/postgres-make-concepts.sql
2929
echo "\echo ''" >> postgres/postgres-make-concepts.sql
3030

31-
echo "\echo 'Scripts which act as dependencies for later concepts.'" >> postgres/postgres-make-concepts.sql
32-
3331
# reporting to stdout the folder being run
3432
echo -n "Dependencies:"
33+
34+
# output table creation calls to the make-concepts script
35+
echo "" >> postgres/postgres-make-concepts.sql
36+
echo "-- dependencies" >> postgres/postgres-make-concepts.sql
37+
3538
for dir_and_table in demographics.icustay_times demographics.weight_durations measurement.urine_output organfailure.kdigo_uo;
3639
do
3740
d=`echo ${dir_and_table} | cut -d. -f1`
3841
tbl=`echo ${dir_and_table} | cut -d. -f2`
42+
43+
# make the sub-folder for postgres if it does not exist
44+
mkdir -p "postgres/${d}"
3945

46+
# convert the bigquery script to psql and output it to the appropriate subfolder
4047
echo -n " ${d}.${tbl} .."
4148
echo "-- THIS SCRIPT IS AUTOMATICALLY GENERATED. DO NOT EDIT IT DIRECTLY." > "postgres/${d}/${tbl}.sql"
4249
echo "DROP TABLE IF EXISTS ${tbl}; CREATE TABLE ${tbl} AS " >> "postgres/${d}/${tbl}.sql"
4350
cat "${d}/${tbl}.sql" | sed -r -e "${REGEX_ARRAY}" | sed -r -e "${REGEX_HOUR_INTERVAL}" | sed -r -e "${REGEX_INT}" | sed -r -e "${REGEX_DATETIME_DIFF}" | sed -r -e "${REGEX_SCHEMA}" | sed -r -e "${REGEX_INTERVAL}" | sed -r -e "${REGEX_SECONDS}" | perl -0777 -pe "${PERL_REGEX_ROUND}" >> "postgres/${d}/${tbl}.sql"
51+
52+
# write out a call to this script in the make concepts file
53+
echo "\i ${d}/${tbl}.sql" >> postgres/postgres-make-concepts.sql
4454
done
4555
echo " done!"
4656

0 commit comments

Comments
 (0)