sws-spark-dissemination-helper 0.0.107__py3-none-any.whl → 0.0.109__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sws_spark_dissemination_helper/SWSPostgresSparkReader.py +8 -4
- sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py +74 -0
- {sws_spark_dissemination_helper-0.0.107.dist-info → sws_spark_dissemination_helper-0.0.109.dist-info}/METADATA +1 -1
- {sws_spark_dissemination_helper-0.0.107.dist-info → sws_spark_dissemination_helper-0.0.109.dist-info}/RECORD +6 -6
- {sws_spark_dissemination_helper-0.0.107.dist-info → sws_spark_dissemination_helper-0.0.109.dist-info}/WHEEL +0 -0
- {sws_spark_dissemination_helper-0.0.107.dist-info → sws_spark_dissemination_helper-0.0.109.dist-info}/licenses/LICENSE +0 -0
|
@@ -291,13 +291,17 @@ class SWSPostgresSparkReader:
|
|
|
291
291
|
self,
|
|
292
292
|
domain_code: str,
|
|
293
293
|
) -> DataFrame:
|
|
294
|
-
|
|
294
|
+
df = self.read_pg_table(
|
|
295
295
|
pg_table=DatasetDatatables.MAPPING_CODE_CORRECTION.id,
|
|
296
|
-
table_name=DatasetDatatables.MAPPING_CODE_CORRECTION.name,
|
|
297
296
|
custom_schema=DatasetDatatables.MAPPING_CODE_CORRECTION.schema,
|
|
298
|
-
domain_code=domain_code,
|
|
299
|
-
unique_columns=["old_code"],
|
|
300
297
|
)
|
|
298
|
+
df.filter(
|
|
299
|
+
col("mapping_type").isNull() | (col("mapping_type") == lit(""))
|
|
300
|
+
).transform(
|
|
301
|
+
correct_domain_filter, domain=domain_code, unique_columns=["old_code"]
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
return df
|
|
301
305
|
|
|
302
306
|
def get_domain_code_source_datasets_ids_dest_dataset_id(
|
|
303
307
|
self, dataset_id: str, domain_code: str = None
|
|
@@ -163,6 +163,80 @@ class SWSSilverIcebergSparkHelper:
|
|
|
163
163
|
|
|
164
164
|
logging.info(f"Checking time validity for {col_name} of type {col_type}")
|
|
165
165
|
|
|
166
|
+
if col_type == "area":
|
|
167
|
+
df_start_year_correction = self.df_mapping_code_correction.filter(
|
|
168
|
+
col("var_type") == lit("start_year")
|
|
169
|
+
)
|
|
170
|
+
df_end_year_correction = self.df_mapping_code_correction.filter(
|
|
171
|
+
col("var_type") == lit("end_year")
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
original_col_order = df.columns
|
|
175
|
+
|
|
176
|
+
df = (
|
|
177
|
+
df.alias("d")
|
|
178
|
+
.join(
|
|
179
|
+
F.broadcast(df_start_year_correction).alias("sy"),
|
|
180
|
+
on=col(f"d.{col_name}") == col("sy.mapping_type"),
|
|
181
|
+
how="left",
|
|
182
|
+
)
|
|
183
|
+
.join(
|
|
184
|
+
F.broadcast(df_end_year_correction).alias("ey"),
|
|
185
|
+
on=col(f"d.{col_name}") == col("ey.mapping_type"),
|
|
186
|
+
how="left",
|
|
187
|
+
)
|
|
188
|
+
.withColumn("valid_new_start_year", col("sy.new_code").isNotNull())
|
|
189
|
+
.withColumn("valid_new_end_year", col("ey.new_code").isNotNull())
|
|
190
|
+
.withColumn(
|
|
191
|
+
"note",
|
|
192
|
+
F.when(
|
|
193
|
+
col("valid_new_start_year"),
|
|
194
|
+
F.array_append(
|
|
195
|
+
col("d.note"),
|
|
196
|
+
F.concat(
|
|
197
|
+
col("sy.note"),
|
|
198
|
+
lit(" from "),
|
|
199
|
+
col("sy.old_code"),
|
|
200
|
+
lit(" to "),
|
|
201
|
+
col("sy.new_code"),
|
|
202
|
+
),
|
|
203
|
+
),
|
|
204
|
+
).otherwise(col("note")),
|
|
205
|
+
)
|
|
206
|
+
.withColumn(
|
|
207
|
+
"note",
|
|
208
|
+
F.when(
|
|
209
|
+
col("valid_new_end_year"),
|
|
210
|
+
F.array_append(
|
|
211
|
+
col("note"),
|
|
212
|
+
F.concat(
|
|
213
|
+
col("ey.note"),
|
|
214
|
+
lit(" from "),
|
|
215
|
+
col("ey.old_code"),
|
|
216
|
+
lit(" to "),
|
|
217
|
+
col("ey.new_code"),
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
).otherwise(col("note")),
|
|
221
|
+
)
|
|
222
|
+
.withColumn(
|
|
223
|
+
f"{col_name}_start_date",
|
|
224
|
+
F.when(
|
|
225
|
+
col("valid_new_start_year"), F.to_date(col("sy.new_code"))
|
|
226
|
+
).otherwise(col(f"d.{col_name}_start_date")),
|
|
227
|
+
)
|
|
228
|
+
.withColumn(
|
|
229
|
+
f"{col_name}_end_date",
|
|
230
|
+
F.when(
|
|
231
|
+
col("valid_new_end_year"), F.to_date(col("ey.new_code"))
|
|
232
|
+
).otherwise(col(f"d.{col_name}_end_date")),
|
|
233
|
+
)
|
|
234
|
+
.selectExpr(
|
|
235
|
+
"d.*", "note", f"{col_name}_start_date", f"{col_name}_end_date"
|
|
236
|
+
)
|
|
237
|
+
.select(*original_col_order)
|
|
238
|
+
)
|
|
239
|
+
|
|
166
240
|
# Iterate through columns and build conditions dynamically
|
|
167
241
|
start_date_condition = col(f"{col_name}_start_date").isNull() | (
|
|
168
242
|
col(f"{col_name}_start_date") <= col(f"{self.time_column}_start_date")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sws-spark-dissemination-helper
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.109
|
|
4
4
|
Summary: A Python helper package providing streamlined Spark functions for efficient data dissemination processes
|
|
5
5
|
Project-URL: Repository, https://bitbucket.org/cioapps/sws-it-python-spark-dissemination-helper
|
|
6
6
|
Author-email: Daniele Mansillo <danielemansillo@gmail.com>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
sws_spark_dissemination_helper/SWSBronzeIcebergSparkHelper.py,sha256=aCi_rGvPkTDF9Sf5veWPeK_-CyP_GuwXLNnSjJRrd4M,19791
|
|
2
2
|
sws_spark_dissemination_helper/SWSGoldIcebergSparkHelper.py,sha256=RhgkLoxAT5AZlrj18SMsbONo3FJGZu7gjLU522vG5lg,19319
|
|
3
|
-
sws_spark_dissemination_helper/SWSPostgresSparkReader.py,sha256=
|
|
4
|
-
sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py,sha256=
|
|
3
|
+
sws_spark_dissemination_helper/SWSPostgresSparkReader.py,sha256=cRLa6KYv7tbGB2_Rpcyvb3ksGu0lX9gpLhnF9nxlxEs,17494
|
|
4
|
+
sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py,sha256=7n9THlgJY9QFZOAFb9BYzBN8cUDr5w1mzsonokzd85k,25203
|
|
5
5
|
sws_spark_dissemination_helper/__init__.py,sha256=Efjoe9V4vGXWVp-DY5P6NbRwIUr_zkZJkDmMi-lf5Bc,262
|
|
6
6
|
sws_spark_dissemination_helper/constants.py,sha256=QKtM8fYB8GWI0yEag4A7NLABRuu1T8qJ156F13YsRzo,11546
|
|
7
7
|
sws_spark_dissemination_helper/utils.py,sha256=6SzrXX0xhvynRyv-vRFDbc6V4UNe_RzKKETZAtefnhg,21341
|
|
8
|
-
sws_spark_dissemination_helper-0.0.
|
|
9
|
-
sws_spark_dissemination_helper-0.0.
|
|
10
|
-
sws_spark_dissemination_helper-0.0.
|
|
11
|
-
sws_spark_dissemination_helper-0.0.
|
|
8
|
+
sws_spark_dissemination_helper-0.0.109.dist-info/METADATA,sha256=cE81bRoInx7Ezl6GEctwvOyqYUVBQIJCM_iuiWoWYdQ,2824
|
|
9
|
+
sws_spark_dissemination_helper-0.0.109.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
10
|
+
sws_spark_dissemination_helper-0.0.109.dist-info/licenses/LICENSE,sha256=zFzeb_j_6pXEHwH8Z0OpIkKFJk7vmhZjdem-K0d4zU4,1073
|
|
11
|
+
sws_spark_dissemination_helper-0.0.109.dist-info/RECORD,,
|
|
File without changes
|