Multigraph - get started

Hi,

I am using the latest v3.1 with Free Enterprise License and I’d like to try the multigraph feature. I read the docs and understand the concepts, but I didn’t find examples from the docs or the posts on this site. Are there any examples (gsql scripts) to demo how to create a multigraph?

Thanks,
John

Hi @John_Chen

1. Start by expressing that you are using the global space
USE GLOBAL

2. Create your graph elements (Vertices and Edges)

CREATE VERTEX Organization (PRIMARY_ID organization_id STRING , name STRING) WITH primary_id_as_attribute="true"
CREATE VERTEX Filing (PRIMARY_ID filing_id UINT, idicij_sar_id UINT, transaction_count FLOAT, transaction_amount FLOAT) WITH primary_id_as_attribute="true"
CREATE VERTEX Country (PRIMARY_ID name STRING , iso STRING, latitude DOUBLE, longitude DOUBLE, population FLOAT, growth_rate FLOAT, area FLOAT, density FLOAT) WITH primary_id_as_attribute="true"
CREATE DIRECTED EDGE FILED (FROM Organization, TO Filing, begin_date STRING, end_date STRING) WITH REVERSE_EDGE="REVERSE_FILING"
CREATE DIRECTED EDGE BENEFICIARY (FROM Filing, TO Organization) WITH REVERSE_EDGE="REVERSE_BENEFICIARY"
CREATE DIRECTED EDGE ORIGINATOR (FROM Organization, TO Filing) WITH REVERSE_EDGE="REVERESE_ORIGINATOR"
CREATE UNDIRECTED EDGE LOCATED (FROM Country, TO Organization)

3. Create your first graph that will use some or all elements in the globally defined schema

CREATE GRAPH fincen_filing(Organization, Filing, FILED, BENEFICIARY, ORIGINATOR, REVERSE_FILING, REVERSE_BENEFICIARY, REVERESE_ORIGINATOR)

4. Create your second graph by pulling in elements from global

CREATE GRAPH fincen_geo(Organization, Country, LOCATED)

And that is it! You can see that Organization is defined in both graphs. When data is added to Organization that will be accessible by either graph. However, you cannot access Country from graph fincen_filing because it isn’t accessible through that graph.

Hopefully, that helps with some clarity. If you have questions feel free to ask below.

Thanks Jon for the reply.

Is there a way to create graph specific vertices/edges? For example, can I create a Country vertex for fincen_filing with some attributes and another Country vertex for fincen_geo with different attributes? Obviously, I cannot have two vertices with the same name in the global space.

John

If you are looking to do that… I would do something like the following:

Vertex “Country

  • Abbr
  • Name
  • Code

For fincen_filing I only use code and don’t care about the rest. In fincen_geo I use Abbr and Name and not code

fincen_geo
America

  • Abbr: USA
  • Name: United States of America

fincen_filing
America

  • Code: 123456

Hi Jon, I got what you are advising. It seems we can only create vertices/edges in global name space, but not in each Graph name space, is it correct?

If you want the element to be shared you should define globally and use it locally in the graph. This will allow you to have that subgraph shared between two graphs.

If you would like to have different attributes with a shared vertex you should do as I mentioned above.

If you would like to have two vertices with different attributes and shared with both graphs you need to give them different names and pass those when you create a graph or schema change job.

Country_1

  • Abbr
  • Name

Country_2

  • code

CREATE GRAPH graph_1(Country_1, Country_2, edge1)
CREATE GRAPH graph_2(Country_1, Vertex_3, edge2, edge3)

2 Likes

you can create a vertex/edge type in local space. see Method 2, top-down DDL
https://docs.tigergraph.com/start/gsql-102/define-the-schema#method-2-top-down-ddl

Using schema change job, you can create locally-visible-only vertex/edge type.

2 Likes

Thanks Mingxi, it’ll certainly make things cleaner. I’ll check it out.