storytracer
commited on
Commit
•
3bdc46a
1
Parent(s):
78eb31b
Upload ol_duckdb.sh with huggingface_hub
Browse files- ol_duckdb.sh +52 -0
ol_duckdb.sh
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Check if exactly two arguments are provided
|
4 |
+
if [ "$#" -ne 2 ]; then
|
5 |
+
echo "Usage: $0 <dump_folder> <duckdb_file>"
|
6 |
+
exit 1
|
7 |
+
fi
|
8 |
+
|
9 |
+
# Assign the folder and DuckDB file arguments to variables
|
10 |
+
FOLDER=$1
|
11 |
+
DUCKDB_FILE=$2
|
12 |
+
|
13 |
+
# Check if the provided folder is a directory
|
14 |
+
if [ ! -d "$FOLDER" ]; then
|
15 |
+
echo "Error: $FOLDER is not a directory"
|
16 |
+
exit 1
|
17 |
+
fi
|
18 |
+
|
19 |
+
# Check if pv is installed
|
20 |
+
PV_INSTALLED=false
|
21 |
+
if command -v pv &> /dev/null; then
|
22 |
+
PV_INSTALLED=true
|
23 |
+
fi
|
24 |
+
|
25 |
+
# List of table names
|
26 |
+
TABLES=("authors" "works" "editions")
|
27 |
+
|
28 |
+
# Function to process each file
|
29 |
+
process_file() {
|
30 |
+
local file=$1
|
31 |
+
local table=$2
|
32 |
+
|
33 |
+
if $PV_INSTALLED; then
|
34 |
+
pv -N "$table" < "$file"
|
35 |
+
else
|
36 |
+
cat "$file"
|
37 |
+
fi | gunzip -c | cut -f5 | duckdb "$DUCKDB_FILE" -c "CREATE TABLE $table AS SELECT * FROM read_json_auto('/dev/stdin', union_by_name=true, ignore_errors=true);"
|
38 |
+
}
|
39 |
+
|
40 |
+
# Process each table
|
41 |
+
for TABLE in "${TABLES[@]}"; do
|
42 |
+
# Search for the file using a regex pattern
|
43 |
+
FILE=$(ls "$FOLDER"/ol_dump_${TABLE}_*.txt.gz 2> /dev/null | head -n 1)
|
44 |
+
|
45 |
+
# Check if the file exists
|
46 |
+
if [ -n "$FILE" ]; then
|
47 |
+
process_file "$FILE" "$TABLE"
|
48 |
+
else
|
49 |
+
echo "Warning: Dump file for $TABLE not found in $FOLDER. Skipping $TABLE."
|
50 |
+
fi
|
51 |
+
done
|
52 |
+
|