Repository navigation
Closed
Labels
bugConfirmed user-visible misbehaviour in official releasest-acceptedThe issue is in our backlog, ready to take
Description
An error occurs when a column of type Array(Tuple(...)) is present in the query. There are only two possible calls of the function tupleElement in the query, none of them have non-constant second argument.
How to reproduce
- ClickHouse server version 20.9.2.20
- Create two tables with one row in each
CREATE DATABASE IF NOT EXISTS test;
CREATE TABLE IF NOT EXISTS test.tc engine = MergeTree PARTITION BY (inn, toYYYYMM(received)) ORDER BY (inn, sessionId)
AS SELECT now() AS received, '123456789' AS inn, '42' AS sessionId;
CREATE TABLE IF NOT EXISTS test.tj engine = MergeTree PARTITION BY (inn, toYYYYMM(received)) ORDER BY (inn, sessionId)
AS SELECT now() AS received, '123456789' AS inn, '42' AS sessionId, '111' AS serial, '222' AS reg;
- Run query
SELECT rq.inn, arrayFirst(t -> isNotNull(t), regInfo.1), arrayFirst(t -> isNotNull(t), regInfo.2)
FROM test.tc AS rq
INNER JOIN (
SELECT rs.inn, rs.sessionId, groupArray((serial, reg)) AS regInfo
FROM test.tj AS rs
GROUP BY inn, sessionId
) AS resp ON (rq.inn = resp.inn) AND (rq.sessionId = resp.sessionId)
WHERE if('123456789' IS NOT NULL, rq.inn = '123456789', 1)
Expected behavior
The query should return the table with 3 columns and 1 row.
If replace the last line with WHERE if('123456789' IS NOT NULL, rq.inn = '123456789', 3) the query returns expected result.
Error message and/or stacktrace
DB::Exception: Second argument to tupleElement must be a constant UInt or String (version 20.9.2.20 (official build)) (from [::ffff:192.168.121.148]:62635) (in query: [skipped, see reduced example]), Stack trace (when copying this message, always include the lines below):
0. Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x18e02790 in /usr/bin/clickhouse
1. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0xe72fdad in /usr/bin/clickhouse
2. DB::FunctionTupleElement::getElementNum(COW<DB::IColumn>::immutable_ptr<DB::IColumn> const&, DB::DataTypeTuple const&) const @ 0x1289aaf0 in /usr/bin/clickhouse
3. DB::FunctionTupleElement::getReturnTypeImpl(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&) const @ 0x1289b918 in /usr/bin/clickhouse
4. DB::DefaultOverloadResolver::getReturnType(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&) const @ 0xfb81505 in /usr/bin/clickhouse
5. DB::FunctionOverloadResolverAdaptor::getReturnTypeWithoutLowCardinality(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&) const @ 0xfba7d2a in /usr/bin/clickhouse
6. DB::FunctionOverloadResolverAdaptor::getReturnType(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&) const @ 0xfba8125 in /usr/bin/clickhouse
7. DB::FunctionOverloadResolverAdaptor::build(std::__1::vector<DB::ColumnWithTypeAndName, std::__1::allocator<DB::ColumnWithTypeAndName> > const&) const @ 0xfbadfec in /usr/bin/clickhouse
8. DB::ExpressionActions::addImpl(DB::ExpressionAction, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x15ad29de in /usr/bin/clickhouse
9. DB::ExpressionActions::add(DB::ExpressionAction const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&) @ 0x15ad2c4d in /usr/bin/clickhouse
10. DB::ScopeStack::addAction(DB::ExpressionAction const&) @ 0x15b703cd in /usr/bin/clickhouse
11. DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x15b7ba0b in /usr/bin/clickhouse
12. DB::ActionsMatcher::visit(DB::ASTFunction const&, std::__1::shared_ptr<DB::IAST> const&, DB::ActionsMatcher::Data&) @ 0x15b7a43b in /usr/bin/clickhouse
13. DB::InDepthNodeVisitor<DB::ActionsMatcher, true, std::__1::shared_ptr<DB::IAST> const>::visit(std::__1::shared_ptr<DB::IAST> const&) @ 0x15b63039 in /usr/bin/clickhouse
14. ? @ 0x15b53d93 in /usr/bin/clickhouse
15. DB::SelectQueryExpressionAnalyzer::appendSelect(DB::ExpressionActionsChain&, bool) @ 0x15b557e6 in /usr/bin/clickhouse
16. DB::ExpressionAnalysisResult::ExpressionAnalysisResult(DB::SelectQueryExpressionAnalyzer&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, bool, bool, bool, std::__1::shared_ptr<DB::FilterInfo> const&, DB::Block const&) @ 0x15b5fa67 in /usr/bin/clickhouse
17. DB::InterpreterSelectQuery::getSampleBlockImpl() @ 0x15b15f2d in /usr/bin/clickhouse
18. ? @ 0x15b1c8ea in /usr/bin/clickhouse
19. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>, std::__1::shared_ptr<DB::IStorage> const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&) @ 0x15b249e2 in /usr/bin/clickhouse
20. DB::InterpreterSelectQuery::InterpreterSelectQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x15b26479 in /usr/bin/clickhouse
21. DB::InterpreterSelectWithUnionQuery::InterpreterSelectWithUnionQuery(std::__1::shared_ptr<DB::IAST> const&, DB::Context const&, DB::SelectQueryOptions const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x15c9e897 in /usr/bin/clickhouse
22. DB::StorageView::read(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, std::__1::shared_ptr<DB::StorageInMemoryMetadata const> const&, DB::SelectQueryInfo const&, DB::Context const&, DB::QueryProcessingStage::Enum, unsigned long, unsigned int) @ 0x160d0909 in /usr/bin/clickhouse
23. DB::ReadFromStorageStep::ReadFromStorageStep(std::__1::shared_ptr<DB::RWLockImpl::LockHolderImpl>, std::__1::shared_ptr<DB::StorageInMemoryMetadata const>&, DB::SelectQueryOptions, std::__1::shared_ptr<DB::IStorage>, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, DB::SelectQueryInfo const&, std::__1::shared_ptr<DB::Context>, DB::QueryProcessingStage::Enum, unsigned long, unsigned long) @ 0x167ed13a in /usr/bin/clickhouse
24. DB::InterpreterSelectQuery::executeFetchColumns(DB::QueryProcessingStage::Enum, DB::QueryPlan&, std::__1::shared_ptr<DB::PrewhereInfo> const&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) @ 0x15b1dff1 in /usr/bin/clickhouse
25. DB::InterpreterSelectQuery::executeImpl(DB::QueryPlan&, std::__1::shared_ptr<DB::IBlockInputStream> const&, std::__1::optional<DB::Pipe>) @ 0x15b21ec3 in /usr/bin/clickhouse
26. DB::InterpreterSelectQuery::buildQueryPlan(DB::QueryPlan&) @ 0x15b239b4 in /usr/bin/clickhouse
27. DB::InterpreterSelectWithUnionQuery::buildQueryPlan(DB::QueryPlan&) @ 0x15c9d6f8 in /usr/bin/clickhouse
28. DB::InterpreterSelectWithUnionQuery::execute() @ 0x15c9d8ca in /usr/bin/clickhouse
29. ? @ 0x15e1ac62 in /usr/bin/clickhouse
30. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::Context&, bool, DB::QueryProcessingStage::Enum, bool) @ 0x15e1c5c2 in /usr/bin/clickhouse
31. DB::TCPHandler::runImpl() @ 0x164c3585 in /usr/bin/clickhouse
Reacted by Sergey Mirvoda
Metadata
Metadata
Assignees
Labels
bugConfirmed user-visible misbehaviour in official releasest-acceptedThe issue is in our backlog, ready to take
Activity
SergeyMirvoda commentedon Sep 28, 2020
Here is the stack from another server (Ubuntu 18.04) with the same query as in the issue.
Also, it reproduced on ClickHouse 20.6.6.7 (CentOS 7)
4ertus2 commentedon Oct 6, 2020
It looks kile literal
1clashes withregInfo.1. We need better column naming for litaral expressions (some DB internals).Close: #15411