Fix ORDER BY and temporal types (#299)

This commit is contained in:
Antonio Andelic 2021-11-16 10:59:25 +01:00 committed by GitHub
parent 6cb293688d
commit 6c971b856e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 2 deletions

View File

@ -42,15 +42,28 @@ bool TypedValueCompare(const TypedValue &a, const TypedValue &b) {
else
return a.ValueDouble() < b.ValueDouble();
case TypedValue::Type::String:
// NOLINTNEXTLINE(modernize-use-nullptr)
return a.ValueString() < b.ValueString();
case TypedValue::Type::Date:
// NOLINTNEXTLINE(modernize-use-nullptr)
return a.ValueDate() < b.ValueDate();
case TypedValue::Type::LocalTime:
// NOLINTNEXTLINE(modernize-use-nullptr)
return a.ValueLocalTime() < b.ValueLocalTime();
case TypedValue::Type::LocalDateTime:
// NOLINTNEXTLINE(modernize-use-nullptr)
return a.ValueLocalDateTime() < b.ValueLocalDateTime();
case TypedValue::Type::Duration:
// NOLINTNEXTLINE(modernize-use-nullptr)
return a.ValueDuration() < b.ValueDuration();
case TypedValue::Type::List:
case TypedValue::Type::Map:
case TypedValue::Type::Vertex:
case TypedValue::Type::Edge:
case TypedValue::Type::Path:
throw QueryRuntimeException("Comparison is not defined for values of type {}.", a.type());
default:
LOG_FATAL("Unhandled comparison for types");
case TypedValue::Type::Null:
LOG_FATAL("Invalid type");
}
}

View File

@ -405,6 +405,70 @@ Feature: Match
"""
Then the result should be empty
Scenario: Test match with order by and date
Given an empty graph
And having executed:
"""
CREATE({a: DATE('2021-12-31')}), ({a: DATE('2021-11-11')}), ({a: DATE('2021-12-28')})
"""
When executing query:
"""
MATCH (n) RETURN n.a ORDER BY n.a
"""
Then the result should be, in order:
| n.a |
| 2021-11-11 |
| 2021-12-28 |
| 2021-12-31 |
Scenario: Test match with order by and localtime
Given an empty graph
And having executed:
"""
CREATE({a: LOCALTIME('09:12:31')}), ({a: LOCALTIME('09:09:20')}), ({a: LOCALTIME('09:11:21')})
"""
When executing query:
"""
MATCH (n) RETURN n.a ORDER BY n.a
"""
Then the result should be, in order:
| n.a |
| 09:09:20.000000000 |
| 09:11:21.000000000 |
| 09:12:31.000000000 |
Scenario: Test match with order by and localdatetime
Given an empty graph
And having executed:
"""
CREATE({a: LOCALDATETIME('2021-11-22T09:12:31')}), ({a: LOCALDATETIME('2021-11-23T09:10:30')}), ({a: LOCALDATETIME('2021-11-10T09:14:21')})
"""
When executing query:
"""
MATCH (n) RETURN n.a ORDER BY n.a
"""
Then the result should be, in order:
| n.a |
| 2021-11-10T09:14:21.000000000 |
| 2021-11-22T09:12:31.000000000 |
| 2021-11-23T09:10:30.000000000 |
Scenario: Test match with order by and duration
Given an empty graph
And having executed:
"""
CREATE({a: DURATION('P12DT3M')}), ({a: DURATION('P11DT8M')}), ({a: DURATION('P11DT60H')})
"""
When executing query:
"""
MATCH (n) RETURN n.a ORDER BY n.a
"""
Then the result should be, in order:
| n.a |
| P11DT8M |
| P12DT3M |
| P13DT12H |
Scenario: Test distinct
Given an empty graph
And having executed: