Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sort in the query to keep linear index per asset in the storage constraint #1010

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 43 additions & 23 deletions src/variables/create.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,57 @@ function _create_variables_tables(connection)
connection,
"CREATE OR REPLACE TEMP SEQUENCE id START 1;
CREATE OR REPLACE TABLE var_storage_level_rep_period AS
WITH filtered_assets AS (
SELECT
t_low.asset,
t_low.year,
t_low.rep_period,
t_low.time_block_start,
t_low.time_block_end
FROM t_lowest_all AS t_low
LEFT JOIN asset
ON t_low.asset = asset.asset
WHERE
asset.type = 'storage'
AND asset.is_seasonal = false
ORDER BY
t_low.asset,
t_low.year,
t_low.rep_period,
t_low.time_block_start
)
SELECT
nextval('id') as index,
t_low.asset,
t_low.year,
t_low.rep_period,
t_low.time_block_start,
t_low.time_block_end
FROM t_lowest_all AS t_low
LEFT JOIN asset
ON t_low.asset = asset.asset
WHERE
asset.type = 'storage'
AND asset.is_seasonal = false;
nextval('id') AS index,
filtered_assets.*
FROM filtered_assets
",
)

DuckDB.query(
connection,
"CREATE OR REPLACE TEMP SEQUENCE id START 1;
CREATE OR REPLACE TABLE var_storage_level_over_clustered_year AS
CREATE OR REPLACE TABLE var_storage_level_over_clustered_year AS
WITH filtered_assets AS (
SELECT
attr.asset,
attr.year,
attr.period_block_start,
attr.period_block_end
FROM asset_timeframe_time_resolution AS attr
LEFT JOIN asset
ON attr.asset = asset.asset
WHERE
asset.type = 'storage'
AND asset.is_seasonal = true
ORDER BY
attr.asset,
attr.year,
attr.period_block_start
)
SELECT
nextval('id') as index,
asset.asset,
attr.year,
attr.period_block_start,
attr.period_block_end,
FROM asset_timeframe_time_resolution AS attr
LEFT JOIN asset
ON attr.asset = asset.asset
WHERE
asset.type = 'storage'
nextval('id') AS index,
filtered_assets.*
FROM filtered_assets
",
)

Expand Down
Loading