Skip to content

Commit

Permalink
Remove insert rule for job dao
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Collado <collado.mike@gmail.com>
  • Loading branch information
collado-mike committed Jul 11, 2022
1 parent 390d34f commit ede162d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
28 changes: 24 additions & 4 deletions api/src/main/java/marquez/db/JobDao.java
Expand Up @@ -268,7 +268,7 @@ default JobRow findOrInsert(

@SqlQuery(
"""
INSERT INTO jobs_view AS j (
INSERT INTO jobs AS j (
uuid,
type,
created_at,
Expand All @@ -294,7 +294,16 @@ INSERT INTO jobs_view AS j (
:location,
:inputs,
:symlinkTargetId
)
) ON CONFLICT (name, namespace_uuid) WHERE parent_job_uuid IS NULL DO
UPDATE SET
updated_at = EXCLUDED.updated_at,
type = EXCLUDED.type,
description = EXCLUDED.description,
current_job_context_uuid = EXCLUDED.current_job_context_uuid,
current_location = EXCLUDED.current_location,
current_inputs = EXCLUDED.current_inputs,
-- update the symlink target if not null. otherwise, keep the old value
symlink_target_uuid = COALESCE(EXCLUDED.symlink_target_uuid, j.symlink_target_uuid)
RETURNING uuid
""")
UUID upsertJob(
Expand Down Expand Up @@ -342,9 +351,10 @@ default JobRow findOrInsert(

@SqlQuery(
"""
INSERT INTO jobs_view AS j (
INSERT INTO jobs AS j (
uuid,
parent_job_uuid,
parent_job_id_string,
type,
created_at,
updated_at,
Expand All @@ -359,6 +369,7 @@ INSERT INTO jobs_view AS j (
) VALUES (
:uuid,
:parentJobUuid,
COALESCE(:parentJobUuid::text, ''),
:type,
:now,
:now,
Expand All @@ -370,7 +381,16 @@ INSERT INTO jobs_view AS j (
:location,
:inputs,
:symlinkTargetId
)
) ON CONFLICT (name, namespace_uuid, parent_job_id_string) DO
UPDATE SET
updated_at = EXCLUDED.updated_at,
type = EXCLUDED.type,
description = EXCLUDED.description,
current_job_context_uuid = EXCLUDED.current_job_context_uuid,
current_location = EXCLUDED.current_location,
current_inputs = EXCLUDED.current_inputs,
-- update the symlink target if not null. otherwise, keep the old value
symlink_target_uuid = COALESCE(EXCLUDED.symlink_target_uuid, j.symlink_target_uuid)
RETURNING uuid
""")
UUID upsertJob(
Expand Down
Expand Up @@ -44,42 +44,4 @@ SELECT f.uuid,
j.current_inputs,
j.symlink_target_uuid
FROM job_fqn f, jobs j
WHERE j.uuid=f.uuid;

CREATE OR REPLACE RULE jobs_view_update AS ON INSERT
TO jobs_view
DO INSTEAD
INSERT INTO jobs (uuid, type, created_at, updated_at, namespace_uuid, name, description, current_version_uuid, namespace_name, current_job_context_uuid, current_location, current_inputs, symlink_target_uuid, parent_job_uuid, parent_job_id_string)
VALUES (NEW.uuid, NEW.type, NEW.created_at, NEW.updated_at, NEW.namespace_uuid, NEW.name, NEW.description, NEW.current_version_uuid, NEW.namespace_name, NEW.current_job_context_uuid, NEW.current_location, NEW.current_inputs, NEW.symlink_target_uuid, NEW.parent_job_uuid, COALESCE(NEW.parent_job_uuid::text, ''))
ON CONFLICT ON CONSTRAINT unique_jobs_namespace_uuid_name_parent DO
UPDATE SET
updated_at = EXCLUDED.updated_at,
type = EXCLUDED.type,
description = EXCLUDED.description,
current_job_context_uuid = EXCLUDED.current_job_context_uuid,
current_location = EXCLUDED.current_location,
current_inputs = EXCLUDED.current_inputs,
-- update the symlink target if not null. otherwise, keep the old value
symlink_target_uuid = COALESCE(EXCLUDED.symlink_target_uuid, jobs.symlink_target_uuid)
RETURNING uuid,
CASE
WHEN parent_job_uuid IS NULL THEN name
ELSE (SELECT jv.name || '.' || jobs.name FROM jobs_view jv WHERE uuid=parent_job_uuid)
END::varchar AS name,
namespace_name,
name AS simple_name,
parent_job_uuid,
CASE
WHEN parent_job_uuid IS NULL THEN NULL
ELSE (SELECT jv.name FROM jobs_view jv WHERE uuid=parent_job_uuid)
END::text AS parent_job_name,
type,
created_at,
updated_at,
namespace_uuid,
description,
current_version_uuid,
current_job_context_uuid,
current_location,
current_inputs,
symlink_target_uuid;
WHERE j.uuid=f.uuid;

0 comments on commit ede162d

Please sign in to comment.