mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
enable nullable for Decimal [CLICKHOUSE-3765]
This commit is contained in:
parent
1ea6bc9691
commit
e11f3ea5bc
@ -77,7 +77,7 @@ public:
|
|||||||
const char * getFamilyName() const override { return TypeName<T>::get(); }
|
const char * getFamilyName() const override { return TypeName<T>::get(); }
|
||||||
|
|
||||||
bool isNumeric() const override { return false; }
|
bool isNumeric() const override { return false; }
|
||||||
bool canBeInsideNullable() const override { return false; }
|
bool canBeInsideNullable() const override { return true; }
|
||||||
bool isFixedAndContiguous() const override { return true; }
|
bool isFixedAndContiguous() const override { return true; }
|
||||||
size_t sizeOfValueIfFixed() const override { return sizeof(T); }
|
size_t sizeOfValueIfFixed() const override { return sizeof(T); }
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ public:
|
|||||||
bool canBeUsedInBooleanContext() const override { return true; }
|
bool canBeUsedInBooleanContext() const override { return true; }
|
||||||
bool isNumber() const override { return true; }
|
bool isNumber() const override { return true; }
|
||||||
bool isInteger() const override { return false; }
|
bool isInteger() const override { return false; }
|
||||||
bool canBeInsideNullable() const override { return false; }
|
bool canBeInsideNullable() const override { return true; }
|
||||||
|
|
||||||
/// Decimal specific
|
/// Decimal specific
|
||||||
|
|
||||||
|
@ -1,14 +1,6 @@
|
|||||||
SET allow_experimental_decimal_type = 1;
|
SET allow_experimental_decimal_type = 1;
|
||||||
SET send_logs_level = 'none';
|
SET send_logs_level = 'none';
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS test.x (a Nullable(Decimal(9, 2))) ENGINE = Memory; -- { serverError 43 }
|
|
||||||
CREATE TABLE IF NOT EXISTS test.x (a Nullable(Decimal(18, 2))) ENGINE = Memory; -- { serverError 43 }
|
|
||||||
CREATE TABLE IF NOT EXISTS test.x (a Nullable(Decimal(38, 2))) ENGINE = Memory; -- { serverError 43 }
|
|
||||||
|
|
||||||
SELECT toNullable(toDecimal32(0, 0)); -- { serverError 43 }
|
|
||||||
SELECT toNullable(toDecimal64(0, 0)); -- { serverError 43 }
|
|
||||||
SELECT toNullable(toDecimal128(0, 0)); -- { serverError 43 }
|
|
||||||
|
|
||||||
SELECT toDecimal32('1.1', 1), toDecimal32('1.1', 2), toDecimal32('1.1', 8);
|
SELECT toDecimal32('1.1', 1), toDecimal32('1.1', 2), toDecimal32('1.1', 8);
|
||||||
SELECT toDecimal32('1.1', 0); -- { serverError 69 }
|
SELECT toDecimal32('1.1', 0); -- { serverError 69 }
|
||||||
SELECT toDecimal32(1.1, 0), toDecimal32(1.1, 1), toDecimal32(1.1, 2), toDecimal32(1.1, 8);
|
SELECT toDecimal32(1.1, 0), toDecimal32(1.1, 1), toDecimal32(1.1, 2), toDecimal32(1.1, 8);
|
||||||
|
39
dbms/tests/queries/0_stateless/00700_decimal_null.reference
Normal file
39
dbms/tests/queries/0_stateless/00700_decimal_null.reference
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
32 32
|
||||||
|
64 64
|
||||||
|
128 128
|
||||||
|
1 1 1
|
||||||
|
2 2 2
|
||||||
|
3 3 3
|
||||||
|
4 4 4
|
||||||
|
5 5 5
|
||||||
|
6 6 6
|
||||||
|
7 7 7
|
||||||
|
8 8 8
|
||||||
|
\N \N
|
||||||
|
\N \N
|
||||||
|
1 1
|
||||||
|
1 1
|
||||||
|
\N
|
||||||
|
\N
|
||||||
|
1
|
||||||
|
1
|
||||||
|
1.10 1.10000 1.10000 1.1000 1.10000000 1.10000000
|
||||||
|
2.20 2.20000 2.20000 2.2000 \N \N
|
||||||
|
3.30 3.30000 3.30000 \N 3.30000000 \N
|
||||||
|
4.40 4.40000 4.40000 \N \N 4.40000000
|
||||||
|
5.50 5.50000 5.50000 \N \N \N
|
||||||
|
0 1
|
||||||
|
0 1
|
||||||
|
0 1
|
||||||
|
1 0
|
||||||
|
1 0
|
||||||
|
1 0
|
||||||
|
5
|
||||||
|
5
|
||||||
|
5
|
||||||
|
3
|
||||||
|
3
|
||||||
|
3
|
||||||
|
2
|
||||||
|
2
|
||||||
|
2
|
65
dbms/tests/queries/0_stateless/00700_decimal_null.sql
Normal file
65
dbms/tests/queries/0_stateless/00700_decimal_null.sql
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
SET send_logs_level = 'none';
|
||||||
|
SET allow_experimental_decimal_type = 1;
|
||||||
|
|
||||||
|
CREATE DATABASE IF NOT EXISTS test;
|
||||||
|
DROP TABLE IF EXISTS test.decimal;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS test.decimal
|
||||||
|
(
|
||||||
|
a DEC(9, 2),
|
||||||
|
b DEC(18, 5),
|
||||||
|
c DEC(38, 5),
|
||||||
|
d Nullable(DEC(9, 4)),
|
||||||
|
e Nullable(DEC(18, 8)),
|
||||||
|
f Nullable(DEC(38, 8))
|
||||||
|
) ENGINE = Memory;
|
||||||
|
|
||||||
|
SELECT toNullable(toDecimal32(32, 0)) AS x, assumeNotNull(x);
|
||||||
|
SELECT toNullable(toDecimal64(64, 0)) AS x, assumeNotNull(x);
|
||||||
|
SELECT toNullable(toDecimal128(128, 0)) AS x, assumeNotNull(x);
|
||||||
|
SELECT NULL AS x, assumeNotNull(x); -- { serverError 48 }
|
||||||
|
|
||||||
|
SELECT ifNull(toDecimal32(1, 0), NULL), ifNull(toDecimal64(1, 0), NULL), ifNull(toDecimal128(1, 0), NULL);
|
||||||
|
SELECT ifNull(toNullable(toDecimal32(2, 0)), NULL), ifNull(toNullable(toDecimal64(2, 0)), NULL), ifNull(toNullable(toDecimal128(2, 0)), NULL);
|
||||||
|
SELECT ifNull(NULL, toDecimal32(3, 0)), ifNull(NULL, toDecimal64(3, 0)), ifNull(NULL, toDecimal128(3, 0));
|
||||||
|
SELECT ifNull(NULL, toNullable(toDecimal32(4, 0))), ifNull(NULL, toNullable(toDecimal64(4, 0))), ifNull(NULL, toNullable(toDecimal128(4, 0)));
|
||||||
|
|
||||||
|
SELECT coalesce(toDecimal32(5, 0), NULL), coalesce(toDecimal64(5, 0), NULL), coalesce(toDecimal128(5, 0), NULL);
|
||||||
|
SELECT coalesce(NULL, toDecimal32(6, 0)), coalesce(NULL, toDecimal64(6, 0)), coalesce(NULL, toDecimal128(6, 0));
|
||||||
|
|
||||||
|
SELECT coalesce(toNullable(toDecimal32(7, 0)), NULL), coalesce(toNullable(toDecimal64(7, 0)), NULL), coalesce(toNullable(toDecimal128(7, 0)), NULL);
|
||||||
|
SELECT coalesce(NULL, toNullable(toDecimal32(8, 0))), coalesce(NULL, toNullable(toDecimal64(8, 0))), coalesce(NULL, toNullable(toDecimal128(8, 0)));
|
||||||
|
|
||||||
|
SELECT nullIf(toNullable(toDecimal32(1, 0)), toDecimal32(1, 0)), nullIf(toNullable(toDecimal64(1, 0)), toDecimal64(1, 0));
|
||||||
|
SELECT nullIf(toDecimal32(1, 0), toNullable(toDecimal32(1, 0))), nullIf(toDecimal64(1, 0), toNullable(toDecimal64(1, 0)));
|
||||||
|
SELECT nullIf(toNullable(toDecimal32(1, 0)), toDecimal32(2, 0)), nullIf(toNullable(toDecimal64(1, 0)), toDecimal64(2, 0));
|
||||||
|
SELECT nullIf(toDecimal32(1, 0), toNullable(toDecimal32(2, 0))), nullIf(toDecimal64(1, 0), toNullable(toDecimal64(2, 0)));
|
||||||
|
SELECT nullIf(toNullable(toDecimal128(1, 0)), toDecimal128(1, 0));
|
||||||
|
SELECT nullIf(toDecimal128(1, 0), toNullable(toDecimal128(1, 0)));
|
||||||
|
SELECT nullIf(toNullable(toDecimal128(1, 0)), toDecimal128(2, 0));
|
||||||
|
SELECT nullIf(toDecimal128(1, 0), toNullable(toDecimal128(2, 0)));
|
||||||
|
|
||||||
|
INSERT INTO test.decimal (a, b, c, d, e, f) VALUES (1.1, 1.1, 1.1, 1.1, 1.1, 1.1);
|
||||||
|
INSERT INTO test.decimal (a, b, c, d) VALUES (2.2, 2.2, 2.2, 2.2);
|
||||||
|
INSERT INTO test.decimal (a, b, c, e) VALUES (3.3, 3.3, 3.3, 3.3);
|
||||||
|
INSERT INTO test.decimal (a, b, c, f) VALUES (4.4, 4.4, 4.4, 4.4);
|
||||||
|
INSERT INTO test.decimal (a, b, c) VALUES (5.5, 5.5, 5.5);
|
||||||
|
|
||||||
|
SELECT * FROM test.decimal ORDER BY d, e, f;
|
||||||
|
SELECT isNull(a), isNotNull(a) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT isNull(b), isNotNull(b) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT isNull(c), isNotNull(c) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT isNull(d), isNotNull(d) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT isNull(e), isNotNull(e) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT isNull(f), isNotNull(f) FROM test.decimal WHERE a = toDecimal32(5.5, 1);
|
||||||
|
SELECT count() FROM test.decimal WHERE a IS NOT NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE b IS NOT NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE c IS NOT NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE d IS NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE e IS NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE f IS NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE d IS NULL AND e IS NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE d IS NULL AND f IS NULL;
|
||||||
|
SELECT count() FROM test.decimal WHERE e IS NULL AND f IS NULL;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS test.decimal;
|
Loading…
Reference in New Issue
Block a user