SlideShare a Scribd company logo
SQL/Graph Query
Procedures: an early draft
oCIG 4 Presentation, 2017-08-17
Peter Furniss, Neo4j
Motivation
Don’t distort SQL with graph querying capabilities
Instead, follow precedents set by SQL/XML and SQL/JSON:
Extend SQL with a new GRAPH_REFERENCE data type (which is opaque)
Extend SQL with the ability to invoke procedures to undertake graph query
processing
Single and dual engine architecture for the implementation of a graph
query engine
Graph query procedures: overview
1) GRAPH_QUERY procedure:
Returns one or more graphs as GRAPH_REFERENCES
Returns one or more table columns
2) GRAPH_TABLE procedure:
Returns one or more table columns only
Graph query procedures: inputs
Mandatory inputs:
Graph inputs: one or multiple GRAPH_REFERENCES
Query specification: a string which is a query statement for the target graph
query language
Optional inputs:
Driver table: A table expression, the types of whose columns are capable of
being processed by the graph query engine/language
Query parameters: A list of named scalar values
Graph query procedures: results
GRAPH_QUERY and GRAPH_TABLE return:
Result table: a named table, containing the data returned by the procedure
after the graph query engine has processed the graph query specified in the
“Query specification” parameter
Example: Creating and returning a graph using
the GRAPH_QUERY procedure
Step 1: Defining the input graph
Assume the following table, SALES_GRAPHS:
Step 1: Defining the input graph
Query snippet:
WITH QUARTERLY_SALES_DETAILS_GRAPH
AS SELECT RESULT_TABLE_FROM_CYPHER_QUERY_1.*
FROM SALES_GRAPHS G
GRAPH_QUERY
(GRAPH_INPUT =>
(SELECT SALES_GRAPH
FROM G
WHERE G.NAME = 'SalesDetail'
AND G.YEAR_QUARTER IS NULL),
Step 2: Defining the graph query
Query snippet:
QUERY_SPECIFICATION =>
OPAQUE endCypherQuery_1
with graph SalesDetail
match (p:Product)-[r:IN]->(o:Order)<-[:HAS]-(s:Store)-[:IN]->(reg:Region)
where datein(o.date, $YEAR_QUARTER_PARAMETER)
return new graph QuarterlySalesDetail
endCypherQuery_1
Step 3: Passing parameters
We assume the existence of a parameter @0 which has been set to ‘2017Q3’
Query snippet:
PASSING @0 AS YEAR_QUARTER_PARAMETER
Step 4: Returning the new graph from GRAPH_QUERY
Query snippet:
COLUMNS
(QuarterlySalesDetail GRAPH_REFERENCE AS SALES_DETAIL)
...
AS RESULT_TABLE_FROM_CYPHER_QUERY_1
Step 5: Post-processing tasks
Query snippet:
INSERT INTO SALES_GRAPHS
(NAME,
YEAR_QUARTER,
SALES_GRAPH)
VALUES
('SalesDetail',
@0,
(SELECT DISTINCT SALES_DETAIL
FROM QUARTERLY_SALES_DETAILS_GRAPH))
After execution, the SALES_GRAPHS table contains:
Putting it all together: the full query
WITH QUARTERLY_SALES_DETAILS_GRAPH
AS SELECT RESULT_TABLE_FROM_CYPHER_QUERY_1.*
FROM SALES_GRAPHS G
GRAPH_QUERY
(INPUT_GRAPH =>
(SELECT SALES_GRAPH
FROM G
WHERE G.NAME = 'SalesDetail'
AND G.YEAR_QUARTER IS NULL), -- the OLTP
“perpetual” graph
QUERY_SPECIFICATION =>
OPAQUE endCypherQuery_1 //delimit graph query
// Cypher query 1: extract a quarterly snapshot of sales
with graph SalesDetail
match
(p:Product)-[r:IN]->(o:Order)<-[:HAShas]-(s:Store)-[:IN]->(r
eg:Region)
where datein(o.date, $YEAR_QUARTER_PARAMETER)
return new graph QuarterlySalesDetail
endCypherQuery_1
<query continues in right box>
PASSING @0 AS YEAR_QUARTER_PARAMETER
COLUMNS
(QuarterlySalesDetail GRAPH_REFERENCE
AS SALES_DETAIL)
)
AS RESULT_TABLE_FROM_CYPHER_QUERY_1
INSERT INTO SALES_GRAPHS -- store graph reference
for quarterly SALES_DETAIL graph
(NAME,
YEAR_QUARTER,
SALES_GRAPH)
VALUES
('SalesDetail',
@0,
(SELECT DISTINCT SALES_DETAIL
FROM QUARTERLY_SALES_DETAILS_GRAPH))

More Related Content

PPT
Lecture15 abap on line
DOC
Alv Grids
DOCX
Performance Project Portfolio
PPTX
Structured query language constraints
PPTX
Box office analysis using SAS
PPTX
Boxoffice analysis using SAS
PPTX
Boxoffice analysis using SAS
PPT
Infix prefix postfix
Lecture15 abap on line
Alv Grids
Performance Project Portfolio
Structured query language constraints
Box office analysis using SAS
Boxoffice analysis using SAS
Boxoffice analysis using SAS
Infix prefix postfix

What's hot (11)

PPTX
Tableau + Redshift views for dummies
DOCX
Software Engineer Screening Question - OOP
PDF
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
PDF
Sql cheat-sheet
DOCX
Spiral array
PPSX
Analytic & Windowing functions in oracle
PDF
Olapsql
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
PDF
Data Visualization With R: Learn To Modify Color Of Plots
PPTX
Vinoth sas presentation RANE industries
Tableau + Redshift views for dummies
Software Engineer Screening Question - OOP
Data Visualization With R: Learn To Modify Title, Axis Labels & Range
Sql cheat-sheet
Spiral array
Analytic & Windowing functions in oracle
Olapsql
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
Data Visualization With R: Learn To Modify Color Of Plots
Vinoth sas presentation RANE industries
Ad

Similar to openCypher: Adding Property Graph Extensions to SQL Using Graph Query Procedures (20)

PPTX
Ground Breakers Romania: Explain the explain_plan
PPTX
Part3 Explain the Explain Plan
PDF
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
PDF
PDF
Cubing and Metrics in SQL, oh my!
PDF
Presentation interpreting execution plans for sql statements
PDF
Planning function on BPC hana system
DOC
Sql functions
PPTX
Murach : HOW to work with controllers and routing
PPTX
Developers' New features of Sql server express 2012
PPT
AIA101.2.Access Queries Accelerated
PDF
Multiple Graphs: Updatable Views
PPTX
ADVANCED MODELLING.pptx
PPT
Less08 Schema
PPT
Sql server ___________session 3(sql 2008)
PDF
Advanced plsql mock_assessment
PPT
Chapter 05 (Built-in SQL Functions) functions
PDF
Interactively querying Google Analytics reports from R using ganalytics
PPTX
Oracle: Functions
PPTX
Oracle: Functions
Ground Breakers Romania: Explain the explain_plan
Part3 Explain the Explain Plan
How to grow GraphQL and remove SQLAlchemy and REST API from a high-load Pytho...
Cubing and Metrics in SQL, oh my!
Presentation interpreting execution plans for sql statements
Planning function on BPC hana system
Sql functions
Murach : HOW to work with controllers and routing
Developers' New features of Sql server express 2012
AIA101.2.Access Queries Accelerated
Multiple Graphs: Updatable Views
ADVANCED MODELLING.pptx
Less08 Schema
Sql server ___________session 3(sql 2008)
Advanced plsql mock_assessment
Chapter 05 (Built-in SQL Functions) functions
Interactively querying Google Analytics reports from R using ganalytics
Oracle: Functions
Oracle: Functions
Ad

More from openCypher (20)

PDF
Learning Timed Automata with Cypher
PDF
Incremental View Maintenance for openCypher Queries
PDF
Formal semantics for Cypher queries and updates
PDF
Cypher.PL: an executable specification of Cypher semantics
PDF
Micro-Servicing Linked Data
PDF
Graph abstraction
PDF
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
PDF
Cypher for Gremlin
PDF
Comparing PGQL, G-Core and Cypher
PDF
Multiple graphs in openCypher
PDF
Eighth openCypher Implementers Group Meeting: Status Update
PDF
Cypher for Gremlin
PDF
Supporting dates and times in Cypher
PDF
Seventh openCypher Implementers Group Meeting: Status Update
PDF
Academic research on graph processing: connecting recent findings to industri...
PDF
Property Graphs with Time
PDF
Cypher.PL: Executable Specification of Cypher written in Prolog
PDF
Use case: processing multiple graphs
PDF
openCypher Technology Compatibility Kit (TCK)
PDF
Cypher Editor in the Web
Learning Timed Automata with Cypher
Incremental View Maintenance for openCypher Queries
Formal semantics for Cypher queries and updates
Cypher.PL: an executable specification of Cypher semantics
Micro-Servicing Linked Data
Graph abstraction
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
Cypher for Gremlin
Comparing PGQL, G-Core and Cypher
Multiple graphs in openCypher
Eighth openCypher Implementers Group Meeting: Status Update
Cypher for Gremlin
Supporting dates and times in Cypher
Seventh openCypher Implementers Group Meeting: Status Update
Academic research on graph processing: connecting recent findings to industri...
Property Graphs with Time
Cypher.PL: Executable Specification of Cypher written in Prolog
Use case: processing multiple graphs
openCypher Technology Compatibility Kit (TCK)
Cypher Editor in the Web

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Spectral efficient network and resource selection model in 5G networks
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Spectral efficient network and resource selection model in 5G networks
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf

openCypher: Adding Property Graph Extensions to SQL Using Graph Query Procedures

  • 1. SQL/Graph Query Procedures: an early draft oCIG 4 Presentation, 2017-08-17 Peter Furniss, Neo4j
  • 2. Motivation Don’t distort SQL with graph querying capabilities Instead, follow precedents set by SQL/XML and SQL/JSON: Extend SQL with a new GRAPH_REFERENCE data type (which is opaque) Extend SQL with the ability to invoke procedures to undertake graph query processing
  • 3. Single and dual engine architecture for the implementation of a graph query engine
  • 4. Graph query procedures: overview 1) GRAPH_QUERY procedure: Returns one or more graphs as GRAPH_REFERENCES Returns one or more table columns 2) GRAPH_TABLE procedure: Returns one or more table columns only
  • 5. Graph query procedures: inputs Mandatory inputs: Graph inputs: one or multiple GRAPH_REFERENCES Query specification: a string which is a query statement for the target graph query language Optional inputs: Driver table: A table expression, the types of whose columns are capable of being processed by the graph query engine/language Query parameters: A list of named scalar values
  • 6. Graph query procedures: results GRAPH_QUERY and GRAPH_TABLE return: Result table: a named table, containing the data returned by the procedure after the graph query engine has processed the graph query specified in the “Query specification” parameter
  • 7. Example: Creating and returning a graph using the GRAPH_QUERY procedure
  • 8. Step 1: Defining the input graph Assume the following table, SALES_GRAPHS:
  • 9. Step 1: Defining the input graph Query snippet: WITH QUARTERLY_SALES_DETAILS_GRAPH AS SELECT RESULT_TABLE_FROM_CYPHER_QUERY_1.* FROM SALES_GRAPHS G GRAPH_QUERY (GRAPH_INPUT => (SELECT SALES_GRAPH FROM G WHERE G.NAME = 'SalesDetail' AND G.YEAR_QUARTER IS NULL),
  • 10. Step 2: Defining the graph query Query snippet: QUERY_SPECIFICATION => OPAQUE endCypherQuery_1 with graph SalesDetail match (p:Product)-[r:IN]->(o:Order)<-[:HAS]-(s:Store)-[:IN]->(reg:Region) where datein(o.date, $YEAR_QUARTER_PARAMETER) return new graph QuarterlySalesDetail endCypherQuery_1
  • 11. Step 3: Passing parameters We assume the existence of a parameter @0 which has been set to ‘2017Q3’ Query snippet: PASSING @0 AS YEAR_QUARTER_PARAMETER
  • 12. Step 4: Returning the new graph from GRAPH_QUERY Query snippet: COLUMNS (QuarterlySalesDetail GRAPH_REFERENCE AS SALES_DETAIL) ... AS RESULT_TABLE_FROM_CYPHER_QUERY_1
  • 13. Step 5: Post-processing tasks Query snippet: INSERT INTO SALES_GRAPHS (NAME, YEAR_QUARTER, SALES_GRAPH) VALUES ('SalesDetail', @0, (SELECT DISTINCT SALES_DETAIL FROM QUARTERLY_SALES_DETAILS_GRAPH))
  • 14. After execution, the SALES_GRAPHS table contains:
  • 15. Putting it all together: the full query WITH QUARTERLY_SALES_DETAILS_GRAPH AS SELECT RESULT_TABLE_FROM_CYPHER_QUERY_1.* FROM SALES_GRAPHS G GRAPH_QUERY (INPUT_GRAPH => (SELECT SALES_GRAPH FROM G WHERE G.NAME = 'SalesDetail' AND G.YEAR_QUARTER IS NULL), -- the OLTP “perpetual” graph QUERY_SPECIFICATION => OPAQUE endCypherQuery_1 //delimit graph query // Cypher query 1: extract a quarterly snapshot of sales with graph SalesDetail match (p:Product)-[r:IN]->(o:Order)<-[:HAShas]-(s:Store)-[:IN]->(r eg:Region) where datein(o.date, $YEAR_QUARTER_PARAMETER) return new graph QuarterlySalesDetail endCypherQuery_1 <query continues in right box> PASSING @0 AS YEAR_QUARTER_PARAMETER COLUMNS (QuarterlySalesDetail GRAPH_REFERENCE AS SALES_DETAIL) ) AS RESULT_TABLE_FROM_CYPHER_QUERY_1 INSERT INTO SALES_GRAPHS -- store graph reference for quarterly SALES_DETAIL graph (NAME, YEAR_QUARTER, SALES_GRAPH) VALUES ('SalesDetail', @0, (SELECT DISTINCT SALES_DETAIL FROM QUARTERLY_SALES_DETAILS_GRAPH))