Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Graph Gurus Episode 14: Pattern Matching

36 vues

Publié le

Pattern Matching using GSQL Interpreted Mode

Publié dans : Logiciels
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Graph Gurus Episode 14: Pattern Matching

  1. 1. Graph Gurus Episode 14 Pattern Matching using GSQL Interpreted Mode
  2. 2. © 2019 TigerGraph. All Rights Reserved Welcome ● Attendees are muted ● If you have any Zoom issues please contact the panelists via chat ● We will have 10 min for Q&A at the end so please send your questions at any time using the Q&A tab in the Zoom menu ● The webinar will be recorded and sent via email 2
  3. 3. © 2019 TigerGraph. All Rights Reserved Today's Gurus 3 Victor Lee Director, Product Management ● BS in Electrical Engineering and Computer Science from UC Berkeley ● MS in Electrical Engineering from Stanford University ● PhD in Computer Science from Kent State University focused on graph data mining ● 15+ years in tech industry Mingxi Wu VP, Engineering ● BS in Computer Science from Fudan University, China ● MS in Computer Science from University of Florida ● PhD in Computer Science from University of Florida ● 19+ years in data management industry & research
  4. 4. © 2019 TigerGraph. All Rights Reserved Agenda 4 ● Pattern Matching Uses in Data Analytics ● GSQL Pattern Matching Syntax and Semantics ● Pattern Matching Using LDBC SNB Data (Demo) ● A Recommendation Application (Demo) ● Q&A
  5. 5. © 2019 TigerGraph. All Rights Reserved Graph Use Cases 5 By Dan McCreary https://medium.com/@dmccreary/a-taxonomy-of-graph-use-cases-2ba34618cf78
  6. 6. © 2019 TigerGraph. All Rights Reserved Graph Use Cases 6 Rule Enforcement Flexible Modeling, Data Integration Insight from Relationships Reporting, Auditing Clustering, Community, Similarity, Ranking Finding Connections, Deep Link Analysis Anti-Fraud Recommendation Master Data Management Machine Learning, Explainable AI Entity Resolution Ad Hoc Exploration, Visual Explainable Results Knowledge Inference Risk Management Data Provenance
  7. 7. © 2019 TigerGraph. All Rights Reserved Graph Use Cases 7 Rule Enforcement Flexible Modeling, Data Integration Insight from Relationships Reporting, Auditing Clustering, Community, Similarity, Ranking Finding Connections, Deep Link Analysis Anti-Fraud Recommendation Master Data Management Machine Learning, Explainable AI Entity Resolution Ad Hoc Exploration, Visual Explainable Results Knowledge Inference Risk Management Data Provenance Pattern Matching/Search
  8. 8. © 2019 TigerGraph. All Rights Reserved Graph Patterns Any arrangement of connected nodes, used as a search input: "Find all the occurrences like this" Pattern Types ● Transactional Patterns ● Social Patterns ● Event Patterns ● Hybrid Patterns Uses ● Recommendation ● Fraud/Crime ● Security/Risk/Rules ● Trends/Insight
  9. 9. © 2019 TigerGraph. All Rights Reserved 9 Detecting Phone-Based Fraud by Analyzing Network or Graph Relationship Features at China Mobile Download the solution brief at - https://info.tigergraph.com/MachineLearning
  10. 10. © 2019 TigerGraph. All Rights Reserved Pattern Matching Overview 10 ● What is a pattern? ○ Pattern is a traversal trace on the graph schema ○ Use regular expression to represent the repetitive steps ○ Pattern can be linear, or nonlinear (tree, circle etc.) ● Example ○ Imagine a schema consisting of a Person vertex type and a Friendship edge type. ○ A pattern ■ Person-(Friendship)-Person-(Friendship)-Person ■ Person-(Friendship*2)-Person
  11. 11. © 2019 TigerGraph. All Rights Reserved Pattern Matching Overview 11 ● What is Pattern Matching? ○ Pattern matching is the process of finding subgraphs in a data graph that conforms to a given query pattern. ○ Input ■ Query Pattern P ■ Data Graph G ○ Output ■ Collection of matched instances M = {subgraphs of G}
  12. 12. © 2019 TigerGraph. All Rights Reserved Query Pattern P Data Graph G
  13. 13. © 2019 TigerGraph. All Rights Reserved Query Pattern P Data Graph G First Match
  14. 14. © 2019 TigerGraph. All Rights Reserved Query Pattern P Data Graph G First Match Second Match
  15. 15. © 2019 TigerGraph. All Rights Reserved Query Pattern P Data Graph G First Match Second Match Third Match
  16. 16. © 2019 TigerGraph. All Rights Reserved GSQL Pattern Matching Overview 16 ● Simple 1-Hop Pattern ● Repeating a 1-Hop Pattern ● Multi-Hop Linear Pattern
  17. 17. © 2019 TigerGraph. All Rights Reserved Simple 1-Hop Pattern 17 Classic GSQL Syntax: FROM X:x -((E1 | E2 | E3):e1)-> Y:y ● Semantics: Traverse from Left to Right GSQL Pattern Matching Syntax: FROM X:x -((E1> | <E2 | E3):e1)- Y:y ● Semantics: Pattern is a whole; each edge's direction is a detail about the pattern
  18. 18. © 2019 TigerGraph. All Rights Reserved Simple 1-Hop Pattern - Variations 18 1. FROM X:x -(E1:e1)- Y:y ○ E1 is an undirected edge. x, y bind to the end points of E1. e1 is alias to E1. 2. FROM X:x -(E2>:e2)- Y:y ○ Right directed edge, x binds to the source of E2, y binds to the target of E2. e2 is alias of E2. 3. FROM X:x -(<E3:e3)- Y:y ○ Left directed edge, y binds to the source of E3, x binds to the target of E3. e3 is alias of E3. 4. FROM X:x -(_:e)- Y:y ○ Any undirected edge pattern. "_" means any undirected edge type. e is alias of "_". 5. FROM X:x -(_>:e)- Y:y ○ Any right directed edge. "_>" means any right directed edge type. e is alias of "_>".
  19. 19. © 2019 TigerGraph. All Rights Reserved Simple 1-Hop Pattern - Variations 19 6. FROM X:x -(<_:e)- Y:y ○ Any left directed edge. "<_" means any left directed edge type. e is alias of "<_". 7. FROM X:x -((<_|_):e)- Y:y ○ Any left directed or any undirected. "|" means OR. e is alias of (<_|_). 8. FROM X:x -((E1|E2>|<E3):e) - Y:y ○ Disjunctive 1-hop edge. (x,y) are connected by E1 or E2 or E3. e is alias of (E1|E2>|<E3). 9. FROM X:x -()- Y:y ○ any edge (directed or undirected) match this 1-hop pattern ○ Same as this: (<_|_>|_)
  20. 20. © 2019 TigerGraph. All Rights Reserved Simple 1-Hop Pattern (cont.) 20
  21. 21. © 2019 TigerGraph. All Rights Reserved 21
  22. 22. © 2019 TigerGraph. All Rights Reserved Repeating a 1-Hop Pattern - Unbounded Variations 22 1. FROM X:x - (E1*) - Y:y ○ X connect to Y via 0 or more repetition of undirected E1. * is called the Kleene star. 2. FROM X:x - (E2>*) - Y:y ○ X connect to Y via 0 or more repetition of rightward E2 3. FROM X:x - (<E3*) - Y:y ○ X connect to Y via 0 or more repetition of leftward E3 4. FROM X:x - (_*) - Y:y ○ X connect to Y via 0 or more undirected edges of any type
  23. 23. © 2019 TigerGraph. All Rights Reserved Repeating a 1-Hop Pattern - Unbounded Variations 23 5. FROM X:x - (_>*) - Y:y ○ X connect to Y via 0 or more right-directed edges of any type 6. FROM X:x - (<_*) - Y:y ○ X connect to Y via 0 or more left-directed edges of any type 7. FROM X:x - ((E1|E2>|<E3)*) - Y:y ○ Either E1, E2> or <E3 can be chosen at each repetition.
  24. 24. © 2019 TigerGraph. All Rights Reserved Repeating a 1-Hop Pattern - Bounded Variations 24 1. FROM X:x - (E1*2..) - Y:y ○ Lower bounds only. There is a chain of at least 2 E1 edges. 2. FROM X:x - (E2>*..3) - Y:y ○ Upper bounds only. There is a chain of between 0 and 3 E2 edges. 3. FROM X:x - (<E3*3..5) - Y:y ○ Both Lower and Upper bounds. There is a chain of 3 to 5 E3 edges. 4. FROM X:x - ((E1|E2>|<E3)*3) - Y:y ○ Exact bound. There is a chain of exactly 3 edges, where each edge is either E1, E2>, or <E3.
  25. 25. © 2019 TigerGraph. All Rights Reserved Repeating a Pattern - Remarks 25 1. Edge aliases cannot be used together with a Kleene star. ○ When an edge is repeated, it would not clear which instance of the edge the alias refers to. 2. Shortest path semantics. ○ When an edge is repeated with the Kleene star, we consider shortest path matches only. ○ Counting and existence check of matched shortest path pattern is tractable.
  26. 26. © 2019 TigerGraph. All Rights Reserved 26 Example: Shortest Matching Path In above figure, for the pattern, 1 - (E>*) - 4, the following paths can reach 4 from 1. 1. 1->2->3->4 2. 1->2->3->5->6->2->3->4 (1 loop) 3. Any path 1>2, looping through 2->3->5->6->2 two or more times, and exiting 2>3>4 Only the first one is the shortest, and considered a match for the pattern.
  27. 27. © 2019 TigerGraph. All Rights Reserved 27 Specifying How Many Repetitions (cont.)
  28. 28. © 2019 TigerGraph. All Rights Reserved 28 Specifying How Many Repetitions (cont.)
  29. 29. © 2019 TigerGraph. All Rights Reserved Multiple-Hop Linear Pattern 29 ● 2-hop pattern ○ FROM X:x - (E1:e1) - Y:y - (E2>:e2)-Z:z 1st hop 2nd hop Similarly, a 3-hop pattern concatenates three 1-hop patterns in sequence, every two connecting patterns share one endpoint. Below Y:y and Z:z are the connecting endpoints. ● 3-hop pattern ○ FROM X:x - (E2>:e2) - Y:y - (<E3:e3)- Z:z - (E4:e4) - U:u 1st hop 2nd hop 3rd hop
  30. 30. © 2019 TigerGraph. All Rights Reserved Multiple-Hop Linear Pattern 30 ● SELECT Clause ○ select pattern’s endpoints only ○ FROM X:x-(E2>:e2)-Y:y-(<E3:e3)-Z:z-(E4:e4)-U:u; ● FROM Clause ○ FROM pattern can be shortened ■ FROM X:x-(E2>:e2)-Y:y-(<E3:e3)-Z:z-(E4:e4)-U:u ⇒ ■ FROM X:x-(E2>.<E3.E4)-U:u; //note: no alias is allowed for E.E style ● WHERE Clause ○ Conjunction of local hop predicate only ○ Last hop local predicate can refer to the starting end point ○ Kleene star breaks local hop predicate ● ACCUM and POST-ACCUM Clause ○ ACCUM clause executed for each matched instance ○ ACCUM to endpoints only
  31. 31. © 2019 TigerGraph. All Rights Reserved How To Use In Upcoming Release 2.4 31 ● Session Parameter ○ set syntax_version="v2" //for pattern match ○ set syntax_version="v1" //default, classic syntax ● Invoke Interpret GSQL Engine ○ INTERPRET QUERY QueryName (p1, p2, ..) //run existing query ○ INTERPRET QUERY () FOR GRAPH graphName { } //adhoc query ● Query Level Syntax Setting ○ CREATE QUERY (p1, p2.,.) Name FOR GRAPH test SYNTAX("v2") { } ○ INTERPRET QUERY () FOR GRAPH test SYNTAX("v1") { }
  32. 32. © 2019 TigerGraph. All Rights Reserved Demo Setup 32
  33. 33. © 2019 TigerGraph. All Rights Reserved Demo Setup 33 E1 1,003,605 E2 2,052,169 E3 1,003,605 E4 229,166 E5 1,611,869 E6 90,492 E7 2,698,393 E8 713,258 E9 309,766 E10 16,080 E11 1,575 E12 6,380 E13 2,052,169 E14 1,003,605 E15 9,892 E16 1,343 E17 111 E18 70 Total : 3.18M vertices 17.25M edges 11 vertex types 25 edge types Vertex Stats Edge Stats Total comment post compan y university city country continent forum person tag tagclass # attributes 6 8 3 3 3 3 3 3 10 3 3 # vertices 3.18 M 2,052,169 1,003,605 1,575 6,380 1,343 111 6 90,492 9,892 16,080 71 E19 180,623 E20 1,438,418 E21 751,677 E22 1,040,749 E23 1,011,420 E24 7,949 E25 21,654
  34. 34. © 2019 TigerGraph. All Rights Reserved Demo Setup 34
  35. 35. © 2019 TigerGraph. All Rights Reserved Demo On Docker 35
  36. 36. © 2019 TigerGraph. All Rights Reserved Summary 36 Version 2.4 Available End Jun ● Pattern Matching enables ● Demo: Pattern Match Using LDBC Social Network Benchmark Data ○ Interpreted Mode on laptop Docker -- run queries instantly as soon as you write them ● Demo: Pattern Matching in a Recommender Application ○ Interpreted Mode again
  37. 37. Q&A Please send your questions via the Q&A menu in Zoom 37
  38. 38. © 2019 TigerGraph. All Rights Reserved Developer Edition Available We now offer Docker versions and VirtualBox versions of the TigerGraph Developer Edition, so you can now run on ● MacOS ● Windows 10 ● Linux Developer Edition Download https://www.tigergraph.com/developer/ 38
  39. 39. © 2019 TigerGraph. All Rights Reserved NEW! Graph Gurus Developer Office Hours 39 Catch up on previous episodes of Graph Gurus: https://www.tigergraph.com/webinars-and-events/ Every Thursday at 11:00 am Pacific Talk directly with our engineers every week. During office hours, you get answers to any questions pertaining to graph modeling and GSQL programming. https://info.tigergraph.com/officehours
  40. 40. © 2019 TigerGraph. All Rights Reserved Additional Resources 40 New Developer Portal https://www.tigergraph.com/developers/ Download the Developer Edition or Enterprise Free Trial https://www.tigergraph.com/download/ Guru Scripts https://github.com/tigergraph/ecosys/tree/master/guru_scripts Join our Developer Forum https://groups.google.com/a/opengsql.org/forum/#!forum/gsql-users @TigerGraphDB youtube.com/tigergraph facebook.com/TigerGraphDB linkedin.com/company/TigerGraph

×