Skip to content

Commit

Permalink
Merge pull request #1781 from kuzudb/issue-1665
Browse files Browse the repository at this point in the history
Fix issue-1665
  • Loading branch information
acquamarin committed Jul 8, 2023
2 parents 711ae67 + 933ba32 commit 4afba41
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ std::shared_ptr<Expression> ExpressionBinder::bindAggregateFunctionExpression(
expression_vector children;
for (auto i = 0u; i < parsedExpression.getNumChildren(); ++i) {
auto child = bindExpression(*parsedExpression.getChild(i));
// rewrite aggregate on node or rel as aggregate on their internal IDs.
// e.g. COUNT(a) -> COUNT(a._id)
if (child->dataType.getLogicalTypeID() == LogicalTypeID::NODE ||
child->dataType.getLogicalTypeID() == LogicalTypeID::REL) {
child = bindInternalIDExpression(child);
auto childTypeID = child->dataType.getLogicalTypeID();
if (isDistinct &&
(childTypeID == LogicalTypeID::NODE || childTypeID == LogicalTypeID::REL)) {
throw BinderException{"DISTINCT is not supported for NODE or REL type."};
}
childrenTypes.push_back(child->dataType);
children.push_back(std::move(child));
Expand Down
3 changes: 2 additions & 1 deletion src/common/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ std::vector<LogicalType> LogicalTypeUtils::getAllValidLogicTypes() {
LogicalType{LogicalTypeID::BLOB}, LogicalType{LogicalTypeID::DATE},
LogicalType{LogicalTypeID::TIMESTAMP}, LogicalType{LogicalTypeID::INTERVAL},
LogicalType{LogicalTypeID::VAR_LIST}, LogicalType{LogicalTypeID::FLOAT},
LogicalType{LogicalTypeID::SERIAL}};
LogicalType{LogicalTypeID::SERIAL}, LogicalType{LogicalTypeID::NODE},
LogicalType{LogicalTypeID::REL}};
}

std::vector<std::string> LogicalTypeUtils::parseStructFields(const std::string& structTypeStr) {
Expand Down
4 changes: 2 additions & 2 deletions test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ Binder exception: The number of rows to skip/limit must be a non-negative intege
---- error
Binder exception: Variable a already exists.

-CASE MaxNodeID
-CASE MinNodeID
-STATEMENT MATCH (a:person) RETURN MIN(a)
---- error
Binder exception: Cannot match a built-in function for given function MIN(INTERNAL_ID). Supported inputs are
Binder exception: Cannot match a built-in function for given function MIN(NODE). Supported inputs are
DISTINCT (BOOL) -> BOOL
(BOOL) -> BOOL
DISTINCT (INT64) -> INT64
Expand Down
18 changes: 10 additions & 8 deletions test/test_files/ldbc/ldbc-interactive/interactive-complex.test
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ Euripides|1
RETURN friend.id AS personId, friend.firstName AS personFirstName, friend.lastName AS personLastName, list_sort(collect(DISTINCT tag.name)) AS tagNames, count(DISTINCT comment) AS replyCount
ORDER BY replyCount DESC, personId ASC
LIMIT 20;
---- 7
8796093022764|Zheng|Xu|[Ashoka,Genghis_Khan,Hadrian,Justinian_I,Mahmud_of_Ghazni,Marcus_Aurelius,Tiberius,Timur]|13
10995116278353|Otto|Muller|[Constantine_the_Great,Genghis_Khan,Justinian_I,Tiberius,Trajan]|11
17592186044994|Jie|Wang|[David,Genghis_Khan]|7
13194139534548|Bing|Zheng|[Genghis_Khan,Hadrian,Solomon]|6
13194139533500|Otto|Becker|[Alexander_the_Great,David,Genghis_Khan,Julius_Caesar,Tiberius]|5
28587302322537|Anh|Nguyen|[Mahmud_of_Ghazni,Trajan]|3
30786325578932|Alexander|Hleb|[David,Mahmud_of_Ghazni]|3
---- error
Binder exception: DISTINCT is not supported for NODE or REL type.

#8796093022764|Zheng|Xu|[Mahmud_of_Ghazni,Ashoka,Tiberius,Marcus_Aurelius,Genghis_Khan,Justinian_I,Hadrian,Timur]|13
#10995116278353|Otto|Muller|[Tiberius,Genghis_Khan,Justinian_I,Constantine_the_Great,Trajan]|11
#17592186044994|Jie|Wang|[Genghis_Khan,David]|7
#13194139534548|Bing|Zheng|[Genghis_Khan,Hadrian,Solomon]|6
#13194139533500|Otto|Becker|[Tiberius,Genghis_Khan,Julius_Caesar,David,Alexander_the_Great]|5
#28587302322537|Anh|Nguyen|[Mahmud_of_Ghazni,Trajan]|3
#30786325578932|Alexander|Hleb|[Mahmud_of_Ghazni,David]|3

# To be completely correct, this query needs to have
# (i) Unbounded shortest path
Expand Down
12 changes: 12 additions & 0 deletions test/test_files/tinysnb/agg/hash.test
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ Elizabeth|[25,40]
2020|[55,22]
2021|[5]

-LOG HashCollectOnNodeTest
-STATEMENT MATCH (p:person) WHERE p.ID = 3 or p.ID = 5 RETURN p.gender, collect(p)
---- 2
1|[{_ID: 0:2, _LABEL: person, ID: 3, fName: Carol, gender: 1, isStudent: False, isWorker: True, age: 45, eyeSight: 5.000000, birthdate: 1940-06-22, registerTime: 1911-08-20 02:32:21, lastJobDuration: 48:24:11, workedHours: [4,5], usedNames: [Carmen,Fred], courseScoresPerTerm: [[8,10]], grades: [91,75,21,95], height: 1.000000}]
2|[{_ID: 0:3, _LABEL: person, ID: 5, fName: Dan, gender: 2, isStudent: False, isWorker: True, age: 20, eyeSight: 4.800000, birthdate: 1950-07-23, registerTime: 2031-11-30 12:25:30, lastJobDuration: 10 years 5 months 13:00:00.000024, workedHours: [1,9], usedNames: [Wolfeschlegelstein,Daniel], courseScoresPerTerm: [[7,4],[8,8],[9]], grades: [76,88,99,89], height: 1.300000}]

-LOG HashCollectOnRelTest
-STATEMENT MATCH (p:person)-[e:knows]->(p1:person) WHERE offset(ID(e)) = 1 or offset(ID(e)) = 4 RETURN p.gender, collect(e)
---- 2
1|[(0:0)-{_LABEL: knows, _ID: 3:1, date: 2021-06-30, meetTime: 1946-08-25 19:07:22, validInterval: 20 years 30 days 48:00:00, comments: [njnojppo9u0jkmf,fjiojioh9h9h89hph]}->(0:2)]
2|[(0:1)-{_LABEL: knows, _ID: 3:4, date: 1950-05-14, meetTime: 1946-08-25 19:07:22, validInterval: 00:23:00, comments: [fwehu9h9832wewew,23u9h989sdfsss]}->(0:2)]

-LOG HashAggCountBlob
-STATEMENT MATCH (m:movies) RETURN m.length > 2542, COUNT(m.content)
-PARALLELISM 4
Expand Down
12 changes: 12 additions & 0 deletions test/test_files/tinysnb/agg/simple.test
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ False
---- 1
[[10,5],[12,8],[4,5],[1,9],[2],[3,4,5,6,7],[1],[10,11,12,3,4,5,6,7]]

-LOG SimpleCollectNodeTest
-STATEMENT MATCH (p:person) WHERE p.ID = 0 WITH collect(p) as friend RETURN friend;
-PARALLELISM 8
---- 1
[{_ID: 0:0, _LABEL: person, ID: 0, fName: Alice, gender: 1, isStudent: True, isWorker: False, age: 35, eyeSight: 5.000000, birthdate: 1900-01-01, registerTime: 2011-08-20 11:25:30, lastJobDuration: 3 years 2 days 13:02:00, workedHours: [10,5], usedNames: [Aida], courseScoresPerTerm: [[10,8],[6,7,8]], grades: [96,54,86,92], height: 1.731000}]

-LOG SimpleCollectRelTest
-STATEMENT MATCH (p:person)-[e:knows]->(p1:person) WHERE p.ID = 0 AND p1.ID = 2 WITH collect(e) as relation RETURN relation;
-PARALLELISM 6
---- 1
[(0:0)-{_LABEL: knows, _ID: 3:0, date: 2021-06-30, meetTime: 1986-10-21 21:08:31.521, validInterval: 10 years 5 months 13:00:00.000024, comments: [rnme,m8sihsdnf2990nfiwf]}->(0:1)]

-LOG SimpleAggMinTimestampTest
-STATEMENT MATCH (a:person) RETURN MIN(a.registerTime)
-PARALLELISM 8
Expand Down

0 comments on commit 4afba41

Please sign in to comment.