#!/bin/bash # uso: q.sh fichero.sql [nombre] -> DuckDB (imagen etl:v2), datos :ro, 10g, sin red. Vista u = unified_20261018. # Escribe solo en e1/ (montado en /e1). Salida por stdout. set -u E=/e1 SQL="/e1/sql/$(basename "$1")"; N="e1-${2:-sql}" AV=$(free -g | awk '/Mem:/{print $7}'); while [ "$AV" -lt 14 ]; do echo "available=${AV}G < 14G: espero" >&2; sleep 30; AV=$(free -g | awk '/Mem:/{print $7}'); done timeout 3600 docker run -i --rm -m 10g --memory-swap 10g --cpus 6 --network none --user 1000:1000 --name "$N" \ -v /:/d:ro -v $E:/e1 \ buscalicitaciones-etl:v2 python3 - "$SQL" <<'PY' import sys, duckdb, time sql = open(sys.argv[1]).read() con = duckdb.connect() con.execute("SET memory_limit='7GB'; SET threads=6; SET temp_directory='/e1/tmp/duck'; SET max_temp_directory_size='30GB';") con.execute("CREATE VIEW u AS SELECT * FROM read_parquet('/d/unified_20261018/*/*/*.parquet', hive_partitioning=1, union_by_name=1)") for stmt in [s for s in sql.split(';\n--;') if s.strip()]: t=time.time() try: r = con.execute(stmt) if r.description: cols=[d[0] for d in r.description]; rows=r.fetchall() print('## '+stmt.strip().splitlines()[0][:110]) print('|'.join(cols)) for row in rows[:400]: print('|'.join('' if v is None else str(v) for v in row)) if len(rows)>400: print(f'... {len(rows)} filas') except Exception as e: print('## ERROR en:', stmt.strip().splitlines()[0][:110]); print(e) print(f'-- {time.time()-t:.1f}s\n', flush=True) PY