|
| 1 | +""" |
| 2 | +Only need to change the table name and the query prototyped on the Athena UI |
| 3 | +by replacing table_name and query_on_athena |
| 4 | +""" |
| 5 | + |
| 6 | +from scripts.helpers.athena_helpers import create_update_table_with_partition |
| 7 | +from scripts.helpers.helpers import get_glue_env_var |
| 8 | + |
| 9 | +environment = get_glue_env_var("environment") |
| 10 | + |
| 11 | +# The target table in liberator refined zone |
| 12 | +table_name = "Parking_cycle_hangar_interim_wait_list" |
| 13 | + |
| 14 | +# The exact same query prototyped in pre-prod(stg) orprod Athena |
| 15 | +query_on_athena = """ |
| 16 | +/********************************************************************************* |
| 17 | +Parking_cycle_hangar_interim_wait_list |
| 18 | +
|
| 19 | +This SQL binds the interim waiting list to the spatial llpg data |
| 20 | +
|
| 21 | +27/11/2024 - Create Query |
| 22 | +*********************************************************************************/ |
| 23 | +/* Obtain the latest llpg data */ |
| 24 | +with llpg as ( |
| 25 | + SELECT * FROM "parking-refined-zone".spatially_enriched_liberator_permit_llpg |
| 26 | + WHERE import_date = (Select MAX(import_date) |
| 27 | + from "parking-refined-zone".spatially_enriched_liberator_permit_llpg)) |
| 28 | +
|
| 29 | +/* Collect and output the imterim Waiting list and link records to above */ |
| 30 | +SELECT |
| 31 | + forename, surname, email, party_id_to, party_id, A.uprn, A.address1, A.address2, A.postcode, |
| 32 | + A.x, A.y, A.lat, A.long, housing_estate, |
| 33 | + |
| 34 | + format_datetime(CAST(CURRENT_TIMESTAMP AS timestamp), 'yyyy-MM-dd HH:mm:ss') AS importdatetime, |
| 35 | +
|
| 36 | + format_datetime(current_date, 'yyyy') AS import_year, |
| 37 | + format_datetime(current_date, 'MM') AS import_month, |
| 38 | + format_datetime(current_date, 'dd') AS import_day, |
| 39 | + format_datetime(current_date, 'yyyyMMdd') AS import_date |
| 40 | +FROM "parking-raw-zone".parking_parking_cycle_hangar_manual_waiting_list as A |
| 41 | +LEFT JOIN llpg as B ON cast(A.uprn as decimal(20,0)) = B.uprn |
| 42 | +WHERE A.import_Date = format_datetime(current_date, 'yyyyMMdd') |
| 43 | +""" |
| 44 | + |
| 45 | +create_update_table_with_partition( |
| 46 | + environment=environment, query_on_athena=query_on_athena, table_name=table_name |
| 47 | +) |
0 commit comments