sws-spark-dissemination-helper 0.0.171__py3-none-any.whl → 0.0.174__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/SWSSilverIcebergSparkHelper.py +24 -24
- sws_spark_dissemination_helper/utils.py +9 -9
- {sws_spark_dissemination_helper-0.0.171.dist-info → sws_spark_dissemination_helper-0.0.174.dist-info}/METADATA +3 -3
- {sws_spark_dissemination_helper-0.0.171.dist-info → sws_spark_dissemination_helper-0.0.174.dist-info}/RECORD +6 -6
- {sws_spark_dissemination_helper-0.0.171.dist-info → sws_spark_dissemination_helper-0.0.174.dist-info}/WHEEL +0 -0
- {sws_spark_dissemination_helper-0.0.171.dist-info → sws_spark_dissemination_helper-0.0.174.dist-info}/licenses/LICENSE +0 -0
|
@@ -103,7 +103,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
103
103
|
# The diss_flag column is needed to initialize the condition expression
|
|
104
104
|
# The note column will contain the eventual reasons why diss_flag has been set to false
|
|
105
105
|
return df.withColumn("diss_flag", lit(True)).withColumn(
|
|
106
|
-
"
|
|
106
|
+
"diss_note", lit([]).cast(ArrayType(StringType()))
|
|
107
107
|
)
|
|
108
108
|
|
|
109
109
|
def read_bronze_data(self) -> DataFrame:
|
|
@@ -182,7 +182,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
182
182
|
for column in cols_to_select
|
|
183
183
|
if column.lower()
|
|
184
184
|
not in (
|
|
185
|
-
"
|
|
185
|
+
"diss_note",
|
|
186
186
|
f"{col_name_lower}_start_date",
|
|
187
187
|
f"{col_name_lower}_end_date",
|
|
188
188
|
)
|
|
@@ -203,36 +203,36 @@ class SWSSilverIcebergSparkHelper:
|
|
|
203
203
|
.withColumn("valid_new_start_year", col("sy.new_code").isNotNull())
|
|
204
204
|
.withColumn("valid_new_end_year", col("ey.new_code").isNotNull())
|
|
205
205
|
.withColumn(
|
|
206
|
-
"
|
|
206
|
+
"new_diss_note",
|
|
207
207
|
F.when(
|
|
208
208
|
col("valid_new_start_year"),
|
|
209
209
|
F.array_append(
|
|
210
|
-
col("d.
|
|
210
|
+
col("d.diss_note"),
|
|
211
211
|
F.concat(
|
|
212
|
-
col("sy.
|
|
212
|
+
col("sy.diss_note"),
|
|
213
213
|
lit(" from "),
|
|
214
214
|
col("sy.old_code"),
|
|
215
215
|
lit(" to "),
|
|
216
216
|
col("sy.new_code"),
|
|
217
217
|
),
|
|
218
218
|
),
|
|
219
|
-
).otherwise(col("d.
|
|
219
|
+
).otherwise(col("d.diss_note")),
|
|
220
220
|
)
|
|
221
221
|
.withColumn(
|
|
222
|
-
"
|
|
222
|
+
"new_diss_note",
|
|
223
223
|
F.when(
|
|
224
224
|
col("valid_new_end_year"),
|
|
225
225
|
F.array_append(
|
|
226
|
-
col("
|
|
226
|
+
col("new_diss_note"),
|
|
227
227
|
F.concat(
|
|
228
|
-
col("ey.
|
|
228
|
+
col("ey.diss_note"),
|
|
229
229
|
lit(" from "),
|
|
230
230
|
col("ey.old_code"),
|
|
231
231
|
lit(" to "),
|
|
232
232
|
col("ey.new_code"),
|
|
233
233
|
),
|
|
234
234
|
),
|
|
235
|
-
).otherwise(col("
|
|
235
|
+
).otherwise(col("new_diss_note")),
|
|
236
236
|
)
|
|
237
237
|
.withColumn(
|
|
238
238
|
f"new_{col_name}_start_date",
|
|
@@ -249,7 +249,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
249
249
|
)
|
|
250
250
|
.select(
|
|
251
251
|
*cols_to_select,
|
|
252
|
-
col("
|
|
252
|
+
col("new_diss_note").alias("diss_note"),
|
|
253
253
|
col(f"new_{col_name}_start_date").alias(f"{col_name}_start_date"),
|
|
254
254
|
col(f"new_{col_name}_end_date").alias(f"{col_name}_end_date"),
|
|
255
255
|
)
|
|
@@ -270,15 +270,15 @@ class SWSSilverIcebergSparkHelper:
|
|
|
270
270
|
start_date_condition & end_date_condition,
|
|
271
271
|
)
|
|
272
272
|
.withColumn("diss_flag", col("diss_flag") & col("condition_result"))
|
|
273
|
-
# In case the condition is satisfied update diss_flag accordingly and append a
|
|
273
|
+
# In case the condition is satisfied update diss_flag accordingly and append a diss_note indicating the reason for the observation exclusion from the dissemination
|
|
274
274
|
.withColumn(
|
|
275
|
-
"
|
|
275
|
+
"diss_note",
|
|
276
276
|
F.when(
|
|
277
277
|
~col("condition_result"),
|
|
278
278
|
F.array_append(
|
|
279
|
-
col("
|
|
279
|
+
col("diss_note"), lit(f"{col_type} out of time validity range")
|
|
280
280
|
),
|
|
281
|
-
).otherwise(col("
|
|
281
|
+
).otherwise(col("diss_note")),
|
|
282
282
|
)
|
|
283
283
|
.drop("condition_result")
|
|
284
284
|
)
|
|
@@ -390,7 +390,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
390
390
|
col_name (str): The DataFrame column name on which to apply the filter
|
|
391
391
|
|
|
392
392
|
Returns:
|
|
393
|
-
DataFrame: The DataFrame with updated `diss_flag` and `
|
|
393
|
+
DataFrame: The DataFrame with updated `diss_flag` and `diss_note` columns based on the check outcome
|
|
394
394
|
"""
|
|
395
395
|
|
|
396
396
|
# Remove the duplicates that may be in the tables
|
|
@@ -428,14 +428,14 @@ class SWSSilverIcebergSparkHelper:
|
|
|
428
428
|
col("diss_flag") & col("condition_result"),
|
|
429
429
|
)
|
|
430
430
|
.withColumn(
|
|
431
|
-
"
|
|
431
|
+
"diss_note",
|
|
432
432
|
F.when(
|
|
433
433
|
~col("condition_result"),
|
|
434
434
|
F.array_append(
|
|
435
|
-
col("
|
|
435
|
+
col("diss_note"),
|
|
436
436
|
lit(f"{col_type} not disseminated for this domain"),
|
|
437
437
|
),
|
|
438
|
-
).otherwise(col("
|
|
438
|
+
).otherwise(col("diss_note")),
|
|
439
439
|
)
|
|
440
440
|
.drop("condition_result")
|
|
441
441
|
)
|
|
@@ -522,16 +522,16 @@ class SWSSilverIcebergSparkHelper:
|
|
|
522
522
|
col("diss_flag") & col("condition_result"),
|
|
523
523
|
)
|
|
524
524
|
.withColumn(
|
|
525
|
-
"
|
|
525
|
+
"diss_note",
|
|
526
526
|
F.when(
|
|
527
527
|
~col("condition_result"),
|
|
528
528
|
F.array_append(
|
|
529
|
-
col("
|
|
529
|
+
col("diss_note"),
|
|
530
530
|
lit(
|
|
531
531
|
f"not disseminated according to exception with note: {row_exception['note']}"
|
|
532
532
|
),
|
|
533
533
|
),
|
|
534
|
-
).otherwise(col("
|
|
534
|
+
).otherwise(col("diss_note")),
|
|
535
535
|
)
|
|
536
536
|
.drop("condition_result")
|
|
537
537
|
)
|
|
@@ -616,7 +616,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
616
616
|
|
|
617
617
|
df = (
|
|
618
618
|
df.withColumn("metadata", F.to_json(col("metadata")))
|
|
619
|
-
.withColumn("
|
|
619
|
+
.withColumn("diss_note", F.to_json(col("diss_note")))
|
|
620
620
|
.coalesce(1)
|
|
621
621
|
)
|
|
622
622
|
|
|
@@ -650,7 +650,7 @@ class SWSSilverIcebergSparkHelper:
|
|
|
650
650
|
"value",
|
|
651
651
|
*self.flag_columns,
|
|
652
652
|
"diss_flag",
|
|
653
|
-
"
|
|
653
|
+
"diss_note",
|
|
654
654
|
],
|
|
655
655
|
)
|
|
656
656
|
tag = upsert_disseminated_table(
|
|
@@ -363,26 +363,26 @@ def map_codes_and_remove_null_duplicates(
|
|
|
363
363
|
"diss_flag", F.when(col("delete"), lit(False)).otherwise(col("diss_flag"))
|
|
364
364
|
)
|
|
365
365
|
.withColumn(
|
|
366
|
-
"
|
|
366
|
+
"diss_note",
|
|
367
367
|
F.when(
|
|
368
368
|
col("delete"),
|
|
369
369
|
F.array_append(
|
|
370
|
-
col("
|
|
370
|
+
col("diss_note"),
|
|
371
371
|
lit(
|
|
372
372
|
f"The observation is not disseminated according to the Mapping - Code correction table"
|
|
373
373
|
),
|
|
374
374
|
),
|
|
375
|
-
).otherwise(col("
|
|
375
|
+
).otherwise(col("diss_note")),
|
|
376
376
|
)
|
|
377
377
|
# Add mapping message to notes
|
|
378
378
|
.withColumn(
|
|
379
|
-
"
|
|
379
|
+
"diss_note",
|
|
380
380
|
F.when(
|
|
381
381
|
~col("is_duplicate")
|
|
382
382
|
& col("new_dim_code").isNotNull()
|
|
383
383
|
& (col("new_dim_code") != lit("")),
|
|
384
384
|
F.array_append(
|
|
385
|
-
col("
|
|
385
|
+
col("diss_note"),
|
|
386
386
|
F.concat(
|
|
387
387
|
lit(f"Dimension {col_name} code was changed from "),
|
|
388
388
|
col(col_name),
|
|
@@ -390,7 +390,7 @@ def map_codes_and_remove_null_duplicates(
|
|
|
390
390
|
col("new_dim_code"),
|
|
391
391
|
),
|
|
392
392
|
),
|
|
393
|
-
).otherwise(col("
|
|
393
|
+
).otherwise(col("diss_note")),
|
|
394
394
|
)
|
|
395
395
|
.withColumn(
|
|
396
396
|
col_name,
|
|
@@ -409,18 +409,18 @@ def map_codes_and_remove_null_duplicates(
|
|
|
409
409
|
).otherwise(col("diss_flag")),
|
|
410
410
|
)
|
|
411
411
|
.withColumn(
|
|
412
|
-
"
|
|
412
|
+
"diss_note",
|
|
413
413
|
F.when(
|
|
414
414
|
col("is_duplicate")
|
|
415
415
|
& col("new_dim_code").isNotNull()
|
|
416
416
|
& (col("new_dim_code") != lit("")),
|
|
417
417
|
F.array_append(
|
|
418
|
-
col("
|
|
418
|
+
col("diss_note"),
|
|
419
419
|
lit(
|
|
420
420
|
f"The code correction was not applied to avoid observation duplications"
|
|
421
421
|
),
|
|
422
422
|
),
|
|
423
|
-
).otherwise(col("
|
|
423
|
+
).otherwise(col("diss_note")),
|
|
424
424
|
)
|
|
425
425
|
# Check the domain specific multiplier first and then the standard multiplier
|
|
426
426
|
.withColumn("value", col("value") * F.coalesce(col("multiplier"), lit(1)))
|
|
@@ -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.174
|
|
4
4
|
Summary: A Python helper package providing streamlined Spark functions for efficient data dissemination processes
|
|
5
5
|
Project-URL: Repository, https://github.com/un-fao/fao-sws-it-python-spark-dissemination-helper
|
|
6
6
|
Author-email: Daniele Mansillo <danielemansillo@gmail.com>
|
|
@@ -31,8 +31,8 @@ Classifier: Operating System :: OS Independent
|
|
|
31
31
|
Classifier: Programming Language :: Python :: 3
|
|
32
32
|
Requires-Python: >=3.9
|
|
33
33
|
Requires-Dist: annotated-types==0.7.0
|
|
34
|
-
Requires-Dist: boto3>=1.40.
|
|
35
|
-
Requires-Dist: botocore>=1.40.
|
|
34
|
+
Requires-Dist: boto3>=1.40.0
|
|
35
|
+
Requires-Dist: botocore>=1.40.0
|
|
36
36
|
Requires-Dist: certifi==2025.1.31
|
|
37
37
|
Requires-Dist: charset-normalizer==3.4.1
|
|
38
38
|
Requires-Dist: idna>=3.10
|
|
@@ -3,11 +3,11 @@ sws_spark_dissemination_helper/SWSDatatablesExportHelper.py,sha256=47DEQpj8HBSa-
|
|
|
3
3
|
sws_spark_dissemination_helper/SWSEasyIcebergSparkHelper.py,sha256=csqKyYglBkJSBvEkEa1_keHarZZAIJHaV0d64gGJy98,26379
|
|
4
4
|
sws_spark_dissemination_helper/SWSGoldIcebergSparkHelper.py,sha256=0dxbVkrhdaASapEffF5PFcgKwAMyJoWBxzgymjZ4JyY,25049
|
|
5
5
|
sws_spark_dissemination_helper/SWSPostgresSparkReader.py,sha256=KpG8gp8Ai9pHDiKhUOTcXWxxmFGeKEE3XKlI_Y-SveU,18453
|
|
6
|
-
sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py,sha256=
|
|
6
|
+
sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py,sha256=EXpqPHbxld8MPShE6Vo8h4y1vpBt_BjMtS4RPJcPeTU,26355
|
|
7
7
|
sws_spark_dissemination_helper/__init__.py,sha256=42TPbk7KxAud_qY3Sr_F4F7VjyofUlxEJkUXAFQsjRo,327
|
|
8
8
|
sws_spark_dissemination_helper/constants.py,sha256=vQmalAqInwPAybgJOfYx99jn47KsKp8jeD8eqmjw-Rs,13471
|
|
9
|
-
sws_spark_dissemination_helper/utils.py,sha256=
|
|
10
|
-
sws_spark_dissemination_helper-0.0.
|
|
11
|
-
sws_spark_dissemination_helper-0.0.
|
|
12
|
-
sws_spark_dissemination_helper-0.0.
|
|
13
|
-
sws_spark_dissemination_helper-0.0.
|
|
9
|
+
sws_spark_dissemination_helper/utils.py,sha256=Ge8zXsUIcvFihALDNLF5kCu_tAdRQUE04xE6Yn9xQF4,22008
|
|
10
|
+
sws_spark_dissemination_helper-0.0.174.dist-info/METADATA,sha256=pcpz4oiaRq6M9u1k7H_h4HPfG9n5R3uvXT33WZY-gf4,2822
|
|
11
|
+
sws_spark_dissemination_helper-0.0.174.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
sws_spark_dissemination_helper-0.0.174.dist-info/licenses/LICENSE,sha256=zFzeb_j_6pXEHwH8Z0OpIkKFJk7vmhZjdem-K0d4zU4,1073
|
|
13
|
+
sws_spark_dissemination_helper-0.0.174.dist-info/RECORD,,
|
|
File without changes
|