#!/bin/bash set -euo pipefail export PGUSER=postgres dropdb parquet || true createdb parquet here=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")") psql parquet << EOF CREATE TABLE no_nulls( rowid INT2, bool_0 INT2, int8_1 INT2, int16_2 INT2, int32_3 INT4, int64_4 INT8, ts_5 int8, double_6 DOUBLE PRECISION, string_7 TEXT, string_8 TEXT, binary_9 TEXT, binary_10 TEXT ); CREATE TABLE nulls (LIKE no_nulls); COPY no_nulls FROM '$here/no-nulls.csv'; COPY nulls FROM '$here/nulls.csv'; CREATE OR REPLACE FUNCTION quote(TEXT) RETURNS TEXT AS \$\$ BEGIN RETURN \$1; END; \$\$ LANGUAGE 'plpgsql' IMMUTABLE; CREATE OR REPLACE FUNCTION datetime(INT8, TEXT) RETURNS TEXT AS \$\$ BEGIN RETURN to_timestamp(\$1) AT TIME ZONE 'UTC'; END; \$\$ LANGUAGE 'plpgsql' IMMUTABLE; CREATE OR REPLACE FUNCTION printf(TEXT, DOUBLE PRECISION) RETURNS TEXT AS \$\$ BEGIN RETURN CAST(\$2 AS DECIMAL(10, 4))::TEXT; END; \$\$ LANGUAGE 'plpgsql' IMMUTABLE; --COPY (SELECT rowid, bool_0, int8_1, int16_2, int32_3, int64_4, datetime(ts_5 / 1000, 'unixepoch'), double_6, string_7, string_8, quote(binary_9), quote(binary_10) FROM nulls LIMIT 3) TO STDOUT WITH (DELIMITER '|', NULL ''); COPY (SELECT rowid, bool_0, int8_1, int16_2, int32_3, int64_4, datetime(ts_5 / 1000, 'unixepoch'), printf('%.4f', double_6) AS double_6, string_7, string_8, quote(binary_9), quote(binary_10) FROM no_nulls) TO STDOUT WITH (DELIMITER '|', NULL ''); EOF