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

Zoltán Borók-Nagy commented on IMPALA-7108:
-------------------------------------------

 

Yes, these kind of queries couldn't be executed before IMPALA-6314.

The bug can be reproduced by the following simpler query:
{noformat}
select * from alltypes where int_col = (select f.id from (select * from 
alltypes limit 1) f);{noformat}
 

The analyzer (wrongly) expects that the subquery 
{noformat}
select f.id from (select * from alltypes limit 1) f{noformat}
returns multiple rows, therefore this query was rejected before IMPALA-6314. 
After IMPALA-6314, we add LIMIT 2 to these kind of subqueries in 
StmtRewriter.mergeExpr() and later we put a CardinalityCheckNode on top of 
them. We check this limit during planning time in the constructor of 
CardinalityCheckNode. However, at that point the planner is smart enough to add 
LIMIT 1 to the subquery, hence breaking our precondition.

It is the responsibility of SelectStmt.returnsSingleRow() to determine that a 
select statement can only return a single row and it fails to do that in this 
case. Adding the following code to SelectStmt.returnsSingleRow() fixes this 
exact issue:
{code:java}
List<TableRef> tableRefs = fromClause_.getTableRefs();
if (tableRefs.size() == 1 && tableRefs.get(0) instanceof InlineViewRef) {
  InlineViewRef inlineView = (InlineViewRef)tableRefs.get(0);
  if (inlineView.queryStmt_ instanceof SelectStmt) {
    SelectStmt selectStmt = (SelectStmt)inlineView.queryStmt_;
    return selectStmt.returnsSingleRow();
  }
}
{code}
But maybe we could do something better or more general. What do you think? Can 
you construct a query that still fails when it shouldn't?

 

>  IllegalStateException hit during CardinalityCheckNode.<init>
> -------------------------------------------------------------
>
>                 Key: IMPALA-7108
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7108
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>    Affects Versions: Impala 3.1.0
>            Reporter: Vincent Tran
>            Assignee: Zoltán Borók-Nagy
>            Priority: Major
>
> The following query produces an IllegalStateException:
> {noformat}
> [localhost:21000] tpch300_parquet> select i.* from lineitem i 
> where i.l_orderkey = ( select t.o_orderkey from ( select * from customer join 
> orders on customer.c_custkey = orders.o_custkey order by 1 limit 1)  t );
> {noformat}
> Could be related to the change in IMPALA-6314
> {noformat}
> I0601 12:24:52.200441  6760 Frontend.java:997] Analyzing query: select i.* 
> from lineitem i where i.l_orderkey = ( select t.o_orderkey from ( select * 
> from customer join orders on customer.c_custkey = orders.o_custkey order by 1 
> limit 1) t )
> I0601 12:24:52.206576  6760 Frontend.java:1009] Analysis finished.
> I0601 12:24:52.210525  6760 jni-util.cc:230] java.lang.IllegalStateException
>       at 
> com.google.common.base.Preconditions.checkState(Preconditions.java:129)
>       at 
> org.apache.impala.planner.CardinalityCheckNode.<init>(CardinalityCheckNode.java:45)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createInlineViewPlan(SingleNodePlanner.java:1104)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createTableRefNode(SingleNodePlanner.java:1525)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createTableRefsPlan(SingleNodePlanner.java:776)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createSelectPlan(SingleNodePlanner.java:614)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createQueryPlan(SingleNodePlanner.java:257)
>       at 
> org.apache.impala.planner.SingleNodePlanner.createSingleNodePlan(SingleNodePlanner.java:147)
>       at org.apache.impala.planner.Planner.createPlan(Planner.java:101)
>       at 
> org.apache.impala.service.Frontend.createExecRequest(Frontend.java:941)
>       at 
> org.apache.impala.service.Frontend.createExecRequest(Frontend.java:1062)
>       at 
> org.apache.impala.service.JniFrontend.createExecRequest(JniFrontend.java:156)
> I0601 12:24:52.274375  6760 status.cc:125] IllegalStateException: null
>     @          0x1891f69  impala::Status::Status()
>     @          0x1e70be6  impala::JniUtil::GetJniExceptionMsg()
>     @          0x1d2e909  impala::JniUtil::CallJniMethod<>()
>     @          0x1d2b563  impala::Frontend::GetExecRequest()
>     @          0x1d4d552  impala::ImpalaServer::ExecuteInternal()
>     @          0x1d4d09a  impala::ImpalaServer::Execute()
>     @          0x1db742c  impala::ImpalaServer::query()
>     @          0x2f0641e  beeswax::BeeswaxServiceProcessor::process_query()
>     @          0x2f0616c  beeswax::BeeswaxServiceProcessor::dispatchCall()
>     @          0x2edfc2d  impala::ImpalaServiceProcessor::dispatchCall()
>     @          0x18502f0  apache::thrift::TDispatchProcessor::process()
>     @          0x1bb1ac9  
> apache::thrift::server::TAcceptQueueServer::Task::run()
>     @          0x1ba90a9  impala::ThriftThread::RunRunnable()
>     @          0x1baa7ad  boost::_mfi::mf2<>::operator()()
>     @          0x1baa643  boost::_bi::list3<>::operator()<>()
>     @          0x1baa38f  boost::_bi::bind_t<>::operator()()
>     @          0x1baa2a2  
> boost::detail::function::void_function_obj_invoker0<>::invoke()
>     @          0x1bef122  boost::function0<>::operator()()
>     @          0x1eda873  impala::Thread::SuperviseThread()
>     @          0x1ee2a0f  boost::_bi::list5<>::operator()<>()
>     @          0x1ee2933  boost::_bi::bind_t<>::operator()()
>     @          0x1ee28f6  boost::detail::thread_data<>::run()
>     @          0x31ddbca  thread_proxy
>     @     0x7f1d612256ba  start_thread
>     @     0x7f1d60f5b41d  clone
> I0601 12:24:52.274433  6760 impala-server.cc:1011] UnregisterQuery(): 
> query_id=b64705fe2b9d154b:e7592d7800000000
> I0601 12:24:52.274439  6760 impala-server.cc:1098] Cancel(): 
> query_id=b64705fe2b9d154b:e7592d7800000000
> {noformat}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to