You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add new tables to calculate the lowest resolution for flows that have a flows relationship (#1183)
* Add new merged table for flows relationships
* Add tests for the merged tables in the data preparation
* Simplify query to get flows relationship
* Improve tests of the data preparation
* Add comments from code review
* Update SQL to create new merged table
* Update tests according to code review
Copy file name to clipboardExpand all lines: src/data-preparation.jl
+6-52
Original file line number
Diff line number
Diff line change
@@ -374,7 +374,7 @@ end
374
374
create_merged_tables!(connection)
375
375
376
376
Create the internal tables of merged flows and assets time partitions to be used in the computation of the lowest and highest resolution tables.
377
-
The inputs tables are the flows table `flow_time_resolution_rep_period` and the assets table `asset_time_resolution_rep_period`.
377
+
The inputs tables are the flows table `flow_time_resolution_rep_period`, the assets table `asset_time_resolution_rep_period` and the `flows_relationships`.
378
378
All merged tables have the same columns: `asset`, `year`, `rep_period`, `time_block_start`, and `time_block_end`.
379
379
Given a "group" `(asset, year, rep_period)`, the table will have the list of all partitions that should be used to compute the resolution tables.
380
380
These are the output tables:
@@ -383,59 +383,13 @@ These are the output tables:
383
383
- `merged_assets_and_out_flows`: Union of `merged_out_flows` and `asset_time_resolution_rep_period`.
384
384
- `merged_all_flows`: Union (i.e., vertically concatenation) of the tables above.
385
385
- `merged_all`: Union of `merged_all_flows` and `asset_time_resolution_rep_period`.
386
+
- `merged_flows_relationship`: Set `asset` from `flow_time_resolution_rep_period` depending on `flows_relationships`
386
387
This function is intended for internal use.
387
388
"""
388
389
functioncreate_merged_tables!(connection)
389
-
# Incoming flows
390
-
DuckDB.execute(
391
-
connection,
392
-
"CREATE OR REPLACE TEMP TABLE merged_in_flows AS
393
-
SELECT DISTINCT to_asset as asset, year, rep_period, time_block_start, time_block_end
394
-
FROM flow_time_resolution_rep_period
395
-
",
396
-
)
397
-
398
-
# Outgoing flows
399
-
DuckDB.execute(
400
-
connection,
401
-
"CREATE OR REPLACE TEMP TABLE merged_out_flows AS
402
-
SELECT DISTINCT from_asset as asset, year, rep_period, time_block_start, time_block_end
403
-
FROM flow_time_resolution_rep_period
404
-
",
405
-
)
406
-
407
-
# Union of all assets and outgoing flows
408
-
DuckDB.execute(
409
-
connection,
410
-
"CREATE OR REPLACE TEMP TABLE merged_assets_and_out_flows AS
0 commit comments