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

ASF GitHub Bot updated CALCITE-7546:
------------------------------------
    Labels: pull-request-available  (was: )

> NullPointerException in SqlToRelConverter for UNNEST(array) AS alias under 
> conformance with allowAliasUnnestItems=true
> ----------------------------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-7546
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7546
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.40.0
>         Environment:   - Calcite: 1.40.0
>   - JDK: Temurin 25+36-LTS
>   - OS: macOS (darwin 23.3.0)
>   - JUnit: 5
>            Reporter: tnakama
>            Priority: Major
>              Labels: pull-request-available
>
>  
>   When SqlConformance#allowAliasUnnestItems() returns true (in stock Calcite 
> this is only SqlConformanceEnum.PRESTO; user-defined conformances overriding 
> this flag
>   are also affected), a query of the form
>   SELECT t FROM UNNEST(ARRAY[1, 2, 3]) AS t
>   throws NullPointerException: fieldNames during SQL-to-Rel conversion.
>   Root cause
>   
>   In SqlToRelConverter#convertFrom, the AS branch with operandCount() == 2 
> (table alias only, no column list) delegates to convertUnnest with fieldNames 
> == null.
>   The allowAliasUnnestItems branch of convertUnnest then calls 
> Objects.requireNonNull(fieldNames, "fieldNames") and throws.
>   The bug is latent under the default conformance because 
> allowAliasUnnestItems() is false there, so the offending branch is never 
> entered. Adding an explicit
>   column list (AS t(x)) also avoids the NPE because convertFrom then routes 
> through the operandCount() == 3 branch that populates fieldNames.
>   Reproducer
>   ---
>   package jp.co.plaid.mila.processing.sql.convert;
>   import org.junit.jupiter.api.Test;
>   import java.sql.Connection;
>   import java.sql.DriverManager;
>   import java.sql.SQLException;
>   import java.sql.Statement;
>   import java.util.Properties;
>   class CalciteUnnestAliasNpeReproducerTest {
>     @Test
>     void unnestWithTableAliasOnly_throwsNpe_underPrestoConformance() throws 
> SQLException {
>       Properties info = new Properties();
>       info.setProperty("conformance", "PRESTO");
>       Connection conn = DriverManager.getConnection("jdbc:calcite:", info);
>       Statement stmt = conn.createStatement();
>       stmt.executeQuery("SELECT t FROM UNNEST(ARRAY[1, 2, 3]) AS t");
>     }
>   }
> ---
>   Expected behavior
>   
>   UNNEST(array) AS alias under a conformance with allowAliasUnnestItems() == 
> true should either:
>   - be treated as AS alias(alias) (single-column alias, matching common 
> BigQuery/Presto-like semantics), or
>   - produce a clear validation error rather than an internal NPE.
>  



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

Reply via email to