-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: load paths, imports, transpile, and CI permissions #2128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,12 @@ jobs: | |
| shell: bash | ||
| run: sqlfluff lint --format github-annotation --annotation-level failure --nofail ${{ steps.get_files_to_lint.outputs.lintees }} > annotations.json | ||
| - name: Annotate | ||
| # Fork PRs cannot create check runs with GITHUB_TOKEN; lint already ran. | ||
| continue-on-error: true | ||
| if: steps.get_files_to_lint.outputs.lintees != '' | ||
| uses: yuzutech/annotations-action@v0.6.0 | ||
| with: | ||
| repo-token: "${{ secrets.GITHUB_TOKEN }}" | ||
| title: "SQLFluff Lint" | ||
| input: "./annotations.json" | ||
| input: "./annotations.json" | ||
| ignore-missing-file: true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ usage () { | |
| die " | ||
| USAGE: ./import_duckdb.sh mimic_data_dir [output_db] | ||
| WHERE: | ||
| mimic_data_dir directory that contains csv.gz or csv files | ||
| mimic_data_dir directory that contains csv.tar.gz or csv files | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't distribute .tar.gz files |
||
| output_db: optional filename for duckdb file (default: mimic3.db)\ | ||
| " | ||
| } | ||
|
|
@@ -84,9 +84,11 @@ make_table_name () { | |
| # load data into database | ||
| find "$MIMIC_DIR" -type f -regex '.*\.csv\(.gz\)*' | while IFS= read -r FILE; do | ||
| make_table_name "$FILE" | ||
| echo "Loading $FILE .. \c" | ||
| # Escape single quotes for SQL string literal | ||
| FILE_SQL=$(printf '%s' "$FILE" | sed "s/'/''/g") | ||
| printf "Loading %s .. " "$FILE" | ||
| try duckdb "$OUTFILE" <<-EOSQL | ||
| COPY $TABLE_NAME FROM '$FILE' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"'); | ||
| COPY $TABLE_NAME FROM '$FILE_SQL' (HEADER, DELIM ',', QUOTE '"', ESCAPE '"'); | ||
| EOSQL | ||
| echo "done!" | ||
| done && echo "Successfully finished loading data into $OUTFILE." | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ mimic-build-gz: | |
| @echo '------------------' | ||
| @echo '' | ||
| @sleep 2 | ||
| psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data_gz.sql -v mimic_data_dir=${datadir} | ||
| psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data_gz.sql -v "mimic_data_dir=$(DATADIR)" | ||
| @echo '' | ||
| @echo '--------------------' | ||
| @echo '-- Adding indexes --' | ||
|
|
@@ -151,7 +151,7 @@ mimic-build: | |
| @echo '------------------' | ||
| @echo '' | ||
| @sleep 2 | ||
| psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data.sql -v mimic_data_dir=${DATADIR} | ||
| psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f postgres_load_data.sql -v "mimic_data_dir=$(DATADIR)" | ||
| @echo '' | ||
| @echo '--------------------' | ||
| @echo '-- Adding indexes --' | ||
|
|
@@ -184,15 +184,15 @@ ifeq ("$(physionetuser)","") | |
| @echo 'Call the makefile again with physionetuser=<USERNAME>' | ||
| @echo ' e.g. make eicu-download datadir=/path/to/data physionetuser=hello@physionet.org' | ||
| else | ||
| wget --user $(physionetuser) --ask-password -P $(DATADIR) -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETURL)" | ||
| wget --user $(physionetuser) --ask-password -P "$(DATADIR)" -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETURL)" | ||
| endif | ||
|
|
||
| mimic-demo-download: | ||
| @echo '------------------------------------------' | ||
| @echo '-- Downloading MIMIC-III from PhysioNet --' | ||
| @echo '------------------------------------------' | ||
| @echo '' | ||
| wget --user $(physionetuser) --ask-password -P $(DATADIR) -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETDEMOURL)" | ||
| wget --user $(physionetuser) --ask-password -P "$(DATADIR)" -A csv.gz -m -p -E -k -K -np -nd "$(PHYSIONETDEMOURL)" | ||
|
|
||
| #This is fairly inelegant and could be tidied with a for loop and an if to check for gzip, | ||
| #but need to maintain compatibility with Windows, which baffling lacks these things | ||
|
|
@@ -281,7 +281,7 @@ concepts: | |
| @echo '---------------------' | ||
| @echo '' | ||
| @sleep 2 | ||
| cd ../../concepts_postgres/ && psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -c "CREATE SCHEMA IF NOT EXISTS mimiciii_derived;" -f postgres-make-concepts.sql | ||
| cd ../../concepts/ && psql "$(DBSTRING)" -v ON_ERROR_STOP=1 -f make-concepts.sql | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will not work |
||
|
|
||
|
|
||
| .PHONY: help mimic clean | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,34 @@ | |
| CHUNKSIZE = 10 ** 6 | ||
| CONNECTION_STRING = "sqlite:///{}".format(DATABASE_NAME) | ||
|
|
||
| # Column dtypes for tables that trigger pandas mixed-type warnings when | ||
| # loaded with the default low_memory chunked inference (see #1237). | ||
| # Types mirror mimic-iii/buildmimic/postgres/postgres_create_tables.sql. | ||
| TABLE_DTYPES = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is great but can you split it into its own PR and add CI that verifies it? |
||
| "chartevents": { | ||
| "WARNING": "Int64", | ||
| "ERROR": "Int64", | ||
| "RESULTSTATUS": "string", | ||
| "STOPPED": "string", | ||
| }, | ||
| "datetimeevents": { | ||
| "WARNING": "Int64", | ||
| "ERROR": "Int64", | ||
| "RESULTSTATUS": "string", | ||
| "STOPPED": "string", | ||
| }, | ||
| "inputevents_cv": { | ||
| "ORIGINALRATE": "float64", | ||
| "ORIGINALRATEUOM": "string", | ||
| "ORIGINALSITE": "string", | ||
| }, | ||
| "noteevents": { | ||
| "CHARTTIME": "string", | ||
| "STORETIME": "string", | ||
| "ISERROR": "string", | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def _table_name_from_csv(filename: str) -> str: | ||
| """Derive SQL table name from a CSV path (literal suffix, not str.strip).""" | ||
|
|
@@ -21,20 +49,39 @@ def _table_name_from_csv(filename: str) -> str: | |
| return name.lower() | ||
|
|
||
|
|
||
| def _read_csv(path, table, **kwargs): | ||
| # low_memory=False avoids dtype re-inference across chunks; table-specific | ||
| # dtypes pin the columns that otherwise flip between numeric/object. | ||
| return pd.read_csv( | ||
| path, | ||
| index_col="ROW_ID", | ||
| low_memory=False, | ||
| dtype=TABLE_DTYPES.get(table), | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
||
| if os.path.exists(DATABASE_NAME): | ||
| msg = "File {} already exists.".format(DATABASE_NAME) | ||
| print(msg) | ||
| sys.exit() | ||
|
|
||
| # Prefer .csv.gz when both exist for the same table; also load plain .csv | ||
| # (import.sh already accepts both). | ||
| files_by_table = {} | ||
| for f in glob("*.csv"): | ||
| files_by_table[_table_name_from_csv(f)] = f | ||
| for f in glob("*.csv.gz"): | ||
| files_by_table[_table_name_from_csv(f)] = f | ||
|
|
||
| for table, f in sorted(files_by_table.items()): | ||
| print("Starting processing {}".format(f)) | ||
| table = _table_name_from_csv(f) | ||
| if os.path.getsize(f) < THRESHOLD_SIZE: | ||
| df = pd.read_csv(f, index_col="ROW_ID") | ||
| df = _read_csv(f, table) | ||
| df.to_sql(table, CONNECTION_STRING) | ||
| else: | ||
| # If the file is too large, let's do the work in chunks | ||
| for chunk in pd.read_csv(f, index_col="ROW_ID", chunksize=CHUNKSIZE): | ||
| for chunk in _read_csv(f, table, chunksize=CHUNKSIZE): | ||
| chunk.to_sql(table, CONNECTION_STRING, if_exists="append") | ||
| print("Finished processing {}".format(f)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too blunt; remove it, add workspace permission