-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!(cdviz-db): use the stored procedure
store_cdevent
instead of …
…direct sql insert
- Loading branch information
Showing
10 changed files
with
121 additions
and
82 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
...llector/.sqlx/query-4f5d9f4efa09b9bb83af1bd459d2c01e4a48916e71ccbae5881b1a13f324da2f.json
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
...llector/.sqlx/query-f9ad1896b6eb169b76af116f7bfd4f66233e9aac3a6143f43bef13b46249f969.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
-- Create "cdevents_lake" table | ||
CREATE TABLE "cdevents_lake" ("id" bigint NOT NULL GENERATED ALWAYS AS IDENTITY, "imported_at" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, "timestamp" timestamptz NOT NULL, "payload" jsonb NOT NULL, "subject" character varying(100) NOT NULL, "predicate" character varying(100) NOT NULL, "version" integer[] NULL, "context_id" character varying(100) NOT NULL, PRIMARY KEY ("id")); | ||
-- Create index "cdevents_lake_context_id_key" to table: "cdevents_lake" | ||
CREATE UNIQUE INDEX "cdevents_lake_context_id_key" ON "cdevents_lake" ("context_id"); | ||
-- Create index "idx_subject" to table: "cdevents_lake" | ||
CREATE INDEX "idx_subject" ON "cdevents_lake" ("subject"); | ||
-- Create index "idx_timestamp" to table: "cdevents_lake" | ||
CREATE INDEX "idx_timestamp" ON "cdevents_lake" ("timestamp"); | ||
-- Set comment to table: "cdevents_lake" | ||
COMMENT ON TABLE "cdevents_lake" IS 'table of stored cdevents without transformation'; | ||
-- Set comment to column: "imported_at" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."imported_at" IS 'the timestamp when the cdevent was stored into the table'; | ||
-- Set comment to column: "timestamp" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."timestamp" IS 'timestamp of cdevents extracted from context.timestamp in the json'; | ||
-- Set comment to column: "payload" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."payload" IS 'the full cdevent in json format'; | ||
-- Set comment to column: "subject" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."subject" IS 'subject extracted from context.type in the json'; | ||
-- Set comment to column: "predicate" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."predicate" IS 'predicate of the subject, extracted from context.type in the json'; | ||
-- Set comment to column: "version" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."version" IS 'the version of the suject s type, extracted from context.type. The version number are split in 0 for major, 1 for minor, 2 for patch'; | ||
-- Set comment to column: "context_id" on table: "cdevents_lake" | ||
COMMENT ON COLUMN "cdevents_lake" ."context_id" IS 'the id of the event, extracted from context.id'; | ||
|
||
create or replace procedure store_cdevent( | ||
cdevent jsonb | ||
) | ||
as $$ | ||
declare | ||
ts timestamp with time zone; | ||
tpe varchar(255); | ||
context_id varchar(100); | ||
tpe_subject varchar(100); | ||
tpe_predicate varchar(100); | ||
tpe_version INTEGER[3]; | ||
begin | ||
context_id := (cdevent -> 'context' ->> 'id'); | ||
tpe := (cdevent -> 'context' ->> 'type'); | ||
tpe_subject := SPLIT_PART(tpe, '.', 3); | ||
tpe_predicate := SPLIT_PART(tpe, '.', 4); | ||
tpe_version[0]:= SPLIT_PART(tpe, '.', 5)::INTEGER; | ||
tpe_version[1]:= SPLIT_PART(tpe, '.', 6)::INTEGER; | ||
tpe_version[2]:= SPLIT_PART(SPLIT_PART(tpe, '.', 7), '-', 1)::INTEGER; | ||
-- if (jsonb_typeof(cdevent -> 'context' ->> 'timestamp') = 'timestampz') then | ||
ts := (cdevent -> 'context' ->> 'timestamp')::timestamp with time zone; | ||
-- else | ||
-- raise exception 'Input Jsonb doesn not contain a valid timestamp'; | ||
-- end if; | ||
insert into "cdevents_lake"("payload", "timestamp", "subject", "predicate", "version", "context_id") values(cdevent, ts, tpe_subject, tpe_predicate, tpe_version, context_id); | ||
end; | ||
$$ language plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
h1:G8sqtBxbE8rQ0ZReTiVO01ugCUK0Z5U1/tn0i10a0H4= | ||
20240316184734.sql h1:P4X1rAK3TUnBFjHwTZw+Lc7l3x9qkKXmTk8Y56GjMvI= | ||
20240401171152.sql h1:Oh6ZIUfdo8j/LCUmA+YWmv28MIJYKsioxYIAOSA2MhI= | ||
h1:kGNUpVkZ+2Ry6GZZbPz9UFUb+Y6TemKiz3AlgdKiHTQ= | ||
20241014134101.sql h1:kRGH4LbTomyoYSmJ6M22O3cTR9d3ds8QbBODiTYe/10= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters