Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #841 from memgraph/gqla-import-overview
Browse files Browse the repository at this point in the history
Add GQLAlchemy import subpage
  • Loading branch information
katarinasupe authored May 2, 2023
2 parents b3a40e6 + e792ab4 commit f2de585
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ module.exports = {
label: "Installation",
to: "/gqlalchemy/installation",
},
{
label: "Import data",
to: "/gqlalchemy/import-data",
},
{
label: "How-to guides",
to: "/gqlalchemy/how-to-guides",
Expand Down
6 changes: 5 additions & 1 deletion gqlalchemy/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ source](/installation.md#source). If you are using [Conda](https://docs.conda.io
GQLAlchemy can't be installed with Python 3.11 [(#203)](https://github.com/memgraph/gqlalchemy/issues/203) and on Windows with Python > 3.9 [(#179)](https://github.com/memgraph/gqlalchemy/issues/179). If this is currently a blocker for you, please let us know by commenting on opened issues.
:::

### 2. Learn how to use GQLAlchemy
### 2. Connect to Memgraph

Check the [Python quick start guide](/memgraph/connect-to-memgraph/drivers/python) to learn how to connect to Memgraph using GQLAlchemy.

### 3. Learn how to use GQLAlchemy

With the help of the [How-to guides](/how-to-guides/overview.md) you can learn how to use GQLAlchemy's features, such as object graph mapper and query builder.

Expand Down
15 changes: 15 additions & 0 deletions gqlalchemy/how-to-guides/ogm.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,21 @@ The indexes will be set on class definition, before instantiation. This ensures
print(db.get_indexes())
```

The other way to create indexes is by creating an instance of `MemgraphIndex` class. For example, to create label index `NodeOne` and label-property index `NodeOne(name)`, run the following code:

```python
from gqlalchemy import Memgraph
from gqlalchemy.models import MemgraphIndex

db = Memgraph()

index1 = MemgraphIndex("NodeOne")
index2 = MemgraphIndex("NodeOne", "name")

db.create_index(index1)
db.create_index(index2)
```

To learn more about indexes, head over to the [indexing reference guide](/memgraph/reference-guide/indexing).

## Create constraints
Expand Down
17 changes: 17 additions & 0 deletions gqlalchemy/how-to-guides/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,20 @@ any of the graph algorithms. Learn how to use on-disk storage in the following
guide:

- [**On-disk storage**](/how-to-guides/on-disk-storage/on-disk-storage.md)

## Graph projections

As subgraphs are mainly used with Memgraph's query modules (graph algorithms),
QueryBuilder's `call()` method enables specifying the subgraph to use with a
certain algorithm.

- [**Create a graph projection**](/gqlalchemy/how-to-guides/query-builder/graph-projection)

## Transform Python graphs into Memgraph graphs

GQLAlchemy holds transformations that can transform NetworkX, PyG and DGL graphs
into Memgraph graphs. These transformations take the source graph object and
translate it to the appropriate Cypher queries. The Cypher queries are then
executed to create a graph inside Memgraph.

- [**Import NetworkX graph into Memgraph**](/gqlalchemy/how-to-guides/networkx)
39 changes: 38 additions & 1 deletion gqlalchemy/how-to-guides/query-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Through this guide, you will learn how to use GQLAlchemy query builder to:
- [**Call procedures**](#call-procedures)
- [**Call procedure with no arguments**](#call-procedure-with-no-arguments)
- [**Call procedure with arguments**](#call-procedure-with-arguments)
- [**Load CSV file**](#load-csv-file)

>Hopefully, this guide will teach you how to properly use GQLAlchemy query builder. If you
>have any more questions, join our community and ping us on [Discord](https://discord.gg/memgraph).
Expand Down Expand Up @@ -1241,7 +1242,8 @@ RETURN objects;
</TabItem>
</Tabs>

## Full code example
<details>
<summary> <b>Code example using all of the above mentioned queries</b> </summary>

```python
from gqlalchemy import create, merge, Memgraph, match, models, call
Expand Down Expand Up @@ -1490,7 +1492,42 @@ results = list(

print("Load from URL with argument:", results, "\n")
```
</details>

## Load CSV file

To load a CSV file using query builder, use the `load_csv()` procedure. Here is an example CSV file:
```
id,name,age,city
100,Daniel,30,London
101,Alex,15,Paris
102,Sarah,17,London
103,Mia,25,Zagreb
104,Lucy,21,Paris
```

To load it, run the following code:

```python
from gqlalchemy import load_csv, Memgraph
from gqlalchemy.utilities import CypherVariable

db = Memgraph()

load_csv(
path="/path-to/people_nodes.csv", header=True, row="row"
)
.create()
.node(
variable="n",
labels="Person",
id=CypherVariable(name="row.id"),
name=CypherVariable(name="row.name"),
age=CypherVariable(name="ToInteger(row.age)"),
city=CypherVariable(name="row.city"),
)
.execute()
```

>Hopefully, this guide has taught you how to properly use GQLAlchemy query builder. If you
>have any more questions, join our community and ping us on [Discord](https://discord.gg/memgraph).
Expand Down
53 changes: 53 additions & 0 deletions gqlalchemy/import-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
id: import-data
title: Import data
sidebar_label: Import data
slug: /import-data
---

You can import data in the following formats:
- [**CSV**](#csv)
- [**JSON**](#json)
- [**Parquet, ORC or IPC/Feather/Arrow**](#parquet-orc-or-ipcfeatherarrow)
- [**Python graphs - NetworkX, PyG or DGL graph**](#python-graphs---networkx-pyg-or-dgl-graph)
- [**Kafka, RedPanda or Pulsar data stream**](#kafka-redpanda-or-pulsar-data-stream)

Besides that, you can create data directly from code using the [**object graph mapper**](/gqlalchemy/how-to-guides/ogm) or [**query builder**](/gqlalchemy/how-to-guides/query-builder).


:::tip
The fastest way to import data into Memgraph is by using the [LOAD CSV clause](/memgraph/import-data/load-csv-clause). It's recommended to first [create indexes](/memgraph/next/how-to-guides/indexes) using the `CREATE INDEX` clause. You can create them by [executing the Cypher query](/memgraph/connect-to-memgraph/drivers/python) or using [object graph mapper](/gqlalchemy/how-to-guides/ogm#create-indexes).
:::

## CSV

To import CSV file into Memgraph via GQLAlchemy, you can use the [`LOAD CSV` clause](/memgraph/import-data/load-csv-clause). That clause can be used by [executing the Cypher query](/memgraph/connect-to-memgraph/drivers/python) or by [building the query with the query builder](/gqlalchemy/how-to-guides/query-builder#load-csv-file). Another way of importing CSV data into Memgraph is by [translating it into a graph](/gqlalchemy/how-to-guides/table-to-graph-importer).

## JSON

To import JSON files into Memgraph via GQLAlchemy, you can call procedures from the [`json_util` module](/mage/query-modules/python/json-util) available in MAGE library. If the JSON data is formatted in a particular style, you can call the [`import_util.json()` procedure](/mage/query-modules/python/import-util#jsonpath) from MAGE. The procedures can be called by [executing Cypher queries](/memgraph/connect-to-memgraph/drivers/python) or [using the query builder](/gqlalchemy/how-to-guides/query-builder#call-procedures).


## Parquet, ORC or IPC/Feather/Arrow

To import Parquet, ORC or IPC/Feather/Arrow file into Memgraph via GQLAlchemy, [transform table data from a file into a graph](/gqlalchemy/how-to-guides/table-to-graph-importer).

:::note
If you want to read from a file system not currently supported by GQLAlchemy, or use a file type currently not readable, you can implement your own by [making a custom file system importer](/gqlalchemy/how-to-guides/custom-file-system-importer).
:::


## Python graphs - NetworkX, PyG or DGL graph

To import NetworkX, PyG or DGL graph into Memgraph via GQLAlchemy, [transform the source graph into Memgraph graph](/gqlalchemy/how-to-guides/networkx).

## Kafka, RedPanda or Pulsar data stream

To consume Kafka, RedPanda or Pulsar data stream, you can write a[appropriate Cypher queries](/memgraph/import-data/data-streams/manage-streams) and [execute](/memgraph/connect-to-memgraph/drivers/python) them, or use GQLAlchemy stream manager for [Kafka, RedPanda](/gqlalchemy/how-to-guides/streams/manage-kafka-streams) or [Pulsar](/gqlalchemy/how-to-guides/streams/manage-pulsar-streams) streams.


## Learn more

To learn how to utilize the GQLAlchemy library with Memgraph, check out the [how-to guides](/gqlalchemy/how-to-guides) or sign up for the [Getting started with Memgraph and Python course](https://app.livestorm.co/memgraph/getting-started-with-memgraph-and-python-on-demand).


1 change: 1 addition & 0 deletions sidebars/sidebarsGQLAlchemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
gqlalchemy: [
"getting-started",
"installation",
"import-data",
{
type: "category",
label: "How-to guides",
Expand Down

0 comments on commit f2de585

Please sign in to comment.