Skip to content

Commit 81b35e5

Browse files
committed
Improve tryParsePropertyGraphElementKeys
1 parent 52da535 commit 81b35e5

8 files changed

Lines changed: 521 additions & 456 deletions

parser.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,25 +3408,35 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
34083408
return nil
34093409
}
34103410

3411+
// element_key
3412+
var elementKey *ast.PropertyGraphElementKey
34113413
if key := p.tryExpectKeywordLike("KEY"); key != nil {
34123414
keyColumns := p.parsePropertyGraphColumnNameList()
3413-
elementKey := &ast.PropertyGraphElementKey{
3415+
elementKey = &ast.PropertyGraphElementKey{
34143416
Key: key.Pos,
34153417
Keys: keyColumns,
34163418
}
3417-
return &ast.PropertyGraphNodeElementKey{
3418-
PropertyGraphElementKey: *elementKey,
3419+
3420+
// if SOURCE KEY doesn't follow, it is node_element_key.
3421+
if !p.Token.IsKeywordLike("SOURCE") {
3422+
return &ast.PropertyGraphNodeElementKey{
3423+
PropertyGraphElementKey: *elementKey,
3424+
}
34193425
}
34203426

34213427
}
34223428

3429+
// the rest of edge_element_keys
3430+
3431+
// source_key
34233432
source := p.expectKeywordLike("SOURCE").Pos
34243433
p.expectKeywordLike("KEY")
34253434
sourceColumns := p.parsePropertyGraphColumnNameList()
34263435
p.expectKeywordLike("REFERENCES")
34273436
sourceReference := p.parseIdent()
34283437
sourceReferenceColumns := p.tryParsePropertyGraphColumnNameList()
34293438

3439+
// destination_key
34303440
destination := p.expectKeywordLike("DESTINATION").Pos
34313441
p.expectKeywordLike("KEY")
34323442
destinationColumns := p.parsePropertyGraphColumnNameList()
@@ -3435,7 +3445,7 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
34353445
destinationReferenceColumns := p.tryParsePropertyGraphColumnNameList()
34363446

34373447
return &ast.PropertyGraphEdgeElementKeys{
3438-
// Element: elementKey,
3448+
Element: elementKey,
34393449
Source: &ast.PropertyGraphSourceKey{
34403450
Source: source,
34413451
Keys: sourceColumns,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE OR REPLACE PROPERTY GRAPH FinGraph
2+
NODE TABLES (
3+
Account AS Account -- element_alias
4+
KEY (id) -- element_key in node_element_key in element_keys
5+
-- label_and_property_list
6+
LABEL DetailedAccount -- LABEL label_name in element_label
7+
PROPERTIES (create_time, is_blocked, nick_name AS name) -- derived_property_list
8+
DEFAULT LABEL -- DEFAULT LABEL in element_label
9+
NO PROPERTIES -- NO PROPERTIES in element_properties
10+
,
11+
Person
12+
-- no element_keys
13+
-- no element_label because of direct element_properties
14+
PROPERTIES ARE ALL COLUMNS EXCEPT (city) -- properties_are
15+
)
16+
EDGE TABLES (
17+
PersonOwnAccount AS PersonOwnAccount
18+
KEY (id, account_id)
19+
SOURCE KEY (id) REFERENCES Person -- source_key without column_name_list
20+
DESTINATION KEY (account_id) REFERENCES Account -- destination_key without column_name_list
21+
LABEL Owns
22+
PROPERTIES ALL COLUMNS,
23+
AccountTransferAccount
24+
SOURCE KEY (id) REFERENCES Account (id) -- source_key
25+
DESTINATION KEY (to_id) REFERENCES Account (id) -- destination_key
26+
LABEL Transfers -- LABEL label_name in element_label
27+
-- without element_properties
28+
)

testdata/input/ddl/create_or_replace_property_graph_fingraph.sql renamed to testdata/input/ddl/create_property_graph_if_not_exists_fingraph.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE OR REPLACE PROPERTY GRAPH FinGraph
1+
CREATE PROPERTY GRAPH IF NOT EXISTS FinGraph
22
NODE TABLES (
33
Account,
44
Person

testdata/input/ddl/create_property_graph_if_not_exists_fingraph_verbose.sql

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)