Skip to content

Commit

Permalink
Improve tryParsePropertyGraphElementKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Sep 19, 2024
1 parent 22b9d6d commit 96c9ff1
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 456 deletions.
18 changes: 14 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3567,25 +3567,35 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
return nil
}

// element_key
var elementKey *ast.PropertyGraphElementKey
if key := p.tryExpectKeywordLike("KEY"); key != nil {
keyColumns := p.parsePropertyGraphColumnNameList()
elementKey := &ast.PropertyGraphElementKey{
elementKey = &ast.PropertyGraphElementKey{
Key: key.Pos,
Keys: keyColumns,
}
return &ast.PropertyGraphNodeElementKey{
PropertyGraphElementKey: *elementKey,

// if SOURCE KEY doesn't follow, it is node_element_key.
if !p.Token.IsKeywordLike("SOURCE") {
return &ast.PropertyGraphNodeElementKey{
PropertyGraphElementKey: *elementKey,
}
}

}

// the rest of edge_element_keys

// source_key
source := p.expectKeywordLike("SOURCE").Pos
p.expectKeywordLike("KEY")
sourceColumns := p.parsePropertyGraphColumnNameList()
p.expectKeywordLike("REFERENCES")
sourceReference := p.parseIdent()
sourceReferenceColumns := p.tryParsePropertyGraphColumnNameList()

// destination_key
destination := p.expectKeywordLike("DESTINATION").Pos
p.expectKeywordLike("KEY")
destinationColumns := p.parsePropertyGraphColumnNameList()
Expand All @@ -3594,7 +3604,7 @@ func (p *Parser) tryParsePropertyGraphElementKeys() ast.PropertyGraphElementKeys
destinationReferenceColumns := p.tryParsePropertyGraphColumnNameList()

return &ast.PropertyGraphEdgeElementKeys{
// Element: elementKey,
Element: elementKey,
Source: &ast.PropertyGraphSourceKey{
Source: source,
Keys: sourceColumns,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE OR REPLACE PROPERTY GRAPH FinGraph
NODE TABLES (
Account AS Account -- element_alias
KEY (id) -- element_key in node_element_key in element_keys
-- label_and_property_list
LABEL DetailedAccount -- LABEL label_name in element_label
PROPERTIES (create_time, is_blocked, nick_name AS name) -- derived_property_list
DEFAULT LABEL -- DEFAULT LABEL in element_label
NO PROPERTIES -- NO PROPERTIES in element_properties
,
Person
-- no element_keys
-- no element_label because of direct element_properties
PROPERTIES ARE ALL COLUMNS EXCEPT (city) -- properties_are
)
EDGE TABLES (
PersonOwnAccount AS PersonOwnAccount
KEY (id, account_id)
SOURCE KEY (id) REFERENCES Person -- source_key without column_name_list
DESTINATION KEY (account_id) REFERENCES Account -- destination_key without column_name_list
LABEL Owns
PROPERTIES ALL COLUMNS,
AccountTransferAccount
SOURCE KEY (id) REFERENCES Account (id) -- source_key
DESTINATION KEY (to_id) REFERENCES Account (id) -- destination_key
LABEL Transfers -- LABEL label_name in element_label
-- without element_properties
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE OR REPLACE PROPERTY GRAPH FinGraph
CREATE PROPERTY GRAPH IF NOT EXISTS FinGraph
NODE TABLES (
Account,
Person
Expand Down

This file was deleted.

Loading

0 comments on commit 96c9ff1

Please sign in to comment.