facebookincubator / velox

A composable and fully extensible C++ execution engine library for data management systems.
https://velox-lib.io/
Apache License 2.0
3.54k stars 1.17k forks source link

Casting JSON to decimal produces incorrect results #11674

Open zhli1142015 opened 5 days ago

zhli1142015 commented 5 days ago

Bug description

  testCast<JsonNativeType, int64_t>(
      JSON(),
      DECIMAL(10, 2),
      {"1234567.89"_sv},
      {123456789});
/var/git/velox/velox/vector/tests/utils/VectorTestBase.cpp:151: Failure
Value of: expected->equalValueAt(actual.get(), i, i)
  Actual: false
Expected: true
at 0: expected 1234567.89, but got 12345.67
Google Test trace:
/var/git/velox/./velox/functions/prestosql/tests/CastBaseTest.h:217: Flat encoding
/var/git/velox/./velox/functions/prestosql/tests/CastBaseTest.h:212: Cast from JSON to DECIMAL(10, 2)

It seems casting JSON to decimal is not supported. Should we disable the toType for decimal, similar to how it's handled for date types? https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/types/JsonType.cpp#L1201

System information

Velox System Info v0.0.2 Commit: e80bf12e3f5db0af81793986b0707477027c4e80 CMake Version: 3.28.3 System: Linux-5.15.167.4-microsoft-standard-WSL2 Arch: x86_64 C++ Compiler: /usr/bin/c++ C++ Compiler Version: 11.4.0 C Compiler: /usr/bin/cc C Compiler Version: 11.4.0 CMake Prefix Path: /usr/local;/usr;/;/usr/local/lib/python3.10/dist-packages/cmake/data;/usr/local;/usr/X11R6;/usr/pkg;/opt

Relevant logs

No response

zhli1142015 commented 5 days ago

cc @Yuhta and @mbasmanova , thanks

mbasmanova commented 5 days ago

CC: @kgpai @karteekmurthys @kagamiori