Skip to content

Commit 96c9ff1

Browse files
committed
Improve tryParsePropertyGraphElementKeys
1 parent 22b9d6d commit 96c9ff1

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
@@ -3567,25 +3567,35 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
35673567
return nil
35683568
}
35693569

3570+
// element_key
3571+
var elementKey *ast.PropertyGraphElementKey
35703572
if key := p.tryExpectKeywordLike("KEY"); key != nil {
35713573
keyColumns := p.parsePropertyGraphColumnNameList()
3572-
elementKey := &ast.PropertyGraphElementKey{
3574+
elementKey = &ast.PropertyGraphElementKey{
35733575
Key: key.Pos,
35743576
Keys: keyColumns,
35753577
}
3576-
return &ast.PropertyGraphNodeElementKey{
3577-
PropertyGraphElementKey: *elementKey,
3578+
3579+
// if SOURCE KEY doesn't follow, it is node_element_key.
3580+
if !p.Token.IsKeywordLike("SOURCE") {
3581+
return &ast.PropertyGraphNodeElementKey{
3582+
PropertyGraphElementKey: *elementKey,
3583+
}
35783584
}
35793585

35803586
}
35813587

3588+
// the rest of edge_element_keys
3589+
3590+
// source_key
35823591
source := p.expectKeywordLike("SOURCE").Pos
35833592
p.expectKeywordLike("KEY")
35843593
sourceColumns := p.parsePropertyGraphColumnNameList()
35853594
p.expectKeywordLike("REFERENCES")
35863595
sourceReference := p.parseIdent()
35873596
sourceReferenceColumns := p.tryParsePropertyGraphColumnNameList()
35883597

3598+
// destination_key
35893599
destination := p.expectKeywordLike("DESTINATION").Pos
35903600
p.expectKeywordLike("KEY")
35913601
destinationColumns := p.parsePropertyGraphColumnNameList()
@@ -3594,7 +3604,7 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
35943604
destinationReferenceColumns := p.tryParsePropertyGraphColumnNameList()
35953605

35963606
return &ast.PropertyGraphEdgeElementKeys{
3597-
// Element: elementKey,
3607+
Element: elementKey,
35983608
Source: &ast.PropertyGraphSourceKey{
35993609
Source: source,
36003610
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)