|
| 1 | +/* |
| 2 | + * Copyright 2018 ABSA Group Limited |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +-- Convert job_definition's additionalSparkConfig from map into array |
| 17 | +update job_definition |
| 18 | +set job_parameters = jsonb_set( |
| 19 | + job_definition.job_parameters::jsonb, |
| 20 | + array ['additionalSparkConfig'], |
| 21 | + updated_additional_spark_config.additional_spark_config, |
| 22 | + true |
| 23 | +) |
| 24 | +from ( |
| 25 | + select job_definition_for_join.id, coalesce(aggregated_additional_spark_config.additional_spark_config::jsonb, '[]'::jsonb) as additional_spark_config |
| 26 | + from ( |
| 27 | + select flattened_additional_spark_config.id, jsonb_agg(flattened_additional_spark_config.additional_spark_config)::jsonb as additional_spark_config |
| 28 | + from ( |
| 29 | + select id, jsonb_each_text(job_definition.job_parameters::jsonb -> 'additionalSparkConfig') as additional_spark_config |
| 30 | + from job_definition |
| 31 | + ) as flattened_additional_spark_config |
| 32 | + group by flattened_additional_spark_config.id |
| 33 | + ) as aggregated_additional_spark_config |
| 34 | + right join job_definition as job_definition_for_join |
| 35 | + on job_definition_for_join.id = aggregated_additional_spark_config.id |
| 36 | +) as updated_additional_spark_config |
| 37 | +where updated_additional_spark_config.id = job_definition.id; |
| 38 | + |
| 39 | +-- Convert job_instance's additionalSparkConfig from map into array |
| 40 | +update job_instance |
| 41 | +set job_parameters = jsonb_set( |
| 42 | + job_instance.job_parameters::jsonb, |
| 43 | + array ['additionalSparkConfig'], |
| 44 | + updated_additional_spark_config.additional_spark_config, |
| 45 | + true |
| 46 | +) |
| 47 | +from ( |
| 48 | + select job_instance_for_join.id, coalesce(aggregated_additional_spark_config.additional_spark_config::jsonb, '[]'::jsonb) as additional_spark_config |
| 49 | + from ( |
| 50 | + select flattened_additional_spark_config.id, jsonb_agg(flattened_additional_spark_config.additional_spark_config)::jsonb as additional_spark_config |
| 51 | + from ( |
| 52 | + select id, jsonb_each_text(job_instance.job_parameters::jsonb -> 'additionalSparkConfig') as additional_spark_config |
| 53 | + from job_instance |
| 54 | + ) as flattened_additional_spark_config |
| 55 | + group by flattened_additional_spark_config.id |
| 56 | + ) as aggregated_additional_spark_config |
| 57 | + right join job_instance as job_instance_for_join |
| 58 | + on job_instance_for_join.id = aggregated_additional_spark_config.id |
| 59 | +) as updated_additional_spark_config |
| 60 | +where updated_additional_spark_config.id = job_instance.id; |
| 61 | + |
| 62 | +-- Convert job_template's additionalSparkConfig from map into array |
| 63 | +update job_template |
| 64 | +set job_parameters = jsonb_set( |
| 65 | + job_template.job_parameters::jsonb, |
| 66 | + array ['additionalSparkConfig'], |
| 67 | + (updated_additional_spark_config.additional_spark_config), |
| 68 | + true |
| 69 | +) |
| 70 | +from ( |
| 71 | + select job_template_for_join.id, coalesce(aggregated_additional_spark_config.additional_spark_config::jsonb, '[]'::jsonb) as additional_spark_config |
| 72 | + from ( |
| 73 | + select flattened_additional_spark_config.id, jsonb_agg(flattened_additional_spark_config.additional_spark_config)::jsonb as additional_spark_config |
| 74 | + from ( |
| 75 | + select id, jsonb_each_text(job_template.job_parameters::jsonb -> 'additionalSparkConfig') as additional_spark_config |
| 76 | + from job_template |
| 77 | + ) as flattened_additional_spark_config |
| 78 | + group by flattened_additional_spark_config.id |
| 79 | + ) as aggregated_additional_spark_config |
| 80 | + right join job_template as job_template_for_join |
| 81 | + on job_template_for_join.id = aggregated_additional_spark_config.id |
| 82 | +) as updated_additional_spark_config |
| 83 | +where updated_additional_spark_config.id = job_template.id; |
| 84 | + |
| 85 | +-- Convert job_template_history's additionalSparkConfig from map into array |
| 86 | +update job_template_history |
| 87 | +set job_template = jsonb_set( |
| 88 | + job_template_history.job_template::jsonb, |
| 89 | + array ['jobParameters','additionalSparkConfig'], |
| 90 | + (updated_additional_spark_config.additional_spark_config), |
| 91 | + true |
| 92 | +) |
| 93 | +from ( |
| 94 | + select job_template_history_for_join.id, coalesce(aggregated_additional_spark_config.additional_spark_config::jsonb, '[]'::jsonb) as additional_spark_config |
| 95 | + from ( |
| 96 | + select flattened_additional_spark_config.id, jsonb_agg(flattened_additional_spark_config.additional_spark_config)::jsonb as additional_spark_config |
| 97 | + from ( |
| 98 | + select id, jsonb_each_text(job_template_history.job_template::jsonb -> 'jobParameters' -> 'additionalSparkConfig') as additional_spark_config |
| 99 | + from job_template_history |
| 100 | + ) as flattened_additional_spark_config |
| 101 | + group by flattened_additional_spark_config.id |
| 102 | + ) as aggregated_additional_spark_config |
| 103 | + right join job_template_history as job_template_history_for_join |
| 104 | + on job_template_history_for_join.id = aggregated_additional_spark_config.id |
| 105 | +) as updated_additional_spark_config |
| 106 | +where updated_additional_spark_config.id = job_template_history.id; |
| 107 | + |
| 108 | +-- Convert workflow_history's additionalSparkConfig from map into array |
| 109 | +with flattened_job_definitions as ( |
| 110 | + select id, jsonb_array_elements(workflow::jsonb -> 'dagDefinitionJoined' -> 'jobDefinitions') as job_definition |
| 111 | + from workflow_history |
| 112 | +), |
| 113 | +flattened_job_definitions_with_ids as ( |
| 114 | + select flattened_job_definitions.id, flattened_job_definitions.job_definition::jsonb -> 'id' as job_id, flattened_job_definitions.job_definition as job_definition |
| 115 | + from flattened_job_definitions |
| 116 | +), |
| 117 | +updated_additional_spark_config as ( |
| 118 | + select flattened_job_definitions_with_ids_for_join.id, flattened_job_definitions_with_ids_for_join.job_id, coalesce(aggregated_additional_spark_config.additional_spark_config::jsonb, '[]'::jsonb) as additional_spark_config |
| 119 | + from ( |
| 120 | + select flattened_additional_spark_config.id, job_id, jsonb_agg(flattened_additional_spark_config.additional_spark_config)::jsonb as additional_spark_config |
| 121 | + from ( |
| 122 | + select id, job_id, jsonb_each_text(job_definition::jsonb -> 'jobParameters' -> 'additionalSparkConfig') as additional_spark_config |
| 123 | + from flattened_job_definitions_with_ids |
| 124 | + ) as flattened_additional_spark_config |
| 125 | + group by flattened_additional_spark_config.id, job_id |
| 126 | + ) as aggregated_additional_spark_config |
| 127 | + right join flattened_job_definitions_with_ids as flattened_job_definitions_with_ids_for_join |
| 128 | + on flattened_job_definitions_with_ids_for_join.id = aggregated_additional_spark_config.id |
| 129 | + AND flattened_job_definitions_with_ids_for_join.job_id = aggregated_additional_spark_config.job_id |
| 130 | +), |
| 131 | +updated_job_definitons as ( |
| 132 | + select flattened_job_definitions_with_ids.id as id, flattened_job_definitions_with_ids.job_id, |
| 133 | + jsonb_set( |
| 134 | + flattened_job_definitions_with_ids.job_definition::jsonb, |
| 135 | + array ['jobParameters','additionalSparkConfig'], |
| 136 | + (updated_additional_spark_config.additional_spark_config), |
| 137 | + true |
| 138 | + ) as job_definitions |
| 139 | + from flattened_job_definitions_with_ids, updated_additional_spark_config |
| 140 | + where flattened_job_definitions_with_ids.id = updated_additional_spark_config.id AND flattened_job_definitions_with_ids.job_id = updated_additional_spark_config.job_id |
| 141 | +), |
| 142 | +aggregated_job_definitions as ( |
| 143 | + select updated_job_definitons.id, jsonb_agg(updated_job_definitons.job_definitions) as job_definitions |
| 144 | + from updated_job_definitons |
| 145 | + group by updated_job_definitons.id |
| 146 | +) |
| 147 | +update workflow_history |
| 148 | +set workflow = jsonb_set(workflow::jsonb, array['dagDefinitionJoined', 'jobDefinitions'], aggregated_job_definitions.job_definitions) |
| 149 | +from aggregated_job_definitions |
| 150 | +where aggregated_job_definitions.id=workflow_history.id; |
0 commit comments