From b849403eb7a09aa8d80adce069f9da807ac0f0e1 Mon Sep 17 00:00:00 2001 From: Adam Kariv Date: Thu, 27 Jun 2024 00:56:01 +0300 Subject: [PATCH] debug simpledb --- .../pipelines/simpledb/process.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/datapackage_pipelines_budgetkey/pipelines/simpledb/process.py b/datapackage_pipelines_budgetkey/pipelines/simpledb/process.py index 3e1c1b38..15219322 100644 --- a/datapackage_pipelines_budgetkey/pipelines/simpledb/process.py +++ b/datapackage_pipelines_budgetkey/pipelines/simpledb/process.py @@ -442,7 +442,7 @@ def debug_source(source, debug): ''', possible_values=['approval', 'payment'], type='string', - default=lambda row: 'payment' if row.get('year_paid') else 'approval', + default=lambda row: ('payment' if row.get('year_paid') else 'approval'), ), dict( name='year', @@ -451,7 +451,7 @@ def debug_source(source, debug): ''', sample_values=[2017, 2023, 2024], type='integer', - default=lambda row: row.get('year_requested') if row['value_kind'] == 'approval' else row.get('year_paid'), + default=lambda row: (row.get('year_requested') if row['value_kind'] == 'approval' else row.get('year_paid')), ), dict( name='amount', @@ -460,7 +460,7 @@ def debug_source(source, debug): ''', sample_values=[1000000, 5000000, 10000000], type='number', - default=lambda row: row.get('amount_approved') if row['value_kind'] == 'approval' else row.get('amount_total'), + default=lambda row: (row.get('amount_approved') if row['value_kind'] == 'approval' else row.get('amount_total')), filter=lambda x: x is not None and x > 0 ), dict( @@ -498,7 +498,7 @@ def debug_source(source, debug): 'private_person', ], type='string', - default=lambda row: row.get('entity_kind') or 'private_person' + default=lambda row: (row.get('entity_kind') or 'private_person') ), ], search=dict( @@ -520,6 +520,11 @@ def debug_source(source, debug): ), ) +def print_descriptor(package: DF.PackageWrapper): + print(json.dumps(package.pkg.descriptor, indent=2)) + yield package.pkg + yield from package + def get_flow(table, params, debug=False): steps = [] source = debug_source(params['source'], debug) @@ -548,6 +553,7 @@ def get_flow(table, params, debug=False): steps.append(DF.select_fields(field_names)) if not debug: + steps.append(print_descriptor) steps.append(DF.dump_to_path(f'/var/datapackages/simpledb/{table}')) steps.append(DF.dump_to_sql({table: {'resource-name': table}})) else: