[ 
https://issues.apache.org/jira/browse/IMPALA-14335?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18015577#comment-18015577
 ] 

Quanlong Huang commented on IMPALA-14335:
-----------------------------------------

[~MadBeeDo] Thanks for reporting this!

A simpler way to reproduce the issue:
{code:sql}
create table my_ice_tbl (i int, s string) partitioned by (p int) stored as 
iceberg;
create table my_tbl(i int);

explain merge into my_ice_tbl t
using (
  select i, row_number() over(order by i) as rk from my_tbl
) as s
on t.i = s.i
when matched then delete
when not matched then insert (i, s) values (s.i, 'new');{code}
The error is "IllegalStateException: Illegal reference to non-materialized 
tuple: tid=2".

BTW, I'm not sure if it's intended to support inline views in the USING clause. 
But it looks useful.

CC [~prozsa] 

> Error when using merge into iceberg table:Illegal reference to 
> non-materialized tuple: tid=2
> --------------------------------------------------------------------------------------------
>
>                 Key: IMPALA-14335
>                 URL: https://issues.apache.org/jira/browse/IMPALA-14335
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Backend
>    Affects Versions: Impala 4.5.0
>         Environment: rocky linux 8
>            Reporter: Pain Sun
>            Priority: Major
>
> When using the MERGE operation in an Iceberg table, an error will occur if 
> the source table contains window functions.
> MERGE INTO test111.icebergtest t USING (
>     select
>         updatetime_day,
>         mainsellernick,
>         code,
>         num_channelid,
>         tid
>     from
>         (
>             select
>                 updatetime_day,
>                 mainsellernick,
>                 code,
>                 num_channelid,
>                 tid,
>                 row_number() over(
>                     partition by updatetime_day,
>                     mainsellernick,
>                     code
>                     order by
>                         updatetime desc
>                 ) as rk
>             from
>                 (
>                     select
>                         20250709 as updatetime_day,
>                         'sjztest' as mainsellernick,
>                         'code1' as code,
>                         'tid1' as tid,
>                         6 as num_channelid,
>                         cast('2025-08-21 00:00:00' as timestamp) as updatetime
>                     union
>                     all
>                     select
>                         20250709 as updatetime_day,
>                         'sjztest' as mainsellernick,
>                         'code1' as code,
>                         'tid1' as tid,
>                         6 as num_channelid,
>                         cast('2025-08-22 00:00:00' as timestamp) as updatetime
>                     union
>                     all
>                     select
>                         20250709 as updatetime_day,
>                         'sjztest' as mainsellernick,
>                         'code3' as code,
>                         'tid3' as tid,
>                         6 as num_channelid,
>                         cast('2025-08-21 00:00:00' as timestamp) as updatetime
>                     union
>                     all
>                     select
>                         20250709 as updatetime_day,
>                         'sjztest' as mainsellernick,
>                         'code5' as code,
>                         'tid5' as tid,
>                         6 as num_channelid,
>                         cast('2025-08-21 00:00:00' as timestamp) as updatetime
>                 ) as a
>         ) as a
>     where
>         rk = 1
> ) s ON t.updatetime_day = s.updatetime_day
> and t.mainsellernick = s.mainsellernick
> and t.code = s.code
> WHEN MATCHED THEN
> UPDATE
> SET
>     t.tid = s.tid,
>     t.num_channelid = s.num_channelid
>     WHEN NOT MATCHED THEN
> INSERT
>     (
>         updatetime_day,
>         mainsellernick,
>         code,
>         tid,
>         num_channelid
>     )
> VALUES
>     (
>         s.updatetime_day,
>         s.mainsellernick,
>         s.code,
>         s.tid,
>         s.num_channelid
>     );
> IllegalStateException: Illegal reference to non-materialized tuple: tid=3
> I0821 14:02:16.392138 134791 jni-util.cc:321] 
> a844461a0a7aa168:55012b5200000000] java.lang.IllegalStateException: Illegal 
> reference to non-materialized tuple: tid=3
>         at 
> com.google.common.base.Preconditions.checkState(Preconditions.java:512)
>         at 
> org.apache.impala.analysis.TupleIsNullPredicate.toThrift(TupleIsNullPredicate.java:94)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:905)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at 
> org.apache.impala.analysis.CastExpr.treeToThriftHelper(CastExpr.java:273)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at 
> org.apache.impala.analysis.CastExpr.treeToThriftHelper(CastExpr.java:273)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at 
> org.apache.impala.analysis.CastExpr.treeToThriftHelper(CastExpr.java:273)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at org.apache.impala.analysis.Expr.treeToThriftHelper(Expr.java:908)
>         at 
> org.apache.impala.analysis.CastExpr.treeToThriftHelper(CastExpr.java:273)
>         at org.apache.impala.analysis.Expr.treeToThrift(Expr.java:883)
>         at org.apache.impala.analysis.Expr.treeToThrift(Expr.java:869)
>         at 
> org.apache.impala.planner.IcebergMergeNode.toThrift(IcebergMergeNode.java:79)
>         at org.apache.impala.planner.PlanNode.toThrift(PlanNode.java:878)
>         at 
> org.apache.impala.planner.PlanNode.treeToThriftHelper(PlanNode.java:585)
>         at org.apache.impala.planner.PlanNode.treeToThrift(PlanNode.java:516)
>         at 
> org.apache.impala.planner.PlanFragment.toThrift(PlanFragment.java:638)
>         at 
> org.apache.impala.service.Frontend.createPlanExecInfo(Frontend.java:1958)
>         at 
> org.apache.impala.service.Frontend.createExecRequest(Frontend.java:1988)
>         at 
> org.apache.impala.service.Frontend.getPlannedExecRequest(Frontend.java:3015)
>         at 
> org.apache.impala.service.Frontend.doCreateExecRequest(Frontend.java:2773)
>         at 
> org.apache.impala.service.Frontend.getTExecRequest(Frontend.java:2291)
>         at 
> org.apache.impala.service.Frontend.createExecRequest(Frontend.java:2032)
>         at 
> org.apache.impala.service.JniFrontend.createExecRequest(JniFrontend.java:171)
> I0821 14:02:16.392177 134791 status.cc:129] 
> a844461a0a7aa168:55012b5200000000] IllegalStateException: Illegal reference 
> to non-materialized tuple: tid=3
>     @          0x10a31d4
>     @          0x1c1a17a
>     @          0x17ce990
>     @          0x24ab806
>     @          0x24aba44
>     @          0x19185ca
>     @          0x19254ba
>     @          0x18a1495
>     @          0x1a1db81
>     @          0x19e8653
>     @           0xf8b7fb
>     @          0x14a8a42
>     @          0x1cff659
>     @          0x264d407
>     @     0x1503959ce1ca
>     @     0x1503928778d3



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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscr...@impala.apache.org
For additional commands, e-mail: issues-all-h...@impala.apache.org

Reply via email to