-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathcopy_concepts_to_versioned_schema.sh
More file actions
37 lines (35 loc) · 1.29 KB
/
copy_concepts_to_versioned_schema.sh
File metadata and controls
37 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# This script copies the concepts in the BigQuery table mimiciv_derived to mimiciv_${VERSION}_derived.
if [ -z "$$1" ]; then
echo "Usage: $0 <version>"
exit 1
fi
export SOURCE_DATASET=mimiciv_derived
export TARGET_DATASET=mimiciv_$1_derived
export PROJECT_ID=physionet-data
# check if the target dataset exists
if bq ls --datasets --project_id ${PROJECT_ID} | grep -q ${TARGET_DATASET}; then
echo "Using existing dataset ${TARGET_DATASET}."
# drop the existing tables in the target dataset
# this includes ones which may not be in the source dataset
for TABLE in `bq ls ${PROJECT_ID}:${TARGET_DATASET} | cut -d' ' -f3`;
do
# skip the first line of dashes
if [[ "${TABLE:0:2}" == '--' ]]; then
continue
fi
bq rm -f -q ${PROJECT_ID}:${TARGET_DATASET}.${TABLE}
done
else
echo "Creating dataset ${PROJECT_ID}:${TARGET_DATASET}"
bq mk --dataset ${PROJECT_ID}:${TARGET_DATASET}
fi
echo "Copying tables from ${SOURCE_DATASET} to ${TARGET_DATASET}."
for TABLE in `bq ls -n 500 ${PROJECT_ID}:${SOURCE_DATASET} | cut -d' ' -f3`;
do
# skip the first line of dashes
if [[ "${TABLE:0:2}" == '--' ]]; then
continue
fi
bq cp -f -q ${PROJECT_ID}:${SOURCE_DATASET}.${TABLE} ${PROJECT_ID}:${TARGET_DATASET}.${TABLE}
done