2018-03-08 00:40:38 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
export PGUSER=postgres
|
|
|
|
|
|
|
|
dropdb parquet || true
|
|
|
|
createdb parquet
|
|
|
|
|
|
|
|
here=$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")
|
|
|
|
|
|
|
|
psql parquet << EOF
|
2018-03-08 01:20:34 +00:00
|
|
|
CREATE TABLE no_nulls1(
|
2018-03-08 00:40:38 +00:00
|
|
|
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
|
|
|
|
);
|
|
|
|
|
2018-03-08 01:20:34 +00:00
|
|
|
CREATE TABLE no_nulls2 (LIKE no_nulls1);
|
|
|
|
CREATE TABLE nulls (LIKE no_nulls1);
|
2018-03-08 00:40:38 +00:00
|
|
|
|
2018-03-08 01:20:34 +00:00
|
|
|
COPY no_nulls1 FROM '$here/no-nulls.csv';
|
|
|
|
COPY no_nulls2 FROM '$here/no-nulls.csv';
|
2018-03-08 00:40:38 +00:00
|
|
|
COPY nulls FROM '$here/nulls.csv';
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION quote(TEXT) RETURNS TEXT AS \$\$
|
|
|
|
BEGIN
|
2018-03-08 01:30:25 +00:00
|
|
|
RETURN CASE WHEN \$1 IS NULL THEN 'NULL' ELSE \$1 END;
|
2018-03-08 00:40:38 +00:00
|
|
|
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
|
2018-03-11 19:04:38 +00:00
|
|
|
RETURN CAST(\$2 AS DECIMAL(10, 2))::TEXT;
|
2018-03-08 00:40:38 +00:00
|
|
|
END;
|
|
|
|
\$\$ LANGUAGE 'plpgsql' IMMUTABLE;
|
|
|
|
EOF
|