1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

feat(datatypes): MCOL-4632 and MCOL-4648, fix cast leads to NULL.

Remove redundant cast.

As C-style casts with a type name in parantheses are interpreted as static_casts this literally just changes the interpretation around (and forces an implicit cast to match the return value of the function).

Switch UBIGINTNULL and UBIGINTEMPTYROW constants for consistency.

Make consistent with relation between BIGINTNULL and BIGINTEMPTYROW & make adapted cast behaviour due to NULL markers more intuitive. (After this change we can simply block the highest possible uint64_t value and if a cast results in it, print the next lower value (2^64 - 2). Previously, (2^64 - 1) was able to be printed, but (2^64 - 2) as being blocked by the UBIGINTNULL constant was not, making finding the appropiate replacement value to give out more confusing.

Introduce MAX_MCS_UBIGINT and MIN_MCS_BIGINT and adapt casts.

Adapt casting to BIGINT to remove NULL marker error.

Add bugfix regression test for MCOL 4632

Add regression test for mcol_4648

Revert "Switch UBIGINTNULL and UBIGINTEMPTYROW constants for consistency."

This reverts commit 83eac11b18937ecb0b4c754dd48e4cb47310f620.
Due to backwards compatability issues.

Refactor casting to MCS[U]Int to datatype functions.

Update regression tests to include other affected datatypes.

Apply formatting.

Refactor according to PR review

Remove redundant new constant, switch to using already existing constant.

Adapt nullstring casting to EMPTYROW markers for backwards compatability.

Adapt tests for backward compatability behaviour allowing text datatypes to be casted to EMPTYROW constant.

Adapt mcol641-functions test according to bug fix.

Update tests according to new expected behaviour.

Adapt tests to new understanding of issue.

Update comments/documentation for MCOL_4632 test.

Adapt to new cast limit logic.

Make bracketing consistent.

Adapt previous regression test to new expected behaviour.
This commit is contained in:
Theresa Hradilak
2023-06-19 15:23:42 +00:00
parent 4b20ced6a7
commit 48562e41f9
12 changed files with 280 additions and 94 deletions

View File

@ -0,0 +1,41 @@
#
# MCOL-4632: Disallow casting to NULL marker values, allow casting to EMPTY ROW values.
#
# Defined in joblisttypes.h: BIGINTNULL = 0x8000000000000000ULL == -9223372036854775808 (when casted to int64_t)
# Defined in joblisttypes.h: BIGINTEMPTYROW = 0x8000000000000001ULL == -9223372036854775807 (when casted to int64_t)
#
DROP DATABASE IF EXISTS mcol_4632;
CREATE DATABASE mcol_4632;
USE mcol_4632;
CREATE TABLE t1
(d1 DECIMAL(30,0), d2 DECIMAL(30,0) NOT NULL,
i1 BIGINT UNSIGNED, i2 BIGINT UNSIGNED NOT NULL,
str1 TEXT, str2 TEXT NOT NULL,
double1 DOUBLE(30,0), double2 DOUBLE(30,0) NOT NULL) ENGINE=ColumnStore;
INSERT INTO t1 VALUES
(-9223372036854775808, -9223372036854775808,
9223372036854775808, 9223372036854775808,
"-9223372036854775808", "-9223372036854775808",
-9223372036854775808.0, -9223372036854775808.0);
INSERT INTO t1 VALUES
(-9223372036854775807, -9223372036854775807,
9223372036854775809, 9223372036854775809,
"-9223372036854775807", "-9223372036854775807",
-9223372036854775807.0, -9223372036854775807.0);
SELECT d1, CAST(d1 AS SIGNED), CAST(d2 AS SIGNED) FROM t1;
d1 CAST(d1 AS SIGNED) CAST(d2 AS SIGNED)
-9223372036854775808 -9223372036854775807 -9223372036854775807
-9223372036854775807 -9223372036854775807 -9223372036854775807
SELECT i1, CAST(i1 AS SIGNED), CAST(i2 AS SIGNED) FROM t1;
i1 CAST(i1 AS SIGNED) CAST(i2 AS SIGNED)
9223372036854775808 -9223372036854775807 -9223372036854775807
9223372036854775809 -9223372036854775807 -9223372036854775807
SELECT str1, CAST(str1 AS SIGNED), CAST(str2 AS SIGNED) FROM t1;
str1 CAST(str1 AS SIGNED) CAST(str2 AS SIGNED)
-9223372036854775808 -9223372036854775807 -9223372036854775807
-9223372036854775807 -9223372036854775807 -9223372036854775807
SELECT double1, CAST(double1 AS SIGNED), CAST(double2 AS SIGNED) FROM t1;
double1 CAST(double1 AS SIGNED) CAST(double2 AS SIGNED)
-9223372036854776000 -9223372036854775807 -9223372036854775807
-9223372036854776000 -9223372036854775807 -9223372036854775807
DROP DATABASE mcol_4632;

View File

@ -0,0 +1,32 @@
--source ../include/have_columnstore.inc
--echo #
--echo # MCOL-4632: Disallow casting to NULL marker values, allow casting to EMPTY ROW values.
--echo #
--echo # Defined in joblisttypes.h: BIGINTNULL = 0x8000000000000000ULL == -9223372036854775808 (when casted to int64_t)
--echo # Defined in joblisttypes.h: BIGINTEMPTYROW = 0x8000000000000001ULL == -9223372036854775807 (when casted to int64_t)
--echo #
--disable_warnings
DROP DATABASE IF EXISTS mcol_4632;
--enable_warnings
CREATE DATABASE mcol_4632;
USE mcol_4632;
CREATE TABLE t1
(d1 DECIMAL(30,0), d2 DECIMAL(30,0) NOT NULL,
i1 BIGINT UNSIGNED, i2 BIGINT UNSIGNED NOT NULL,
str1 TEXT, str2 TEXT NOT NULL,
double1 DOUBLE(30,0), double2 DOUBLE(30,0) NOT NULL) ENGINE=ColumnStore;
INSERT INTO t1 VALUES
(-9223372036854775808, -9223372036854775808,
9223372036854775808, 9223372036854775808,
"-9223372036854775808", "-9223372036854775808",
-9223372036854775808.0, -9223372036854775808.0);
INSERT INTO t1 VALUES
(-9223372036854775807, -9223372036854775807,
9223372036854775809, 9223372036854775809,
"-9223372036854775807", "-9223372036854775807",
-9223372036854775807.0, -9223372036854775807.0);
SELECT d1, CAST(d1 AS SIGNED), CAST(d2 AS SIGNED) FROM t1;
SELECT i1, CAST(i1 AS SIGNED), CAST(i2 AS SIGNED) FROM t1;
SELECT str1, CAST(str1 AS SIGNED), CAST(str2 AS SIGNED) FROM t1;
SELECT double1, CAST(double1 AS SIGNED), CAST(double2 AS SIGNED) FROM t1;
DROP DATABASE mcol_4632;

View File

@ -0,0 +1,36 @@
#
# MCOL-4648: Disallow casting to NULL marker values, allow casting to EMPTY ROW values.
#
# Defined in joblisttypes.h: UBIGINTNULL == 0xFFFFFFFFFFFFFFFEULL == 18446744073709551614
# Defined in joblisttypes.h: UBIGINTEMPTYROW == 0xFFFFFFFFFFFFFFFFULL == 18446744073709551615
#
DROP DATABASE IF EXISTS mcol_4648;
CREATE DATABASE mcol_4648;
USE mcol_4648;
CREATE TABLE t1
(d1 DECIMAL(30,0), d2 DECIMAL(30,0) NOT NULL,
str1 TEXT, str2 TEXT NOT NULL,
double1 DOUBLE(30,0), double2 DOUBLE(30,0) NOT NULL) ENGINE=ColumnStore;
INSERT INTO t1 VALUES
(18446744073709551614, 18446744073709551614,
"18446744073709551614", "18446744073709551614",
18446744073709551614.0, 18446744073709551614.0);
INSERT INTO t1 VALUES
(18446744073709551615, 18446744073709551615,
"18446744073709551615", "18446744073709551615",
18446744073709551615.0, 18446744073709551615.0);
SELECT d1, CAST(d1 AS UNSIGNED), CAST(d2 AS UNSIGNED) FROM t1;
d1 CAST(d1 AS UNSIGNED) CAST(d2 AS UNSIGNED)
18446744073709551614 18446744073709551613 18446744073709551613
18446744073709551615 18446744073709551615 18446744073709551615
SELECT str1, CAST(str1 AS UNSIGNED), CAST(str2 AS UNSIGNED) FROM t1;
str1 CAST(str1 AS UNSIGNED) CAST(str2 AS UNSIGNED)
18446744073709551614 18446744073709551613 18446744073709551613
18446744073709551615 18446744073709551615 18446744073709551615
# Doubles only store about 15 digits of precision for decimal places, therefore both inserted numbers
# are rounded to 18446744073709552000.0 and we expect them to be casted to EMPTYROW value each.
SELECT double1, CAST(double1 AS UNSIGNED), CAST(double2 AS UNSIGNED) FROM t1;
double1 CAST(double1 AS UNSIGNED) CAST(double2 AS UNSIGNED)
18446744073709552000 18446744073709551615 18446744073709551615
18446744073709552000 18446744073709551615 18446744073709551615
DROP DATABASE mcol_4648;

View File

@ -0,0 +1,30 @@
--source ../include/have_columnstore.inc
--echo #
--echo # MCOL-4648: Disallow casting to NULL marker values, allow casting to EMPTY ROW values.
--echo #
--echo # Defined in joblisttypes.h: UBIGINTNULL == 0xFFFFFFFFFFFFFFFEULL == 18446744073709551614
--echo # Defined in joblisttypes.h: UBIGINTEMPTYROW == 0xFFFFFFFFFFFFFFFFULL == 18446744073709551615
--echo #
--disable_warnings
DROP DATABASE IF EXISTS mcol_4648;
--enable_warnings
CREATE DATABASE mcol_4648;
USE mcol_4648;
CREATE TABLE t1
(d1 DECIMAL(30,0), d2 DECIMAL(30,0) NOT NULL,
str1 TEXT, str2 TEXT NOT NULL,
double1 DOUBLE(30,0), double2 DOUBLE(30,0) NOT NULL) ENGINE=ColumnStore;
INSERT INTO t1 VALUES
(18446744073709551614, 18446744073709551614,
"18446744073709551614", "18446744073709551614",
18446744073709551614.0, 18446744073709551614.0);
INSERT INTO t1 VALUES
(18446744073709551615, 18446744073709551615,
"18446744073709551615", "18446744073709551615",
18446744073709551615.0, 18446744073709551615.0);
SELECT d1, CAST(d1 AS UNSIGNED), CAST(d2 AS UNSIGNED) FROM t1;
SELECT str1, CAST(str1 AS UNSIGNED), CAST(str2 AS UNSIGNED) FROM t1;
--echo # Doubles only store about 15 digits of precision for decimal places, therefore both inserted numbers
--echo # are rounded to 18446744073709552000.0 and we expect them to be casted to EMPTYROW value each.
SELECT double1, CAST(double1 AS UNSIGNED), CAST(double2 AS UNSIGNED) FROM t1;
DROP DATABASE mcol_4648;