mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 20:12:02 +00:00
More tests
This commit is contained in:
parent
e074a154dd
commit
399634a1bc
@ -15,11 +15,9 @@
|
|||||||
#include <DataTypes/DataTypeString.h>
|
#include <DataTypes/DataTypeString.h>
|
||||||
#include <DataTypes/DataTypeDateTime.h>
|
#include <DataTypes/DataTypeDateTime.h>
|
||||||
#include <DataTypes/DataTypeDateTime64.h>
|
#include <DataTypes/DataTypeDateTime64.h>
|
||||||
#include <DataTypes/DataTypeEnum.h>
|
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
#include <DataTypes/DataTypesDecimal.h>
|
#include <DataTypes/DataTypesDecimal.h>
|
||||||
#include <DataTypes/DataTypeFactory.h>
|
#include <DataTypes/DataTypeFactory.h>
|
||||||
#include <base/EnumReflection.h>
|
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <DataTypes/DataTypeString.h>
|
#include <DataTypes/DataTypeString.h>
|
||||||
#include <DataTypes/DataTypeDate.h>
|
#include <DataTypes/DataTypeDate.h>
|
||||||
#include <DataTypes/DataTypesNumber.h>
|
#include <DataTypes/DataTypesNumber.h>
|
||||||
|
#include <DataTypes/DataTypesDecimal.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -367,7 +368,28 @@ DataTypePtr getMostSubtype(const DataTypes & types, bool throw_if_result_is_noth
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: Decimals
|
/// Decimals
|
||||||
|
{
|
||||||
|
bool all_decimals = true;
|
||||||
|
UInt32 min_scale = std::numeric_limits<UInt32>::max();
|
||||||
|
UInt32 min_precision = std::numeric_limits<UInt32>::max();
|
||||||
|
for (const auto & type : types)
|
||||||
|
{
|
||||||
|
if (isDecimal(type))
|
||||||
|
{
|
||||||
|
min_scale = std::min(min_scale, getDecimalScale(*type));
|
||||||
|
min_precision = std::min(min_precision, getDecimalPrecision(*type));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
all_decimals = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all_decimals)
|
||||||
|
return createDecimal<DataTypeDecimal>(min_precision, min_scale);
|
||||||
|
}
|
||||||
|
|
||||||
/// All other data types (UUID, AggregateFunction, Enum...) are compatible only if they are the same (checked in trivial cases).
|
/// All other data types (UUID, AggregateFunction, Enum...) are compatible only if they are the same (checked in trivial cases).
|
||||||
return get_nothing_or_throw("");
|
return get_nothing_or_throw("");
|
||||||
|
@ -293,6 +293,10 @@ private:
|
|||||||
return execute2<KeyType, UInt256>(row_count, args, res_type);
|
return execute2<KeyType, UInt256>(row_count, args, res_type);
|
||||||
case TypeIndex::Float64:
|
case TypeIndex::Float64:
|
||||||
return execute2<KeyType, Float64>(row_count, args, res_type);
|
return execute2<KeyType, Float64>(row_count, args, res_type);
|
||||||
|
case TypeIndex::Decimal128:
|
||||||
|
return execute2<KeyType, Decimal128>(row_count, args, res_type);
|
||||||
|
case TypeIndex::Decimal256:
|
||||||
|
return execute2<KeyType, Decimal256>(row_count, args, res_type);
|
||||||
default:
|
default:
|
||||||
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal column type {} for values in arguments of function {}",
|
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal column type {} for values in arguments of function {}",
|
||||||
res_value_type->getName(), getName());
|
res_value_type->getName(), getName());
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <IO/WriteHelpers.h>
|
#include <IO/WriteHelpers.h>
|
||||||
#include <Common/HashTable/Hash.h>
|
#include <Common/HashTable/Hash.h>
|
||||||
#include <Interpreters/InternalTextLogsQueue.h>
|
#include <Interpreters/InternalTextLogsQueue.h>
|
||||||
#include <Common/CurrentThread.h>
|
|
||||||
#include <base/terminalColors.h>
|
#include <base/terminalColors.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,18 +1,84 @@
|
|||||||
|
-- { echoOn }
|
||||||
|
|
||||||
|
SELECT 1.1::Decimal(60, 30);
|
||||||
1.1
|
1.1
|
||||||
|
SELECT round(1.1::Decimal(60, 30));
|
||||||
1
|
1
|
||||||
|
SELECT round(1.1::Decimal(60, 30), 1);
|
||||||
1.1
|
1.1
|
||||||
|
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 1);
|
||||||
1.2
|
1.2
|
||||||
|
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 30);
|
||||||
1.234567890123456789012345678901
|
1.234567890123456789012345678901
|
||||||
|
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 31);
|
||||||
1.234567890123456789012345678901
|
1.234567890123456789012345678901
|
||||||
|
SELECT round(1.234567890123456789012345678901::Decimal(60, 30), 20);
|
||||||
1.23456789012345678901
|
1.23456789012345678901
|
||||||
|
SELECT hex(1.234567890123456789012345678901::Decimal(60, 30));
|
||||||
356C760E4FC986A2A39F1A950F00000000000000000000000000000000000000
|
356C760E4FC986A2A39F1A950F00000000000000000000000000000000000000
|
||||||
|
SELECT bin(1.234567890123456789012345678901::Decimal(60, 30));
|
||||||
0011010101101100011101100000111001001111110010011000011010100010101000111001111100011010100101010000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0011010101101100011101100000111001001111110010011000011010100010101000111001111100011010100101010000111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
|
SELECT reinterpret(unhex(hex(1.234567890123456789012345678901::Decimal(60, 30))), 'Decimal(60, 30)');
|
||||||
1.234567890123456789012345678901
|
1.234567890123456789012345678901
|
||||||
|
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
4.65
|
4.65
|
||||||
|
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
||||||
4.65
|
4.65
|
||||||
|
SELECT arrayMin([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
1.2
|
||||||
|
SELECT arrayMax([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
3.45
|
||||||
|
SELECT arrayAvg([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
2.325
|
||||||
|
SELECT round(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]), 6);
|
||||||
|
4.14
|
||||||
|
SELECT toTypeName(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]));
|
||||||
|
Float64
|
||||||
|
SELECT arrayCumSum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
[1.2,4.65]
|
||||||
|
SELECT arrayCumSumNonNegative([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
[1.2,4.65]
|
||||||
|
SELECT arrayDifference([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
[0,2.25]
|
||||||
|
SELECT arrayCompact([1.2::Decimal(60, 30) AS x, x, x, x, 3.45::Decimal(3, 2) AS y, y, x, x]);
|
||||||
[1.2,3.45,1.2]
|
[1.2,3.45,1.2]
|
||||||
|
SELECT 1.2::Decimal(2, 1) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
|
||||||
1
|
1
|
||||||
|
SELECT 1.23::Decimal(3, 2) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
|
||||||
0
|
0
|
||||||
|
SELECT 1.2::Decimal(60, 30) IN (1.2::Decimal(2, 1));
|
||||||
1
|
1
|
||||||
|
SELECT toTypeName([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
||||||
Array(Decimal(76, 30))
|
Array(Decimal(76, 30))
|
||||||
|
SELECT toTypeName(arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]));
|
||||||
Decimal(76, 30)
|
Decimal(76, 30)
|
||||||
|
SELECT arrayJoin(sumMap(x)) FROM (SELECT [('Hello', 1.2::Decimal256(30)), ('World', 3.4::Decimal256(30))]::Map(String, Decimal256(30)) AS x UNION ALL SELECT [('World', 5.6::Decimal256(30)), ('GoodBye', -111.222::Decimal256(30))]::Map(String, Decimal256(30))) ORDER BY 1;
|
||||||
|
('GoodBye',-111.222)
|
||||||
|
('Hello',1.2)
|
||||||
|
('World',9)
|
||||||
|
SELECT mapAdd(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
|
||||||
|
{'GoodBye':-111.222,'Hello':1.2,'World':9}
|
||||||
|
SELECT mapSubtract(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
|
||||||
|
{'GoodBye':111.222,'Hello':1.2,'World':-2.2}
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt256)));
|
||||||
|
[2,3]
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt128))));
|
||||||
|
Array(UInt128)
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128))));
|
||||||
|
Array(Int128)
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128)));
|
||||||
|
[2,3]
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8)));
|
||||||
|
[2,3]
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8))));
|
||||||
|
Array(Int8)
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(70), 2.34::Decimal256(60), 3.456::Decimal256(50)], [2.34::Decimal256(65), 3.456::Decimal256(55), 4.5678::Decimal256(45)]));
|
||||||
|
[2.34,3.456]
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(1)], [1.12::Decimal256(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
|
||||||
|
[1.1]
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(2)], [1.12::Decimal256(2)]));
|
||||||
|
[]
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal128(1)], [1.12::Decimal128(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
|
||||||
|
[1.1]
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal128(2)], [1.12::Decimal128(2)]));
|
||||||
|
[]
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
-- { echoOn }
|
||||||
|
|
||||||
SELECT 1.1::Decimal(60, 30);
|
SELECT 1.1::Decimal(60, 30);
|
||||||
SELECT round(1.1::Decimal(60, 30));
|
SELECT round(1.1::Decimal(60, 30));
|
||||||
SELECT round(1.1::Decimal(60, 30), 1);
|
SELECT round(1.1::Decimal(60, 30), 1);
|
||||||
@ -13,6 +15,17 @@ SELECT reinterpret(unhex(hex(1.234567890123456789012345678901::Decimal(60, 30)))
|
|||||||
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
SELECT arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
||||||
|
|
||||||
|
SELECT arrayMin([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
SELECT arrayMax([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
SELECT arrayAvg([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
|
||||||
|
SELECT round(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]), 6);
|
||||||
|
SELECT toTypeName(arrayProduct([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]));
|
||||||
|
|
||||||
|
SELECT arrayCumSum([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
SELECT arrayCumSumNonNegative([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
SELECT arrayDifference([1.2::Decimal(60, 30), 3.45::Decimal(61, 29)]);
|
||||||
|
|
||||||
SELECT arrayCompact([1.2::Decimal(60, 30) AS x, x, x, x, 3.45::Decimal(3, 2) AS y, y, x, x]);
|
SELECT arrayCompact([1.2::Decimal(60, 30) AS x, x, x, x, 3.45::Decimal(3, 2) AS y, y, x, x]);
|
||||||
|
|
||||||
SELECT 1.2::Decimal(2, 1) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
|
SELECT 1.2::Decimal(2, 1) IN (1.2::Decimal(60, 30), 3.4::Decimal(60, 30));
|
||||||
@ -21,3 +34,21 @@ SELECT 1.2::Decimal(60, 30) IN (1.2::Decimal(2, 1));
|
|||||||
|
|
||||||
SELECT toTypeName([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
SELECT toTypeName([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]);
|
||||||
SELECT toTypeName(arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]));
|
SELECT toTypeName(arraySum([1.2::Decimal(60, 30), 3.45::Decimal(3, 2)]));
|
||||||
|
|
||||||
|
SELECT arrayJoin(sumMap(x)) FROM (SELECT [('Hello', 1.2::Decimal256(30)), ('World', 3.4::Decimal256(30))]::Map(String, Decimal256(30)) AS x UNION ALL SELECT [('World', 5.6::Decimal256(30)), ('GoodBye', -111.222::Decimal256(30))]::Map(String, Decimal256(30))) ORDER BY 1;
|
||||||
|
|
||||||
|
SELECT mapAdd(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
|
||||||
|
SELECT mapSubtract(map('Hello', 1.2::Decimal128(30), 'World', 3.4::Decimal128(30)), map('World', 5.6::Decimal128(30), 'GoodBye', -111.222::Decimal128(30)));
|
||||||
|
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt256)));
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(UInt128))));
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128))));
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int128)));
|
||||||
|
SELECT arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8)));
|
||||||
|
SELECT toTypeName(arraySort(arrayIntersect([1, 2, 3]::Array(UInt256), [2, 3, 4]::Array(Int8))));
|
||||||
|
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(70), 2.34::Decimal256(60), 3.456::Decimal256(50)], [2.34::Decimal256(65), 3.456::Decimal256(55), 4.5678::Decimal256(45)]));
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(1)], [1.12::Decimal256(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal256(2)], [1.12::Decimal256(2)]));
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal128(1)], [1.12::Decimal128(2)])); -- Note: this is correct but the semantics has to be clarified in the docs.
|
||||||
|
SELECT arraySort(arrayIntersect([1.1::Decimal128(2)], [1.12::Decimal128(2)]));
|
||||||
|
Loading…
Reference in New Issue
Block a user