[MCOL-807] HOUR() function returns NULL when it should not Created: 2017-07-10  Updated: 2018-06-14  Resolved: 2018-06-14

Status: Closed
Project: MariaDB ColumnStore
Component/s: MariaDB Server
Affects Version/s: 1.0.9
Fix Version/s: 1.2.0

Type: Bug Priority: Major
Reporter: Marc Ballarin Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Blocks
is blocked by MCOL-392 TIME datatype is not supported Closed
Epic Link: ColumnStore Compatibility Improvements
Sprint: 2018-12

 Description   

Hi,

the following query returns NULL when run on a table with engine Columnstore and the correct result when run on an identical table with engine Aria:

CREATE TABLE test_stats1 (
  ts DATETIME DEFAULT NULL
) ENGINE = Columnstore;
CREATE TABLE test_stats2 (
  ts DATETIME DEFAULT NULL
) ENGINE = Aria;
 
INSERT INTO test_stats1 VALUES ('2017-07-07 12:00:00');
INSERT INTO test_stats2 VALUES ('2017-07-07 12:00:00');
 
SELECT HOUR(TIMEDIFF(MAX(ts), now())) FROM test_stats1;
-> NULL
SELECT HOUR(TIMEDIFF(MAX(ts), now())) FROM test_stats2;
-> 73

Strangely, omitting HOUR() works correctly:

SELECT TIMEDIFF(MAX(ts), now()) FROM test_stats1;
-> -74:43:31
SELECT TIMEDIFF(MAX(ts), now()) FROM test_stats2;
-> -74:43:34



 Comments   
Comment by David Thompson (Inactive) [ 2017-07-12 ]

The columnstore distributed version of timediff currently returns the value as a string since the time datatype is not yet supported. The columnstore distributed hour function assumes a string should be converted as a datetime value and so a time values is not considered valid so it ends up null.

Likely this should be fixed when time datatype is added.

As a workaround you could potentially instead use string manipulation functions to extract the hour portion?

Comment by Marc Ballarin [ 2017-07-18 ]

FYI, I ended up using SUBSTRING_INDEX(TIMEDIFF(...), ':', 1). This works in both cases.

Comment by Andrew Hutchings (Inactive) [ 2018-05-01 ]

This is fixed as part of MCOL-392

Comment by Daniel Lee (Inactive) [ 2018-05-29 ]

Build tested: 1.2.0-1 source

/root/columnstore/mariadb-columnstore-server
commit 4334641df0df040e0f53332c11dc8e29dc34b8b7
Merge: 960853c cd5e845
Author: David.Hall <david.hall@mariadb.com>
Date: Mon Apr 9 13:23:44 2018 -0500

Merge pull request #107 from mariadb-corporation/dev-merge-up-20180409

Dev merge up 20180409

/root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine
commit e79daac8a9b1c8047aeabc3d73ae137cc151f84e
Merge: 8790177 8a3c5e0
Author: Andrew Hutchings <andrew@linuxjedi.co.uk>
Date: Tue May 15 15:34:19 2018 +0100

Merge pull request #472 from drrtuy/MCOL-1073

MCOL-1073 Removed DecomSrv

ColumnStore returned negative hours and both aris and innodb return a positive hour numbers.

All three table types did return a negative time stamp by TIMEDIFF(MAX(ts), now()).

So is it a bug in the server or in the Columnstore? From what I read, it is pointing to a bug in ColumnStore.

[root@localhost ~]# mcsmysql mytest
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 10.2.14-MariaDB-log Columnstore 1.2.0-1

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mytest]> CREATE TABLE test_stats1 (
-> ts DATETIME DEFAULT NULL
-> ) ENGINE = Columnstore;
Query OK, 0 rows affected (0.11 sec)

MariaDB [mytest]> CREATE TABLE test_stats2 (
-> ts DATETIME DEFAULT NULL
-> ) ENGINE = Aria;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mytest]>
MariaDB [mytest]> INSERT INTO test_stats1 VALUES ('2017-07-07 12:00:00');
Query OK, 1 row affected (0.13 sec)

MariaDB [mytest]> INSERT INTO test_stats2 VALUES ('2017-07-07 12:00:00');
Query OK, 1 row affected (0.00 sec)

MariaDB [mytest]> SELECT HOUR(TIMEDIFF(MAX(ts), now())) FROM test_stats1;
--------------------------------

HOUR(TIMEDIFF(MAX(ts), now()))

--------------------------------

-838

--------------------------------
1 row in set (0.04 sec)

MariaDB [mytest]> SELECT HOUR(TIMEDIFF(MAX(ts), now())) FROM test_stats2;
--------------------------------

HOUR(TIMEDIFF(MAX(ts), now()))

--------------------------------

838

--------------------------------
1 row in set, 1 warning (0.00 sec)

MariaDB [mytest]> SELECT MAX(ts), TIMEDIFF(MAX(ts), now()) FROM test_stats2;
---------------------------------------------+

MAX(ts) TIMEDIFF(MAX(ts), now())

---------------------------------------------+

2017-07-07 12:00:00 -838:59:59

---------------------------------------------+
1 row in set, 1 warning (0.01 sec)

MariaDB [mytest]> SELECT MAX(ts), TIMEDIFF(MAX(ts), now()) FROM test_stats1;
---------------------------------------------+

MAX(ts) TIMEDIFF(MAX(ts), now())

---------------------------------------------+

2017-07-07 12:00:00 -838:59:59

---------------------------------------------+
1 row in set (0.01 sec)

Tried query from the literal date and it also returned positive numbers. That's because the front end evaluated the hour().

Comment by Andrew Hutchings (Inactive) [ 2018-06-04 ]

Pull request for engine and regression suite. Now HOUR() returns positive time only.

Also updated MariaDB Server's documentation to express this behaviour.

Comment by Daniel Lee (Inactive) [ 2018-06-14 ]

Build verified: 1.2.0-1 source

/root/columnstore/mariadb-columnstore-server
commit 3bfc3ad5f1e91e6f325b89fefaf62a6b38ca889a
Merge: 4334641 742af4d
Author: David.Hall <david.hall@mariadb.com>
Date: Thu May 31 09:40:12 2018 -0500

Merge pull request #119 from mariadb-corporation/1.1-merge-up-20180531

Merge develop-1.1 into develop

/root/columnstore/mariadb-columnstore-server/mariadb-columnstore-engine
commit 1caa98ff46777a389cdfd4ae369865391a884c27
Merge: 60a4d14 d9e6ba9
Author: David.Hall <david.hall@mariadb.com>
Date: Mon Jun 11 10:20:49 2018 -0500

Merge pull request #494 from mariadb-corporation/MCOL-1433

MCOL-1433 Fix several functions for TIME handling

Generated at Thu Feb 08 02:23:58 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.