mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
array functions for Decimal [CLICKHOUSE-3765CLICKHOUSE-3765]
This commit is contained in:
parent
94997889c5
commit
e0b1e9a1ca
@ -131,23 +131,14 @@ public:
|
||||
bool isParametric() const override { return true; }
|
||||
bool haveSubtypes() const override { return false; }
|
||||
bool shouldAlignRightInPrettyFormats() const override { return true; }
|
||||
bool textCanContainOnlyValidUTF8() const override { return true; }
|
||||
bool isComparable() const override { return true; }
|
||||
bool isValueRepresentedByNumber() const override { return true; }
|
||||
bool isValueRepresentedByInteger() const override { return true; }
|
||||
bool isValueRepresentedByUnsignedInteger() const override { return false; }
|
||||
bool isValueUnambiguouslyRepresentedInContiguousMemoryRegion() const override { return true; }
|
||||
bool haveMaximumSizeOfValue() const override { return true; }
|
||||
size_t getSizeOfValueInMemory() const override { return sizeof(T); }
|
||||
bool isCategorial() const override { return isValueRepresentedByInteger(); }
|
||||
|
||||
bool canBeUsedAsVersion() const override { return false; }
|
||||
bool isSummable() const override { return true; }
|
||||
bool canBeUsedInBitOperations() const override { return false; }
|
||||
bool isUnsignedInteger() const override { return false; }
|
||||
bool canBeUsedInBooleanContext() const override { return true; }
|
||||
bool isNumber() const override { return true; }
|
||||
bool isInteger() const override { return false; }
|
||||
bool canBeInsideNullable() const override { return true; }
|
||||
|
||||
/// Decimal specific
|
||||
|
@ -0,0 +1,38 @@
|
||||
Array(Decimal(9, 3)) Array(Decimal(18, 3)) Array(Decimal(38, 3))
|
||||
Array(Decimal(9, 2)) Array(Decimal(18, 2)) Array(Decimal(38, 2))
|
||||
Decimal(9, 3) Decimal(18, 3) Decimal(38, 3)
|
||||
Decimal(9, 2) Decimal(18, 2) Decimal(38, 2)
|
||||
Tuple(Decimal(9, 1), Decimal(18, 1), Decimal(38, 1)) Decimal(9, 1) Decimal(18, 1) Decimal(38, 1)
|
||||
0.100
|
||||
0.200
|
||||
0.300
|
||||
0.400
|
||||
0.500
|
||||
0.600
|
||||
0.700
|
||||
0.800
|
||||
0.900
|
||||
(9.1,9.2,9.3) 9.1 9.2 9.3
|
||||
[0.100,0.200,0.300] [0.100,0.200] [0.200,0.300] [0.100] [0.200]
|
||||
[0.400,0.500,0.600] [0.400,0.500] [0.500,0.600] [0.400] [0.500]
|
||||
[0.700,0.800,0.900] [0.700,0.800] [0.800,0.900] [0.700] [0.800]
|
||||
[1.10,1.20] [1.10] [1.20] [1.10] [1.20]
|
||||
[2.10,2.20] [2.10] [2.20] [2.10] [2.20]
|
||||
[3.10,3.20] [3.10] [3.20] [3.10] [3.20]
|
||||
[0.100,0.200,0.300,0.000] [0.000,0.100,0.200,0.300]
|
||||
[0.400,0.500,0.600,0.000] [0.000,0.400,0.500,0.600]
|
||||
[0.700,0.800,0.900,0.000] [0.000,0.700,0.800,0.900]
|
||||
3 3 3
|
||||
2 2 2
|
||||
0 0 0
|
||||
0 0 0
|
||||
1 1 1
|
||||
1 1 1
|
||||
3 3 3
|
||||
2 2 2
|
||||
1 0
|
||||
1 0
|
||||
1 0
|
||||
1 0
|
||||
2 0
|
||||
3 0
|
102
dbms/tests/queries/0_stateless/00700_decimal_complex_types.sql
Normal file
102
dbms/tests/queries/0_stateless/00700_decimal_complex_types.sql
Normal file
@ -0,0 +1,102 @@
|
||||
SET allow_experimental_decimal_type = 1;
|
||||
SET send_logs_level = 'none';
|
||||
|
||||
CREATE DATABASE IF NOT EXISTS test;
|
||||
DROP TABLE IF EXISTS test.decimal;
|
||||
|
||||
CREATE TABLE test.decimal
|
||||
(
|
||||
a Array(Decimal32(3)),
|
||||
b Array(Decimal64(3)),
|
||||
c Array(Decimal128(3)),
|
||||
nest Nested
|
||||
(
|
||||
a Decimal(9,2),
|
||||
b Decimal(18,2),
|
||||
c Decimal(38,2)
|
||||
),
|
||||
tup Tuple(Decimal32(1), Decimal64(1), Decimal128(1))
|
||||
) ENGINE = Memory;
|
||||
|
||||
INSERT INTO test.decimal (a, b, c, nest.a, nest.b, nest.c, tup)
|
||||
VALUES ([0.1, 0.2, 0.3], [0.4, 0.5, 0.6], [0.7, 0.8, 0.9], [1.1, 1.2], [2.1, 2.2], [3.1, 3.2], (9.1, 9.2, 9.3));
|
||||
|
||||
SELECT toTypeName(a), toTypeName(b), toTypeName(c) FROM test.decimal;
|
||||
SELECT toTypeName(nest.a), toTypeName(nest.b), toTypeName(nest.c) FROM test.decimal;
|
||||
SELECT toTypeName(a[1]), toTypeName(b[2]), toTypeName(c[3]) FROM test.decimal;
|
||||
SELECT toTypeName(nest.a[1]), toTypeName(nest.b[1]), toTypeName(nest.c[1]) FROM test.decimal;
|
||||
SELECT toTypeName(tup), toTypeName(tup.1), toTypeName(tup.2), toTypeName(tup.3) FROM test.decimal;
|
||||
|
||||
SELECT arrayJoin(a) FROM test.decimal;
|
||||
SELECT arrayJoin(b) FROM test.decimal;
|
||||
SELECT arrayJoin(c) FROM test.decimal;
|
||||
|
||||
SELECT tup, tup.1, tup.2, tup.3 FROM test.decimal;
|
||||
SELECT a, arrayPopBack(a), arrayPopFront(a), arrayResize(a, 1), arraySlice(a, 2, 1) FROM test.decimal;
|
||||
SELECT b, arrayPopBack(b), arrayPopFront(b), arrayResize(b, 1), arraySlice(b, 2, 1) FROM test.decimal;
|
||||
SELECT c, arrayPopBack(c), arrayPopFront(c), arrayResize(c, 1), arraySlice(c, 2, 1) FROM test.decimal;
|
||||
SELECT nest.a, arrayPopBack(nest.a), arrayPopFront(nest.a), arrayResize(nest.a, 1), arraySlice(nest.a, 2, 1) FROM test.decimal;
|
||||
SELECT nest.b, arrayPopBack(nest.b), arrayPopFront(nest.b), arrayResize(nest.b, 1), arraySlice(nest.b, 2, 1) FROM test.decimal;
|
||||
SELECT nest.c, arrayPopBack(nest.c), arrayPopFront(nest.c), arrayResize(nest.c, 1), arraySlice(nest.c, 2, 1) FROM test.decimal;
|
||||
SELECT arrayPushBack(a, toDecimal32(0, 3)), arrayPushFront(a, toDecimal32(0, 3)) FROM test.decimal;
|
||||
SELECT arrayPushBack(b, toDecimal64(0, 3)), arrayPushFront(b, toDecimal64(0, 3)) FROM test.decimal;
|
||||
SELECT arrayPushBack(c, toDecimal128(0, 3)), arrayPushFront(c, toDecimal128(0, 3)) FROM test.decimal;
|
||||
|
||||
SELECT arrayPushBack(a, toDecimal32(0, 2)) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayPushBack(b, toDecimal64(0, 2)) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayPushBack(c, toDecimal128(0, 2)) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayPushFront(a, toDecimal32(0, 4)) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayPushFront(b, toDecimal64(0, 4)) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayPushFront(c, toDecimal128(0, 4)) FROM test.decimal; -- { serverError 386 }
|
||||
|
||||
SELECT length(a), length(b), length(c) FROM test.decimal;
|
||||
SELECT length(nest.a), length(nest.b), length(nest.c) FROM test.decimal;
|
||||
SELECT empty(a), empty(b), empty(c) FROM test.decimal;
|
||||
SELECT empty(nest.a), empty(nest.b), empty(nest.c) FROM test.decimal;
|
||||
SELECT notEmpty(a), notEmpty(b), notEmpty(c) FROM test.decimal;
|
||||
SELECT notEmpty(nest.a), notEmpty(nest.b), notEmpty(nest.c) FROM test.decimal;
|
||||
SELECT arrayUniq(a), arrayUniq(b), arrayUniq(c) FROM test.decimal;
|
||||
SELECT arrayUniq(nest.a), arrayUniq(nest.b), arrayUniq(nest.c) FROM test.decimal;
|
||||
|
||||
SELECT has(a, toDecimal32(0.1, 3)), has(a, toDecimal32(1.0, 3)) FROM test.decimal;
|
||||
SELECT has(b, toDecimal64(0.4, 3)), has(b, toDecimal64(1.0, 3)) FROM test.decimal;
|
||||
SELECT has(c, toDecimal128(0.7, 3)), has(c, toDecimal128(1.0, 3)) FROM test.decimal;
|
||||
|
||||
SELECT has(a, toDecimal32(0.1, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(a, toDecimal32(0.1, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(a, toDecimal64(0.1, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(a, toDecimal128(0.1, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(b, toDecimal32(0.4, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(b, toDecimal64(0.4, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(b, toDecimal64(0.4, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(b, toDecimal128(0.4, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(c, toDecimal32(0.7, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(c, toDecimal64(0.7, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(c, toDecimal128(0.7, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT has(c, toDecimal128(0.7, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
|
||||
SELECT indexOf(a, toDecimal32(0.1, 3)), indexOf(a, toDecimal32(1.0, 3)) FROM test.decimal;
|
||||
SELECT indexOf(b, toDecimal64(0.5, 3)), indexOf(b, toDecimal64(1.0, 3)) FROM test.decimal;
|
||||
SELECT indexOf(c, toDecimal128(0.9, 3)), indexOf(c, toDecimal128(1.0, 3)) FROM test.decimal;
|
||||
|
||||
SELECT indexOf(a, toDecimal32(0.1, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(a, toDecimal32(0.1, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(a, toDecimal64(0.1, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(a, toDecimal128(0.1, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(b, toDecimal32(0.4, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(b, toDecimal64(0.4, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(b, toDecimal64(0.4, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(b, toDecimal128(0.4, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(c, toDecimal32(0.7, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(c, toDecimal64(0.7, 3)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(c, toDecimal128(0.7, 2)) FROM test.decimal; -- { serverError 43 }
|
||||
SELECT indexOf(c, toDecimal128(0.7, 4)) FROM test.decimal; -- { serverError 43 }
|
||||
|
||||
SELECT arrayConcat(a, b) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayConcat(a, c) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayConcat(b, c) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayConcat(a, nest.a) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayConcat(b, nest.b) FROM test.decimal; -- { serverError 386 }
|
||||
SELECT arrayConcat(c, nest.c) FROM test.decimal; -- { serverError 386 }
|
||||
|
||||
DROP TABLE IF EXISTS test.decimal;
|
@ -14,12 +14,12 @@ ORDER BY (d2, d3);
|
||||
|
||||
INSERT INTO test.decimal (d1, d2, d3) VALUES (4.2, 4.2, 4.2);
|
||||
|
||||
SELECT count() FROM test.decimal WHERE d1 = toDecimal32('4.2', 1);
|
||||
SELECT count() FROM test.decimal WHERE d1 != toDecimal32('4.2', 2);
|
||||
SELECT count() FROM test.decimal WHERE d1 < toDecimal32('4.2', 3);
|
||||
SELECT count() FROM test.decimal WHERE d1 > toDecimal32('4.2', 4);
|
||||
SELECT count() FROM test.decimal WHERE d1 <= toDecimal32('4.2', 5);
|
||||
SELECT count() FROM test.decimal WHERE d1 >= toDecimal32('4.2', 6);
|
||||
SELECT count() FROM test.decimal WHERE d1 = toDecimal32('4.2', 8);
|
||||
SELECT count() FROM test.decimal WHERE d1 != toDecimal32('4.2', 8);
|
||||
SELECT count() FROM test.decimal WHERE d1 < toDecimal32('4.2', 8);
|
||||
SELECT count() FROM test.decimal WHERE d1 > toDecimal32('4.2', 8);
|
||||
SELECT count() FROM test.decimal WHERE d1 <= toDecimal32('4.2', 8);
|
||||
SELECT count() FROM test.decimal WHERE d1 >= toDecimal32('4.2', 8);
|
||||
|
||||
INSERT INTO test.decimal (d1, d2, d3)
|
||||
SELECT toDecimal32(number % 10, 8), toDecimal64(number, 8), toDecimal128(number, 8) FROM system.numbers LIMIT 50;
|
||||
|
Loading…
Reference in New Issue
Block a user