AGEFreighterを使った簡単なグラフデータのデモ

Apache AGEのハンズオンをやらんとならんので、ざっと書いた。

# deploy Azure Database for PostgreSQL
# add AGE extension to 'azure.extensions' and 'shared_preload_libraries' in 'parameters' section in 'Settings' blade on Azure Portal
# https://techcommunity.microsoft.com/blog/adforpostgresql/introducing-support-for-graph-data-in-azure-database-for-postgresql-preview/4275628

# or, run docker container
docker pull apache/age
docker run \
    --name age  \
    -p 5455:5432 \
    -e POSTGRES_USER=postgres \
    -e POSTGRES_PASSWORD=postgresPW \
    -e POSTGRES_DB=postgres \
    -d \
    apache/age

# uv install
# https://docs.astral.sh/uv/guides/install-python/

# macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

# make a directory
mkdir test
cd test

# create venv
uv venv
source .venv/bin/activate

# download dummy_generator.py
curl -O https://raw.githubusercontent.com/rioriost/agefreighter/refs/heads/main/tests/dummy_generator.py

# add Faker
uv add faker

# edit dummy_generator.py line 13-14 to reduce the number of rows and items
row_cnt  = 100000
item_cnt = 10000

# run dummy_generator.py
chmod 755 dummy_generator.py
./dummy_generator.py

# check the generated CSV file
head -n 5 *. csv

# download test.py
curl -O https://raw.githubusercontent.com/rioriost/agefreighter/refs/heads/main/tests/test_agefreighter.py

# add AGEFreighter
uv add agefreighter

# export an env var
# Azure
export PG_CONNECTION_STRING="host=your_server.postgres.database.azure.com port=5432 dbname=postgres user=account password=your_password"
# Docker
export PG_CONNECTION_STRING="host=localhost port=5455 dbname=postgres user=postgres password=postgresPW"

# exeucte test
chmod 755 test_agefreighter.py
./test_agefreighter.py

# check the data injecting with psql
# Azure
psql -h your_server.postgres.database.azure.com -p 5432 -d postgres -U account
# Docker
psql -h localhost -p 5455 -d postgres -U postgres

postgres=# SET search_path = ag_catalog, "$user", public;
postgres=# SELECT * FROM ag_label;

タイトルとURLをコピーしました