Skip to content
Snippets Groups Projects
Commit 8fcc1d67 authored by Quazgar's avatar Quazgar
Browse files

Merge: Fix >= and <= operators for date queries

This adds two missing branches in the `getDateWhereClause` function and fixes an consistency in the `constructDateTimeWhereClauseForColumn` function.

# Focus

1. Don't let the whitespace changes confuse you.
2. The changes in `constructDateTimeWhereClauseForColumn` merely add an "OR value_ns IS NULL".
3. The changes in `getDataWhereClause` add an ELSEIF branch for each operator.
parents 6b700f3c 4ebc0376
No related branches found
No related tags found
No related merge requests found
...@@ -47,6 +47,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -47,6 +47,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### ### Fixed ###
* Fixed the `>=` and `<=` operators for comparisons in POV query filters with
stored DATE values. The fix makes the implementation consistent
However, the current definition and implementation of the
`>=` and `<=` operators for date and datetime is unintuitive and the operators
should have another name. Something like "overlap with or smaller/greater
than".
* Semi-fix in `retrieveEntityParents`. The old implementation was buggy and * Semi-fix in `retrieveEntityParents`. The old implementation was buggy and
would return no parent name or even a wrong one for old entity versions in would return no parent name or even a wrong one for old entity versions in
some cases. The semi-fix will allways return the current name of the parent some cases. The semi-fix will allways return the current name of the parent
......
...@@ -85,7 +85,14 @@ BEGIN ...@@ -85,7 +85,14 @@ BEGIN
RETURN CONCAT(" ", RETURN CONCAT(" ",
seconds_col, operator, vDateTimeSecLow, IF(vDateTimeNSLow IS NULL, '', CONCAT(' OR (',seconds_col,'=', vDateTimeSecLow, ' AND ',nanos_col, operator, vDateTimeNSLow, ')'))); seconds_col, operator, vDateTimeSecLow, IF(vDateTimeNSLow IS NULL, '', CONCAT(' OR (',seconds_col,'=', vDateTimeSecLow, ' AND ',nanos_col, operator, vDateTimeNSLow, ')')));
ELSEIF operator = '>=' or operator = '<=' THEN ELSEIF operator = '>=' or operator = '<=' THEN
RETURN CONCAT(" ",seconds_col, operator, vDateTimeSecLow, IF(vDateTimeNSLow IS NULL, '', CONCAT(' AND (',seconds_col, operator_prefix, vDateTimeSecLow, ' OR ',nanos_col, operator, vDateTimeNSLow, ')'))); RETURN CONCAT(
" ", seconds_col, operator, vDateTimeSecLow,
IF(vDateTimeNSLow IS NULL,
'',
CONCAT(
' AND (', seconds_col, operator_prefix, vDateTimeSecLow,
' OR ', nanos_col, operator, vDateTimeNSLow,
' OR ', nanos_col, ' IS NULL)')));
ELSEIF operator = "(" THEN ELSEIF operator = "(" THEN
RETURN IF(vDateTimeNSLow IS NULL,CONCAT(" ",seconds_col,"=", vDateTimeSecLow),CONCAT(" ",seconds_col,"=",vDateTimeSecLow," AND ",nanos_col,"=",vDateTimeNSLow)); RETURN IF(vDateTimeNSLow IS NULL,CONCAT(" ",seconds_col,"=", vDateTimeSecLow),CONCAT(" ",seconds_col,"=",vDateTimeSecLow," AND ",nanos_col,"=",vDateTimeNSLow));
ELSEIF operator = "!(" THEN ELSEIF operator = "!(" THEN
...@@ -106,15 +113,20 @@ DELIMITER // ...@@ -106,15 +113,20 @@ DELIMITER //
CREATE FUNCTION db_2_0.getDateWhereClause(vDateTimeDotNotation VARCHAR(255), operator CHAR(4)) RETURNS VARCHAR(20000) DETERMINISTIC CREATE FUNCTION db_2_0.getDateWhereClause(vDateTimeDotNotation VARCHAR(255), operator CHAR(4)) RETURNS VARCHAR(20000) DETERMINISTIC
BEGIN BEGIN
DECLARE isInterval INTEGER DEFAULT LOCATE('--',vDateTimeDotNotation); DECLARE isInterval INTEGER DEFAULT LOCATE('--',vDateTimeDotNotation);
-- ILB is short for Inclusive Lower Boundary
DECLARE vILB VARCHAR(255) DEFAULT IF(isInterval != 0, SUBSTRING_INDEX(vDateTimeDotNotation, '--', 1), vDateTimeDotNotation); DECLARE vILB VARCHAR(255) DEFAULT IF(isInterval != 0, SUBSTRING_INDEX(vDateTimeDotNotation, '--', 1), vDateTimeDotNotation);
-- EUB is short for Exclusive Upper Boundary
DECLARE vEUB VARCHAR(255) DEFAULT IF(isInterval != 0, SUBSTRING_INDEX(vDateTimeDotNotation, '--', -1), NULL); DECLARE vEUB VARCHAR(255) DEFAULT IF(isInterval != 0, SUBSTRING_INDEX(vDateTimeDotNotation, '--', -1), NULL);
DECLARE vILB_Date INTEGER DEFAULT SUBSTRING_INDEX(vILB, '.', 1); DECLARE vILB_Date INTEGER DEFAULT SUBSTRING_INDEX(vILB, '.', 1);
DECLARE vEUB_Date INTEGER DEFAULT SUBSTRING_INDEX(vEUB, '.', 1); DECLARE vEUB_Date INTEGER DEFAULT SUBSTRING_INDEX(vEUB, '.', 1);
-- hasTime is actually hasNotTime
DECLARE hasTime INTEGER DEFAULT LOCATE('.NULL.NULL',vILB); DECLARE hasTime INTEGER DEFAULT LOCATE('.NULL.NULL',vILB);
-- Day of Month (0-31, 0 means any)
DECLARE dom INTEGER DEFAULT vILB_Date % 100; DECLARE dom INTEGER DEFAULT vILB_Date % 100;
-- Month (0-12, 0 means any)
DECLARE mon INTEGER DEFAULT ((vILB_Date % 10000) - dom) / 100; DECLARE mon INTEGER DEFAULT ((vILB_Date % 10000) - dom) / 100;
-- Year
DECLARE yea INTEGER DEFAULT (vILB_Date - (vILB_Date % 10000)) / 10000; DECLARE yea INTEGER DEFAULT (vILB_Date - (vILB_Date % 10000)) / 10000;
SELECT vILB_Date != vEUB_Date INTO isInterval;
IF operator = '=' and hasTime != 0 THEN IF operator = '=' and hasTime != 0 THEN
RETURN CONCAT(" subdata.value=", vILB_Date); RETURN CONCAT(" subdata.value=", vILB_Date);
...@@ -161,6 +173,32 @@ BEGIN ...@@ -161,6 +173,32 @@ BEGIN
ELSE ELSE
RETURN CONCAT(" subdata.value>=",vEUB_Date); RETURN CONCAT(" subdata.value>=",vEUB_Date);
END IF; END IF;
ELSEIF operator = "<=" THEN
IF mon != 0 and dom != 0 THEN
-- Full date YYYY-MM-DD
RETURN CONCAT(" subdata.value<=", vILB_Date,
" or (subdata.value<=", yea*10000 + mon*100, " and subdata.value%100=0)");
ELSEIF mon != 0 THEN
-- Date is fragment YYYY-MM
RETURN CONCAT(" subdata.value<", vEUB_Date);
ELSE
-- Date is fragment YYYY
RETURN CONCAT(" subdata.value<", vEUB_Date);
END IF;
ELSEIF operator = ">=" THEN
IF mon != 0 and dom != 0 THEN
-- Full date YYYY-MM-DD
RETURN CONCAT(" subdata.value>=", vILB_Date,
" or (subdata.value>=", yea*10000 + mon*100, " and subdata.value%100=0)" +
" or (subdata.value>=", yea*10000, " and subdata.value%10000=0)");
ELSEIF mon != 0 THEN
-- Date is fragment YYYY-MM
RETURN CONCAT(" subdata.value>=", yea*10000 + mon*100,
" or (subdata.value>=", yea*10000, " and subdata.value%10000=0)");
ELSE
-- Date is fragment YYYY
RETURN CONCAT(" subdata.value>=", yea*10000);
END IF;
END IF; END IF;
return ' 0=1'; return ' 0=1';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment