-
Notifications
You must be signed in to change notification settings - Fork 6
Description
rgcam::runQuery() fails for GCAM-Europe regions but works for GCAM-core regions
When running queries that require double slash through rgcam, rgcam::runQuery(conn, co2_query, scenario, reg), the function fails whenever reg corresponds to a GCAM-Europe region, while it runs correctly for GCAM-core regions.
For example, if we introduce a double slash between subsector and technology:
co2_query <- "<emissionsQueryBuilder title=\"CO2 emissions by tech (nested subsector) (excluding resource production)\"> <axis1 name=\"technology\">technology</axis1> <axis2 name=\"Year\" optional=\"true\">emissions</axis2> <xPath buildList=\"true\" dataName=\"emissions\" group=\"false\" sumAll=\"false\" optional=\"true\"> *[@type = 'sector' ]/*[@type='subsector']//*[@type='technology')]//CO2/emissions/node() </xPath> <comments/> </emissionsQueryBuilder>"
The same query runs successfully in Model Interface, but fails in the rgcam package when querying GCAM-Europe regions.
Inspecting the output using the MI, we observed two irregularities when running the query with and without the double slash between subsector and technology:
1. Different values for some sector–subsector–technology entries
Example output differences:
| scenario | region | sector | subsector | technology | 1990 | 2005 | 2010 | 2015 | 2020 | 2025 | 2030 | 2035 | 2040 | 2045 | 2050 | 2065 | 2080 | 2095 | Units |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Ref (query with single slash) | Spain | alumina | gas | gas | 0.00662193 | 0.00399082 | 0.0529131 | 0.0772193 | 0.0889154 | 0.09128569 | 0.08693893 | 0.07746966 | 0.0675153 | 0.06089516 | 0.056721945 | 0 | 0 | 0 | MTC |
| Ref (query with double slash) | Spain | alumina | gas | gas | 0.01324386 | 0.00798164 | 0.1058262 | 0.1544386 | 0.1778308 | 0.18257138 | 0.17387786 | 0.15493932 | 0.1350306 | 0.12179032 | 0.11344389 | 0 | 0 | 0 | MTC |
2. New EU electricity-grid-related sectors missing unless // is used in XPath
The GCAM-Europe version introduces new electricity-grid sectors, which are base load generation, intermediate generation, peak generation, and subpeak generation. These only appear when XPath includes a double slash.
The exact error message when running:
rgcam::runQuery(conn, co2_query, scenario, "Spain")
is:
About to perform query: collection()/scenario About to perform query: collection()/scenario[ (@name='EU_NECP_LTT-Rev1' and @date='2025-10-11T09:44:43+01:00') ]/world/region[ (@name='Spain') ]/*[@type = 'sector' ]/*[@type='subsector']//*[@type='technology')]// CO2/emissions/node() In Function: 1765368225619 java.lang.ArrayIndexOutOfBoundsException: 8 at ModelInterface.ModelGUI2.xmldb.RunMIQuery.buildTable(RunMIQuery.java:188) ... Stopped at ...: java.lang.ArrayIndexOutOfBoundsException: 8 Rows: 0 Columns: 0
while, for instance running:
rgcam::runQuery(conn, co2_query, scenario, "USA")
works well.
@pralitp, do you have any idea why this query:
works correctly in MI, but fails when executed through rgcam, specifically for GCAM-Europe regions?
We though it could be related to:
-
differences in sector hierarchy introduced by the EU grid disaggregation?
-
an XPath expression that MI tolerates but
rgcam/BaseX does not? -
assumptions in
RunMIQuery.buildTable()that break with deeper or duplicated structures?
Any guidance would be very helpful! Thank you in advance!!