Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 


In this blog a script is introduced to export a SAP HANA Graph workspace into the dot language.


SAP HANA Graph is part of the SAP HANA core. It adds native support for graph processing to SAP HANA with own objects and language (GraphScript). A graph is based on two tables, one for the nodes and one for the edges. Both are combined in a so-called graph workspace.

For a deeper understanding please refer to this blog.

GraphViz & The Dot Language

GraphViz is a software to visualize graphs. To describe these graphs the DOT language is used. The final visualization can be calculated by a variant of algorithms like dot or neato.

Idea & Solution

SAP HANA Graph allows to view a graph with its own graph viewer. Beside this, it's possible to export the graph objects (base tables, etc.). A conversion to a graph format like dot is currently not supported. This can be helpful to visualize the data with other tools, algorithms and parameters. In addition, sharing is much easier.

The script introduced in this blog allows the user to export SAP HANA graphs into a dot file. It queries the GRAPH_WORKSPACES system view to get all needed metadata. Using this metadata it knows which tables are used by the graph workspace and their relation to each other and can generate the dot file.

In SAP HANA it's possible to add additional attributes to a node and to an edge by adding columns to the base table. These columns can be queried in GraphScript procedures. To include them as well, all columns are stored in a special attribute called __custom_attributes as key-value pairs, both wrapped in single quotes. They aren't included directly as attributes to avoid naming conflict with predefined dot-attributes. Please refer the "Example output" section for an example.


The script is written in Python and can be found in this GitHub repository. Python 2.7 is needed to use it.

Command line

The script can be used from the command line with the following mandatory parameters:

Parameter short Parameter long Description
dh db_host Host of the SAP HANA database
dp db_port SQL port of the SAP HANA database
du db_user Database user with access to the graph workspace
dpw db_password Password of the database user
dws db_workspace_schema Graph workspace schema name
dwn db_workspace_name Graph workspace name
f file  Output file

python -dh host -dp 12345 -du user -dpw password -dws schema -dwn workspace -f

In python

Beside the command line, the export functionality can be used directly in python:
export = DotExport(user=user, password=password, host=host, port=port, workspace_name=workspace_name, workspace_schema_name=workspace_schema_name)

Example output

The following is a part from the export of the Greek Mythology Graph Example used in the SAP HANA Graph Reference:
strict digraph {
node_0 [label="Chaos", __custom_attributes="'NAME'='Chaos', 'TYPE'='primordial deity', 'RESIDENCE'='None'"]
node_1 [label="Gaia", __custom_attributes="'NAME'='Gaia', 'TYPE'='primordial deity', 'RESIDENCE'='None'"]
node_0 -> node_1 [__custom_attributes="'KEY'='1', 'SOURCE'='Chaos', 'TARGET'='Gaia', 'TYPE'='hasDaughter'"]

All columns and their values including the ones, which are not used by the graph workspace (e.g. TYPE) are stored in the __custom_attributes attribute.