Skip to content

Commit aad8ea6

Browse files
committed
fixes for compatibility with mac os x sed and bash 3.x
1 parent 469fe4d commit aad8ea6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mimic-iv/concepts/convert_bigquery_to_postgres.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# This shell script converts BigQuery .sql files into PostgreSQL .sql files.
33

44
# String replacements are necessary for some queries.
5-
export REGEX_SCHEMA='s/`physionet-data.(mimic_core|mimic_icu|mimic_derived|mimic_hosp).(.+?)`/\1.\2/g'
5+
export REGEX_SCHEMA='s/`physionet-data.(mimiciv_hosp|mimiciv_icu|mimiciv_derived).([A-Za-z0-9_-]+)`/\1.\2/g'
66
# Note that these queries are very senstive to changes, e.g. adding whitespaces after comma can already change the behavior.
7-
export REGEX_DATETIME_DIFF="s/DATETIME_DIFF\((.+?),\s?(.+?),\s?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATETIME_DIFF(\1,\2,'\3')/g"
8-
export REGEX_DATETIME_TRUNC="s/DATETIME_TRUNC\((.+?),\s?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATE_TRUNC('\2', \1)/g"
7+
export REGEX_DATETIME_DIFF="s/DATETIME_DIFF\(([^,]+), ?([^,]+), ?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATETIME_DIFF(\1, \2, '\3')/g"
8+
export REGEX_DATETIME_TRUNC="s/DATETIME_TRUNC\(([^,]+), ?(DAY|MINUTE|SECOND|HOUR|YEAR)\)/DATE_TRUNC('\2', \1)/g"
99
# Add necessary quotes to INTERVAL, e.g. "INTERVAL 5 hour" to "INTERVAL '5' hour"
10-
export REGEX_INTERVAL="s/interval\s([[:digit:]]+)\s(hour|day|month|year)/INTERVAL '\1' \2/gI"
10+
export REGEX_INTERVAL="s/interval ([[:digit:]]+) (hour|day|month|year)/INTERVAL '\1' \2/gI"
1111
# Add numeric cast to ROUND(), e.g. "ROUND(1.234, 2)" to "ROUND( CAST(1.234 as numeric), 2)".
1212
export PERL_REGEX_ROUND='s/ROUND\(((.|\n)*?)\, /ROUND\( CAST\( \1 as numeric\)\,/g'
1313
# Specific queries for some problems that arose with some files.
@@ -83,7 +83,7 @@ do
8383
# only run SQL queries
8484
if [[ "${fn: -4}" == ".sql" ]]; then
8585
# table name is file name minus extension
86-
tbl="${fn::-4}"
86+
tbl="${fn%????}"
8787

8888
# skip first_day_sofa as it depends on other firstday queries, we'll generate it later
8989
# we also skipped tables generated in the "Dependencies" loop above.

0 commit comments

Comments
 (0)