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

mysql decimal nullable -> DB::Exception: Attempt to read after eof #7690

Closed
PHaroZ opened this issue Nov 8, 2019 · 13 comments · Fixed by #18718
Closed

mysql decimal nullable -> DB::Exception: Attempt to read after eof #7690

PHaroZ opened this issue Nov 8, 2019 · 13 comments · Fixed by #18718
Assignees
Labels
bug Confirmed user-visible misbehaviour in official release comp-decimal comp-foreign-db Integrations with other databases comp-mysql

Comments

@PHaroZ
Copy link

PHaroZ commented Nov 8, 2019

Hi,

Describe the bug or unexpected behaviour
When I try to INSERT SELECT from a remote mysql table it leads to DB::Exception: Attempt to read after eof when a source column is of type decimal(xx,yy) NULL and have null value.
This issue also occurs when I try to cast a column from a mysql decimal(xx,yy) NULL to a clickhouse Nullable(Decimal(xx,yy))

How to reproduce
CH version : 19.13.3.26 and 19.16.2.2 (official build)

First run the following mysql statements on a mysql server

create table chSource (dn decimal(10,2) null);
insert into chSource VALUES(42.1), (null);

Then in a clickhouse server run

SELECT CAST(dn AS Nullable(Decimal(10,2)))
FROM mysql('mysqlServer:3306','mysqlDatabase','chSource','user','password');

and you obtain

[2a12e65e4fac] 2019.11.08 13:12:23.326313 {c65e05cd-d0c9-4dcd-99b1-218180d10eaf} [ 44 ] <Error> executeQuery: Code: 32, e.displayText() = DB::Exception: Attempt to read after eof (version 19.13.3.26 (official build)) (from 127.0.0.1:36672) (in query: SELECT CAST(dn, 'Nullable(Decimal(10, 2))') FROM mysql('172.23.0.1:3306', 'test', 'chSource', 'root', 'root')), Stack trace:

0. /usr/bin/clickhouse-server(StackTrace::StackTrace()+0x30) [0x7f6b5f0]
1. /usr/bin/clickhouse-server(DB::Exception::Exception(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)+0x25) [0x3c46865]
2. /usr/bin/clickhouse-server(DB::throwReadAfterEOF()+0x55) [0x37b517d]
3. /usr/bin/clickhouse-server(void DB::readDecimalText<DB::Decimal<long> >(DB::ReadBuffer&, DB::Decimal<long>&, unsigned int, unsigned int&, bool)+0x4d7) [0x6cd5337]
4. /usr/bin/clickhouse-server(DB::DataTypeDecimal<DB::Decimal<long> >::readText(DB::Decimal<long>&, DB::ReadBuffer&, unsigned int, unsigned int, bool)+0x5a) [0x6cd56ea]
5. /usr/bin/clickhouse-server(void DB::ConvertThroughParsing<DB::DataTypeString, DB::DataTypeDecimal<DB::Decimal<long> >, DB::NameCast, (DB::ConvertFromStringExceptionMode)0, (DB::ConvertFromStringParsingMode)0>::execute<unsigned int>(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long, unsigned int)+0x22d) [0x400da8d]
6. /usr/bin/clickhouse-server(std::_Function_handler<void (DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long), DB::FunctionCast::createDecimalWrapper<DB::Decimal<long> >(std::shared_ptr<DB::IDataType const> const&, DB::DataTypeDecimal<DB::Decimal<long> > const*) const::{lambda(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)#1}>::_M_invoke(std::_Any_data const&, DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long&&, std::_Any_data const&)+0x87f) [0x401007f]
7. /usr/bin/clickhouse-server(DB::FunctionCast::prepareRemoveNullable(std::shared_ptr<DB::IDataType const> const&, std::shared_ptr<DB::IDataType const> const&, bool) const::{lambda(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)#1}::operator()(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long) const+0x3bc) [0x3ff0e6c]
8. /usr/bin/clickhouse-server(DB::PreparedFunctionCast::executeImpl(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long)+0xa3) [0x3ff0803]
9. /usr/bin/clickhouse-server(DB::PreparedFunctionImpl::execute(DB::Block&, std::vector<unsigned long, std::allocator<unsigned long> > const&, unsigned long, unsigned long, bool)+0x27c) [0x72a473c]
10. /usr/bin/clickhouse-server(DB::ExpressionAction::execute(DB::Block&, bool) const+0x281) [0x7488a11]
11. /usr/bin/clickhouse-server(DB::ExpressionActions::execute(DB::Block&, bool) const+0x45) [0x748a135]
12. /usr/bin/clickhouse-server(DB::ExpressionBlockInputStream::readImpl()+0x4b) [0x73276ab]
13. /usr/bin/clickhouse-server(DB::IBlockInputStream::read()+0x187) [0x6c160a7]
14. /usr/bin/clickhouse-server(DB::ExpressionBlockInputStream::readImpl()+0x2f) [0x732768f]
15. /usr/bin/clickhouse-server(DB::IBlockInputStream::read()+0x187) [0x6c160a7]
16. /usr/bin/clickhouse-server(DB::AsynchronousBlockInputStream::calculate()+0x5b) [0x6c0fadb]
17. /usr/bin/clickhouse-server() [0x6c0fea0]
18. /usr/bin/clickhouse-server(ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::_List_iterator<ThreadFromGlobalPool>)+0x1a7) [0x3c785e7]
19. /usr/bin/clickhouse-server(ThreadFromGlobalPool::ThreadFromGlobalPool<ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::function<void ()>, int, std::optional<unsigned long>)::{lambda()#3}>(ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::function<void ()>, int, std::optional<unsigned long>)::{lambda()#3}&&)::{lambda()#1}::operator()() const+0x3e) [0x3c78bce]
20. /usr/bin/clickhouse-server(ThreadPoolImpl<std::thread>::worker(std::_List_iterator<std::thread>)+0x1a6) [0x3c760f6]
21. /usr/bin/clickhouse-server() [0xba3e1a0]
22. /lib/x86_64-linux-gnu/libpthread.so.0(+0x76db) [0x7f8e7dc5c6db]
23. /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7f8e7d3e388f]

Received exception from server (version 19.13.3):
Code: 32. DB::Exception: Received from localhost:9000. DB::Exception: Attempt to read after eof. 

Then same query with non-null value in he mysql source table return the expected result.

Nonetheless I would like to thank you for your job, CH rocks 👍

@PHaroZ PHaroZ added the bug Confirmed user-visible misbehaviour in official release label Nov 8, 2019
@alexey-milovidov alexey-milovidov added the comp-foreign-db Integrations with other databases label Nov 8, 2019
@Slach
Copy link
Contributor

Slach commented Nov 27, 2019

still reproduced on Clickhouse 19.17 and MySQL 5.1

@Slach
Copy link
Contributor

Slach commented Nov 27, 2019

temp workaround is using Nullable(Float64) or Nullable(Float32) is not good solution

@Slach
Copy link
Contributor

Slach commented Mar 25, 2020

@4ertus2 any news about this issue?

@PHaroZ
Copy link
Author

PHaroZ commented Apr 28, 2020

@Slach The issue still exist with v20.3.7.46 (the latest current version)

@Slach
Copy link
Contributor

Slach commented Jul 16, 2020

@Enmk any news about this issue?

@keyboardblue
Copy link

Still reproduce on 20.5.3.27, any updates there?

@filimonov
Copy link
Contributor

See #11512

@fktr
Copy link

fktr commented Aug 18, 2020

Still reproduce on 20.6.3, any updates there?

@qoega
Copy link
Member

qoega commented Sep 22, 2020

You can check on build from master(for example via testing release) or wait 20.10 release.

@webparadoxer
Copy link

HttpCode:500 ; ;Code: 32, e.displayText() = DB::Exception: Attempt to read after eof: while executing 'FUNCTION CAST(_dummy_0 : 0, 'Nullable(Decimal(9, 2))' :: 1) -> CAST(_dummy_0, 'Nullable(Decimal(9, 2))') Nullable(Decimal(9, 2)) : 2' (version 20.12.4.5 (official build))

@filimonov
Copy link
Contributor

So that didn't help #14535 ...
@zhang2014 are you interested in fixing that?

@zhang2014
Copy link
Contributor

Minimal example : SELECT CAST(arrayJoin(['42.1', NULL]) AS Nullable(Decimal(10,2)));

I will try to fix it.

@leandrogutierrez148
Copy link

instead of use

SELECT ... CAST(expr as Nullable(Decimal64(2))), ... FROM ...

try

SELECT ... toDecimal64OrNull(expr, S), ... FROM ..

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 comp-decimal comp-foreign-db Integrations with other databases comp-mysql
Projects
None yet
Development

Successfully merging a pull request may close this issue.