Full support for Decimal #3721

This commit is contained in:
Alexey Milovidov 2018-12-19 05:43:09 +03:00
parent 689de0289f
commit 36836faf62
4 changed files with 30 additions and 15 deletions

View File

@ -8,7 +8,6 @@
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypeNothing.h>
#include <DataTypes/getLeastSupertype.h>
#include <Interpreters/convertFieldToType.h>
#include <Common/Exception.h>
#include <ext/size.h>

View File

@ -7,7 +7,6 @@
#include <DataTypes/getLeastSupertype.h>
#include <DataTypes/DataTypeArray.h>
#include <Interpreters/castColumn.h>
#include <Interpreters/convertFieldToType.h>
#include <common/intExp.h>
#include <cmath>
@ -608,33 +607,28 @@ public:
void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t) override
{
const ColumnConst * array = checkAndGetColumnConst<ColumnArray>(block.getByPosition(arguments[1]).column.get());
if (!array)
{
throw Exception{"Second argument of function " + getName() + " must be constant array.", ErrorCodes::ILLEGAL_COLUMN};
}
auto in_column = block.getByPosition(arguments[0]).column;
const auto & in_type = block.getByPosition(arguments[0]).type;
auto array_column = block.getByPosition(arguments[1]).column;
const auto & array_type = block.getByPosition(arguments[1]).type;
const auto & return_type = block.getByPosition(result).type;
auto column_result = return_type->createColumn();
auto out = column_result.get();
if (!in_type->equals(*return_type))
{
in_column = castColumn(block.getByPosition(arguments[0]), return_type, context);
}
if (!array_type->equals(*return_type))
array_column = castColumn(block.getByPosition(arguments[1]), std::make_shared<DataTypeArray>(return_type), context);
const auto in = in_column.get();
auto boundaries = array->getValue<Array>();
auto boundaries = typeid_cast<const ColumnConst &>(*array_column).getValue<Array>();
size_t num_boundaries = boundaries.size();
if (!num_boundaries)
throw Exception("Empty array is illegal for boundaries in " + getName() + " function", ErrorCodes::BAD_ARGUMENTS);
for (size_t i = 0; i < num_boundaries; ++i)
boundaries[i] = convertFieldToType(boundaries[i], *return_type);
if (!executeNum<UInt8>(in, out, boundaries)
&& !executeNum<UInt16>(in, out, boundaries)
&& !executeNum<UInt32>(in, out, boundaries)

View File

@ -61,3 +61,23 @@
0.07000 4.00000
0.08000 4.00000
0.09000 4.00000
0.00000 0.04000
0.01000 0.04000
0.02000 0.04000
0.03000 0.04000
0.04000 0.04000
0.05000 0.05000
0.06000 0.06000
0.07000 0.06000
0.08000 0.06000
0.09000 0.06000
0.00000 0.04000
0.01000 0.04000
0.02000 0.04000
0.03000 0.04000
0.04000 0.04000
0.05000 0.05000
0.06000 0.06000
0.07000 0.06000
0.08000 0.06000
0.09000 0.06000

View File

@ -7,6 +7,7 @@ SELECT 1 as x, roundDown(x, [6, 5, 4]);
SET send_logs_level = 'none';
SELECT 1 as x, roundDown(x, []); -- { serverError 43 }
SELECT 1 as x, roundDown(x, emptyArrayUInt8()); -- { serverError 44 }
SELECT roundDown(number, [number]) FROM system.numbers LIMIT 10; -- { serverError 44 }
SELECT 1 as x, roundDown(x, [1]);
SELECT 1 as x, roundDown(x, [1.5]);
@ -14,4 +15,5 @@ SELECT 1 as x, roundDown(x, [1.5]);
SELECT number % 10 as x, roundDown(x, (SELECT groupArray(number * 1.25) FROM numbers(100000))) FROM system.numbers LIMIT 10;
SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [4, 5, 6]) FROM system.numbers LIMIT 10;
SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [toDecimal64(0.04, 5), toDecimal64(0.05, 5), toDecimal64(0.06, 5)]) FROM system.numbers LIMIT 10;
SELECT toDecimal64(number, 5) / 100 as x, roundDown(x, [toDecimal32(0.04, 2), toDecimal32(0.05, 2), toDecimal32(0.06, 2)]) FROM system.numbers LIMIT 10;