Skip to content

Commit

Permalink
joke’s on me, functions are parsed enough they must go into schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mirabilos committed Nov 18, 2023
1 parent e30b980 commit 8a677ff
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions acquire/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ BEGIN
RETURNING schemaname INTO sid;
EXECUTE format('CREATE SCHEMA %I;', sid);
EXECUTE format('SET search_path TO %I, jensjs, public;', sid);

-- (ts, owd, qdelay, vqnb, ecnin, ecnout, bitfive, ismark, isdrop, flow, len)
CREATE TABLE p (
pk BIGSERIAL PRIMARY KEY,
Expand All @@ -50,6 +51,7 @@ BEGIN
flow TEXT NOT NULL
);
CREATE INDEX p_ts ON p (ts);

-- (ts, membytes, npkts, handover, vcap, tsofs, rcap)
CREATE TABLE q (
pk BIGSERIAL PRIMARY KEY,
Expand All @@ -62,6 +64,7 @@ BEGIN
tsofs NUMERIC(20, 9) NOT NULL
);
CREATE INDEX q_ts ON q (ts);

CREATE VIEW o (ofs, d) AS
WITH
p1 AS (
Expand All @@ -84,10 +87,12 @@ BEGIN
fa1 AS (
SELECT ia1.*, ts - fabs AS d FROM ia1)
SELECT iabs, d FROM fa1;

CREATE VIEW fqdelay (dts, msvdelay, msrdelay, mslatency) AS
SELECT ts - d, qdelay * 1000, (qdelay - vqnb) * 1000, owd * 1000
FROM p, o
ORDER BY ts;

CREATE VIEW fbandwidth (dts, load, rcapacity, vcapacity, pktsizebytes) AS
WITH
prefiltered AS (
Expand Down Expand Up @@ -125,6 +130,12 @@ BEGIN
(TRUNC(vbw) / 1000000)::NUMERIC(10,6) AS vcapacity,
pktsizebytes
FROM filled, o ORDER BY ts;

CREATE OR REPLACE FUNCTION maptime(IN graphtime NUMERIC)
RETURNS NUMERIC(20, 9) AS '
SELECT d + graphtime FROM o;
' LANGUAGE 'sql';

RETURN sid;
END;
$$ LANGUAGE 'plpgsql';
Expand Down Expand Up @@ -174,9 +185,4 @@ BEGIN
END;
$$ LANGUAGE 'plpgsql';

CREATE OR REPLACE FUNCTION maptime(IN graphtime NUMERIC)
RETURNS NUMERIC(20, 9) AS $$
SELECT d + graphtime FROM o;
$$ LANGUAGE 'sql';

COMMIT;

0 comments on commit 8a677ff

Please sign in to comment.