-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runless events - refactor job_versions_io_mapping (#2654)
* get lineage from job_versions_io_mapping table only Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com> * add made_current_at field to job_versions Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com> --------- Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
- Loading branch information
1 parent
a5a0e55
commit b73fb15
Showing
10 changed files
with
617 additions
and
71 deletions.
There are no files selected for viewing
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 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
65 changes: 65 additions & 0 deletions
65
api/src/main/java/marquez/db/migrations/V67_2_JobVersionsIOMappingBackfillJob.java
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,65 @@ | ||
/* | ||
* Copyright 2018-2023 contributors to the Marquez project | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package marquez.db.migrations; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.flywaydb.core.api.MigrationVersion; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.flywaydb.core.api.migration.JavaMigration; | ||
import org.jdbi.v3.core.Jdbi; | ||
|
||
@Slf4j | ||
public class V67_2_JobVersionsIOMappingBackfillJob implements JavaMigration { | ||
|
||
public static final String UPDATE_QUERY = | ||
""" | ||
UPDATE job_versions_io_mapping | ||
SET | ||
job_uuid = j.uuid, | ||
job_symlink_target_uuid = j.symlink_target_uuid, | ||
is_current_job_version = (jv.uuid = j.current_version_uuid)::BOOLEAN, | ||
made_current_at = NOW() | ||
FROM job_versions jv | ||
INNER JOIN jobs_view j ON j.uuid = jv.job_uuid | ||
WHERE jv.uuid = job_versions_io_mapping.job_version_uuid | ||
"""; | ||
|
||
@Override | ||
public MigrationVersion getVersion() { | ||
return MigrationVersion.fromVersion("67.2"); | ||
} | ||
|
||
@Override | ||
public void migrate(Context context) throws Exception { | ||
Jdbi jdbi = Jdbi.create(context.getConnection()); | ||
jdbi.withHandle(h -> h.createUpdate(UPDATE_QUERY).execute()); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Back fill job_uuid and is_current_job_version in job_versions_io_mapping table"; | ||
} | ||
|
||
@Override | ||
public Integer getChecksum() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isUndo() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canExecuteInTransaction() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isBaselineMigration() { | ||
return false; | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
.../main/resources/marquez/db/migration/V67.1__job_versions_io_mapping_add_job_reference.sql
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,12 @@ | ||
ALTER TABLE job_versions_io_mapping ADD COLUMN job_uuid uuid REFERENCES jobs(uuid) ON DELETE CASCADE; | ||
ALTER TABLE job_versions_io_mapping ADD COLUMN job_symlink_target_uuid uuid REFERENCES jobs(uuid) ON DELETE CASCADE; | ||
ALTER TABLE job_versions_io_mapping ADD COLUMN is_current_job_version boolean DEFAULT FALSE; | ||
ALTER TABLE job_versions_io_mapping ADD COLUMN made_current_at TIMESTAMP; | ||
|
||
-- To add job_uuid to the unique constraint, we first drop the primary key, then recreate it; note given that job_version_uuid can be NULL, we need to check that job_version_uuid != NULL before inserting (duplicate columns otherwise) | ||
ALTER TABLE job_versions_io_mapping DROP CONSTRAINT job_versions_io_mapping_pkey; | ||
ALTER TABLE job_versions_io_mapping ALTER COLUMN job_version_uuid DROP NOT NULL; | ||
|
||
CREATE INDEX job_versions_io_mapping_job_uuid_job_symlink_target_uuid ON job_versions_io_mapping (job_uuid, job_symlink_target_uuid); | ||
|
||
ALTER TABLE job_versions_io_mapping ADD CONSTRAINT job_versions_io_mapping_mapping_pkey UNIQUE (job_version_uuid, dataset_uuid, io_type, job_uuid); |
Oops, something went wrong.