Skip to content
START FOR FREE
START FOR FREE
  • SUPPORT
  • COMMUNITY
Menu
  • SUPPORT
  • COMMUNITY
MENUMENU
  • Products
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      Watch a TigerGraph Demo

      TIGERGRAPH CLOUD

      • Overview
      • TigerGraph Cloud Suite
      • FAQ
      • Pricing

      USER TOOLS

      • GraphStudio
      • Insights
      • Application Workbenches
      • Connectors and Drivers
      • Starter Kits
      • openCypher Support

      TIGERGRAPH DB

      • Overview
      • GSQL Query Language
      • Compare Editions

      GRAPH DATA SCIENCE

      • Graph Data Science Library
      • Machine Learning Workbench
  • Solutions
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      Watch a TigerGraph Demo

      Solutions

      • Solutions Overview

      INCREASE REVENUE

      • Customer Journey/360
      • Product Marketing
      • Entity Resolution
      • Recommendation Engine

      MANAGE RISK

      • Fraud Detection
      • Anti-Money Laundering
      • Threat Detection
      • Risk Monitoring

      IMPROVE OPERATIONS

      • Supply Chain Analysis
      • Energy Management
      • Network Optimization

      By Industry

      • Advertising, Media & Entertainment
      • Financial Services
      • Healthcare & Life Sciences

      FOUNDATIONAL

      • AI & Machine Learning
      • Time Series Analysis
      • Geospatial Analysis
  • Customers
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      CUSTOMER SUCCESS STORIES

      • Ford
      • Intuit
      • JPMorgan Chase
      • READ MORE SUCCESS STORIES
      • Jaguar Land Rover
      • United Health Group
      • Xbox
  • Partners
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      PARTNER PROGRAM

      • Partner Benefits
      • TigerGraph Partners
      • Sign Up
      TigerGraph partners with organizations that offer complementary technology solutions and services.​
  • Resources
    • The World’s Fastest and Most Scalable Graph Platform

      LEARN MORE

      BLOG

      • TigerGraph Blog

      RESOURCES

      • Resource Library
      • Benchmarks
      • Demos
      • O'Reilly Graph + ML Book

      EVENTS & WEBINARS

      • Graph+AI Summit
      • Graph for All - Million Dollar Challenge
      • Events &Trade Shows
      • Webinars

      DEVELOPERS

      • Documentation
      • Ecosystem
      • Developers Hub
      • Community Forum

      SUPPORT

      • Contact Support
      • Production Guidelines

      EDUCATION

      • Training & Certifications
  • Company
    • Join the World’s Fastest and Most Scalable Graph Platform

      WE ARE HIRING

      COMPANY

      • Company Overview
      • Leadership
      • Legal Terms
      • Patents
      • Security and Compliance

      CAREERS

      • Join Us
      • Open Positions

      AWARDS

      • Awards and Recognition
      • Leader in Forrester Wave
      • Gartner Research

      PRESS RELEASE

      • Read All Press Releases
      TigerGraph Recognized in 2022 Gartner® Critical Capabilities for Cloud Database Management Systems for Analytical Use Cases
      January 12, 2023
      Read More »

      NEWS

      • Read All News

      A Shock to the System: ShockNet Predicts How Economic Shocks Could Affect the World Economy

      TigerGraph Recognized for the First Time in the 2022 Gartner® Magic Quadrant™ for Cloud Database Management Systems

  • START FREE
    • The World’s Fastest and Most Scalable Graph Platform

      GET STARTED

      • Request a Demo
      • CONTACT US
      • Try TigerGraph
      • START FREE
      • TRY AN ONLINE DEMO

Enhanced Pattern Matching Query Syntax

  • Mingxi Wu
  • April 30, 2019
  • blog, Developers, GSQL
  • Blog >
  • Enhanced Pattern Matching Query Syntax

In our upcoming 2.4 release, TigerGraph will offer a major syntax extension in GSQL – pattern matching.

Pattern matching enables users to focus on specifying what multi-hop path pattern they want in a query block, without worrying about the direction of the underlying data flow. They can think about the pattern as one query block (SELECT-FROM-WHERE) instead of several individual blocks. The pattern can be fixed length or variable length (using Kleene stars for repeated hops), which significantly shortens the GSQL query length.

In this blog, we give a preview of this pattern matching syntax. And we will hand this feature to you in the upcoming 2.4 release. All examples focus on the FROM clause, where the path pattern is specified and the aliases are bound. Other clauses such as WHERE clause, ACCUM clause etc. are omitted for brevity.

1-Hop Atomic Pattern

Let’s start with the basics. Below we first show a 1-hop fix length pattern, and a 1-hop variable length pattern (star pattern). The description of each pattern is under each FROM clause. For a given edge, if it is undirected, we do not put any decoration around it. For a directed edge, we use “>” or “<” to indicate its direction, such that user can know the source and target vertex types based on the edge definition.

    • 1-hop pattern
      1. FROM X:x – (E1:e1) – Y:y
        • Undirected edge
      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.
      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.
      4. FROM X:x – (_:e) – Y:y
        • Any undirected edge
      5. FROM X:x – (_>:e) – Y:y
        • Any right directed edge
      6. FROM X:x – (<_:e) – Y:y
        • Any left directed edge
      7. FROM X:x – ((<_|_):e) – Y:y
        • Any left directed or any undirected
      8. FROM X:x – ((E1|E2>|<E3):e) – Y:y
        • Disjunctive 1-hop edge. (x,y) are connected by E1 or E2 or E3.
      9. FROM X:x – () – Y:y
        • any edge (directed or undirected) match this 1-hop pattern
        • Same as this: (<_|_>|_)
    • 1-hop star pattern — repetition of an edge pattern, 0 or more times
      1. FROM X:x – (E1*) – Y:y
      2. FROM X:x – (E2>*) – Y:y
      3. FROM X:x – (<E3*) – Y:y
      4. FROM X:x – (_*) – Y:y
      5. FROM X:x – ((E1|E2>|<E3)*) – Y:y
    • 1-hop star pattern with bounds
      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.

 

Multiple Hop Pattern—Succinct Representation

With the above single hop pattern, we can extend it to a multiple hop pattern. Below are some examples to go to 2 and 3 hops.

  • 2-hop pattern
    • FROM X:x-(E1:e1)-Y:y-(E2>:e2)-Z:z
      • If we don’t need to refer to y in any expression, we can use the following syntax sugar to concatenate E1 and E2.
        • FROM X:x-(E1:e1.E2>:e2)-Z:z
      • If we don’t need to refer to e1 or e2 either, we can further simplify the path expression:
        • FROM X:x-(E1.E2>)-Z:z
  • 3-hop pattern
    • FROM X:x-(E2>:e2)-Y:y-(<E3:e3)-Z:z-(E4:e4)-U:u
      • If we only need to reference the end vertices and not any of the intermediate vertices or edges, we can shorten the expression:
        • FROM X:x-(E2>.<E3.E4)-Y:y

 

An Example Based on the LDBC benchmark

The LDBC Social Network Benchmark employs a social forum schema, and has three query workloads to ask different types of queries on this social data.

For example, IC_6 ask the following question:

Given a start Person and some Tag, find the other Tags that occur together with this Tag on Posts that were created by start Person’s friends and friends of friends (excluding start Person). Return top 10 Tags, and the count of Posts that were created by these Persons, which contain both this Tag and the given Tag.

Below is the GSQL implementation using the pattern match syntax.

CREATE QUERY ic_6(VERTEX<Person> personId, STRING tagName) FOR GRAPH ldbc_snb {
  TYPEDEF tuple<STRING tagName, INT postCount> tagStats;

  SetAccum<VERTEX<Post>> @@postAll;
  SumAccum<INT> @postCount;
  HeapAccum<tagStats>(10, postCount DESC, tagName ASC) @@tagStatsTop;

  vPerson = { personId };
  aggPersonPostTag =
    SELECT t3
    FROM vPerson:s
        -((Person_KNOWS_Person>|<Person_KNOWS_Person)*1..2)-Person:t1
        -(<Post_HAS_CREATOR_Person:e2)-Post:t2
        -(Post_HAS_TAG_Tag>:e3)-Tag:t3
    WHERE s != t1
    ACCUM CASE WHEN t3.name == tagName THEN @@postAll += t2 END;

  vPost = { @@postAll };
  vTag =
    SELECT t
    FROM vPost:s-(Post_HAS_TAG_Tag>:e)-Tag:t
    ACCUM CASE WHEN t.name != tagName THEN [email protected] += 1 END
    POST-ACCUM @@tagStatsTop += tagStats(t.name, [email protected]);

  PRINT @@tagStatsTop;
}

 

In conclusion, we see significant ease-of-use improvement with the pattern match syntax extension. It more and more guides the user to focus on declarative thinking, instead of imperative thinking. We hope you will enjoy it and please send your valuable feedback to us.

You Might Also Like

TigerGraph Showcases Unrivaled Performance at Scale

TigerGraph Showcases Unrivaled Performance at Scale

January 12, 2023
How to Create a Visual Graph Analytics Application Using TigerGraph Insights in 30 mins

How to Create a Visual Graph...

November 14, 2022
Turbocharge your business intelligence with TigerGraph’s ML Workbench on TigerGraph Cloud

Turbocharge your business intelligence with TigerGraph’s...

November 14, 2022

Introducing TigerGraph 3.0

July 1, 2020

Everything to Know to Pass your TigerGraph Certification Test

June 24, 2020

Neo4j 4.0 Fabric – A Look Behind the Curtain

February 7, 2020

TigerGraph Blog

  • Categories
    • blogs
      • About TigerGraph
      • Benchmark
      • Business
      • Community
      • Compliance
      • Customer
      • Customer 360
      • Cybersecurity
      • Developers
      • Digital Twin
      • eCommerce
      • Emerging Use Cases
      • Entity Resolution
      • Finance
      • Fraud / Anti-Money Laundering
      • GQL
      • Graph Database Market
      • Graph Databases
      • GSQL
      • Healthcare
      • Machine Learning / AI
      • Podcast
      • Supply Chain
      • TigerGraph
      • TigerGraph Cloud
    • Graph AI On Demand
      • Analysts and Research
      • Customer 360 and Entity Resolution
      • Customer Spotlight
      • Development
      • Finance, Banking, Insurance
      • Keynote
      • Session
    • Video
  • Recent Posts

    • It’s Time to Harness the Power of Graph Technology [Infographic]
    • TigerGraph Showcases Unrivaled Performance at Scale
    • TigerGraph 101 An Introduction to Graph | Jan 26th @ 9am PST
    • Data Science Salon New York
    • Tech For Retail
    TigerGraph

    Product

    SOLUTIONS

    customers

    RESOURCES

    start for free

    TIGERGRAPH DB
    • Overview
    • Features
    • GSQL Query Language
    GRAPH DATA SCIENCE
    • Graph Data Science Library
    • Machine Learning Workbench
    TIGERGRAPH CLOUD
    • Overview
    • Cloud Starter Kits
    • Login
    • FAQ
    • Pricing
    • Cloud Marketplaces
    USEr TOOLS
    • GraphStudio
    • TigerGraph Insights
    • Application Workbenches
    • Connectors and Drivers
    • Starter Kits
    • openCypher Support
    SOLUTIONS
    • Why Graph?
    industry
    • Advertising, Media & Entertainment
    • Financial Services
    • Healthcare & Life Sciences
    use cases
    • Benefits
    • Product & Service Marketing
    • Entity Resolution
    • Customer 360/MDM
    • Recommendation Engine
    • Anti-Money Laundering
    • Cybersecurity Threat Detection
    • Fraud Detection
    • Risk Assessment & Monitoring
    • Energy Management
    • Network & IT Management
    • Supply Chain Analysis
    • AI & Machine Learning
    • Geospatial Analysis
    • Time Series Analysis
    success stories
    • Customer Success Stories

    Partners

    Partner program
    • Partner Benefits
    • TigerGraph Partners
    • Sign Up
    LIBRARY
    • Resources
    • Benchmark
    • Webinars
    Events
    • Trade Shows
    • Graph + AI Summit
    • Million Dollar Challenge
    EDUCATION
    • Training & Certifications
    Blog
    • TigerGraph Blog
    DEVELOPERS
    • Developers Hub
    • Community Forum
    • Documentation
    • Ecosystem

    COMPANY

    Company
    • Overview
    • Careers
    • News
    • Press Release
    • Awards
    • Legal
    • Patents
    • Security and Compliance
    • Contact
    Get Started
    • Start Free
    • Compare Editions
    • Online Demo - Test Drive
    • Request a Demo

    Product

    • Overview
    • TigerGraph 3.0
    • TIGERGRAPH DB
    • TIGERGRAPH CLOUD
    • GRAPHSTUDIO
    • TRY NOW

    customers

    • success stories

    RESOURCES

    • LIBRARY
    • Events
    • EDUCATION
    • BLOG
    • DEVELOPERS

    SOLUTIONS

    • SOLUTIONS
    • use cases
    • industry

    Partners

    • partner program

    company

    • Overview
    • news
    • Press Release
    • Awards

    start for free

    • Request Demo
    • take a test drive
    • SUPPORT
    • COMMUNITY
    • CONTACT
    • Copyright © 2023 TigerGraph
    • Privacy Policy
    • Linkedin
    • Facebook
    • Twitter

    Copyright © 2020 TigerGraph | Privacy Policy

    Copyright © 2020 TigerGraph Privacy Policy

    • SUPPORT
    • COMMUNITY
    • COMPANY
    • CONTACT
    • Linkedin
    • Facebook
    • Twitter

    Copyright © 2020 TigerGraph

    Privacy Policy

    • Products
    • Solutions
    • Customers
    • Partners
    • Resources
    • Company
    • START FREE
    START FOR FREE
    START FOR FREE
    TigerGraph
    PRODUCT
    PRODUCT
    • Overview
    • GraphStudio UI
    • Graph Data Science Library
    TIGERGRAPH DB
    • Overview
    • Features
    • GSQL Query Language
    TIGERGRAPH CLOUD
    • Overview
    • Cloud Starter Kits
    TRY TIGERGRAPH
    • Get Started for Free
    • Compare Editions
    SOLUTIONS
    SOLUTIONS
    • Why Graph?
    use cases
    • Benefits
    • Product & Service Marketing
    • Entity Resolution
    • Customer Journey/360
    • Recommendation Engine
    • Anti-Money Laundering (AML)
    • Cybersecurity Threat Detection
    • Fraud Detection
    • Risk Assessment & Monitoring
    • Energy Management
    • Network Resources Optimization
    • Supply Chain Analysis
    • AI & Machine Learning
    • Geospatial Analysis
    • Time Series Analysis
    industry
    • Advertising, Media & Entertainment
    • Financial Services
    • Healthcare & Life Sciences
    CUSTOMERS
    read all success stories

     

    PARTNERS
    Partner program
    • Partner Benefits
    • TigerGraph Partners
    • Sign Up
    RESOURCES
    LIBRARY
    • Resource Library
    • Benchmark
    • Webinars
    Events
    • Trade Shows
    • Graph + AI Summit
    • Graph for All - Million Dollar Challenge
    EDUCATION
    • TigerGraph Academy
    • Certification
    Blog
    • TigerGraph Blog
    DEVELOPERS
    • Developers Hub
    • Community Forum
    • Documentation
    • Ecosystem
    COMPANY
    COMPANY
    • Overview
    • Leadership
    • Careers  
    NEWS
    PRESS RELEASE
    AWARDS
    START FREE
    Start Free
    • Request a Demo
    • SUPPORT
    • COMMUNITY
    • CONTACT
    Dr. Jay Yu

    Dr. Jay Yu | VP of Product and Innovation

    Dr. Jay Yu is the VP of Product and Innovation at TigerGraph, responsible for driving product strategy and roadmap, as well as fostering innovation in graph database engine and graph solutions. He is a proven hands-on full-stack innovator, strategic thinker, leader, and evangelist for new technology and product, with 25+ years of industry experience ranging from highly scalable distributed database engine company (Teradata), B2B e-commerce services startup, to consumer-facing financial applications company (Intuit). He received his PhD from the University of Wisconsin - Madison, where he specialized in large scale parallel database systems

    Todd Blaschka | COO

    Todd Blaschka is a veteran in the enterprise software industry. He is passionate about creating entirely new segments in data, analytics and AI, with the distinction of establishing graph analytics as a Gartner Top 10 Data & Analytics trend two years in a row. By fervently focusing on critical industry and customer challenges, the companies under Todd's leadership have delivered significant quantifiable results to the largest brands in the world through channel and solution sales approach. Prior to TigerGraph, Todd led go to market and customer experience functions at Clustrix (acquired by MariaDB), Dataguise and IBM.