mirror of
https://github.com/cldellow/sqlite-parquet-vtable.git
synced 2025-09-10 22:28:53 +00:00
Add a pg oracle
- define `datetime`, `printf` fns in pg so it produces similar output as sqlite - tidy up input data to be less wide To do: some fns to make it easy to generate a new test case. Probably want to mount all the 3 parquets simultaneously and refer to the sqlite table by the same name as the pg table.
This commit is contained in:
55
parquet-generator/create-pg-db
Executable file
55
parquet-generator/create-pg-db
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/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
|
Reference in New Issue
Block a user