From 1b508e56f2758c3882027bf4db5da7d2bdd7b164 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:15:54 +0800 Subject: [PATCH 1/3] Support get attribute of date/time/datetime. --- src/visitor/DeduceTypeVisitor.cpp | 28 +++-- .../tck/features/expression/Attribute.feature | 105 ++++++++++++++++++ 2 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 tests/tck/features/expression/Attribute.feature diff --git a/src/visitor/DeduceTypeVisitor.cpp b/src/visitor/DeduceTypeVisitor.cpp index d8a0a3806..58723e4f7 100644 --- a/src/visitor/DeduceTypeVisitor.cpp +++ b/src/visitor/DeduceTypeVisitor.cpp @@ -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); diff --git a/tests/tck/features/expression/Attribute.feature b/tests/tck/features/expression/Attribute.feature new file mode 100644 index 000000000..3896f47df --- /dev/null +++ b/tests/tck/features/expression/Attribute.feature @@ -0,0 +1,105 @@ +# 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 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 {k1 : 1, k2: true}.k1 AS k + """ + Then the result should be, in any order: + | k | + | 1 | + 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)-[e:like]->() WHERE id(v) == 'Tim Duncan' RETURN e.likeness + """ + Then the result should be, in any order: + | e.likeness | + | 95 | + | 95 | + + 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 | + | NULL | + 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 | + | NULL | + 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 | + | NULL | + 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 | + | NULL | + 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 | + | NULL | + 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 | + | NULL | + | NULL | + + 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 From 2e671724c413de6ba501e7e3213e2dae75674889 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Wed, 21 Jul 2021 12:01:33 +0800 Subject: [PATCH 2/3] Return unknown prop --- tests/tck/features/expression/Attribute.feature | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/tck/features/expression/Attribute.feature b/tests/tck/features/expression/Attribute.feature index 3896f47df..b8844717e 100644 --- a/tests/tck/features/expression/Attribute.feature +++ b/tests/tck/features/expression/Attribute.feature @@ -59,43 +59,43 @@ Feature: Attribute """ Then the result should be, in any order: | not_exists_attr | - | NULL | + | 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 | - | NULL | + | 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 | - | NULL | + | 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 | - | NULL | + | 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 | - | NULL | + | 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 | - | NULL | - | NULL | + | UNKNOWN_PROP | + | UNKNOWN_PROP | Scenario: Invalid type When executing query: From 73a97ebc83afe96890dd8d02ef7faa35dc770cc4 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Wed, 28 Jul 2021 11:40:03 +0800 Subject: [PATCH 3/3] Allow the case insensitive property for date time. --- .../tck/features/expression/Attribute.feature | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/tck/features/expression/Attribute.feature b/tests/tck/features/expression/Attribute.feature index b8844717e..05993c0b0 100644 --- a/tests/tck/features/expression/Attribute.feature +++ b/tests/tck/features/expression/Attribute.feature @@ -15,6 +15,13 @@ Feature: Attribute 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 @@ -22,6 +29,13 @@ Feature: Attribute 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 @@ -29,6 +43,13 @@ Feature: Attribute 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 @@ -36,6 +57,13 @@ Feature: Attribute 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 @@ -43,6 +71,13 @@ Feature: Attribute 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 @@ -51,6 +86,14 @@ Feature: Attribute | 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: