You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Alessandro Solimando (Jira)" <ji...@apache.org> on 2025/01/23 17:56:00 UTC

[jira] [Updated] (CALCITE-6795) Correlated sub-query is not resolving correlation variables

     [ https://issues.apache.org/jira/browse/CALCITE-6795?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alessandro Solimando updated CALCITE-6795:
------------------------------------------
    Summary: Correlated sub-query is not resolving correlation variables  (was: Correlated sub-query is not resolving correlation varables.)

> Correlated sub-query is not resolving correlation variables
> -----------------------------------------------------------
>
>                 Key: CALCITE-6795
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6795
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.38.0
>            Reporter: Justin Swett
>            Priority: Major
>
> The following test will result in a NPE "variable $cor0 is not found".
> {code:java}
>   @Test void testCSS() {
>     String query = "SELECT p.\"product_name\", SUM(s.\"store_sales\"), "
>         + "(SELECT MAX(s2.\"store_sales\") FROM \"sales_fact_1997\" s2 "
>         + "WHERE s2.\"product_id\" = p.\"product_id\") AS max_sold_for_product "
>         + "FROM \"product\" p "
>         + "JOIN \"sales_fact_1997\" s ON p.\"product_id\" = s.\"product_id\" "
>         + "GROUP BY p.\"product_name\", p.\"product_id\"";    String expected = "SELECT \"product\".\"product_name\", SUM(\"sales_fact_1997\".\"store_sales\"), (((SELECT MAX(\"store_sales\")\n"
>         + "FROM \"foodmart\".\"sales_fact_1997\"\n"
>         + "WHERE \"product_id\" = \"sales_fact_19970\".\"time_id\"))) AS \"MAX_SOLD_FOR_PRODUCT\"\n"
>         + "FROM \"foodmart\".\"product\"\n"
>         + "INNER JOIN \"foodmart\".\"sales_fact_1997\" ON \"product\".\"product_id\" = \"sales_fact_1997\".\"product_id\"\n"
>         + "GROUP BY \"product\".\"product_name\", \"product\".\"product_id\"";
>     sql(query).withConfig(c -> c.withExpand(false)).ok(expected);
>   } {code}
>  
> At first glance, the issue seems to be related to whether or not the correlation appears to be in scope. Stepping through `SqlToRelConverter.getCorrelationUse` I noticed that correlInCurrentScope is false and if I set value to true then the test passes.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)