Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second argument to tupleElement must be a constant UInt or String #15411

Closed
victor-sushko opened this issue Sep 28, 2020 · 2 comments · Fixed by #62185
Closed

Second argument to tupleElement must be a constant UInt or String #15411

victor-sushko opened this issue Sep 28, 2020 · 2 comments · Fixed by #62185
Labels
bug Confirmed user-visible misbehaviour in official release st-accepted The issue is in our backlog, ready to take st-hold We've paused the work on issue for some reason

Comments

@victor-sushko
Copy link

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
@victor-sushko victor-sushko added the bug Confirmed user-visible misbehaviour in official release label Sep 28, 2020
@SergeyMirvoda
Copy link
Contributor

SergeyMirvoda commented 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)

2020.09.28 12:26:38.560516 [ 11396 ] {0738b390-f230-47e5-8a42-76e0222b89b7} <Error> executeQuery: Code: 43, e.displayText() = DB::Exception: Second argument to tupleElement must be a constant UInt or String (version 20.9.2.20 (official build)) (from 192.168.121.130:50245) (in 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) FORMAT TabSeparatedWithNamesAndTypes;), 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::InterpreterFactory::get(std::__1::shared_ptr<DB::IAST>&, DB::Context&, DB::QueryProcessingStage::Enum) @ 0x15a8efcf in /usr/bin/clickhouse
23. ? @ 0x15e1aad8 in /usr/bin/clickhouse
24. DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, bool, DB::Context&, std::__1::function<void (std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>) @ 0x15e1c9e9 in /usr/bin/clickhouse
25. DB::HTTPHandler::processQuery(DB::Context&, Poco::Net::HTTPServerRequest&, HTMLForm&, Poco::Net::HTTPServerResponse&, DB::HTTPHandler::Output&) @ 0x16466fb9 in /usr/bin/clickhouse
26. DB::HTTPHandler::handleRequest(Poco::Net::HTTPServerRequest&, Poco::Net::HTTPServerResponse&) @ 0x1646aa6b in /usr/bin/clickhouse
27. Poco::Net::HTTPServerConnection::run() @ 0x18ce23e3 in /usr/bin/clickhouse
28. Poco::Net::TCPServerConnection::start() @ 0x18d205fb in /usr/bin/clickhouse
29. Poco::Net::TCPServerDispatcher::run() @ 0x18d20a8b in /usr/bin/clickhouse
30. Poco::PooledThread::run() @ 0x18e9f566 in /usr/bin/clickhouse
31. Poco::ThreadImpl::runnableEntry(void*) @ 0x18e9a960 in /usr/bin/clickhouse


@4ertus2
Copy link
Contributor

4ertus2 commented Oct 6, 2020

It looks kile literal 1 clashes with regInfo.1. We need better column naming for litaral expressions (some DB internals).

@alexey-milovidov alexey-milovidov added the st-accepted The issue is in our backlog, ready to take label Nov 9, 2020
@alexey-milovidov alexey-milovidov added the st-hold We've paused the work on issue for some reason label Oct 9, 2022
fm4v added a commit that referenced this issue Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release st-accepted The issue is in our backlog, ready to take st-hold We've paused the work on issue for some reason
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants