sws-spark-dissemination-helper 0.0.160__py3-none-any.whl → 0.0.162__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/SWSEasyIcebergSparkHelper.py +77 -29
- sws_spark_dissemination_helper/SWSGoldIcebergSparkHelper.py +25 -0
- sws_spark_dissemination_helper/constants.py +3 -0
- {sws_spark_dissemination_helper-0.0.160.dist-info → sws_spark_dissemination_helper-0.0.162.dist-info}/METADATA +1 -1
- {sws_spark_dissemination_helper-0.0.160.dist-info → sws_spark_dissemination_helper-0.0.162.dist-info}/RECORD +7 -7
- {sws_spark_dissemination_helper-0.0.160.dist-info → sws_spark_dissemination_helper-0.0.162.dist-info}/WHEEL +0 -0
- {sws_spark_dissemination_helper-0.0.160.dist-info → sws_spark_dissemination_helper-0.0.162.dist-info}/licenses/LICENSE +0 -0
|
@@ -276,11 +276,17 @@ class SWSEasyIcebergSparkHelper:
|
|
|
276
276
|
if not self.keep_history:
|
|
277
277
|
final_query += "\nWHERE o.replaced_on IS NULL"
|
|
278
278
|
|
|
279
|
-
logging.info("Final query for merging observation and
|
|
279
|
+
logging.info("Final query for merging observation and observation_coordinates")
|
|
280
280
|
logging.info(final_query)
|
|
281
281
|
|
|
282
282
|
df_obs_denorm = self.spark.sql(final_query)
|
|
283
283
|
|
|
284
|
+
df_obs_denorm.writeTo(
|
|
285
|
+
self.iceberg_tables.DENORMALIZED_OBSERVATION.iceberg_id
|
|
286
|
+
).createOrReplace()
|
|
287
|
+
|
|
288
|
+
logging.info(f"{self.iceberg_tables.DENORMALIZED_OBSERVATION.table} write")
|
|
289
|
+
|
|
284
290
|
return df_obs_denorm
|
|
285
291
|
|
|
286
292
|
def _gen_denormalized_observation_sql_from_tag(self) -> DataFrame:
|
|
@@ -418,7 +424,13 @@ class SWSEasyIcebergSparkHelper:
|
|
|
418
424
|
|
|
419
425
|
df_meta_denorm = self.spark.sql(
|
|
420
426
|
f"""
|
|
421
|
-
select
|
|
427
|
+
select
|
|
428
|
+
/*+
|
|
429
|
+
BROADCAST({self.dataset_tables.METADATA_ELEMENT_TYPE.iceberg_id}),
|
|
430
|
+
BROADCAST({self.dataset_tables.METADATA_TYPE.iceberg_id}),
|
|
431
|
+
BROADCAST({self.dataset_tables.LANGUAGE.iceberg_id}),
|
|
432
|
+
*/
|
|
433
|
+
m.observation as observation_id,
|
|
422
434
|
mt.code as type,
|
|
423
435
|
met.code as element_type,
|
|
424
436
|
l.country_code as language,
|
|
@@ -431,7 +443,11 @@ class SWSEasyIcebergSparkHelper:
|
|
|
431
443
|
"""
|
|
432
444
|
)
|
|
433
445
|
|
|
434
|
-
|
|
446
|
+
df_meta_denorm.writeTo(
|
|
447
|
+
self.iceberg_tables.DENORMALIZED_METADATA.iceberg_id
|
|
448
|
+
).createOrReplace()
|
|
449
|
+
|
|
450
|
+
logging.info(f"{self.iceberg_tables.DENORMALIZED_METADATA.table} write")
|
|
435
451
|
|
|
436
452
|
return df_meta_denorm
|
|
437
453
|
|
|
@@ -456,25 +472,31 @@ class SWSEasyIcebergSparkHelper:
|
|
|
456
472
|
)
|
|
457
473
|
|
|
458
474
|
def _gen_grouped_metadata_sql(self) -> DataFrame:
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
.groupby("observation_id")
|
|
475
|
-
.agg(F.collect_list("metadata").alias("metadata"))
|
|
475
|
+
df_meta_grouped = self.spark.sql(
|
|
476
|
+
f"""
|
|
477
|
+
SELECT
|
|
478
|
+
observation_id,
|
|
479
|
+
collect_list(
|
|
480
|
+
map(
|
|
481
|
+
'type', type,
|
|
482
|
+
'element_type', element_type,
|
|
483
|
+
'language', language,
|
|
484
|
+
'value', value
|
|
485
|
+
)
|
|
486
|
+
) AS metadata
|
|
487
|
+
FROM {self.iceberg_tables.DENORMALIZED_METADATA.iceberg_id}
|
|
488
|
+
GROUP BY observation_id
|
|
489
|
+
"""
|
|
476
490
|
)
|
|
477
491
|
|
|
492
|
+
df_meta_grouped.writeTo(
|
|
493
|
+
self.iceberg_tables.GROUPED_METADATA.iceberg_id
|
|
494
|
+
).createOrReplace()
|
|
495
|
+
|
|
496
|
+
logging.info(f"{self.iceberg_tables.GROUPED_METADATA.table} write")
|
|
497
|
+
|
|
498
|
+
return df_meta_grouped
|
|
499
|
+
|
|
478
500
|
def _gen_denormalied_data(self) -> DataFrame:
|
|
479
501
|
return (
|
|
480
502
|
self._gen_denormalized_observation()
|
|
@@ -488,15 +510,15 @@ class SWSEasyIcebergSparkHelper:
|
|
|
488
510
|
)
|
|
489
511
|
|
|
490
512
|
def _gen_denormalied_data_sql(self) -> DataFrame:
|
|
491
|
-
return (
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
513
|
+
return self.spark.sql(
|
|
514
|
+
f"""
|
|
515
|
+
SELECT
|
|
516
|
+
o.*,
|
|
517
|
+
m.metadata
|
|
518
|
+
FROM {self.iceberg_tables.GROUPED_METADATA.iceberg_id} AS o
|
|
519
|
+
LEFT JOIN {self.iceberg_tables.GROUPED_METADATA.iceberg_id} AS m
|
|
520
|
+
ON o.id = m.observation_id
|
|
521
|
+
"""
|
|
500
522
|
)
|
|
501
523
|
|
|
502
524
|
def _gen_denormalied_data_sql_from_tag(self) -> DataFrame:
|
|
@@ -669,3 +691,29 @@ class SWSEasyIcebergSparkHelper:
|
|
|
669
691
|
logging.debug(f"Tag with Added csv Table: {tag}")
|
|
670
692
|
|
|
671
693
|
logging.info("Filtered data tags successfully written")
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
1
|
|
697
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
698
|
+
1
|
|
699
|
+
1
|
|
700
|
+
2
|
|
701
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
702
|
+
2
|
|
703
|
+
1
|
|
704
|
+
1
|
|
705
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
706
|
+
1
|
|
707
|
+
1
|
|
708
|
+
2
|
|
709
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
710
|
+
2
|
|
711
|
+
1
|
|
712
|
+
1
|
|
713
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
714
|
+
1
|
|
715
|
+
1
|
|
716
|
+
1
|
|
717
|
+
frozenset({"1", "0", "7", "9", "4", "8", "6", "3", "2", "5"})
|
|
718
|
+
1
|
|
719
|
+
1
|
|
@@ -271,6 +271,31 @@ class SWSGoldIcebergSparkHelper:
|
|
|
271
271
|
|
|
272
272
|
return df
|
|
273
273
|
|
|
274
|
+
def write_gold_faostat_data_to_iceberg_and_csv(self, df: DataFrame) -> DataFrame:
|
|
275
|
+
"""The expected input to this function is the output of the sws disseminated function"""
|
|
276
|
+
df.writeTo(self.iceberg_tables.GOLD_FAOSTAT.iceberg_id).createOrReplace()
|
|
277
|
+
|
|
278
|
+
logging.info(
|
|
279
|
+
f"Gold FAOSTAT table written to {self.iceberg_tables.GOLD_FAOSTAT.iceberg_id}"
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
self.spark.sql(
|
|
283
|
+
f"ALTER TABLE {self.iceberg_tables.GOLD_FAOSTAT.iceberg_id} CREATE OR REPLACE TAG `{self.tag_name}`"
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
logging.info(f"gold FAOSTAT tag '{self.tag_name}' created")
|
|
287
|
+
|
|
288
|
+
df_1 = df.coalesce(1)
|
|
289
|
+
|
|
290
|
+
save_cache_csv(
|
|
291
|
+
df=df_1,
|
|
292
|
+
bucket=self.bucket,
|
|
293
|
+
prefix=self.iceberg_tables.GOLD_FAOSTAT.csv_prefix,
|
|
294
|
+
tag_name=self.tag_name,
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
return df
|
|
298
|
+
|
|
274
299
|
def write_gold_sws_validated_sws_dissemination_tag(
|
|
275
300
|
self, df: DataFrame, tags: Tags
|
|
276
301
|
) -> DataFrame:
|
|
@@ -254,6 +254,9 @@ class IcebergTables:
|
|
|
254
254
|
self.__tag_name = tag_name
|
|
255
255
|
|
|
256
256
|
# TODO Fix later with a more appropriate DATABASE
|
|
257
|
+
self.DENORMALIZED_OBSERVATION = self._create_iceberg_table("BRONZE", suffix="denormalized_observation")
|
|
258
|
+
self.DENORMALIZED_METADATA = self._create_iceberg_table("BRONZE", suffix="denormalized_metadata")
|
|
259
|
+
self.GROUPED_METADATA = self._create_iceberg_table("BRONZE", suffix="grouped_metadata")
|
|
257
260
|
self.TABLE = self._create_iceberg_table("BRONZE")
|
|
258
261
|
self.TABLE_FILTERED = self._create_iceberg_table("BRONZE", suffix="filtered")
|
|
259
262
|
self.BRONZE = self._create_iceberg_table("BRONZE")
|
|
@@ -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.162
|
|
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>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
sws_spark_dissemination_helper/SWSBronzeIcebergSparkHelper.py,sha256=ocuau0WtpyRwui0qwdQ_Rxh4nYPOyZoHpGKaWRa6B3Q,28868
|
|
2
2
|
sws_spark_dissemination_helper/SWSDatatablesExportHelper.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
sws_spark_dissemination_helper/SWSEasyIcebergSparkHelper.py,sha256=
|
|
4
|
-
sws_spark_dissemination_helper/SWSGoldIcebergSparkHelper.py,sha256=
|
|
3
|
+
sws_spark_dissemination_helper/SWSEasyIcebergSparkHelper.py,sha256=Ko_gUE4ar2iR1zvIXiyq_bvfLVVjDrHwMJpef8CWipk,26235
|
|
4
|
+
sws_spark_dissemination_helper/SWSGoldIcebergSparkHelper.py,sha256=cHEKA4whB4tVzZrsRoGkbdSDRgdfZA77xifYvA2XZMU,22091
|
|
5
5
|
sws_spark_dissemination_helper/SWSPostgresSparkReader.py,sha256=KpG8gp8Ai9pHDiKhUOTcXWxxmFGeKEE3XKlI_Y-SveU,18453
|
|
6
6
|
sws_spark_dissemination_helper/SWSSilverIcebergSparkHelper.py,sha256=qioLv3SlJEfk0LzTiwfXRtZXVImPOJUeh9k1XwHC-pA,26225
|
|
7
7
|
sws_spark_dissemination_helper/__init__.py,sha256=42TPbk7KxAud_qY3Sr_F4F7VjyofUlxEJkUXAFQsjRo,327
|
|
8
|
-
sws_spark_dissemination_helper/constants.py,sha256=
|
|
8
|
+
sws_spark_dissemination_helper/constants.py,sha256=zviO6huxWTWonHv4v2M8zKr7HXCDMBGqjHx-eTfGT2A,13487
|
|
9
9
|
sws_spark_dissemination_helper/utils.py,sha256=G7lQqNRrvqZpgm9WmddD7fWsI8IVn09x1p3cV3458EA,21963
|
|
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.
|
|
10
|
+
sws_spark_dissemination_helper-0.0.162.dist-info/METADATA,sha256=WRolvgcPvN8XgSPJ9fo0DirLLBSdEQ8b0fUhoayKSmY,2824
|
|
11
|
+
sws_spark_dissemination_helper-0.0.162.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
12
|
+
sws_spark_dissemination_helper-0.0.162.dist-info/licenses/LICENSE,sha256=zFzeb_j_6pXEHwH8Z0OpIkKFJk7vmhZjdem-K0d4zU4,1073
|
|
13
|
+
sws_spark_dissemination_helper-0.0.162.dist-info/RECORD,,
|
|
File without changes
|