Skip to content

Commit

Permalink
Add doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU authored and ray6080 committed Nov 21, 2023
1 parent 9e85665 commit 7a5435f
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/binder/bind/bind_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ std::unique_ptr<BoundRegularQuery> Binder::bindQuery(const RegularQuery& regular
auto boundRegularQuery = std::make_unique<BoundRegularQuery>(
regularQuery.getIsUnionAll(), normalizedSingleQueries[0]->getStatementResult()->copy());
for (auto& normalizedSingleQuery : normalizedSingleQueries) {
validateReadNotFollowUpdate(*normalizedSingleQuery);
boundRegularQuery->addSingleQuery(std::move(normalizedSingleQuery));
}
validateIsAllUnionOrUnionAll(*boundRegularQuery);
Expand Down
12 changes: 0 additions & 12 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,6 @@ void Binder::validateIsAllUnionOrUnionAll(const BoundRegularQuery& regularQuery)
}
}

void Binder::validateReadNotFollowUpdate(const NormalizedSingleQuery& singleQuery) {
bool hasSeenUpdateClause = false;
for (auto i = 0u; i < singleQuery.getNumQueryParts(); ++i) {
auto normalizedQueryPart = singleQuery.getQueryPart(i);
if (hasSeenUpdateClause && normalizedQueryPart->hasReadingClause()) {
throw BinderException(
"Read after update is not supported. Try query with multiple statements.");
}
hasSeenUpdateClause |= normalizedQueryPart->hasUpdatingClause();
}
}

void Binder::validateTableType(table_id_t tableID, TableType expectedTableType) {
if (catalog.getReadOnlyVersion()->getTableSchema(tableID)->tableType != expectedTableType) {
throw BinderException("aa");
Expand Down
4 changes: 0 additions & 4 deletions src/include/binder/binder.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,6 @@ class Binder {

static void validateIsAllUnionOrUnionAll(const BoundRegularQuery& regularQuery);

// We don't support read after write for simplicity. User should instead querying through
// multiple statement.
static void validateReadNotFollowUpdate(const NormalizedSingleQuery& singleQuery);

void validateTableType(common::table_id_t tableID, common::TableType expectedTableType);
void validateTableExist(const std::string& tableName);

Expand Down
3 changes: 3 additions & 0 deletions src/planner/plan/plan_subquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ void QueryPlanner::planSubqueryIfNecessary(
if (ExpressionVisitor::hasSubquery(*expression)) {
auto expressionCollector = std::make_unique<ExpressionCollector>();
for (auto& expr : expressionCollector->collectTopLevelSubqueryExpressions(expression)) {
if (plan.getSchema()->isExpressionInScope(*expr)) {
continue;
}
planSubquery(expr, plan);
}
}
Expand Down
20 changes: 15 additions & 5 deletions test/test_files/demo_db/demo_db.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

-CASE DemoDBTest

-LOG CountSubquery
-STATEMENT MATCH (a:User) RETURN a.name, COUNT { MATCH (a)<-[:Follows]-(b:User) } AS num_follower ORDER BY num_follower;
---- 4
Adam|0
Karissa|1
Noura|1
Zhang|2

-LOG Limit1
-STATEMENT MATCH (u:User) RETURN u.name ORDER BY u.age DESC LIMIT 3;
---- 3
Expand Down Expand Up @@ -119,13 +127,14 @@ Noura|{_NODES: [{_ID: 0:2, _LABEL: User, name: Zhang, age: 50}], _RELS: [(0:0)-{
Zhang|{_NODES: [], _RELS: [(0:0)-{_LABEL: Follows, _ID: 2:1, since: 2020}->(0:2)]}
Zhang|{_NODES: [{_ID: 0:1, _LABEL: User, name: Karissa, age: 40}], _RELS: [(0:0)-{_LABEL: Follows, _ID: 2:0, since: 2020}->(0:1),(0:1)-{_LABEL: Follows, _ID: 2:2, since: 2021}->(0:2)]}

-LOG VarLengthFilter
-STATEMENT MATCH p = (a:User)-[:Follows*1..2 (r, _ | WHERE r.since < 2022) ]->(b:User) WHERE a.name = 'Adam' RETURN DISTINCT b.name;
-LOG RecursiveJoinFilter
-STATEMENT MATCH p = (a:User)-[:Follows*1..2 (r, n | WHERE r.since < 2022 AND n.age > 45) ]->(b:User)
WHERE a.name = 'Adam' RETURN DISTINCT b.name, COUNT(*);
---- 2
Karissa
Zhang
Karissa|1
Zhang|1

-LOG VarLengthFilter2
-LOG RecursiveJoinFilter2
-STATEMENT MATCH (a:User)-[e:Follows*1..2 (r, n | WHERE r.since > 2020 | {r.since}, {n.name})]->(b:User)
WHERE a.age > 0
RETURN nodes(e), rels(e);
Expand Down Expand Up @@ -302,6 +311,7 @@ Adam|30
---- 1
Adam|30


-LOG With1
-STATEMENT MATCH (a:User) WITH avg(a.age) as avgAge MATCH (b:User) WHERE b.age > avgAge RETURN *;
---- 2
Expand Down
27 changes: 27 additions & 0 deletions test/test_files/demo_db/demo_db_create.test
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,30 @@ Adam|Zhang|Kitchener
A|B|Toronto
Karissa|Zhang|Kitchener
Zhang|Noura|Guelph

-CASE DependentCreate
-STATEMENT MATCH (a:User {name:'Adam'})<-[:Follows]-(b:User) RETURN COUNT(*)
---- 1
0
-STATEMENT MATCH (a:User {name:'Adam'})
WITH a
MATCH (b:User {name:'Bob'}) CREATE (a)<-[:Follows]-(b)
WITH a, b
MATCH (c:User {name:'Zhang'}) CREATE (a)<-[:Follows]-(c)
RETURN a.name, b.name, c.name
---- 0

-STATEMENT MATCH (a:User {name:'Adam'})<-[:Follows]-(b:User) RETURN COUNT(*)
---- 1
0
-STATEMENT MATCH (a:User {name:'Adam'})
WITH a
MATCH (b:User {name:'Karissa'}) CREATE (a)<-[e1:Follows {since:2023}]-(b)
WITH a, e1
MATCH (c:User {name:'Zhang'}) CREATE (a)<-[e2:Follows {since:2024}]-(c)
RETURN e1.*, e2.*
---- 1
2023|2024
-STATEMENT MATCH (a:User {name:'Adam'})<-[:Follows]-(b:User) RETURN COUNT(*)
---- 1
2
32 changes: 28 additions & 4 deletions test/test_files/demo_db/demo_db_delete.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,39 @@
-STATEMENT MATCH (u:User) RETURN COUNT(*)
---- 1
5
-STATEMENT MATCH (u:User) WHERE u.name = 'Alice' DELETE u
---- ok
-STATEMENT MATCH (u:User) WHERE u.name = 'Alice' DELETE u RETURN u.*;
---- 1
Alice|35
-STATEMENT MATCH (u:User) RETURN COUNT(*)
---- 1
4

-CASE DeleteRelTest
-STATEMENT MATCH (u:User)-[f:Follows]->(u1:User) WHERE u.name = 'Adam' AND u1.name = 'Karissa' DELETE f
---- ok
-STATEMENT MATCH (u:User)-[f:Follows]->(u1:User) WHERE u.name = 'Adam' AND u1.name = 'Karissa' DELETE f RETURN f.*;
---- 1
2020
-STATEMENT MATCH (u:User)-[f:Follows]->(u1:User) WHERE u.name='Adam' RETURN u1.name
---- 1
Zhang

-CASE DetachDelete
-STATEMENT MATCH ()-[]->() RETURN COUNT(*)
---- 1
8
-STATEMENT MATCH (u:User) WHERE u.name = 'Adam' DETACH DELETE u RETURN u;
---- 1
{_ID: 0:0, _LABEL: User, name: Adam, age: 30}
-STATEMENT MATCH ()-[]->() RETURN COUNT(*)
---- 1
5

-CASE DeleteAllTest
-STATEMENT MATCH (u:User) DETACH DELETE u RETURN u.*;
---- 4
Adam|30
Karissa|40
Noura|25
Zhang|50
-STATEMENT MATCH ()-[]->() RETURN COUNT(*)
---- 1
0
12 changes: 2 additions & 10 deletions test/test_files/exceptions/binder/binder_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,6 @@ Binder exception: p1.age has data type INT64 but (STRING) was expected.
---- error
Binder exception: Union and union all can't be used together.

-LOG ReadAfterUpdate
-STATEMENT MATCH (a:person) SET a.age = 35 WITH a MATCH (a)-[:knows]->(b:person) RETURN a.age
---- error
Binder exception: Read after update is not supported. Try query with multiple statements.
-STATEMENT MATCH (a:person) WHERE a.age = 35 DELETE a WITH a MATCH (a)-[:knows]->(b:person) RETURN a.age
---- error
Binder exception: Read after update is not supported. Try query with multiple statements.

-LOG SetDataTypeMisMatch
-STATEMENT MATCH (a:person) SET a.age = 'hh'
---- error
Expand Down Expand Up @@ -554,12 +546,12 @@ Binder exception: Invalid number of arguments for macro ADD5.
---- error
Binder exception: Invalid number of arguments for macro ADD4.

-CASE CopyToNPYFormat
-LOG CopyToNPYFormat
-STATEMENT COPY (MATCH (a:person) RETURN a) TO 'person.npy';
---- error
Binder exception: COPY TO currently only supports csv and parquet files.

-CASE InvalidArgCast
-LOG InvalidArgCast
-STATEMENT RETURN cast("[sdf, fsd, fad]", "STRING[]", "3rd arg");
---- error
Binder exception: Invalid number of arguments for given function CAST. Expected: 2, Actual: 3.
Expand Down
4 changes: 4 additions & 0 deletions test/test_files/update_node/create_read_tinysnb.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
---- 2
0|Alice|35|11|new|70
2|Bob|30|13|new|60
-STATEMENT CREATE (a:person {ID: 12, age:22}) WITH a MATCH (b:person) WHERE b.age < a.age RETURN b.fName;
---- 2
Dan
Elizabeth
10 changes: 10 additions & 0 deletions test/test_files/update_node/delete_tinysnb.test
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ Runtime exception: Deleted nodes has connected edges in the backward direction.
-STATEMENT MATCH (a:person) RETURN COUNT(*)
---- 1
8

-CASE DetachDeleteRead
-STATEMENT MATCH (a) WHERE a.ID = 0 DETACH DELETE a
WITH a
MATCH (b:person) WHERE b.age > a.age
RETURN a.age, b.fName, b.age;
---- 3
35|Carol|45
35|Greg|40
35|Hubert Blaine Wolfeschlegelsteinhausenbergerdorff|83
9 changes: 9 additions & 0 deletions test/test_files/update_node/set_read.test
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ Alice2021-06-30
Bob1950-05-14
Carol2000-01-01
Dan

-CASE SetReadTest4
-STATEMENT MATCH (a:person) WHERE a.ID = 0
SET a.age = 22
WITH a
MATCH (b:person)
RETURN b.fName, b.age
---- 1
# Check if b0.age = 22

0 comments on commit 7a5435f

Please sign in to comment.