SlideShare a Scribd company logo
Graph Gurus 31
GSQL Writing Best Practices
Part 1 - Thinking in GSQL
1
© 2020 TigerGraph. All Rights Reserved
Today's Host
2
David Ronald
Director of Product Marketing
● BSc in Applied Physics from Strathclyde University, MSc
in Optoelectronic & Laser Devices from St Andrews
● Prior work in artificial intelligence, natural linguistic
programming and telecommunications technology
● 18+ years in tech industry
© 2020 TigerGraph. All Rights Reserved
Today's Presenter
3
Xinyu Chang
Director of Customer Solutions
● Co-authored GSQL, TigerGraph’s query language,
and expertise in graph solutions and algorithms
● Developed solutions for many Fortune 50
companies
● Over 5 years with TigerGraph
© 2020 TigerGraph. All Rights Reserved
Some Housekeeping Items
● Although your phone is muted we do want to answer your questions -
submit your questions at any time using the Q&A tab in the menu
● The webinar is being recorded and will uploaded to our website shortly
(https://www.tigergraph.com/webinars/) and the URL will be emailed
you
● If you have issues with Zoom please contact the panelists via chat
4
© 2020 TigerGraph. All Rights Reserved
Thinking in GSQL - Agenda
5
1. Review the Basics
2. The Thinking Steps
3. Example 1
4. Example 2
5. Example 3
The Basics
6
© 2020 TigerGraph. All Rights Reserved
The Basics
Data Declare Session
Query Logic Session
7
© 2020 TigerGraph. All Rights Reserved
The Basics
8
GSQL traverses the graph from one set of vertices, through selected edges originated from the
starting set, to another set of vertices:
cardiology
cardiac
electrophysiology,
echocardiog
raphy
Cardiology
© 2020 TigerGraph. All Rights Reserved
The Basics
The query always starts with a seed
vertex set - that is where your traversal
logic originates from
Start from a single vertex:
CREATE QUERY example(VERTEX input_ver) FOR GRAPH g {
start_set = {input_ver};
….
}
● Here start_set is the variable
name of vertex set variable
● A vertex set variable is where
a SELECT statement starts from
● A vertex set variable is also the
outcome of a SELECT
statement
● In this case the vertex set
start_set only contains one
single vertex that is the input
parameter
● This is the recommended way
to start your traversal logic
9
© 2020 TigerGraph. All Rights Reserved
The Basics
Start from a set of vertex:
CREATE QUERY example(SET<VERTEX> input_set) FOR
GRAPH g {
start_set = input_set;
….
}
Start from a type of vertex, and all vertices:
CREATE QUERY example() FOR GRAPH g {
start_set = {Claim.*};
start_set2 = {ANY};
….
}
10
© 2020 TigerGraph. All Rights Reserved
The Basics
Find all the claims of a patient
11
CREATE QUERY GetClaims(vertex<User> input_patient) FOR GRAPH Social {
Start = {input_patient};
Claims = SELECT t FROM Start:s-(reverse_Associated:e)-Claim:t;
PRINT Claims;
}
Input
Patient
ClaimA
ClaimB
ClaiC
Start Claimsreverse_Associated
s
s
s
t
t
t
e
e
e
● Start is a vertex set initialized by the input
vertex input_patient
● FROM clause finds edges which match the
pattern: source vertex is in Start, edge type
is reverse_Associated, and target vertex
is restricted to User type.
● For each edge satisfies the conditions in
the FROM clauses, s, e and t are aliases
of source vertex, edge and target vertex.
● s, e and t are not keywords, you can
rename them.
● Claims is a new vertex set equal to t.
11
© 2020 TigerGraph. All Rights Reserved
The Basics
resultSet = SELECT vSet
FROM ( edgeSet | vertexSet )
[whereClause] [accumClause]
[postAccumClause] [havingClause]
[orderClause] [limitClause] ;
• FROM: select active vertices & edges.
• WHERE: conditionally filter the active sets
• ACCUM: iterate on edge set; compute with accumulators
• POST-ACCUM: iterate on vertex sets; compute with accumulators
• HAVING: conditionally filter the result set
• ORDER BY: sort
• LIMIT: max number of items
• SELECT: result from source or target set
12
ACCUM
POST-ACCUM
WHERE
FROM
LIMIT
SELECT
ORDER BY
HAVING
© 2020 TigerGraph. All Rights Reserved 13
Accumulators
A
E
B
D
C
Accumulator
2
1
1
Accumulators are special type of variables that accumulate information about the graph during the traversal
Accumulating phase 1: receiving messages, the messages received will be temporarily put to a bucket that
belongs to the accumulator
Accumulating phase 2: The accumulator will aggregate the messages it received based on its accumulator
type - the aggregated value will become the accumulator’s value, and its value can be accessed
Graph
2,1,1
Value: 0Value: 4
© 2020 TigerGraph. All Rights Reserved
Accumulators
14
For example:
The teacher collects test papers from all
students and calculates an average score.
Teacher: accumulator
Student: vertex/edge
Test paper: message sent to accumulator
Average Score: final value of accumulator
Phase 1: teacher collects all the test paper
Phase 2: teacher grades it and calculate
the average score.
© 2020 TigerGraph. All Rights Reserved
Local Accumulators:
• Each selected vertex has its own
accumulator
• Local means per vertex - each vertex does
its own processing and considers what it
can see/read/write
15
Global Accumulators:
• Stored in stored globally, visible
to all
• All vertices and edges have
access
e.x. SumAccum @A;
4
@@B
2,1,1
15
@A
1,4,10
10
4
1
2
1
1
e.x. SumAccum @@B;
@A
@A
@A
@A
Accumulators
© 2020 TigerGraph. All Rights Reserved
Accumulators
The GSQL language provides many different accumulators, which follow the
same rules for receiving and accessing data - each of them, however, has its
unique way of aggregating values
16
Old Value:
2
New Value:
11
1, 3, 5
1
3 5
SumAccum<int>
Old Value:
2
New Value:
5
1, 3, 5
1 3
MaxAccum<int>
Old Value:
2
New Value:
1
1, 3, 5
1 3
MinAccum<int>
Old Value:
2
New Value:
2.75
1, 3, 5
1 3
AvgAccum
5 5 5
Computes and stores the
cumulative sum of numeric
values or the cumulative
concatenation of text values.
The MaxAccum types
calculate and store the
cumulative maximum of
a series of values.
Calculates and stores
the cumulative mean of
a series of numeric
values.
The MinAccum types
calculate and store the
cumulative minimum of
a series of values.
© 2020 TigerGraph. All Rights Reserved
The GSQL language provides many different accumulators, which follow the
same rules for receiving and accessing data - each of them, however, has its
unique way of aggregating values.
17
Old Value:
[2]
New Value:
[2,1,3,5]
1, 3, 3, 5
1 3 5
SetAccum<int>
Old Value:
[2]
New Value:
[2,1,5,3,3]
1, 5, 3, 3
1 3
ListAccum<int>
Old Value:
[1->1]
New Value:
1->6
5->2
1->2
1->3
5->2
1->2 1->3
MapAccum<int,SumAccum<int>>
Old Value:
[userD,150]
New Value:
[userC,300,
UserD,150,
userA,100]
userC,300
userA,100
(“userA”, 100)
HeapAccum<Tuple>
5 5->23 3 (“userC”, 300)
Maintains a collection of
unique elements.
Maintains a sequential
collection of elements.
Maintains a collection of
(key -> value) pairs.
Maintains a sorted collection of
tuples and enforces a
maximum number of tuples in
the collection
Accumulators
The Thinking Steps
18
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
1. Design a traversal plan
Where to start from? What are the steps? What edge to use for
each step?
2. Choose and define the accumulators
What needs to be in the result? Where is the info needed? What
accumulator to use?
3. Populate the accumulators
How do we gather the info to the right place?
4. Print the result
19
Example 1
20
Order the specialties in descending order
by the number of Claims
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
1. Design a traversal plan
Where to start from? Specialty? Claim?
What are the steps?
What edge to use for each step?
21
Claim -> Prescriber -> SubSpecialty -> Specialty
submit, subspecialty_prescriber,
specialty_sub_specilaty
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
2. Choose and define the accumulators
What is the final result?
Where is the info needed for the final result?
What accumulator to use?
22
Specialties order by number of the claims
Number of claims is a integer summed value. So
we are using SumAccum<INT>
We need to count the number of claims, so the info
is on Claim vertexes
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
3. Populate the accumulators
How do we gather the info to the right place?
23
Pass the number of claims from claims vertexes to
specialty vertexes
Example 2
24
Given a prescriber, who are the top k other
prescribers sharing the most patient?
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
1. Design a traversal plan
Where to start from?
What are the steps?
What edge to use for each step?
25
Input Prescriber -> Claims -> Patients
-> Claims -> Prescribers
Submit, associate, submit, associate
Input Prescriber
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
2. Choose and define the accumulators
What is the final result?
Where is the info needed for the final result?
What accumulator to use?
26
Top k prescribers with most common patients
SumAccum? SetAccum?
Patient vertexes
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
3. Populate the accumulators
How do we gather the info to the right place?
27
Pass patient IDs to the prescribers
Example 3
28
Given a prescriber, who are the other
prescribers being referred?
Refer: a patient has a second claims that are no
longer than a given period of time after the first
claim. The prescriber of the first claim referred
the prescriber of the second claim.
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
1. Design a traversal plan
Where to start from?
What are the steps?
What edge to use for each step?
29
Input Prescriber -> Claims -> Patients
-> Claims -> Prescribers
Submit, associate, submit, associate
Input Prescriber
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
2. Choose and define the accumulators
What is the final result?
Where is the info needed for the final result?
What accumulator to use?
30
The referral edges between input prescribers and
referred prescribers
ListAccum of dates
Claims of the input prescriber, patient
Other Claims of the patient
© 2020 TigerGraph. All Rights Reserved
The Thinking Steps
3. Populate the accumulators
How do we gather the info to the right place?
31
Pass the dates of claims of the input prescriber to
the patient vertex
Q&A
Please submit your questions via the Q&A tab in Zoom
© 2020 TigerGraph. All Rights Reserved
More Questions?
Join our Developer Forum
https://groups.google.com/a/opengsql.org/forum/#!forum/gsql-users
Sign up for our Developer Office Hours (every Thursday at 11 AM PDT)
https://info.tigergraph.com/officehours
33
© 2020 TigerGraph. All Rights Reserved
Additional Resources
Start Free at TigerGraph Cloud Today!
https://www.tigergraph.com/cloud/
Test Drive Online Demo
https://www.tigergraph.com/demo
Download the Developer Edition
https://www.tigergraph.com/download/
Guru Scripts
https://github.com/tigergraph/ecosys/tree/master/guru_scripts
34
© 2020 TigerGraph. All Rights Reserved
Upcoming Online Events
Roundtable on Fraud Detection with Graph and
Machine Learning
Tuesday, March 24, at 11am PDT
https://www.experoinc.com/get/fraud-with-tigergraph
35
Roundtable on Fraud
Detection with Graph and
Machine Learning
Thank You

More Related Content

Similar to Graph Gurus Episode 31: GSQL Writing Best Practices Part 1 (20)

PDF
Using Graph Algorithms for Advanced Analytics - Part 2 Centrality
TigerGraph
 
PDF
Graph Gurus Episode 29: Using Graph Algorithms for Advanced Analytics Part 3
TigerGraph
 
PDF
Graph Gurus Episode 26: Using Graph Algorithms for Advanced Analytics Part 1
TigerGraph
 
PDF
Graph Gurus Episode 7: Connecting the Dots in Real-Time: Deep Link Analysis w...
TigerGraph
 
PPTX
Graph Gurus Episode 35: No Code Graph Analytics to Get Insights from Petabyte...
TigerGraph
 
PDF
Using Graph Algorithms for Advanced Analytics - Part 5 Classification
TigerGraph
 
PDF
Graph Gurus Episode 32: Using Graph Algorithms for Advanced Analytics Part 5
TigerGraph
 
PDF
Machine Learning Feature Design with TigerGraph 3.0 No-Code GUI
TigerGraph
 
PPTX
Graph Database Query Languages
Jay Coskey
 
PDF
Graph Gurus Episode 25: Unleash the Business Value of Your Data Lake with Gra...
TigerGraph
 
PDF
Graph Gurus Episode 12: Tiger Graph v2.3 Overview
TigerGraph
 
PDF
Using Graph Algorithms for Advanced Analytics - Part 2 Centrality
TigerGraph
 
PDF
Graph Gurus Episode 27: Using Graph Algorithms for Advanced Analytics Part 2
TigerGraph
 
PPTX
Follow the money with graphs
Stanka Dalekova
 
PDF
Bill howe 8_graphs
Mahammad Valiyev
 
PDF
Graphing Grifters: Identify & Display Patterns of Corruption With Oracle Graph
Jim Czuprynski
 
PDF
final_presentation
Jonathan Sumrall
 
PPT
An Introduction to Graph Databases
InfiniteGraph
 
PDF
Graph Gurus Episode 6: Community Detection
TigerGraph
 
PDF
05 neo4j gds graph catalog
Neo4j
 
Using Graph Algorithms for Advanced Analytics - Part 2 Centrality
TigerGraph
 
Graph Gurus Episode 29: Using Graph Algorithms for Advanced Analytics Part 3
TigerGraph
 
Graph Gurus Episode 26: Using Graph Algorithms for Advanced Analytics Part 1
TigerGraph
 
Graph Gurus Episode 7: Connecting the Dots in Real-Time: Deep Link Analysis w...
TigerGraph
 
Graph Gurus Episode 35: No Code Graph Analytics to Get Insights from Petabyte...
TigerGraph
 
Using Graph Algorithms for Advanced Analytics - Part 5 Classification
TigerGraph
 
Graph Gurus Episode 32: Using Graph Algorithms for Advanced Analytics Part 5
TigerGraph
 
Machine Learning Feature Design with TigerGraph 3.0 No-Code GUI
TigerGraph
 
Graph Database Query Languages
Jay Coskey
 
Graph Gurus Episode 25: Unleash the Business Value of Your Data Lake with Gra...
TigerGraph
 
Graph Gurus Episode 12: Tiger Graph v2.3 Overview
TigerGraph
 
Using Graph Algorithms for Advanced Analytics - Part 2 Centrality
TigerGraph
 
Graph Gurus Episode 27: Using Graph Algorithms for Advanced Analytics Part 2
TigerGraph
 
Follow the money with graphs
Stanka Dalekova
 
Bill howe 8_graphs
Mahammad Valiyev
 
Graphing Grifters: Identify & Display Patterns of Corruption With Oracle Graph
Jim Czuprynski
 
final_presentation
Jonathan Sumrall
 
An Introduction to Graph Databases
InfiniteGraph
 
Graph Gurus Episode 6: Community Detection
TigerGraph
 
05 neo4j gds graph catalog
Neo4j
 

More from TigerGraph (20)

PDF
MAXIMIZING THE VALUE OF SCIENTIFIC INFORMATION TO ACCELERATE INNOVATION
TigerGraph
 
PDF
Better Together: How Graph database enables easy data integration with Spark ...
TigerGraph
 
PDF
Building an accurate understanding of consumers based on real-world signals
TigerGraph
 
PDF
Care Intervention Assistant - Omaha Clinical Data Information System
TigerGraph
 
PDF
Correspondent Banking Networks
TigerGraph
 
PDF
Delivering Large Scale Real-time Graph Analytics with Dell Infrastructure and...
TigerGraph
 
PDF
Deploying an End-to-End TigerGraph Enterprise Architecture using Kafka, Maria...
TigerGraph
 
PDF
Fraud Detection and Compliance with Graph Learning
TigerGraph
 
PDF
Fraudulent credit card cash-out detection On Graphs
TigerGraph
 
PDF
FROM DATAFRAMES TO GRAPH Data Science with pyTigerGraph
TigerGraph
 
PDF
Customer Experience Management
TigerGraph
 
PDF
Graph+AI for Fin. Services
TigerGraph
 
PDF
Davraz - A graph visualization and exploration software.
TigerGraph
 
PDF
Plume - A Code Property Graph Extraction and Analysis Library
TigerGraph
 
PDF
TigerGraph.js
TigerGraph
 
PDF
GRAPHS FOR THE FUTURE ENERGY SYSTEMS
TigerGraph
 
PDF
Hardware Accelerated Machine Learning Solution for Detecting Fraud and Money ...
TigerGraph
 
PDF
How to Build An AI Based Customer Data Platform: Learn the design patterns fo...
TigerGraph
 
PDF
Recommendation Engine with In-Database Machine Learning
TigerGraph
 
PDF
Supply Chain and Logistics Management with Graph & AI
TigerGraph
 
MAXIMIZING THE VALUE OF SCIENTIFIC INFORMATION TO ACCELERATE INNOVATION
TigerGraph
 
Better Together: How Graph database enables easy data integration with Spark ...
TigerGraph
 
Building an accurate understanding of consumers based on real-world signals
TigerGraph
 
Care Intervention Assistant - Omaha Clinical Data Information System
TigerGraph
 
Correspondent Banking Networks
TigerGraph
 
Delivering Large Scale Real-time Graph Analytics with Dell Infrastructure and...
TigerGraph
 
Deploying an End-to-End TigerGraph Enterprise Architecture using Kafka, Maria...
TigerGraph
 
Fraud Detection and Compliance with Graph Learning
TigerGraph
 
Fraudulent credit card cash-out detection On Graphs
TigerGraph
 
FROM DATAFRAMES TO GRAPH Data Science with pyTigerGraph
TigerGraph
 
Customer Experience Management
TigerGraph
 
Graph+AI for Fin. Services
TigerGraph
 
Davraz - A graph visualization and exploration software.
TigerGraph
 
Plume - A Code Property Graph Extraction and Analysis Library
TigerGraph
 
TigerGraph.js
TigerGraph
 
GRAPHS FOR THE FUTURE ENERGY SYSTEMS
TigerGraph
 
Hardware Accelerated Machine Learning Solution for Detecting Fraud and Money ...
TigerGraph
 
How to Build An AI Based Customer Data Platform: Learn the design patterns fo...
TigerGraph
 
Recommendation Engine with In-Database Machine Learning
TigerGraph
 
Supply Chain and Logistics Management with Graph & AI
TigerGraph
 
Ad

Recently uploaded (20)

PPTX
Digital Token based Electronic payment system.pptx
revathi148366
 
PPTX
Credit Card Fraud Detection Presentation
rasmilalama
 
PPTX
Slide studies GC- CRC - PC - HNC baru.pptx
LLen8
 
PPTX
fashion industry boom.pptx an economics project
TGMPandeyji
 
PDF
[1library.net] creating a culture of cyber security at work
University of [X]
 
PDF
apidays Munich 2025 - Geospatial Artificial Intelligence (GeoAI) with OGC API...
apidays
 
PPTX
Enterprise Architecture and TOGAF Presn
starksolutionsindia
 
PPTX
apidays Munich 2025 - Effectively incorporating API Security into the overall...
apidays
 
PPTX
Solution+Architecture+Review+-+Sample.pptx
manuvratsingh1
 
PPTX
GLOBAL_Gender-module-5_committing-equity-responsive-budget.pptx
rashmisahu90
 
PDF
apidays Munich 2025 - Integrate Your APIs into the New AI Marketplace, Senthi...
apidays
 
PDF
apidays Munich 2025 - Making Sense of AI-Ready APIs in a Buzzword World, Andr...
apidays
 
PDF
Responsibilities of a Certified Data Engineer | IABAC
Seenivasan
 
PPTX
Data Analysis for Business - make informed decisions, optimize performance, a...
Slidescope
 
PPTX
Insurance-Analytics-Branch-Dashboard (1).pptx
trivenisapate02
 
PDF
Basotho Satisfaction with Electricity(Statspack)
KatlehoMefane
 
PPTX
Lecture_9_EPROM_Flash univeristy lecture fall 2022
ssuser5047c5
 
PPTX
apidays Munich 2025 - Federated API Management and Governance, Vince Baker (D...
apidays
 
PPTX
Nursing Shift Supervisor 24/7 in a week .pptx
amjadtanveer
 
DOCX
Online Delivery Restaurant idea and analyst the data
sejalsengar2323
 
Digital Token based Electronic payment system.pptx
revathi148366
 
Credit Card Fraud Detection Presentation
rasmilalama
 
Slide studies GC- CRC - PC - HNC baru.pptx
LLen8
 
fashion industry boom.pptx an economics project
TGMPandeyji
 
[1library.net] creating a culture of cyber security at work
University of [X]
 
apidays Munich 2025 - Geospatial Artificial Intelligence (GeoAI) with OGC API...
apidays
 
Enterprise Architecture and TOGAF Presn
starksolutionsindia
 
apidays Munich 2025 - Effectively incorporating API Security into the overall...
apidays
 
Solution+Architecture+Review+-+Sample.pptx
manuvratsingh1
 
GLOBAL_Gender-module-5_committing-equity-responsive-budget.pptx
rashmisahu90
 
apidays Munich 2025 - Integrate Your APIs into the New AI Marketplace, Senthi...
apidays
 
apidays Munich 2025 - Making Sense of AI-Ready APIs in a Buzzword World, Andr...
apidays
 
Responsibilities of a Certified Data Engineer | IABAC
Seenivasan
 
Data Analysis for Business - make informed decisions, optimize performance, a...
Slidescope
 
Insurance-Analytics-Branch-Dashboard (1).pptx
trivenisapate02
 
Basotho Satisfaction with Electricity(Statspack)
KatlehoMefane
 
Lecture_9_EPROM_Flash univeristy lecture fall 2022
ssuser5047c5
 
apidays Munich 2025 - Federated API Management and Governance, Vince Baker (D...
apidays
 
Nursing Shift Supervisor 24/7 in a week .pptx
amjadtanveer
 
Online Delivery Restaurant idea and analyst the data
sejalsengar2323
 
Ad

Graph Gurus Episode 31: GSQL Writing Best Practices Part 1

  • 1. Graph Gurus 31 GSQL Writing Best Practices Part 1 - Thinking in GSQL 1
  • 2. © 2020 TigerGraph. All Rights Reserved Today's Host 2 David Ronald Director of Product Marketing ● BSc in Applied Physics from Strathclyde University, MSc in Optoelectronic & Laser Devices from St Andrews ● Prior work in artificial intelligence, natural linguistic programming and telecommunications technology ● 18+ years in tech industry
  • 3. © 2020 TigerGraph. All Rights Reserved Today's Presenter 3 Xinyu Chang Director of Customer Solutions ● Co-authored GSQL, TigerGraph’s query language, and expertise in graph solutions and algorithms ● Developed solutions for many Fortune 50 companies ● Over 5 years with TigerGraph
  • 4. © 2020 TigerGraph. All Rights Reserved Some Housekeeping Items ● Although your phone is muted we do want to answer your questions - submit your questions at any time using the Q&A tab in the menu ● The webinar is being recorded and will uploaded to our website shortly (https://www.tigergraph.com/webinars/) and the URL will be emailed you ● If you have issues with Zoom please contact the panelists via chat 4
  • 5. © 2020 TigerGraph. All Rights Reserved Thinking in GSQL - Agenda 5 1. Review the Basics 2. The Thinking Steps 3. Example 1 4. Example 2 5. Example 3
  • 7. © 2020 TigerGraph. All Rights Reserved The Basics Data Declare Session Query Logic Session 7
  • 8. © 2020 TigerGraph. All Rights Reserved The Basics 8 GSQL traverses the graph from one set of vertices, through selected edges originated from the starting set, to another set of vertices: cardiology cardiac electrophysiology, echocardiog raphy Cardiology
  • 9. © 2020 TigerGraph. All Rights Reserved The Basics The query always starts with a seed vertex set - that is where your traversal logic originates from Start from a single vertex: CREATE QUERY example(VERTEX input_ver) FOR GRAPH g { start_set = {input_ver}; …. } ● Here start_set is the variable name of vertex set variable ● A vertex set variable is where a SELECT statement starts from ● A vertex set variable is also the outcome of a SELECT statement ● In this case the vertex set start_set only contains one single vertex that is the input parameter ● This is the recommended way to start your traversal logic 9
  • 10. © 2020 TigerGraph. All Rights Reserved The Basics Start from a set of vertex: CREATE QUERY example(SET<VERTEX> input_set) FOR GRAPH g { start_set = input_set; …. } Start from a type of vertex, and all vertices: CREATE QUERY example() FOR GRAPH g { start_set = {Claim.*}; start_set2 = {ANY}; …. } 10
  • 11. © 2020 TigerGraph. All Rights Reserved The Basics Find all the claims of a patient 11 CREATE QUERY GetClaims(vertex<User> input_patient) FOR GRAPH Social { Start = {input_patient}; Claims = SELECT t FROM Start:s-(reverse_Associated:e)-Claim:t; PRINT Claims; } Input Patient ClaimA ClaimB ClaiC Start Claimsreverse_Associated s s s t t t e e e ● Start is a vertex set initialized by the input vertex input_patient ● FROM clause finds edges which match the pattern: source vertex is in Start, edge type is reverse_Associated, and target vertex is restricted to User type. ● For each edge satisfies the conditions in the FROM clauses, s, e and t are aliases of source vertex, edge and target vertex. ● s, e and t are not keywords, you can rename them. ● Claims is a new vertex set equal to t. 11
  • 12. © 2020 TigerGraph. All Rights Reserved The Basics resultSet = SELECT vSet FROM ( edgeSet | vertexSet ) [whereClause] [accumClause] [postAccumClause] [havingClause] [orderClause] [limitClause] ; • FROM: select active vertices & edges. • WHERE: conditionally filter the active sets • ACCUM: iterate on edge set; compute with accumulators • POST-ACCUM: iterate on vertex sets; compute with accumulators • HAVING: conditionally filter the result set • ORDER BY: sort • LIMIT: max number of items • SELECT: result from source or target set 12 ACCUM POST-ACCUM WHERE FROM LIMIT SELECT ORDER BY HAVING
  • 13. © 2020 TigerGraph. All Rights Reserved 13 Accumulators A E B D C Accumulator 2 1 1 Accumulators are special type of variables that accumulate information about the graph during the traversal Accumulating phase 1: receiving messages, the messages received will be temporarily put to a bucket that belongs to the accumulator Accumulating phase 2: The accumulator will aggregate the messages it received based on its accumulator type - the aggregated value will become the accumulator’s value, and its value can be accessed Graph 2,1,1 Value: 0Value: 4
  • 14. © 2020 TigerGraph. All Rights Reserved Accumulators 14 For example: The teacher collects test papers from all students and calculates an average score. Teacher: accumulator Student: vertex/edge Test paper: message sent to accumulator Average Score: final value of accumulator Phase 1: teacher collects all the test paper Phase 2: teacher grades it and calculate the average score.
  • 15. © 2020 TigerGraph. All Rights Reserved Local Accumulators: • Each selected vertex has its own accumulator • Local means per vertex - each vertex does its own processing and considers what it can see/read/write 15 Global Accumulators: • Stored in stored globally, visible to all • All vertices and edges have access e.x. SumAccum @A; 4 @@B 2,1,1 15 @A 1,4,10 10 4 1 2 1 1 e.x. SumAccum @@B; @A @A @A @A Accumulators
  • 16. © 2020 TigerGraph. All Rights Reserved Accumulators The GSQL language provides many different accumulators, which follow the same rules for receiving and accessing data - each of them, however, has its unique way of aggregating values 16 Old Value: 2 New Value: 11 1, 3, 5 1 3 5 SumAccum<int> Old Value: 2 New Value: 5 1, 3, 5 1 3 MaxAccum<int> Old Value: 2 New Value: 1 1, 3, 5 1 3 MinAccum<int> Old Value: 2 New Value: 2.75 1, 3, 5 1 3 AvgAccum 5 5 5 Computes and stores the cumulative sum of numeric values or the cumulative concatenation of text values. The MaxAccum types calculate and store the cumulative maximum of a series of values. Calculates and stores the cumulative mean of a series of numeric values. The MinAccum types calculate and store the cumulative minimum of a series of values.
  • 17. © 2020 TigerGraph. All Rights Reserved The GSQL language provides many different accumulators, which follow the same rules for receiving and accessing data - each of them, however, has its unique way of aggregating values. 17 Old Value: [2] New Value: [2,1,3,5] 1, 3, 3, 5 1 3 5 SetAccum<int> Old Value: [2] New Value: [2,1,5,3,3] 1, 5, 3, 3 1 3 ListAccum<int> Old Value: [1->1] New Value: 1->6 5->2 1->2 1->3 5->2 1->2 1->3 MapAccum<int,SumAccum<int>> Old Value: [userD,150] New Value: [userC,300, UserD,150, userA,100] userC,300 userA,100 (“userA”, 100) HeapAccum<Tuple> 5 5->23 3 (“userC”, 300) Maintains a collection of unique elements. Maintains a sequential collection of elements. Maintains a collection of (key -> value) pairs. Maintains a sorted collection of tuples and enforces a maximum number of tuples in the collection Accumulators
  • 19. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 1. Design a traversal plan Where to start from? What are the steps? What edge to use for each step? 2. Choose and define the accumulators What needs to be in the result? Where is the info needed? What accumulator to use? 3. Populate the accumulators How do we gather the info to the right place? 4. Print the result 19
  • 20. Example 1 20 Order the specialties in descending order by the number of Claims
  • 21. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 1. Design a traversal plan Where to start from? Specialty? Claim? What are the steps? What edge to use for each step? 21 Claim -> Prescriber -> SubSpecialty -> Specialty submit, subspecialty_prescriber, specialty_sub_specilaty
  • 22. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 2. Choose and define the accumulators What is the final result? Where is the info needed for the final result? What accumulator to use? 22 Specialties order by number of the claims Number of claims is a integer summed value. So we are using SumAccum<INT> We need to count the number of claims, so the info is on Claim vertexes
  • 23. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 3. Populate the accumulators How do we gather the info to the right place? 23 Pass the number of claims from claims vertexes to specialty vertexes
  • 24. Example 2 24 Given a prescriber, who are the top k other prescribers sharing the most patient?
  • 25. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 1. Design a traversal plan Where to start from? What are the steps? What edge to use for each step? 25 Input Prescriber -> Claims -> Patients -> Claims -> Prescribers Submit, associate, submit, associate Input Prescriber
  • 26. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 2. Choose and define the accumulators What is the final result? Where is the info needed for the final result? What accumulator to use? 26 Top k prescribers with most common patients SumAccum? SetAccum? Patient vertexes
  • 27. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 3. Populate the accumulators How do we gather the info to the right place? 27 Pass patient IDs to the prescribers
  • 28. Example 3 28 Given a prescriber, who are the other prescribers being referred? Refer: a patient has a second claims that are no longer than a given period of time after the first claim. The prescriber of the first claim referred the prescriber of the second claim.
  • 29. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 1. Design a traversal plan Where to start from? What are the steps? What edge to use for each step? 29 Input Prescriber -> Claims -> Patients -> Claims -> Prescribers Submit, associate, submit, associate Input Prescriber
  • 30. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 2. Choose and define the accumulators What is the final result? Where is the info needed for the final result? What accumulator to use? 30 The referral edges between input prescribers and referred prescribers ListAccum of dates Claims of the input prescriber, patient Other Claims of the patient
  • 31. © 2020 TigerGraph. All Rights Reserved The Thinking Steps 3. Populate the accumulators How do we gather the info to the right place? 31 Pass the dates of claims of the input prescriber to the patient vertex
  • 32. Q&A Please submit your questions via the Q&A tab in Zoom
  • 33. © 2020 TigerGraph. All Rights Reserved More Questions? Join our Developer Forum https://groups.google.com/a/opengsql.org/forum/#!forum/gsql-users Sign up for our Developer Office Hours (every Thursday at 11 AM PDT) https://info.tigergraph.com/officehours 33
  • 34. © 2020 TigerGraph. All Rights Reserved Additional Resources Start Free at TigerGraph Cloud Today! https://www.tigergraph.com/cloud/ Test Drive Online Demo https://www.tigergraph.com/demo Download the Developer Edition https://www.tigergraph.com/download/ Guru Scripts https://github.com/tigergraph/ecosys/tree/master/guru_scripts 34
  • 35. © 2020 TigerGraph. All Rights Reserved Upcoming Online Events Roundtable on Fraud Detection with Graph and Machine Learning Tuesday, March 24, at 11am PDT https://www.experoinc.com/get/fraud-with-tigergraph 35 Roundtable on Fraud Detection with Graph and Machine Learning