|
2 | 2 | # This shell script converts BigQuery .sql files into PostgreSQL .sql files. |
3 | 3 |
|
4 | 4 | # 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' |
6 | 6 | # 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" |
9 | 9 | # 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" |
11 | 11 | # Add numeric cast to ROUND(), e.g. "ROUND(1.234, 2)" to "ROUND( CAST(1.234 as numeric), 2)". |
12 | 12 | export PERL_REGEX_ROUND='s/ROUND\(((.|\n)*?)\, /ROUND\( CAST\( \1 as numeric\)\,/g' |
13 | 13 | # Specific queries for some problems that arose with some files. |
|
83 | 83 | # only run SQL queries |
84 | 84 | if [[ "${fn: -4}" == ".sql" ]]; then |
85 | 85 | # table name is file name minus extension |
86 | | - tbl="${fn::-4}" |
| 86 | + tbl="${fn%????}" |
87 | 87 |
|
88 | 88 | # skip first_day_sofa as it depends on other firstday queries, we'll generate it later |
89 | 89 | # we also skipped tables generated in the "Dependencies" loop above. |
|
0 commit comments