Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Support get attribute of date/time/datetime (#1268)
Browse files Browse the repository at this point in the history
* Support get attribute of date/time/datetime.

* Return unknown prop

* Allow the case insensitive property for date time.

Co-authored-by: Yee <[email protected]>
Co-authored-by: cpw <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2021
1 parent becb32e commit fa612c7
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/visitor/DeduceTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,26 @@ void DeduceTypeVisitor::visit(SubscriptExpression *expr) {
void DeduceTypeVisitor::visit(AttributeExpression *expr) {
expr->left()->accept(this);
if (!ok()) return;
// TODO: Time, DateTime, Date
if (type_ != Value::Type::MAP && type_ != Value::Type::VERTEX && type_ != Value::Type::EDGE &&
!isSuperiorType(type_)) {
std::stringstream ss;
ss << "`" << expr->toString() << "', expected Map, Vertex or Edge but was " << type_ << ": "
<< expr->left()->toString();
status_ = Status::SemanticError(ss.str());
return;
switch (type_) {
case Value::Type::MAP:
case Value::Type::VERTEX:
case Value::Type::EDGE:
case Value::Type::DATE:
case Value::Type::TIME:
case Value::Type::DATETIME:
// nothing
break;
default: {
if (!isSuperiorType(type_)) {
std::stringstream ss;
ss << "`" << expr->toString() <<
"', expected type with attribute like Date, Time, DateTime, "
"Map, Vertex or Edge but was " <<
type_ << ": " << expr->left()->toString();
status_ = Status::SemanticError(ss.str());
return;
}
}
}

expr->right()->accept(this);
Expand Down
148 changes: 148 additions & 0 deletions tests/tck/features/expression/Attribute.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Copyright (c) 2021 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
Feature: Attribute

Background:
Given a graph with space named "nba"

Scenario: Attribute for basic type
When executing query:
"""
RETURN date("2021-07-19").month AS month
"""
Then the result should be, in any order:
| month |
| 7 |
When executing query:
"""
RETURN date("2021-07-19").MoNth AS month
"""
Then the result should be, in any order:
| month |
| 7 |
When executing query:
"""
RETURN time("02:59:40").minute AS minute
"""
Then the result should be, in any order:
| minute |
| 59 |
When executing query:
"""
RETURN time("02:59:40").MinUte AS minute
"""
Then the result should be, in any order:
| minute |
| 59 |
When executing query:
"""
RETURN datetime("2021-07-19T02:59:40").minute AS minute
"""
Then the result should be, in any order:
| minute |
| 59 |
When executing query:
"""
RETURN datetime("2021-07-19T02:59:40").mInutE AS minute
"""
Then the result should be, in any order:
| minute |
| 59 |
When executing query:
"""
RETURN {k1 : 1, k2: true}.k1 AS k
"""
Then the result should be, in any order:
| k |
| 1 |
When executing query:
"""
RETURN {k1 : 1, k2: true}.K1 AS k
"""
Then the result should be, in any order:
| k |
| UNKNOWN_PROP |
When executing query:
"""
MATCH (v) WHERE id(v) == 'Tim Duncan' RETURN v.name
"""
Then the result should be, in any order:
| v.name |
| "Tim Duncan" |
When executing query:
"""
MATCH (v) WHERE id(v) == 'Tim Duncan' RETURN v.Name
"""
Then the result should be, in any order:
| v.Name |
| UNKNOWN_PROP |
When executing query:
"""
MATCH (v)-[e:like]->() WHERE id(v) == 'Tim Duncan' RETURN e.likeness
"""
Then the result should be, in any order:
| e.likeness |
| 95 |
| 95 |
When executing query:
"""
MATCH (v)-[e:like]->() WHERE id(v) == 'Tim Duncan' RETURN e.Likeness
"""
Then the result should be, in any order:
| e.Likeness |
| UNKNOWN_PROP |
| UNKNOWN_PROP |

Scenario: Not exists attribute
When executing query:
"""
RETURN date("2021-07-19").not_exists_attr AS not_exists_attr
"""
Then the result should be, in any order:
| not_exists_attr |
| UNKNOWN_PROP |
When executing query:
"""
RETURN time("02:59:40").not_exists_attr AS not_exists_attr
"""
Then the result should be, in any order:
| not_exists_attr |
| UNKNOWN_PROP |
When executing query:
"""
RETURN datetime("2021-07-19T02:59:40").not_exists_attr AS not_exists_attr
"""
Then the result should be, in any order:
| not_exists_attr |
| UNKNOWN_PROP |
When executing query:
"""
RETURN {k1 : 1, k2: true}.not_exists_attr AS not_exists_attr
"""
Then the result should be, in any order:
| not_exists_attr |
| UNKNOWN_PROP |
When executing query:
"""
MATCH (v) WHERE id(v) == 'Tim Duncan' RETURN v.not_exists_attr
"""
Then the result should be, in any order:
| v.not_exists_attr |
| UNKNOWN_PROP |
When executing query:
"""
MATCH (v)-[e:like]->() WHERE id(v) == 'Tim Duncan' RETURN e.not_exists_attr
"""
Then the result should be, in any order:
| e.not_exists_attr |
| UNKNOWN_PROP |
| UNKNOWN_PROP |

Scenario: Invalid type
When executing query:
"""
RETURN (true).attr
"""
Then a SemanticError should be raised at runtime: `true.attr', expected type with attribute like Date, Time, DateTime, Map, Vertex or Edge but was BOOL: true

0 comments on commit fa612c7

Please sign in to comment.