├── .github
├── FUNDING.yml
└── workflows
│ └── codecov.yml
├── .gitignore
├── .travis.yml
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── debian
├── changelog
├── control
├── control.in
├── copyright
├── pgversions
├── rules
├── source
│ └── format
└── watch
├── docker-entrypoint-initdb.d
└── 00-create-extension-postgraph.sql
├── logo.png
├── old
└── regress
│ ├── age_load.out
│ ├── catalog.out
│ ├── catalog.sql
│ ├── drop.out
│ ├── drop.sql
│ ├── expr.out
│ ├── expr.sql
│ ├── geometric.out
│ ├── geometric.sql
│ ├── index.out
│ ├── index.sql
│ ├── scan.out
│ ├── scan.sql
│ └── typecasting.out
├── postgraph.control
├── regress
├── .gitignore
├── GNUmakefile
├── expected
│ ├── aggregation.out
│ ├── cypher_call.out
│ ├── cypher_create.out
│ ├── cypher_delete.out
│ ├── cypher_match.out
│ ├── cypher_merge.out
│ ├── cypher_remove.out
│ ├── cypher_set.out
│ ├── cypher_setop.out
│ ├── cypher_unwind.out
│ ├── cypher_vle.out
│ ├── cypher_with.out
│ ├── drop.out
│ ├── expr.out
│ ├── graphid.out
│ ├── gtype.out
│ ├── lists.out
│ ├── load_csv.out
│ ├── network.out
│ ├── new_cypher.out
│ ├── order_by.out
│ ├── postgis.out
│ ├── range.out
│ ├── regex.out
│ ├── temporal.out
│ ├── traversal_functions.out
│ ├── tsearch.out
│ ├── variable_edge_functions.out
│ ├── vector.out
│ └── vertex.out
├── regress.c
├── sql
│ ├── aggregation.sql
│ ├── cypher_call.sql
│ ├── cypher_create.sql
│ ├── cypher_delete.sql
│ ├── cypher_match.sql
│ ├── cypher_merge.sql
│ ├── cypher_remove.sql
│ ├── cypher_set.sql
│ ├── cypher_setop.sql
│ ├── cypher_unwind.sql
│ ├── cypher_vle.sql
│ ├── cypher_with.sql
│ ├── expr.sql
│ ├── graphid.sql
│ ├── gtype.sql
│ ├── lists.sql
│ ├── load_csv.sql
│ ├── network.sql
│ ├── new_cypher.sql
│ ├── order_by.sql
│ ├── postgis.sql
│ ├── range.sql
│ ├── regex.sql
│ ├── temporal.sql
│ ├── traversal_functions.sql
│ ├── tsearch.sql
│ ├── variable_edge_functions.sql
│ └── vector.sql
└── test.csv
├── sql
├── postgraph-aggregation.sql.in
├── postgraph-edge.sql.in
├── postgraph-geometric.sql.in
├── postgraph-graphid.sql.in
├── postgraph-gtype-lists.sql.in
├── postgraph-gtype.sql.in
├── postgraph-network.sql.in
├── postgraph-number-functions.sql.in
├── postgraph-postgis.sql.in
├── postgraph-range.sql.in
├── postgraph-string-functions.sql.in
├── postgraph-temporal.sql.in
├── postgraph-traversal.sql.in
├── postgraph-tsearch.sql.in
├── postgraph-typecasting.sql.in
├── postgraph-variable_edge.sql.in
├── postgraph-vertex.sql.in
└── postgraph.sql.in
├── src
├── backend
│ ├── access
│ │ └── ivfflat
│ │ │ ├── ivfbuild.c
│ │ │ ├── ivfflat.c
│ │ │ ├── ivfinsert.c
│ │ │ ├── ivfkmeans.c
│ │ │ ├── ivfscan.c
│ │ │ ├── ivfutils.c
│ │ │ └── ivfvacuum.c
│ ├── catalog
│ │ ├── ag_catalog.c
│ │ ├── ag_graph.c
│ │ ├── ag_label.c
│ │ └── ag_namespace.c
│ ├── commands
│ │ ├── graph_commands.c
│ │ └── label_commands.c
│ ├── executor
│ │ ├── cypher_create.c
│ │ ├── cypher_delete.c
│ │ ├── cypher_merge.c
│ │ ├── cypher_set.c
│ │ └── cypher_utils.c
│ ├── nodes
│ │ ├── ag_nodes.c
│ │ ├── cypher_copyfuncs.c
│ │ ├── cypher_outfuncs.c
│ │ └── cypher_readfuncs.c
│ ├── optimizer
│ │ ├── cypher_createplan.c
│ │ ├── cypher_pathnode.c
│ │ └── cypher_paths.c
│ ├── parser
│ │ ├── .gitignore
│ │ ├── ag_scanner.l
│ │ ├── cypher_analyze.c
│ │ ├── cypher_clause.c
│ │ ├── cypher_expr.c
│ │ ├── cypher_gram.y
│ │ ├── cypher_item.c
│ │ ├── cypher_keywords.c
│ │ ├── cypher_parse_agg.c
│ │ ├── cypher_parse_node.c
│ │ ├── cypher_parser.c
│ │ ├── cypher_transform_entity.c
│ │ └── sql_expr.c
│ ├── postgraph.c
│ └── utils
│ │ ├── adt
│ │ ├── age_graphid_ds.c
│ │ ├── cypher_funcs.c
│ │ ├── edge.c
│ │ ├── graphid.c
│ │ ├── gtype.c
│ │ ├── gtype_ext.c
│ │ ├── gtype_geometric.c
│ │ ├── gtype_gin.c
│ │ ├── gtype_network.c
│ │ ├── gtype_numbers.c
│ │ ├── gtype_ops.c
│ │ ├── gtype_parser.c
│ │ ├── gtype_postgis.c
│ │ ├── gtype_range.c
│ │ ├── gtype_string.c
│ │ ├── gtype_temporal.c
│ │ ├── gtype_tsearch.c
│ │ ├── gtype_typecasting.c
│ │ ├── gtype_util.c
│ │ ├── queue.c
│ │ ├── traversal.c
│ │ ├── variable_edge.c
│ │ ├── vector.c
│ │ └── vertex.c
│ │ ├── ag_func.c
│ │ ├── cache
│ │ └── ag_cache.c
│ │ └── path_finding
│ │ ├── dfs.c
│ │ └── global_graph.c
└── include
│ ├── access
│ └── ivfflat.h
│ ├── catalog
│ ├── ag_catalog.h
│ ├── ag_graph.h
│ ├── ag_label.h
│ └── ag_namespace.h
│ ├── commands
│ └── label_commands.h
│ ├── executor
│ ├── cypher_executor.h
│ └── cypher_utils.h
│ ├── nodes
│ ├── ag_nodes.h
│ ├── cypher_copyfuncs.h
│ ├── cypher_nodes.h
│ ├── cypher_outfuncs.h
│ └── cypher_readfuncs.h
│ ├── optimizer
│ ├── cypher_createplan.h
│ ├── cypher_pathnode.h
│ └── cypher_paths.h
│ ├── parser
│ ├── .gitignore
│ ├── ag_scanner.h
│ ├── cypher_analyze.h
│ ├── cypher_clause.h
│ ├── cypher_expr.h
│ ├── cypher_gram.h
│ ├── cypher_item.h
│ ├── cypher_keywords.h
│ ├── cypher_kwlist.h
│ ├── cypher_parse_agg.h
│ ├── cypher_parse_node.h
│ ├── cypher_parser.h
│ └── cypher_transform_entity.h
│ ├── postgraph.h
│ └── utils
│ ├── ag_cache.h
│ ├── ag_func.h
│ ├── edge.h
│ ├── global_graph.h
│ ├── graphid.h
│ ├── graphid_ds.h
│ ├── gtype.h
│ ├── gtype_ext.h
│ ├── gtype_parser.h
│ ├── gtype_temporal.h
│ ├── gtype_typecasting.h
│ ├── path_finding.h
│ ├── queue.h
│ ├── traversal.h
│ ├── variable_edge.h
│ ├── vector.h
│ └── vertex.h
└── tools
├── PerfectHash.pm
├── gen_keywordlist.pl
└── git
└── commit-msg
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: PostGraph
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
14 |
--------------------------------------------------------------------------------
/.github/workflows/codecov.yml:
--------------------------------------------------------------------------------
1 | - name: Upload coverage reports to Codecov
2 | uses: codecov/codecov-action@v3
3 | env:
4 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.so
3 | build.sh
4 | .idea
5 | .deps
6 | .DS_Store
7 | .vscode
8 | postgraph--*.sql
9 | src/backend/parser/temp_rules
10 | src/backend/parser/temp.text
11 | src/backend/parser/tmp_postgres
12 | update.patch
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: c
2 | os: linux
3 | dist: bionic
4 | arch: amd64
5 | jobs:
6 | include:
7 | - name: PostgreSQL 14
8 | compiler: gcc
9 | addons:
10 | apt:
11 | packages:
12 | - postgresql-14-postgis-3
13 | - postgresql-server-dev-14
14 | script:
15 | - sudo make install -j$(nproc)
16 | - make installcheck
17 | after_failure: cat regress/regression.diffs
18 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2023 PostGraphDB
2 | #
3 | # This program is free software: you can redistribute it and/or modify
4 | # it under the terms of the GNU Affero General Public License as
5 | # published by the Free Software Foundation, either version 3 of the
6 | # License, or (at your option) any later version.
7 | #
8 | # This program is distributed in the hope that it will be useful,
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 | # GNU Affero General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU Affero General Public License
14 | # along with this program. If not, see .
15 | #
16 | # For PostgreSQL Database Management System:
17 | # (formerly known as Postgres, then as Postgres95)
18 | #
19 | # Portions Copyright (c) 2020-2023, Apache Software Foundation
20 |
21 | FROM postgres:14
22 |
23 | RUN apt-get update
24 | RUN apt-get install --assume-yes --no-install-recommends --no-install-suggests \
25 | bison \
26 | build-essential \
27 | flex \
28 | postgresql-server-dev-14
29 |
30 | COPY . /postgraph
31 | RUN cd /postgraph && make install
32 |
33 | COPY docker-entrypoint-initdb.d/00-create-extension-postgraph.sql /docker-entrypoint-initdb.d/00-create-extension-postgraph.sql
34 |
35 | CMD ["postgres", "-c", "shared_preload_libraries=postgraph"]
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PostGraph
2 |
3 |
4 |
5 |
6 |
7 |
8 | ## Introduction
9 | PostGraph is a multi-model, graph centric query engine build on Postgres. PostGraph is designed to work fast with your OLTP, OLAP and AI Applications.
10 |
11 | ## Requirements
12 | - Linux
13 | - PostGIS 3.3
14 | - Development Files for PostgreSQL and PostGIS
15 |
16 | ## Building & Installation From Source
17 |
18 | Download and Install the postgres_for_postgraph source
19 | ```bash
20 | git clone https://github.com/PostGraphDB/postgres_for_postgraph
21 | cd postgres_for_postgraph
22 | ./configure --prefix=($pwd)
23 | make
24 | sudo make install
25 | ```
26 |
27 | Install PostGIS
28 |
29 | Install PostGraph
30 | ```bash
31 | git clone https://github.com/PostGraphDB/postgraph
32 | cd postgraph
33 | make POSTGIS_DIR=/path/to/postgis/source/files
34 | sudo make install
35 | ```
36 |
37 | Once PostGraph is installed, it needs to be enabled in each database you want to use it in. In the example below we use a database named `postgraph`.
38 | ```bash
39 | createdb postgraph
40 | psql postgraph -c "CREATE EXTENSION PostGIS"
41 | psql postgraph -c "CREATE EXTENSION LTree"
42 | psql postgraph -c "CREATE EXTENSION PostGraph"
43 | ```
44 |
45 | You can find the location of the `postgresql.conf` file as given next:
46 | ```bash
47 | $ which postgres
48 | /usr/local/pgsql/bin/postgres
49 | $ ls /usr/local/pgsql/data/postgresql.conf
50 | /usr/local/pgsql/data/postgresql.conf
51 | ```
52 | As can be seen, the PostgreSQL binaries are in the `bin` subdirectory while the `postgresql.conf` file is in the `data` subdirectory.
53 |
54 | Set the following in `postgresql.conf` depending on the version of PostGraph and it's dependecy PostGIS:
55 | ```bash
56 | shared_preload_libraries = 'postgraph'
57 | ```
58 |
59 | POSTGIS Dependencies:
60 | autoconf automake libtool libxml2-devel geos-devel proj-devel protobuf-devel protobuf-c-compiler protobuf-compiler gdal-devel
61 |
62 | ## Quick Start
63 |
64 | Use `psql` to start a command line session with your database
65 | ```bash
66 | psql postgraph
67 | ```
68 |
69 | Create a graph
70 | ```sql
71 | CREATE GRAPH graph_name;
72 | ```
73 |
74 | Set the Graph being used
75 | ```sql
76 | USE GRAPH graph_name;
77 | ```
78 |
79 | Create Data with the CREATE command
80 | ```sql
81 | CREATE (v { name: 'Hello Graph!'}) RETURN v;
82 | ```
83 |
84 | Find data with the MATCH command
85 | ```sql
86 | MATCH (n) RETURN n;
87 | ```
88 |
89 | ## Thank You to All the Supporters!
90 | 
91 | 
92 |
--------------------------------------------------------------------------------
/debian/changelog:
--------------------------------------------------------------------------------
1 | postgraph (1.1.1) UNRELEASED; urgency=medium
2 |
3 | * Initial release
4 |
5 | -- Sarthak Jaiswal Mon, 17 Jul 2023 15:34:58 +0530
--------------------------------------------------------------------------------
/debian/control:
--------------------------------------------------------------------------------
1 | # License: AGPL v3
2 |
3 | # Copyright (C) 2007 Free Software Foundation, Inc.
4 | # Everyone is permitted to copy and distribute verbatim copies
5 | # of this license document, but changing it is not allowed.
6 |
7 | # Preamble
8 |
9 | # The GNU Affero General Public License is a free, copyleft license for
10 | # software and other kinds of works, specifically designed to ensure
11 | # cooperation with the community in the case of network server software.
12 |
13 |
14 |
15 | Source: postgraph
16 | Section: database
17 | Priority: optional
18 | Maintainer: PostgraphDB
19 | Uploaders:
20 | Sarthak Jaiswal ,
21 | Ahmar Zaidi ,
22 | Build-Depends:
23 | debhelper-compat (= 13),
24 | build-essential,
25 | postgresql-14,
26 | libreadline-dev,
27 | zlib1g-dev,
28 | flex,
29 | bison,
30 | Standards-Version: 4.5.1
31 | Rules-Requires-Root: no
32 | Homepage: https://age.apache.org
33 |
34 | Package: postgraph
35 | Architecture: all
36 | Depends:
37 | ${misc:Depends},
38 | ${postgresql:Depends},
39 | ${shlibs:Depends},
40 | Description: Postgraph is an extension for Postgres with the explicit goal of combining the power of graph modeling together
41 | with the full fledged power of the Postgres ecosystem.
42 | Originally a fork of Apache AGE, PostGraph will combine a graph based model and query language with the power of the open source
43 | Postgres community.
44 |
--------------------------------------------------------------------------------
/debian/control.in:
--------------------------------------------------------------------------------
1 | # License: AGPL v3
2 |
3 | # Copyright (C) 2007 Free Software Foundation, Inc.
4 | # Everyone is permitted to copy and distribute verbatim copies
5 | # of this license document, but changing it is not allowed.
6 |
7 | # Preamble
8 |
9 | # The GNU Affero General Public License is a free, copyleft license for
10 | # software and other kinds of works, specifically designed to ensure
11 | # cooperation with the community in the case of network server software.
12 |
13 |
14 |
15 | Source: postgraph
16 | Section: database
17 | Priority: optional
18 | Maintainer: Debian PostgreSQL Maintainers
19 | Uploaders:
20 | Sarthak Jaiswal ,
21 | Ahmar Zaidi ,
22 | Build-Depends:
23 | debhelper-compat (= 13),
24 | build-essential,
25 | postgresql-14,
26 | libreadline-dev,
27 | zlib1g-dev,
28 | flex,
29 | bison,
30 | Standards-Version: 4.5.1
31 | Rules-Requires-Root: no
32 |
33 | Package: postgraph
34 | Architecture: all
35 | Depends:
36 | ${misc:Depends},
37 | ${postgresql:Depends},
38 | ${shlibs:Depends},
39 | Description: Postgraph is an extension for Postgres with the explicit goal of combining the power of graph modeling together
40 | with the full fledged power of the Postgres ecosystem.
41 | Originally a fork of Apache AGE, PostGraph will combine a graph based model and query language with the power of the open source
42 | Postgres community.
--------------------------------------------------------------------------------
/debian/copyright:
--------------------------------------------------------------------------------
1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2 | Upstream-Name: postgraph
3 | Upstream-Contact: PostgraphDB
4 | Source: https://github.com/apache/age
5 |
6 | Files: *
7 | Copyright:
8 |
9 |
10 |
11 | License: AGPL v3
12 |
13 | Copyright (C) 2007 Free Software Foundation, Inc.
14 | Everyone is permitted to copy and distribute verbatim copies
15 | of this license document, but changing it is not allowed.
16 |
17 | Preamble
18 |
19 | The GNU Affero General Public License is a free, copyleft license for
20 | software and other kinds of works, specifically designed to ensure
21 | cooperation with the community in the case of network server software.
22 |
23 | The licenses for most software and other practical works are designed
24 | to take away your freedom to share and change the works. By contrast,
25 | our General Public Licenses are intended to guarantee your freedom to
26 | share and change all versions of a program--to make sure it remains free
27 | software for all its users.ns and limitations
28 | under the License. -->
29 |
--------------------------------------------------------------------------------
/debian/pgversions:
--------------------------------------------------------------------------------
1 | 14
--------------------------------------------------------------------------------
/debian/rules:
--------------------------------------------------------------------------------
1 | #!/usr/bin/make -f
2 |
3 | %:
4 | dh $@
5 |
6 | override_dh_installdocs:
7 | dh_installdocs --all README.*
--------------------------------------------------------------------------------
/debian/source/format:
--------------------------------------------------------------------------------
1 | 3.0 (quilt)
2 |
--------------------------------------------------------------------------------
/debian/watch:
--------------------------------------------------------------------------------
1 | version=4
2 | https://github.com/PostGraphDB/postgraph .*/(.*).tar.gz
3 |
--------------------------------------------------------------------------------
/docker-entrypoint-initdb.d/00-create-extension-postgraph.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * For PostgreSQL Database Management System:
18 | * (formerly known as Postgres, then as Postgres95)
19 | *
20 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
21 | */
22 |
23 | CREATE EXTENSION postgraph;
24 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PostGraphDB/postgraph/72a080d3367aea6e0ffffaed54a9d0b025caee32/logo.png
--------------------------------------------------------------------------------
/old/regress/drop.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | LOAD 'postgraph';
20 | SET search_path TO postgraph;
21 | SELECT create_graph('drop');
22 | NOTICE: graph "drop" has been created
23 | create_graph
24 | --------------
25 |
26 | (1 row)
27 |
28 | DROP EXTENSION postgraph;
29 | NOTICE: drop cascades to 2 other objects
30 | DETAIL: drop cascades to table drop._ag_label_vertex
31 | drop cascades to table drop._ag_label_edge
32 | NOTICE: graph "drop" has been dropped
33 | NOTICE: drop cascades to 3 other objects
34 | DETAIL: drop cascades to table regex._ag_label_vertex
35 | drop cascades to table regex._ag_label_edge
36 | drop cascades to table regex."Person"
37 | NOTICE: graph "regex" has been dropped
38 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'drop';
39 | nspname
40 | ---------
41 | (0 rows)
42 |
43 | SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'postgraph';
44 | tablename
45 | -----------
46 | (0 rows)
47 |
48 | -- Recreate the extension and validate we can recreate a graph
49 | CREATE EXTENSION postgraph;
50 | SELECT create_graph('drop');
51 | NOTICE: graph "drop" has been created
52 | create_graph
53 | --------------
54 |
55 | (1 row)
56 |
57 | -- Create a schema that uses the gtype, so we can't just drop postgraph.
58 | CREATE SCHEMA other_schema;
59 | CREATE TABLE other_schema.tbl (id gtype);
60 | -- Should Fail because gtype can't be dropped
61 | DROP EXTENSION postgraph;
62 | NOTICE: drop cascades to 2 other objects
63 | DETAIL: drop cascades to table drop._ag_label_vertex
64 | drop cascades to table drop._ag_label_edge
65 | NOTICE: graph "drop" has been dropped
66 | ERROR: cannot drop extension postgraph because other objects depend on it
67 | DETAIL: column id of table other_schema.tbl depends on type gtype
68 | HINT: Use DROP ... CASCADE to drop the dependent objects too.
69 | -- Check the graph still exist, because the DROP command failed
70 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'drop';
71 | nspname
72 | ---------
73 | drop
74 | (1 row)
75 |
76 | -- Should succeed, delete the 'drop' schema and leave 'other_schema'
77 | DROP EXTENSION postgraph CASCADE;
78 | NOTICE: drop cascades to 2 other objects
79 | DETAIL: drop cascades to table drop._ag_label_vertex
80 | drop cascades to table drop._ag_label_edge
81 | NOTICE: graph "drop" has been dropped
82 | NOTICE: drop cascades to column id of table other_schema.tbl
83 | -- 'other_schema' should exist, 'drop' should be deleted
84 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname IN ('other_schema', 'drop');
85 | nspname
86 | --------------
87 | other_schema
88 | (1 row)
89 |
90 |
--------------------------------------------------------------------------------
/old/regress/drop.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | SELECT create_graph('drop');
24 |
25 | DROP EXTENSION postgraph;
26 |
27 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'drop';
28 |
29 | SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'postgraph';
30 |
31 | -- Recreate the extension and validate we can recreate a graph
32 | CREATE EXTENSION postgraph;
33 |
34 | SELECT create_graph('drop');
35 |
36 | -- Create a schema that uses the gtype, so we can't just drop postgraph.
37 | CREATE SCHEMA other_schema;
38 |
39 | CREATE TABLE other_schema.tbl (id gtype);
40 |
41 | -- Should Fail because gtype can't be dropped
42 | DROP EXTENSION postgraph;
43 |
44 | -- Check the graph still exist, because the DROP command failed
45 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname = 'drop';
46 |
47 | -- Should succeed, delete the 'drop' schema and leave 'other_schema'
48 | DROP EXTENSION postgraph CASCADE;
49 |
50 | -- 'other_schema' should exist, 'drop' should be deleted
51 | SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname IN ('other_schema', 'drop');
52 |
--------------------------------------------------------------------------------
/old/regress/typecasting.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 | LOAD 'postgraph';
18 | SET extra_float_digits = 0;
19 | SET search_path TO postgraph;
20 | SELECT text_to_gtype(NULL::text);
21 | text_to_gtype
22 | ---------------
23 |
24 | (1 row)
25 |
26 | SELECT 'Hello World' ::text::gtype;
27 | gtype
28 | ---------------
29 | "Hello World"
30 | (1 row)
31 |
32 |
--------------------------------------------------------------------------------
/postgraph.control:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 |
18 | default_version = '0.1.0'
19 | comment = 'postgraph database extension'
20 | module_pathname = '$libdir/postgraph'
21 | relocatable = false
22 | schema = 'postgraph'
23 |
--------------------------------------------------------------------------------
/regress/.gitignore:
--------------------------------------------------------------------------------
1 | /instance/
2 | /log/
3 | /results/
4 | regression.*
5 |
--------------------------------------------------------------------------------
/regress/expected/cypher_call.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 | LOAD 'postgraph';
18 | SET search_path TO postgraph;
19 | CREATE GRAPH cypher_call;
20 | NOTICE: graph "cypher_call" has been created
21 | create_graph
22 | --------------
23 |
24 | (1 row)
25 |
26 | USE GRAPH cypher_call;
27 | use_graph
28 | -----------
29 |
30 | (1 row)
31 |
32 | --
33 | -- Create table to hold the start and end vertices to test the SRF
34 | --
35 | CYPHER CALL sin(1) as a RETURN a;
36 | a
37 | --------------------
38 | 0.8414709848078965
39 | (1 row)
40 |
41 | CYPHER CALL sin(1) as b RETURN b;
42 | b
43 | --------------------
44 | 0.8414709848078965
45 | (1 row)
46 |
47 | CYPHER WITH [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst CALL unnest(lst) as b RETURN b;
48 | b
49 | ----
50 | 1
51 | 2
52 | 3
53 | 4
54 | 5
55 | 6
56 | 7
57 | 8
58 | 9
59 | 10
60 | (10 rows)
61 |
62 | CYPHER WITH [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst CALL unnest(lst) as b WHERE b % 2 = 0 RETURN b;
63 | b
64 | ----
65 | 2
66 | 4
67 | 6
68 | 8
69 | 10
70 | (5 rows)
71 |
72 | CYPHER CALL unnest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) as b RETURN b;
73 | b
74 | ----
75 | 1
76 | 2
77 | 3
78 | 4
79 | 5
80 | 6
81 | 7
82 | 8
83 | 9
84 | 10
85 | (10 rows)
86 |
87 | CYPHER CALL pg_catalog.generate_series(1, 2, 3);
88 | ERROR: syntax error at or near "."
89 | LINE 1: CYPHER CALL pg_catalog.generate_series(1, 2, 3);
90 | ^
91 | MATCH (n) CALL this_isnt_a_real_function(1, 2, 3);
92 | ERROR: syntax error at or near ";"
93 | LINE 1: MATCH (n) CALL this_isnt_a_real_function(1, 2, 3);
94 | ^
95 | CYPHER CALL { RETURN 1 } RETURN 2;
96 | ?column?
97 | ----------
98 | 2
99 | (1 row)
100 |
101 | CYPHER CALL { RETURN 1 as a } RETURN a;
102 | a
103 | ---
104 | 1
105 | (1 row)
106 |
107 | CYPHER CALL { CREATE (n) } RETURN n;
108 | ERROR: Call Cypher Subquery must end with a RETURN
109 | CYPHER CALL { CREATE (n) RETURN n as n } RETURN n;
110 | n
111 | --------------------------------------------------------
112 | {"id": 281474976710657, "label": "", "properties": {}}
113 | (1 row)
114 |
115 | --
116 | -- Clean up
117 | --
118 | DROP GRAPH cypher_call CASCADE;
119 | NOTICE: drop cascades to 2 other objects
120 | DETAIL: drop cascades to table cypher_call._ag_label_vertex
121 | drop cascades to table cypher_call._ag_label_edge
122 | NOTICE: graph "cypher_call" has been dropped
123 | drop_graph
124 | ------------
125 |
126 | (1 row)
127 |
128 | --
129 | -- End
130 | --
131 |
--------------------------------------------------------------------------------
/regress/expected/cypher_unwind.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | LOAD 'postgraph';
20 | SET search_path TO postgraph;
21 | CREATE GRAPH cypher_unwind;
22 | NOTICE: graph "cypher_unwind" has been created
23 | create_graph
24 | --------------
25 |
26 | (1 row)
27 |
28 | USE GRAPH cypher_unwind;
29 | use_graph
30 | -----------
31 |
32 | (1 row)
33 |
34 | UNWIND [1, 2, 3] AS i RETURN i;
35 | i
36 | ---
37 | 1
38 | 2
39 | 3
40 | (3 rows)
41 |
42 | CREATE ({a: [1, 2, 3]}), ({a: [4, 5, 6]});
43 | --
44 | (0 rows)
45 |
46 | MATCH (n) WITH n.a AS a UNWIND a AS i RETURN *;
47 | a | i
48 | -----------+---
49 | [1, 2, 3] | 1
50 | [1, 2, 3] | 2
51 | [1, 2, 3] | 3
52 | [4, 5, 6] | 4
53 | [4, 5, 6] | 5
54 | [4, 5, 6] | 6
55 | (6 rows)
56 |
57 | CYPHER WITH [[1, 2], [3, 4], 5] AS nested
58 | UNWIND nested AS x
59 | UNWIND x AS y
60 | RETURN y;
61 | y
62 | ---
63 | 1
64 | 2
65 | 3
66 | 4
67 | 5
68 | (5 rows)
69 |
70 | CYPHER WITH [[1, 2], [3, 4], 5] AS nested
71 | UNWIND nested AS x
72 | UNWIND x AS y
73 | RETURN x, y;
74 | x | y
75 | --------+---
76 | [1, 2] | 1
77 | [1, 2] | 2
78 | [3, 4] | 3
79 | [3, 4] | 4
80 | 5 | 5
81 | (5 rows)
82 |
83 | CYPHER WITH [1, 2, 3, 4, 5] AS lst
84 | UNWIND lst AS x WHERE x % 2 = 0
85 | RETURN x;
86 | x
87 | ---
88 | 2
89 | 4
90 | (2 rows)
91 |
92 | -- TODO
93 | MATCH (n_1)
94 | WITH collect(n_1) as n
95 | UNWIND n as a
96 | SET a.i = 1
97 | RETURN a;
98 | ERROR: SET clause can only update vertex and edges
99 | -- TODO
100 | MATCH (n_1)
101 | WITH collect(n_1) as n
102 | UNWIND n as a
103 | RETURN a;
104 | a
105 | ----------------------------------------------------------------------
106 | {"id": 281474976710657, "label": "", "properties": {"a": [1, 2, 3]}}
107 | {"id": 281474976710658, "label": "", "properties": {"a": [4, 5, 6]}}
108 | (2 rows)
109 |
110 | MATCH (n_1)
111 | WITH collect(n_1) as n
112 | UNWIND n as a
113 | RETURN a;
114 | a
115 | ----------------------------------------------------------------------
116 | {"id": 281474976710657, "label": "", "properties": {"a": [1, 2, 3]}}
117 | {"id": 281474976710658, "label": "", "properties": {"a": [4, 5, 6]}}
118 | (2 rows)
119 |
120 | MATCH (n_1)
121 | WITH collect(n_1) as n
122 | UNWIND n as a
123 | SET a.i = 1
124 | RETURN a;
125 | ERROR: SET clause can only update vertex and edges
126 | MATCH (n_1)
127 | WITH collect(n_1) as n
128 | UNWIND n as a
129 | WITH a
130 | SET a.i = 1
131 | RETURN a;
132 | ERROR: SET clause can only update vertex and edges
133 | MATCH (n_1)
134 | WITH collect(n_1) as n
135 | UNWIND n as a
136 | CREATE ({i: a.i})
137 | RETURN a;
138 | a
139 | ----------------------------------------------------------------------
140 | {"id": 281474976710657, "label": "", "properties": {"a": [1, 2, 3]}}
141 | {"id": 281474976710658, "label": "", "properties": {"a": [4, 5, 6]}}
142 | (2 rows)
143 |
144 | CREATE ()-[:e {a: [1, 2, 3]}]->();
145 | --
146 | (0 rows)
147 |
148 | CREATE ()-[:e {a: [1, 2, 3]}]->();
149 | --
150 | (0 rows)
151 |
152 | MATCH t=()-[:e]->()
153 | UNWIND relationships(t) as rel
154 | RETURN rel;
155 | rel
156 | -------------------------------------------------------------------------------------------------------------------------------
157 | {"id": 844424930131969, "start_id": 281474976710661, "end_id": 281474976710662, "label": "e", "properties": {"a": [1, 2, 3]}}
158 | {"id": 844424930131970, "start_id": 281474976710663, "end_id": 281474976710664, "label": "e", "properties": {"a": [1, 2, 3]}}
159 | (2 rows)
160 |
161 | DROP GRAPH cypher_unwind CASCADE;
162 | NOTICE: drop cascades to 3 other objects
163 | DETAIL: drop cascades to table cypher_unwind._ag_label_vertex
164 | drop cascades to table cypher_unwind._ag_label_edge
165 | drop cascades to table cypher_unwind.e
166 | NOTICE: graph "cypher_unwind" has been dropped
167 | drop_graph
168 | ------------
169 |
170 | (1 row)
171 |
172 |
--------------------------------------------------------------------------------
/regress/expected/cypher_with.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 2019-2020, Bitnine Global
19 | */
20 |
21 | LOAD 'postgraph';
22 | SET search_path TO postgraph;
23 | CREATE GRAPH cypher_with;
24 | NOTICE: graph "cypher_with" has been created
25 | create_graph
26 | --------------
27 |
28 | (1 row)
29 |
30 | USE GRAPH cypher_with;
31 | use_graph
32 | -----------
33 |
34 | (1 row)
35 |
36 | CYPHER WITH true AS b RETURN b;
37 | b
38 | ------
39 | true
40 | (1 row)
41 |
42 | CREATE ({i: 1}), ({i: 1, j: 2}), ({i: 2});
43 | --
44 | (0 rows)
45 |
46 | MATCH (n) WITH n as a WHERE n.i = 1 RETURN a;
47 | a
48 | ----------------------------------------------------------------------
49 | {"id": 281474976710657, "label": "", "properties": {"i": 1}}
50 | {"id": 281474976710658, "label": "", "properties": {"i": 1, "j": 2}}
51 | (2 rows)
52 |
53 | MATCH (n) WITH n as a WHERE n.i = 1 and n.j = 2 RETURN a;
54 | a
55 | ----------------------------------------------------------------------
56 | {"id": 281474976710658, "label": "", "properties": {"i": 1, "j": 2}}
57 | (1 row)
58 |
59 | CYPHER WITH generate_series(1, 10) as i RETURN i;
60 | i
61 | ----
62 | 1
63 | 2
64 | 3
65 | 4
66 | 5
67 | 6
68 | 7
69 | 8
70 | 9
71 | 10
72 | (10 rows)
73 |
74 | CYPHER WITH generate_series(1, 10, 2) as i RETURN i;
75 | i
76 | ---
77 | 1
78 | 3
79 | 5
80 | 7
81 | 9
82 | (5 rows)
83 |
84 | --Error
85 | WITH 1 + 1 RETURN i;
86 | ERROR: syntax error at or near "1"
87 | LINE 1: WITH 1 + 1 RETURN i;
88 | ^
89 | DROP GRAPH cypher_with CASCADE;
90 | NOTICE: drop cascades to 2 other objects
91 | DETAIL: drop cascades to table cypher_with._ag_label_vertex
92 | drop cascades to table cypher_with._ag_label_edge
93 | NOTICE: graph "cypher_with" has been dropped
94 | drop_graph
95 | ------------
96 |
97 | (1 row)
98 |
99 |
--------------------------------------------------------------------------------
/regress/expected/graphid.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | LOAD 'postgraph';
20 | SET search_path TO postgraph;
21 | -- basic comparisons
22 | SELECT '0'::graphid = '0'::graphid, '0'::graphid = '1'::graphid;
23 | ?column? | ?column?
24 | ----------+----------
25 | t | f
26 | (1 row)
27 |
28 | SELECT '0'::graphid <> '0'::graphid, '0'::graphid <> '1'::graphid;
29 | ?column? | ?column?
30 | ----------+----------
31 | f | t
32 | (1 row)
33 |
34 | SELECT '0'::graphid < '1'::graphid,
35 | '0'::graphid < '0'::graphid,
36 | '1'::graphid < '0'::graphid;
37 | ?column? | ?column? | ?column?
38 | ----------+----------+----------
39 | t | f | f
40 | (1 row)
41 |
42 | SELECT '0'::graphid > '1'::graphid,
43 | '0'::graphid > '0'::graphid,
44 | '1'::graphid > '0'::graphid;
45 | ?column? | ?column? | ?column?
46 | ----------+----------+----------
47 | f | f | t
48 | (1 row)
49 |
50 | SELECT '0'::graphid <= '1'::graphid,
51 | '0'::graphid <= '0'::graphid,
52 | '1'::graphid <= '0'::graphid;
53 | ?column? | ?column? | ?column?
54 | ----------+----------+----------
55 | t | t | f
56 | (1 row)
57 |
58 | SELECT '0'::graphid >= '1'::graphid,
59 | '0'::graphid >= '0'::graphid,
60 | '1'::graphid >= '0'::graphid;
61 | ?column? | ?column? | ?column?
62 | ----------+----------+----------
63 | f | t | t
64 | (1 row)
65 |
66 | -- b-tree index
67 | CREATE TABLE graphid_table (gid graphid);
68 | INSERT INTO graphid_table VALUES ('0'), ('1'), ('2');
69 | CREATE INDEX ON graphid_table (gid);
70 | SET enable_seqscan = OFF;
71 | EXPLAIN (COSTS OFF) SELECT * FROM graphid_table WHERE gid = '1';
72 | QUERY PLAN
73 | --------------------------------------------------------------
74 | Index Only Scan using graphid_table_gid_idx on graphid_table
75 | Index Cond: (gid = '1'::graphid)
76 | (2 rows)
77 |
78 | EXPLAIN (COSTS OFF) SELECT * FROM graphid_table WHERE gid > '0';
79 | QUERY PLAN
80 | --------------------------------------------------------------
81 | Index Only Scan using graphid_table_gid_idx on graphid_table
82 | Index Cond: (gid > '0'::graphid)
83 | (2 rows)
84 |
85 | SET enable_seqscan = ON;
86 | DROP TABLE graphid_table;
87 |
--------------------------------------------------------------------------------
/regress/expected/load_csv.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2025 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 | LOAD 'postgraph';
18 | CREATE GRAPH load_csv;
19 | NOTICE: graph "load_csv" has been created
20 | create_graph
21 | --------------
22 |
23 | (1 row)
24 |
25 | USE GRAPH load_csv;
26 | use_graph
27 | -----------
28 |
29 | (1 row)
30 |
31 | CYPHER LOAD CSV '~/postgraph/regress/test.csv'
32 | RETURN *;
33 | --
34 | (0 rows)
35 |
36 | DROP GRAPH load_csv CASCADE;
37 | NOTICE: drop cascades to 2 other objects
38 | DETAIL: drop cascades to table load_csv._ag_label_vertex
39 | drop cascades to table load_csv._ag_label_edge
40 | NOTICE: graph "load_csv" has been dropped
41 | drop_graph
42 | ------------
43 |
44 | (1 row)
45 |
46 |
--------------------------------------------------------------------------------
/regress/expected/order_by.out:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 2019-2020, Bitnine Global
19 | */
20 | LOAD 'postgraph';
21 | CREATE GRAPH order_by;
22 | NOTICE: graph "order_by" has been created
23 | create_graph
24 | --------------
25 |
26 | (1 row)
27 |
28 | USE GRAPH order_by;
29 | use_graph
30 | -----------
31 |
32 | (1 row)
33 |
34 | CREATE ();
35 | --
36 | (0 rows)
37 |
38 | CREATE ({i: '1', j: 1});
39 | --
40 | (0 rows)
41 |
42 | CREATE ({i: 1});
43 | --
44 | (0 rows)
45 |
46 | CREATE ({i: 1.0});
47 | --
48 | (0 rows)
49 |
50 | CREATE ({i: 1::numeric});
51 | --
52 | (0 rows)
53 |
54 | CREATE ({i: true});
55 | --
56 | (0 rows)
57 |
58 | CREATE ({i: false});
59 | --
60 | (0 rows)
61 |
62 | CREATE ({i: {key: 'value'}});
63 | --
64 | (0 rows)
65 |
66 | CREATE ({i: [1]});
67 | --
68 | (0 rows)
69 |
70 | MATCH (u) RETURN u.i ORDER BY u.i;
71 | ERROR: syntax error at or near "ORDER"
72 | LINE 1: MATCH (u) RETURN u.i ORDER BY u.i;
73 | ^
74 | MATCH (u) RETURN u.i ORDER BY u.i DESC;
75 | ERROR: syntax error at or near "ORDER"
76 | LINE 1: MATCH (u) RETURN u.i ORDER BY u.i DESC;
77 | ^
78 | MATCH (u) RETURN u.i ORDER BY u.i ASC;
79 | ERROR: syntax error at or near "ORDER"
80 | LINE 1: MATCH (u) RETURN u.i ORDER BY u.i ASC;
81 | ^
82 | MATCH (x) RETURN x.j ORDER BY x.j NULLS FIRST;
83 | ERROR: syntax error at or near "ORDER"
84 | LINE 1: MATCH (x) RETURN x.j ORDER BY x.j NULLS FIRST;
85 | ^
86 | MATCH (x) RETURN x.j ORDER BY x.j NULLS LAST;
87 | ERROR: syntax error at or near "ORDER"
88 | LINE 1: MATCH (x) RETURN x.j ORDER BY x.j NULLS LAST;
89 | ^
90 | MATCH (x) RETURN x.i ORDER BY x.i USING <;
91 | ERROR: syntax error at or near "ORDER"
92 | LINE 1: MATCH (x) RETURN x.i ORDER BY x.i USING <;
93 | ^
94 | DROP GRAPH order_by CASCADE;
95 | NOTICE: drop cascades to 2 other objects
96 | DETAIL: drop cascades to table order_by._ag_label_vertex
97 | drop cascades to table order_by._ag_label_edge
98 | NOTICE: graph "order_by" has been dropped
99 | drop_graph
100 | ------------
101 |
102 | (1 row)
103 |
104 |
--------------------------------------------------------------------------------
/regress/sql/cypher_call.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | LOAD 'postgraph';
19 | SET search_path TO postgraph;
20 |
21 | CREATE GRAPH cypher_call;
22 | USE GRAPH cypher_call;
23 |
24 | --
25 | -- Create table to hold the start and end vertices to test the SRF
26 | --
27 | CYPHER CALL sin(1) as a RETURN a;
28 |
29 | CYPHER CALL sin(1) as b RETURN b;
30 |
31 | CYPHER WITH [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst CALL unnest(lst) as b RETURN b;
32 |
33 | CYPHER WITH [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst CALL unnest(lst) as b WHERE b % 2 = 0 RETURN b;
34 |
35 | CYPHER CALL unnest([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) as b RETURN b;
36 |
37 | CYPHER CALL pg_catalog.generate_series(1, 2, 3);
38 |
39 | MATCH (n) CALL this_isnt_a_real_function(1, 2, 3);
40 |
41 | CYPHER CALL { RETURN 1 } RETURN 2;
42 |
43 | CYPHER CALL { RETURN 1 as a } RETURN a;
44 |
45 | CYPHER CALL { CREATE (n) } RETURN n;
46 |
47 | CYPHER CALL { CREATE (n) RETURN n as n } RETURN n;
48 |
49 |
50 | --
51 | -- Clean up
52 | --
53 | DROP GRAPH cypher_call CASCADE;
54 |
55 | --
56 | -- End
57 | --
58 |
--------------------------------------------------------------------------------
/regress/sql/cypher_remove.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH cypher_remove;
24 | USE GRAPH cypher_remove;
25 |
26 | --test 1
27 | CREATE (:test_1);
28 | CREATE (:test_1 {i: 0, j: 5, a: 0});
29 | CREATE (:test_1 {i: 1});
30 |
31 | MATCH (n:test_1) REMOVE n.i ;
32 | MATCH (n:test_1) RETURN n;
33 |
34 | --test 2
35 | CREATE (:test_2);
36 | CREATE (:test_2 {i: 0, j: 5, a: 0});
37 | CREATE (:test_2 {i: 1});
38 |
39 | MATCH (n:test_2) REMOVE n.j RETURN n;
40 | MATCH (n:test_2) RETURN n;
41 |
42 | --test 3 Validate Paths are updated
43 | CREATE (:test_3 { i : 20 } )-[:test_3_edge {j:20}]->(:test_3 {i:10});
44 |
45 | MATCH p=(n)-[:test_3_edge]->() REMOVE n.i RETURN p;
46 |
47 | --test 4 Edges
48 | MATCH (n) REMOVE n.i RETURN n;
49 | CREATE (:test_4 { i : 20 } )-[:test_4_edge {j:20}]->(:test_4 {i:10});
50 |
51 | MATCH ()-[n]->(:test_4) REMOVE n.i RETURN n;
52 | MATCH ()-[n]->(:test_4) RETURN n;
53 |
54 | --test 5 two REMOVE clauses
55 | CREATE (:test_5 {i: 1, j : 2, k : 3}) ;
56 |
57 | MATCH (n:test_5)
58 | REMOVE n.i
59 | REMOVE n.j
60 | RETURN n
61 | ;
62 |
63 |
64 | MATCH (n:test_5)
65 | RETURN n
66 | ;
67 |
68 | --test 6 Create a loop and see that set can work after create
69 | CREATE (:test_6 {j: 5, y: 99});
70 |
71 | MATCH (n {j: 5})
72 | CREATE p=(n)-[e:e {j:34}]->(n)
73 | REMOVE n.y
74 | RETURN n, p
75 | ;
76 | MATCH (n:test_6) RETURN n;
77 |
78 |
79 | --test 7 Create a loop and see that set can work after create
80 | CREATE (:test_7)-[e:e {j:34}]->()
81 | REMOVE e.y
82 | RETURN e
83 | ;
84 |
85 | MATCH (n:test_7) RETURN n;
86 |
87 |
88 |
89 | --test 8
90 | MATCH (n:test_7)
91 | MATCH (n)-[e:e {j:34}]->()
92 | REMOVE n.y
93 | RETURN n
94 | ;
95 |
96 | --Handle Inheritance
97 | CREATE ( {i : 1 });
98 | MATCH (n) REMOVE n.i RETURN n;
99 | MATCH (n) RETURN n;
100 |
101 | -- prepared statements
102 | /*
103 | CREATE ( {i : 1 });
104 | PREPARE p_1 AS MATCH (n) REMOVE n.i RETURN n ;
105 | EXECUTE p_1;
106 |
107 | CREATE ( {i : 1 });
108 | EXECUTE p_1;
109 | -- pl/pgsql
110 | CREATE ( {i : 1 });
111 |
112 | CREATE FUNCTION remove_test()
113 | RETURNS TABLE(vertex vertex)
114 | LANGUAGE plpgsql
115 | VOLATILE
116 | AS $BODY$
117 | BEGIN
118 | RETURN QUERY MATCH (n) REMOVE n.i RETURN n;
119 | END
120 | $BODY$;
121 |
122 | SELECT remove_test();
123 |
124 | CREATE ( {i : 1 });
125 | SELECT remove_test();
126 |
127 | */
128 | --
129 | -- Updating Multiple Fields
130 | --
131 | MATCH (n) RETURN n;
132 | MATCH (n) REMOVE n.i, n.j, n.k RETURN n;
133 | MATCH (n) RETURN n;
134 |
135 | CREATE ()-[:edge_multi_property { i: 5, j: 20}]->();
136 | MATCH ()-[e:edge_multi_property]-() RETURN e;
137 | MATCH ()-[e:edge_multi_property]-() REMOVE e.i, e.j RETURN e;
138 |
139 | --Errors
140 | REMOVE n.i;
141 |
142 | MATCH (n) REMOVE n.i = NULL;
143 |
144 | MATCH (n) REMOVE wrong_var.i;
145 |
146 | --
147 | -- Clean up
148 | --
149 | DROP FUNCTION remove_test;
150 | DROP GRAPH cypher_remove CASCADE;
151 |
152 | --
153 | -- End
154 | --
155 |
--------------------------------------------------------------------------------
/regress/sql/cypher_set.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH cypher_set;
24 | USE GRAPH cypher_set;
25 |
26 | CREATE (:v);
27 | CREATE (:v {i: 0, j: 5, a: 0});
28 | CREATE (:v {i: 1});
29 |
30 | --Simple SET test case
31 | MATCH (n) SET n.i = 3;
32 |
33 | MATCH (n) WHERE n.j = 5 SET n.i = NULL RETURN n;
34 | MATCH (n) RETURN n;
35 |
36 | MATCH (n) SET n.i = NULL RETURN n;
37 | MATCH (n) RETURN n;
38 |
39 | MATCH (n) SET n.i = 3 RETURN n;
40 | MATCH (n) RETURN n;
41 |
42 | --Handle Inheritance
43 | CREATE ();
44 | MATCH (n) SET n.i = 3 RETURN n;
45 | MATCH (n) RETURN n;
46 |
47 | --Validate Paths are updated
48 | MATCH (n) CREATE (n)-[:e {j:20}]->(:other_v {k:10}) RETURN n;
49 | MATCH p=(n)-[]->() SET n.i = 50 RETURN p;
50 |
51 | --Edges
52 | MATCH ()-[n]-(:other_v) SET n.i = 3 RETURN n;
53 | MATCH ()-[n]->(:other_v) RETURN n;
54 |
55 |
56 | MATCH (n {j: 5}) SET n.y = 50 SET n.z = 99 RETURN n;
57 |
58 | MATCH (n {j: 5}) RETURN n;
59 |
60 | --Create a loop and see that set can work after create
61 | MATCH (n {j: 5}) CREATE p=(n)-[e:e {j:34}]->(n) SET n.y = 99 RETURN n, p;
62 |
63 | --Create a loop and see that set can work after create
64 | CREATE ()-[e:e {j:34}]->() SET e.y = 99 RETURN e;
65 |
66 | MATCH (n) MATCH (n)-[e:e {j:34}]->() SET n.y = 1 RETURN n;
67 |
68 | MATCH (n) MATCH ()-[e:e {j:34}]->(n) SET n.y = 2 RETURN n;
69 |
70 | MATCH (n)-[]->(n) SET n.y = 99 RETURN n;
71 |
72 | MATCH (n) MATCH (n)-[]->(m) SET n.t = 150 RETURN n;
73 |
74 | -- prepared statements
75 | /*
76 | PREPARE p_1 AS MATCH (n) SET n.i = 3 RETURN n ;
77 | EXECUTE p_1;
78 |
79 | EXECUTE p_1;
80 |
81 | PREPARE p_2 AS MATCH (n) SET n.i = $var_name RETURN n ;
82 | EXECUTE p_2('{"var_name": 4}');
83 |
84 | EXECUTE p_2('{"var_name": 6}');
85 |
86 | CREATE FUNCTION set_test()
87 | RETURNS TABLE(vertex vertex)
88 | LANGUAGE plpgsql
89 | VOLATILE
90 | AS $BODY$
91 | BEGIN
92 | RETURN QUERY MATCH (n) SET n.i = 7 RETURN n ;
93 | END
94 | $BODY$;
95 |
96 | SELECT set_test();
97 |
98 | SELECT set_test();
99 | */
100 | --
101 | -- Updating multiple fieds
102 | --
103 | MATCH (n) SET n.i = 3, n.j = 5 RETURN n ;
104 |
105 | MATCH (n)-[m]->(n) SET m.y = n.y RETURN n, m;
106 |
107 | --Errors
108 | SET n.i = NULL;
109 |
110 | MATCH (n) SET wrong_var.i = 3;
111 |
112 | MATCH (n) SET i = 3;
113 |
114 | --
115 | -- SET refactor regression tests
116 | --
117 |
118 | -- INSERT INTO
119 | /*
120 | CREATE TABLE tbl (result vertex);
121 |
122 |
123 | MATCH (u:vertices) return u ;
124 | MATCH (u:begin)-[:edge]->(v:end) return u, v ;
125 |
126 | INSERT INTO tbl (MATCH (u:vertices) SET u.i = 7 return u ;
127 | INSERT INTO tbl (MATCH (u:vertices) SET u.i = 13 return u ;
128 |
129 | SELECT * FROM tbl;
130 | */
131 | CREATE (u:vertices) ;
132 | CREATE (u:begin)-[:edge]->(v:end) ;
133 | MATCH (u:vertices) return u ;
134 |
135 | BEGIN;
136 | MATCH (u:vertices) SET u.i = 1, u.j = 3, u.k = 5 return u ;
137 | MATCH (u:vertices) return u ;
138 |
139 | MATCH (u:vertices) SET u.i = 2, u.j = 4, u.k = 6 return u ;
140 | MATCH (u:vertices) return u ;
141 |
142 | MATCH (u:vertices) SET u.i = 3, u.j = 6, u.k = 9 return u ;
143 | MATCH (u:vertices) return u ;
144 |
145 | MATCH (u:begin)-[:edge]->(v:end) SET u.i = 1, v.i = 2, u.j = 3, v.j = 4 return u, v ;
146 | MATCH (u:begin)-[:edge]->(v:end) return u, v ;
147 |
148 | MATCH (u:begin)-[:edge]->(v:end) SET u.i = 2, v.i = 1, u.j = 4, v.j = 3 return u, v ;
149 | MATCH (u:begin)-[:edge]->(v:end) return u, v ;
150 | END;
151 |
152 | MATCH (u:vertices) return u ;
153 | MATCH (u:begin)-[:edge]->(v:end) return u, v ;
154 |
155 | -- test lists
156 | MATCH (n) SET n.i = [3, 'test', [1, 2, 3], {id: 1}, 1.0, 1.0::numeric] RETURN n;
157 |
158 | MATCH (n) RETURN n;
159 |
160 | -- test that lists get updated in paths
161 | MATCH p=(u:begin)-[:edge]->(v:end) SET u.i = [1, 2, 3] return u, p ;
162 |
163 | MATCH p=(u:begin)-[:edge]->(v:end) return u, p ;
164 |
165 | -- test empty lists
166 | MATCH (n) SET n.i = [] RETURN n;
167 |
168 | MATCH (n) RETURN n;
169 |
170 | -- test maps
171 | MATCH (n) SET n.i = {prop1: 3, prop2:'test', prop3: [1, 2, 3], prop4: {id: 1}, prop5: 1.0, prop6:1.0::numeric} RETURN n;
172 |
173 | MATCH (n) RETURN n;
174 |
175 | -- test maps in paths
176 | MATCH p=(u:begin)-[:edge]->(v:end) SET u.i = {prop1: 1, prop2: 2, prop3: 3} return u, p ;
177 |
178 | MATCH p=(u:begin)-[:edge]->(v:end) return u, p ;
179 |
180 | -- test empty maps
181 | MATCH (n) SET n.i = {} RETURN n;
182 |
183 | MATCH (n) RETURN n;
184 |
185 | --
186 | -- Clean up
187 | --
188 | DROP TABLE tbl;
189 | DROP FUNCTION set_test;
190 | DROP GRAPH cypher_set CASCADE;
191 |
--------------------------------------------------------------------------------
/regress/sql/cypher_setop.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | LOAD 'postgraph';
19 | SET search_path TO postgraph;
20 |
21 | CREATE GRAPH set_op;
22 |
23 | USE GRAPH set_op;
24 |
25 | CREATE ();
26 |
27 |
28 | MATCH (n) RETURN n UNION MATCH (n) RETURN n;
29 |
30 | MATCH (n) RETURN n UNION ALL MATCH (n) RETURN n;
31 |
32 | MATCH (n) RETURN n UNION RETURN 1;
33 |
34 | MATCH (n) RETURN n UNION RETURN NULL;
35 |
36 | RETURN [1,2,3] UNION RETURN 1;
37 |
38 | RETURN NULL UNION RETURN NULL;
39 |
40 | RETURN NULL UNION ALL RETURN NULL;
41 |
42 | MATCH (n) RETURN n UNION MATCH (n) RETURN n UNION MATCH (n) RETURN n;
43 |
44 | MATCH (n) RETURN n UNION ALL MATCH (n) RETURN n UNION ALL MATCH(n) RETURN n;
45 |
46 | MATCH (n) RETURN n UNION ALL MATCH (n) RETURN n UNION MATCH(n) RETURN n;
47 |
48 | MATCH (n) RETURN n UNION MATCH (n) RETURN n UNION ALL MATCH(n) RETURN n;
49 |
50 | RETURN NULL UNION ALL RETURN NULL UNION ALL RETURN NULL;
51 |
52 | RETURN NULL UNION ALL RETURN NULL UNION RETURN NULL;
53 |
54 | RETURN NULL UNION RETURN NULL UNION ALL RETURN NULL;
55 |
56 | RETURN 1.0::int UNION RETURN 1::float UNION ALL RETURN 2.0::float;
57 |
58 | RETURN 1.0::int UNION RETURN 1.0::float UNION ALL RETURN 1::int;
59 |
60 | RETURN 1.0::float UNION RETURN 1::int UNION RETURN 1::float;
61 |
62 |
63 | -- Intersect
64 |
65 | MATCH (n) RETURN n INTERSECT MATCH (m) RETURN m;
66 |
67 | MATCH (n) RETURN n INTERSECT ALL MATCH (m) RETURN m;
68 |
69 |
70 | -- Except
71 | MATCH (n) RETURN n EXCEPT MATCH (m) RETURN m;
72 |
73 | MATCH (n) RETURN n EXCEPT ALL MATCH (m) RETURN m;
74 |
75 | -- Operator Precedence
76 |
77 | RETURN 2.0::int UNION (RETURN 1::float UNION ALL RETURN 1.0::float);
78 |
79 | (RETURN 2.0::int UNION RETURN 1::float ) UNION ALL RETURN 1.0::float;
80 |
81 |
82 | -- Errors
83 | MATCH (n) RETURN n UNION ALL MATCH (m) RETURN n;
84 |
85 | DROP GRAPH set_op;
86 |
--------------------------------------------------------------------------------
/regress/sql/cypher_unwind.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH cypher_unwind;
24 | USE GRAPH cypher_unwind;
25 |
26 | UNWIND [1, 2, 3] AS i RETURN i;
27 |
28 | CREATE ({a: [1, 2, 3]}), ({a: [4, 5, 6]});
29 |
30 | MATCH (n) WITH n.a AS a UNWIND a AS i RETURN *;
31 |
32 | CYPHER WITH [[1, 2], [3, 4], 5] AS nested
33 | UNWIND nested AS x
34 | UNWIND x AS y
35 | RETURN y;
36 |
37 | CYPHER WITH [[1, 2], [3, 4], 5] AS nested
38 | UNWIND nested AS x
39 | UNWIND x AS y
40 | RETURN x, y;
41 |
42 | CYPHER WITH [1, 2, 3, 4, 5] AS lst
43 | UNWIND lst AS x WHERE x % 2 = 0
44 | RETURN x;
45 |
46 | -- TODO
47 | MATCH (n_1)
48 | WITH collect(n_1) as n
49 | UNWIND n as a
50 | SET a.i = 1
51 | RETURN a;
52 |
53 | -- TODO
54 | MATCH (n_1)
55 | WITH collect(n_1) as n
56 | UNWIND n as a
57 | RETURN a;
58 |
59 | MATCH (n_1)
60 | WITH collect(n_1) as n
61 | UNWIND n as a
62 | RETURN a;
63 |
64 | MATCH (n_1)
65 | WITH collect(n_1) as n
66 | UNWIND n as a
67 | SET a.i = 1
68 | RETURN a;
69 |
70 | MATCH (n_1)
71 | WITH collect(n_1) as n
72 | UNWIND n as a
73 | WITH a
74 | SET a.i = 1
75 | RETURN a;
76 |
77 | MATCH (n_1)
78 | WITH collect(n_1) as n
79 | UNWIND n as a
80 | CREATE ({i: a.i})
81 | RETURN a;
82 |
83 | CREATE ()-[:e {a: [1, 2, 3]}]->();
84 | CREATE ()-[:e {a: [1, 2, 3]}]->();
85 |
86 | MATCH t=()-[:e]->()
87 | UNWIND relationships(t) as rel
88 | RETURN rel;
89 |
90 | DROP GRAPH cypher_unwind CASCADE;
91 |
--------------------------------------------------------------------------------
/regress/sql/cypher_vle.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH cypher_vle;
24 | USE GRAPH cypher_vle;
25 |
26 | -- Create a graph to test
27 | CREATE (b:begin)-[:edge {name: 'main edge'}]->(u1:middle)-[:edge {name: 'main edge'}]->(u2:middle)-[:edge {name: 'main edge'}]->(u3:middle)-[:edge {name: 'main edge'}]->(e:end),
28 | (u1)-[:self_loop {name: 'self loop'}]->(u1),
29 | (e)-[:self_loop {name: 'self loop'}]->(e),
30 | (b)-[:alternate_edge {name: 'alternate edge'}]->(u1),
31 | (u2)-[:alternate_edge {name: 'alternate edge'}]->(u3),
32 | (u3)-[:alternate_edge {name: 'alternate edge'}]->(e),
33 | (u2)-[:bypass_edge {name: 'bypass edge'}]->(e),
34 | (e)-[:alternate_edge {name: 'backup edge'}]->(u3),
35 | (u3)-[:alternate_edge {name: 'backup edge'}]->(u2),
36 | (u2)-[:bypass_edge {name: 'bypass edge'}]->(b)
37 | RETURN b, e;
38 |
39 | -- Test the VLE match integration
40 | -- Each should find 400
41 | MATCH (u:begin)-[*]->(v:end) RETURN count(*);
42 | MATCH (u:begin)-[*..]->(v:end) RETURN count(*);
43 | MATCH (u:begin)-[*0..]->(v:end) RETURN count(*);
44 | MATCH (u:begin)-[*1..]->(v:end) RETURN count(*);
45 | MATCH (u:begin)-[*1..200]->(v:end) RETURN count(*);
46 | -- Each should find 2
47 | MATCH (u:begin)<-[*]-(v:end) RETURN count(*);
48 | MATCH (u:begin)<-[*..]-(v:end) RETURN count(*);
49 | MATCH (u:begin)<-[*0..]-(v:end) RETURN count(*);
50 | MATCH (u:begin)<-[*1..]-(v:end) RETURN count(*);
51 | MATCH (u:begin)<-[*1..200]-(v:end) RETURN count(*);
52 | -- Each should find 7092
53 | MATCH (u:begin)-[*]-(v:end) RETURN count(*);
54 | MATCH (u:begin)-[*..]-(v:end) RETURN count(*);
55 | MATCH (u:begin)-[*0..]-(v:end) RETURN count(*);
56 | MATCH (u:begin)-[*1..]-(v:end) RETURN count(*);
57 | MATCH (u:begin)-[*1..200]-(v:end) RETURN count(*);
58 | -- Each should find 1
59 | MATCH (u:begin)-[:edge*]-(v:end) RETURN count(*);
60 | MATCH (u:begin)-[:edge* {name: 'main edge'}]-(v:end) RETURN count(*);
61 | MATCH (u:begin)-[* {name: 'main edge'}]-(v:end) RETURN count(*);
62 | -- Each should find 1
63 | MATCH ()<-[*4..4 {name: 'main edge'}]-() RETURN count(*);
64 | MATCH (u)<-[*4..4 {name: 'main edge'}]-() RETURN count(*);
65 | MATCH ()<-[*4..4 {name: 'main edge'}]-(v) RETURN count(*);
66 | -- Each should find 2922
67 | MATCH ()-[*]->() RETURN count(*);
68 | MATCH (u)-[*]->() RETURN count(*);
69 | MATCH ()-[*]->(v) RETURN count(*);
70 | -- Should find 2
71 | MATCH (u:begin)<-[e*]-(v:end) RETURN e;
72 | -- Should find 5
73 | MATCH p=(:begin)<-[*1..1]-()-[]-() RETURN p ORDER BY p;
74 | -- Should find 2922
75 | MATCH p=()-[*]->(v) RETURN count(*);
76 | -- Should find 2
77 | MATCH p=(u:begin)-[*3..3]->(v:end) RETURN p;
78 | -- Should find 12
79 | MATCH p=(u:begin)-[*3..3]-(v:end) RETURN p;
80 | -- Each should find 2
81 | MATCH p=(u:begin)<-[*]-(v:end) RETURN p;
82 | MATCH p=(u:begin)<-[e*]-(v:end) RETURN p;
83 | MATCH p=(u:begin)<-[e*]-(v:end) RETURN e;
84 | MATCH p=(:begin)<-[*]-()<-[]-(:end) RETURN p;
85 | -- Each should return 31
86 | MATCH ()-[e1]->(v)-[e2]->() RETURN count(*);
87 | MATCH ()-[e1*1..1]->(v)-[e2*1..1]->() RETURN count(*);
88 | MATCH (v)-[e1*1..1]->()-[e2*1..1]->() RETURN count(*);
89 | MATCH ()-[e1]->(v)-[e2*1..1]->() RETURN count(*);
90 | MATCH ()-[e1]->()-[e2*1..1]->() RETURN count(*);
91 | MATCH ()-[e1*1..1]->(v)-[e2]->() RETURN count(*);
92 | MATCH ()-[e1*1..1]->()-[e2]->() RETURN count(*);
93 | MATCH (a)-[e1]->(a)-[e2*1..1]->() RETURN count(*);
94 | MATCH (a) MATCH (a)-[e1*1..1]->(v) RETURN count(*);
95 | MATCH (a) MATCH ()-[e1*1..1]->(a) RETURN count(*);
96 | MATCH (a)-[e*1..1]->() RETURN count(*);
97 |
98 | -- Should return 1 path
99 | MATCH p=()<-[e1*]-(:end)-[e2*]->(:begin) RETURN p $$) AS (result traversal);
100 | -- Each should return 3
101 | MATCH (u:begin)-[e*0..1]->(v) RETURN id(u), e, id(v) $$) AS (u gtype, e variable_edge, v gtype);
102 | MATCH p=(u:begin)-[e*0..1]->(v) RETURN p $$) AS (p traversal);
103 | -- Each should return 5
104 | MATCH (u)-[e*0..0]->(v) RETURN id(u), e, id(v) $$) AS (u gtype, e variable_edge, v gtype);
105 | MATCH p=(u)-[e*0..0]->(v) RETURN id(u), p, id(v) $$) AS (u gtype, p traversal, v gtype);
106 | -- Each should return 13 and will be the same
107 | MATCH p=()-[*0..0]->()-[]->() RETURN p $$) AS (p traversal);
108 | MATCH p=()-[]->()-[*0..0]->() RETURN p $$) AS (p traversal);
109 |
110 | MATCH (u)-[*]-(v) RETURN count(*);
111 | MATCH (u)-[*0..1]-(v) RETURN count(*);
112 | MATCH (u)-[*..1]-(v) RETURN count(*);
113 | MATCH (u)-[*..5]-(v) RETURN count(*);
114 |
115 | MATCH p=(:begin)<-[ve1*]-(:end), (:end)-[ve2*]->(:begin) RETURN ve1 && ve2;
116 | MATCH p=()<-[ve1:edge*]-(), ()-[ve2:alternate_edge*]->() RETURN ve1 && ve2;
117 | SELECT * FROM ag_label;
118 |
119 | --
120 | -- Clean up
121 | --
122 | DROP GRAPH cypher_vle CASCADE;
123 |
124 | --
125 | -- End
126 | --
127 |
--------------------------------------------------------------------------------
/regress/sql/cypher_with.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 2019-2020, Bitnine Global
19 | */
20 |
21 | LOAD 'postgraph';
22 | SET search_path TO postgraph;
23 |
24 | CREATE GRAPH cypher_with;
25 | USE GRAPH cypher_with;
26 |
27 | CYPHER WITH true AS b RETURN b;
28 |
29 | CREATE ({i: 1}), ({i: 1, j: 2}), ({i: 2});
30 |
31 | MATCH (n) WITH n as a WHERE n.i = 1 RETURN a;
32 |
33 | MATCH (n) WITH n as a WHERE n.i = 1 and n.j = 2 RETURN a;
34 |
35 |
36 | CYPHER WITH generate_series(1, 10) as i RETURN i;
37 |
38 | CYPHER WITH generate_series(1, 10, 2) as i RETURN i;
39 |
40 | --Error
41 | WITH 1 + 1 RETURN i;
42 |
43 |
44 | DROP GRAPH cypher_with CASCADE;
45 |
--------------------------------------------------------------------------------
/regress/sql/graphid.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | -- basic comparisons
24 | SELECT '0'::graphid = '0'::graphid, '0'::graphid = '1'::graphid;
25 | SELECT '0'::graphid <> '0'::graphid, '0'::graphid <> '1'::graphid;
26 | SELECT '0'::graphid < '1'::graphid,
27 | '0'::graphid < '0'::graphid,
28 | '1'::graphid < '0'::graphid;
29 | SELECT '0'::graphid > '1'::graphid,
30 | '0'::graphid > '0'::graphid,
31 | '1'::graphid > '0'::graphid;
32 | SELECT '0'::graphid <= '1'::graphid,
33 | '0'::graphid <= '0'::graphid,
34 | '1'::graphid <= '0'::graphid;
35 | SELECT '0'::graphid >= '1'::graphid,
36 | '0'::graphid >= '0'::graphid,
37 | '1'::graphid >= '0'::graphid;
38 |
39 | -- b-tree index
40 | CREATE TABLE graphid_table (gid graphid);
41 | INSERT INTO graphid_table VALUES ('0'), ('1'), ('2');
42 | CREATE INDEX ON graphid_table (gid);
43 | SET enable_seqscan = OFF;
44 | EXPLAIN (COSTS OFF) SELECT * FROM graphid_table WHERE gid = '1';
45 | EXPLAIN (COSTS OFF) SELECT * FROM graphid_table WHERE gid > '0';
46 | SET enable_seqscan = ON;
47 | DROP TABLE graphid_table;
48 |
--------------------------------------------------------------------------------
/regress/sql/lists.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 2019-2020, Bitnine Global
19 | */
20 |
21 | LOAD 'postgraph';
22 | SET search_path TO postgraph;
23 |
24 | CREATE GRAPH lists;
25 | USE GRAPH lists;
26 |
27 | --
28 | -- list literal
29 | --
30 | -- empty list
31 | RETURN [];
32 |
33 | -- list of scalar values
34 | RETURN ['str', 1, 1.0, true, null] ;
35 |
36 | -- nested lists
37 | RETURN [['str'], [1, [1.0], [[true]]], null] ;
38 |
39 | --list concatenation
40 | RETURN ['str', 1, 1.0] + [true, null];
41 |
42 | -- IN
43 | RETURN 1 IN ['str', 1, 1.0, true, null];
44 | RETURN 'str' IN ['str', 1, 1.0, true, null];
45 | RETURN 1.0 IN ['str', 1, 1.0, true, null];
46 | RETURN true IN ['str', 1, 1.0, true, null];
47 | RETURN [1,3,5,[2,4,6]] IN ['str', 1, 1.0, true, null, [1,3,5,[2,4,6]]];
48 | RETURN {bool: true, int: 1} IN ['str', 1, 1.0, true, null, {bool: true, int: 1}, [1,3,5,[2,4,6]]];
49 | RETURN null IN ['str', 1, 1.0, true, null];
50 | RETURN null IN ['str', 1, 1.0, true];
51 | RETURN 'str' IN null ;
52 | RETURN 0 IN ['str', 1, 1.0, true, null];
53 | RETURN 1.1 IN ['str', 1, 1.0, true, null];
54 | RETURN 'Str' IN ['str', 1, 1.0, true, null];
55 | RETURN [1,3,5,[2,4,5]] IN ['str', 1, 1.0, true, null, [1,3,5,[2,4,6]]];
56 | RETURN {bool: true, int: 2} IN ['str', 1, 1.0, true, null, {bool: true, int: 1}, [1,3,5,[2,4,6]]];
57 | RETURN null IN 'str' ;
58 | RETURN 'str' IN 'str' ;
59 |
60 | -- TODO ALL, ANY/SOME, NONE
61 |
62 | -- list access
63 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][0];
64 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][5];
65 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][10];
66 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1];
67 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-3];
68 | -- should return null
69 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][11];
70 |
71 | -- list slice
72 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][0..];
73 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][..11];
74 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][0..0];
75 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][10..10];
76 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][0..1];
77 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][9..10];
78 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1..];
79 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1..11];
80 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-3..11];
81 | RETURN [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10][-1..10];
82 | RETURN 0[0..1];
83 | RETURN 0[[0]..[1]];
84 | RETURN [0][0..-2147483649];
85 |
86 | -- access and slice operators nested
87 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[0] ;
88 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[2] ;
89 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-1] ;
90 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[2][-2] ;
91 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[2][-2..] ;
92 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..] ;
93 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-1..][-1..] ;
94 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-1..][0] ;
95 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-1..][-1] ;
96 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-2..-1] ;
97 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-4..-2] ;
98 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-4..-2][-2] ;
99 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-4..-2][0] ;
100 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-4..-2][-2][-2..] ;
101 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-4..-2][-2][-2..][0] ;
102 |
103 | -- empty list
104 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-1..][-2..-2] ;
105 |
106 | -- should return null
107 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[2][3] ;
108 | CYPHER WITH [0, 1, [2, 3, 4], 5, [6, 7, 8], 9] as l RETURN l[-2..][-1..][-2] ;
109 |
110 | -- size() of a string
111 | RETURN size('12345') ;
112 | RETURN size("1234567890") ;
113 | -- size() of an array
114 | RETURN size([1, 2, 3, 4, 5]) ;
115 | RETURN size([]) ;
116 | RETURN size(null) ;
117 | -- head
118 | RETURN head([1, 2, 3, 4, 5]) ;
119 | RETURN head([1]) ;
120 | RETURN head([]) ;
121 | RETURN head(null) ;
122 | -- last
123 | RETURN last([1, 2, 3, 4, 5]) ;
124 | RETURN last([1]) ;
125 | RETURN last([]) ;
126 | RETURN last(null) ;
127 |
128 | -- range()
129 | RETURN range(0, 10);
130 | RETURN range(0, 10, 1);
131 | RETURN range(0, -10, -3);
132 | RETURN range(0, 10, 11);
133 | RETURN range(-20, 10, 5);
134 | RETURN range(0, 10, -1);
135 | RETURN range(null, -10, -3);
136 | RETURN range(0, null, -3);
137 | RETURN range(0, -10.0, -3.0);
138 |
139 |
140 | --
141 | -- Cleanup
142 | --
143 | DROP GRAPH lists CASCADE;
144 |
145 | --
146 | -- End of tests
147 | --
148 |
--------------------------------------------------------------------------------
/regress/sql/load_csv.sql:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | * Copyright (C) 2023-2025 PostGraphDB
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU Affero General Public License as
7 | * published by the Free Software Foundation, either version 3 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Affero General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Affero General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | LOAD 'postgraph';
20 |
21 | CREATE GRAPH load_csv;
22 | USE GRAPH load_csv;
23 |
24 |
25 | CYPHER LOAD CSV '~/postgraph/regress/test.csv'
26 | RETURN *;
27 |
28 | DROP GRAPH load_csv CASCADE;
29 |
--------------------------------------------------------------------------------
/regress/sql/order_by.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023-2024 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 2019-2020, Bitnine Global
19 | */
20 |
21 | LOAD 'postgraph';
22 |
23 | CREATE GRAPH order_by;
24 | USE GRAPH order_by;
25 |
26 | CREATE ();
27 | CREATE ({i: '1', j: 1});
28 | CREATE ({i: 1});
29 | CREATE ({i: 1.0});
30 | CREATE ({i: 1::numeric});
31 | CREATE ({i: true});
32 | CREATE ({i: false});
33 | CREATE ({i: {key: 'value'}});
34 | CREATE ({i: [1]});
35 |
36 | MATCH (u) RETURN u.i ORDER BY u.i;
37 |
38 | MATCH (u) RETURN u.i ORDER BY u.i DESC;
39 |
40 | MATCH (u) RETURN u.i ORDER BY u.i ASC;
41 |
42 | MATCH (x) RETURN x.j ORDER BY x.j NULLS FIRST;
43 |
44 | MATCH (x) RETURN x.j ORDER BY x.j NULLS LAST;
45 |
46 | MATCH (x) RETURN x.i ORDER BY x.i USING <;
47 |
48 | DROP GRAPH order_by CASCADE;
--------------------------------------------------------------------------------
/regress/sql/regex.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH regex;
24 | USE GRAPH regex;
25 |
26 | CREATE (n:Person {name: 'John'}) ;
27 | CREATE (n:Person {name: 'Jeff'}) ;
28 | CREATE (n:Person {name: 'Joan'}) ;
29 |
30 | --
31 | -- =~ cypher case sensitive regular expression
32 | --
33 | MATCH (n:Person) WHERE n.name =~ 'JoHn' RETURN n;
34 | MATCH (n:Person) WHERE n.name =~ '(?i)JoHn' RETURN n;
35 | MATCH (n:Person) WHERE n.name =~ 'Jo.n' RETURN n;
36 | MATCH (n:Person) WHERE n.name =~ 'J.*' RETURN n;
37 |
38 | --
39 | -- ~ POSIX case sensitive regular expression
40 | --
41 | MATCH (n:Person) WHERE n.name ~ 'JoHn' RETURN n;
42 | MATCH (n:Person) WHERE n.name ~ '(?i)JoHn' RETURN n;
43 | MATCH (n:Person) WHERE n.name ~ 'Jo.n' RETURN n;
44 | MATCH (n:Person) WHERE n.name ~ 'J.*' RETURN n;
45 |
46 | --
47 | -- ~* POSIX case insensitive regular expression
48 | --
49 | MATCH (n:Person) WHERE n.name ~* 'john' RETURN n;
50 | MATCH (n:Person) WHERE n.name ~* '(?i)john' RETURN n;
51 | MATCH (n:Person) WHERE n.name ~* 'jo.n' RETURN n;
52 | MATCH (n:Person) WHERE n.name ~* 'j.*' RETURN n;
53 | MATCH (n:Person) WHERE n.name ~* '.*' RETURN n;
54 | MATCH (n:Person) WHERE n.name ~* 'JOHN' RETURN n;
55 |
56 | --
57 | -- !~ POSIX case sensitive regular expression not match
58 | --
59 | MATCH (n:Person) WHERE n.name !~ 'john' RETURN n;
60 | MATCH (n:Person) WHERE n.name !~ '(?i)john' RETURN n;
61 | MATCH (n:Person) WHERE n.name !~ 'jo.n' RETURN n;
62 | MATCH (n:Person) WHERE n.name !~ 'j.*' RETURN n;
63 | MATCH (n:Person) WHERE n.name !~ '.*' RETURN n;
64 | MATCH (n:Person) WHERE n.name !~ 'JOHN' RETURN n;
65 |
66 | --
67 | -- !~* POSIX case sensitive regular expression not match
68 | --
69 | MATCH (n:Person) WHERE n.name !~* 'john' RETURN n;
70 | MATCH (n:Person) WHERE n.name !~* '(?i)john' RETURN n;
71 | MATCH (n:Person) WHERE n.name !~* 'jo.n' RETURN n;
72 | MATCH (n:Person) WHERE n.name !~* 'j.*' RETURN n;
73 | MATCH (n:Person) WHERE n.name !~* '.*' RETURN n;
74 | MATCH (n:Person) WHERE n.name !~* 'JOHN' RETURN n;
75 |
76 | DROP GRAPH regex CASCADE;
77 |
--------------------------------------------------------------------------------
/regress/sql/traversal_functions.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 |
24 | CREATE GRAPH traversal_functions;
25 | USE GRAPH traversal_functions;
26 |
27 | --
28 | -- Create table to hold the start and end vertices to test the SRF
29 | --
30 |
31 | -- Create a graph to test
32 | CREATE (b:begin)-[:edge]->(u1:middle)-[:edge]->(u2:middle)-[:edge]->(u3:middle)-[:edge]->(e:end),
33 | (u1)-[:self_loop]->(u1),
34 | (e)-[:self_loop]->(e),
35 | (b)-[:alternate_edge]->(u1),
36 | (u2)-[:alternate_edge]->(u3),
37 | (u3)-[:alternate_edge]->(e),
38 | (u2)-[:bypass_edge]->(e),
39 | (e)-[:alternate_edge]->(u3),
40 | (u3)-[:alternate_edge]->(u2),
41 | (u2)-[:bypass_edge]->(b);
42 |
43 |
44 | MATCH p=(u:begin)-[*3..3]->(v:end) RETURN size(p);
45 | MATCH p=(u:begin)-[*]->(v:end) RETURN DISTINCT @-@ p;
46 |
47 | MATCH p=(u:begin)-[*3..3]->(v:end) RETURN relationships(p) ;
48 |
49 | MATCH p=(u:begin)-[*3..3]->(v:end) RETURN nodes(p);
50 | MATCH p=(u:begin)-[*3..3]->(v:end) WITH nodes(p) as nodes RETURN nodes[1];
51 | MATCH p=(u:begin)-[*3..3]->(v:end) WITH nodes(p) as nodes RETURN nodes[size(nodes) - 1];
52 |
53 | --
54 | -- Clean up
55 | --
56 | DROP GRAPH traversal_functions CASCADE;
57 |
58 | --
59 | -- End
60 | --
61 |
--------------------------------------------------------------------------------
/regress/sql/variable_edge_functions.sql:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | LOAD 'postgraph';
21 | SET search_path TO postgraph;
22 |
23 | CREATE GRAPH variable_edge_functions;
24 | USE GRAPH variable_edge_functions;
25 | --
26 | -- Create table to hold the start and end vertices to test the SRF
27 | --
28 |
29 | -- Create a graph to test
30 | CREATE (b:begin)-[:edge]->(u1:middle)-[:edge]->(u2:middle)-[:edge]->(u3:middle)-[:edge]->(e:end),
31 | (u1)-[:self_loop]->(u1),
32 | (e)-[:self_loop]->(e),
33 | (b)-[:alternate_edge]->(u1),
34 | (u2)-[:alternate_edge]->(u3),
35 | (u3)-[:alternate_edge]->(e),
36 | (u2)-[:bypass_edge]->(e),
37 | (e)-[:alternate_edge]->(u3),
38 | (u3)-[:alternate_edge]->(u2),
39 | (u2)-[:bypass_edge]->(b);
40 |
41 |
42 | MATCH (:begin)-[e*3..3]->(:end) RETURN nodes(e);
43 | MATCH (:begin)-[e*3..3]->(:end) WITH nodes(e) as nodes RETURN nodes[1];
44 | MATCH (:begin)-[e*3..3]->(:end) WITH nodes(e) as nodes RETURN nodes[size(nodes) - 1];
45 |
46 |
47 | MATCH (:begin)-[e*3..3]->(:end) RETURN relationships(e);
48 | MATCH (:begin)-[e*3..3]->(:end) WITH relationships(e) as edges RETURN edges[1];
49 | MATCH (:begin)-[e*3..3]->(:end) WITH relationships(e) as edges RETURN edges[size(edges) - 1];
50 |
51 |
52 | MATCH (:begin)-[ve*3..3]->(:end)
53 | MATCH ()-[e]->()
54 | RETURN e @> ve, id(e), edges(ve);
55 |
56 | MATCH (:begin)-[ve*3..3]->(:end)
57 | MATCH ()-[e]->()
58 | RETURN ve <@ e, id(e), edges(ve);
59 |
60 | MATCH (:begin)-[e*]->(:end) RETURN DISTINCT @-@ e;
61 |
62 | --
63 | -- Clean up
64 | --
65 | DROP GRAPH variable_edge_functions CASCADE;
66 |
67 | --
68 | -- End
69 | --
70 |
--------------------------------------------------------------------------------
/regress/test.csv:
--------------------------------------------------------------------------------
1 | booker12,9012,Rachel,Booker
2 | grey07,2070,Laura,Grey
3 | johnson81,4081,Craig,Johnson
4 | jenkins46,9346,Mary,Jenkins
5 | smith79,5079,Jamie,Smith
6 |
--------------------------------------------------------------------------------
/sql/postgraph-geometric.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | --
19 | -- Geometric Operators
20 | --
21 | CREATE FUNCTION intersection_point(gtype, gtype)
22 | RETURNS gtype
23 | LANGUAGE c
24 | IMMUTABLE
25 | CALLED ON NULL INPUT
26 | PARALLEL SAFE
27 | AS 'MODULE_PATHNAME', 'gtype_intersection_point';
28 |
29 | CREATE OPERATOR # (FUNCTION = intersection_point, LEFTARG = gtype, RIGHTARG = gtype);
30 |
31 | CREATE FUNCTION gtype_closest_point(gtype, gtype)
32 | RETURNS gtype
33 | LANGUAGE c
34 | IMMUTABLE
35 | CALLED ON NULL INPUT
36 | PARALLEL SAFE
37 | AS 'MODULE_PATHNAME', 'gtype_closest_point';
38 |
39 | CREATE OPERATOR ## (FUNCTION = gtype_closest_point, LEFTARG = gtype, RIGHTARG = gtype);
40 |
41 | CREATE FUNCTION gtype_vertical(gtype)
42 | RETURNS boolean
43 | LANGUAGE c
44 | IMMUTABLE
45 | CALLED ON NULL INPUT
46 | PARALLEL SAFE
47 | AS 'MODULE_PATHNAME', 'gtype_vertical';
48 |
49 | CREATE OPERATOR ?| (FUNCTION = gtype_vertical, RIGHTARG = gtype);
50 |
51 |
52 | CREATE FUNCTION gtype_horizontal(gtype)
53 | RETURNS boolean
54 | LANGUAGE c
55 | IMMUTABLE
56 | CALLED ON NULL INPUT
57 | PARALLEL SAFE
58 | AS 'MODULE_PATHNAME', 'gtype_horizontal';
59 |
60 | CREATE OPERATOR ?- (FUNCTION = gtype_horizontal, RIGHTARG = gtype);
61 |
62 |
63 | CREATE FUNCTION gtype_center(gtype)
64 | RETURNS gtype
65 | LANGUAGE c
66 | IMMUTABLE
67 | CALLED ON NULL INPUT
68 | PARALLEL SAFE
69 | AS 'MODULE_PATHNAME', 'gtype_center';
70 |
71 | CREATE OPERATOR @@ (FUNCTION = gtype_center, RIGHTARG = gtype);
72 |
73 | CREATE FUNCTION gtype_distance(gtype)
74 | RETURNS gtype
75 | LANGUAGE c
76 | IMMUTABLE
77 | CALLED ON NULL INPUT
78 | PARALLEL SAFE
79 | AS 'MODULE_PATHNAME', 'gtype_distance';
80 |
81 | CREATE OPERATOR @-@ (FUNCTION = gtype_distance, RIGHTARG = gtype);
82 |
83 | CREATE FUNCTION gtype_perp(gtype, gtype)
84 | RETURNS boolean
85 | LANGUAGE c
86 | IMMUTABLE
87 | CALLED ON NULL INPUT
88 | PARALLEL SAFE
89 | AS 'MODULE_PATHNAME', 'gtype_perp';
90 |
91 | CREATE OPERATOR ?-| (FUNCTION = gtype_perp, LEFTARG = gtype, RIGHTARG = gtype);
92 |
93 | CREATE FUNCTION gtype_parallel(gtype, gtype)
94 | RETURNS boolean
95 | LANGUAGE c
96 | IMMUTABLE
97 | CALLED ON NULL INPUT
98 | PARALLEL SAFE
99 | AS 'MODULE_PATHNAME', 'gtype_parallel';
100 |
101 | CREATE OPERATOR ?|| (FUNCTION = gtype_parallel, LEFTARG = gtype, RIGHTARG = gtype);
102 |
103 | --
104 | -- Geometric Functions
105 | --
106 | CREATE FUNCTION height(gtype)
107 | RETURNS gtype
108 | LANGUAGE c
109 | IMMUTABLE
110 | CALLED ON NULL INPUT
111 | PARALLEL SAFE
112 | AS 'MODULE_PATHNAME', 'gtype_height';
113 |
114 | CREATE FUNCTION width(gtype)
115 | RETURNS gtype
116 | LANGUAGE c
117 | IMMUTABLE
118 | CALLED ON NULL INPUT
119 | PARALLEL SAFE
120 | AS 'MODULE_PATHNAME', 'gtype_width';
121 |
122 | CREATE FUNCTION bound_box(gtype, gtype)
123 | RETURNS gtype
124 | LANGUAGE c
125 | IMMUTABLE
126 | CALLED ON NULL INPUT
127 | PARALLEL SAFE
128 | AS 'MODULE_PATHNAME', 'gtype_bound_box';
129 |
130 |
--------------------------------------------------------------------------------
/sql/postgraph-graphid.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | --
19 | -- graphid - comparison operators (=, <>, <, >, <=, >=)
20 | --
21 | CREATE FUNCTION graphid_eq(postgraph.graphid, postgraph.graphid)
22 | RETURNS boolean
23 | LANGUAGE c
24 | IMMUTABLE
25 | RETURNS NULL ON NULL INPUT
26 | PARALLEL SAFE
27 | AS 'MODULE_PATHNAME';
28 |
29 | CREATE OPERATOR = (
30 | FUNCTION = graphid_eq,
31 | LEFTARG = graphid,
32 | RIGHTARG = graphid,
33 | COMMUTATOR = =,
34 | NEGATOR = <>,
35 | RESTRICT = eqsel,
36 | JOIN = eqjoinsel,
37 | HASHES,
38 | MERGES
39 | );
40 |
41 | CREATE FUNCTION graphid_ne(graphid, graphid)
42 | RETURNS boolean
43 | LANGUAGE c
44 | IMMUTABLE
45 | RETURNS NULL ON NULL INPUT
46 | PARALLEL SAFE
47 | AS 'MODULE_PATHNAME';
48 |
49 | CREATE OPERATOR <> (
50 | FUNCTION = graphid_ne,
51 | LEFTARG = graphid,
52 | RIGHTARG = graphid,
53 | COMMUTATOR = <>,
54 | NEGATOR = =,
55 | RESTRICT = neqsel,
56 | JOIN = neqjoinsel
57 | );
58 |
59 | CREATE FUNCTION graphid_lt(graphid, graphid)
60 | RETURNS boolean
61 | LANGUAGE c
62 | IMMUTABLE
63 | RETURNS NULL ON NULL INPUT
64 | PARALLEL SAFE
65 | AS 'MODULE_PATHNAME';
66 |
67 | CREATE FUNCTION graphid_gt(graphid, graphid)
68 | RETURNS boolean
69 | LANGUAGE c
70 | IMMUTABLE
71 | RETURNS NULL ON NULL INPUT
72 | PARALLEL SAFE
73 | AS 'MODULE_PATHNAME';
74 |
75 |
76 | CREATE FUNCTION graphid_le(graphid, graphid)
77 | RETURNS boolean
78 | LANGUAGE c
79 | IMMUTABLE
80 | RETURNS NULL ON NULL INPUT
81 | PARALLEL SAFE
82 | AS 'MODULE_PATHNAME';
83 |
84 | CREATE FUNCTION graphid_ge(graphid, graphid)
85 | RETURNS boolean
86 | LANGUAGE c
87 | IMMUTABLE
88 | RETURNS NULL ON NULL INPUT
89 | PARALLEL SAFE
90 | AS 'MODULE_PATHNAME';
91 |
92 |
93 | --
94 | -- graphid - B-tree support functions
95 | --
96 | -- comparison support
97 | CREATE FUNCTION graphid_btree_cmp(graphid, graphid)
98 | RETURNS int
99 | LANGUAGE c
100 | IMMUTABLE
101 | RETURNS NULL ON NULL INPUT
102 | PARALLEL SAFE
103 | AS 'MODULE_PATHNAME';
104 |
105 | -- sort support
106 | CREATE FUNCTION graphid_btree_sort(internal)
107 | RETURNS void
108 | LANGUAGE c
109 | IMMUTABLE
110 | RETURNS NULL ON NULL INPUT
111 | PARALLEL SAFE
112 | AS 'MODULE_PATHNAME';
113 |
114 |
115 |
116 | --
117 | -- graphid functions
118 | --
119 | CREATE FUNCTION _graphid(label_id int, entry_id bigint)
120 | RETURNS graphid
121 | LANGUAGE c
122 | IMMUTABLE
123 | PARALLEL SAFE
124 | AS 'MODULE_PATHNAME';
125 |
126 | CREATE FUNCTION _label_name(graph_oid oid, graphid)
127 | RETURNS cstring
128 | LANGUAGE c
129 | STABLE
130 | PARALLEL SAFE
131 | AS 'MODULE_PATHNAME';
132 |
133 | CREATE FUNCTION _extract_label_id(graphid)
134 | RETURNS label_id
135 | LANGUAGE c
136 | STABLE
137 | PARALLEL SAFE
138 | AS 'MODULE_PATHNAME';
139 |
140 |
141 |
142 | CREATE OPERATOR < (
143 | FUNCTION = graphid_lt,
144 | LEFTARG = graphid,
145 | RIGHTARG = graphid,
146 | COMMUTATOR = >,
147 | NEGATOR = >=,
148 | RESTRICT = scalarltsel,
149 | JOIN = scalarltjoinsel
150 | );
151 |
152 | CREATE OPERATOR > (
153 | FUNCTION = graphid_gt,
154 | LEFTARG = graphid,
155 | RIGHTARG = graphid,
156 | COMMUTATOR = <,
157 | NEGATOR = <=,
158 | RESTRICT = scalargtsel,
159 | JOIN = scalargtjoinsel
160 | );
161 |
162 | CREATE OPERATOR <= (
163 | FUNCTION = graphid_le,
164 | LEFTARG = graphid,
165 | RIGHTARG = graphid,
166 | COMMUTATOR = >=,
167 | NEGATOR = >,
168 | RESTRICT = scalarlesel,
169 | JOIN = scalarlejoinsel);
170 |
171 | CREATE OPERATOR >= (
172 | FUNCTION = graphid_ge,
173 | LEFTARG = graphid,
174 | RIGHTARG = graphid,
175 | COMMUTATOR = <=,
176 | NEGATOR = <,
177 | RESTRICT = scalargesel,
178 | JOIN = scalargejoinsel
179 | );
180 |
181 | --
182 | -- graphid - hash operator class
183 | --
184 | CREATE FUNCTION graphid_hash_cmp(graphid)
185 | RETURNS INTEGER
186 | LANGUAGE c
187 | IMMUTABLE
188 | PARALLEL SAFE
189 | AS 'MODULE_PATHNAME';
190 |
191 | CREATE OPERATOR CLASS graphid_ops_hash
192 | DEFAULT FOR TYPE graphid
193 | USING hash
194 | AS
195 | OPERATOR 1 =,
196 | FUNCTION 1 graphid_hash_cmp(graphid);
197 | --
198 | -- btree operator classes for graphid
199 | --
200 | CREATE OPERATOR CLASS graphid_ops
201 | DEFAULT FOR TYPE graphid
202 | USING btree
203 | AS
204 | OPERATOR 1 <,
205 | OPERATOR 2 <=,
206 | OPERATOR 3 =,
207 | OPERATOR 4 >=,
208 | OPERATOR 5 >,
209 | FUNCTION 1 graphid_btree_cmp (graphid, graphid),
210 | FUNCTION 2 graphid_btree_sort (internal);
211 |
--------------------------------------------------------------------------------
/sql/postgraph-gtype-lists.sql.in:
--------------------------------------------------------------------------------
1 |
2 |
3 | --
4 | -- gtype - list literal (`[expr, ...]`)
5 | --
6 |
7 | CREATE FUNCTION gtype_build_list(VARIADIC "any")
8 | RETURNS gtype
9 | LANGUAGE c
10 | IMMUTABLE
11 | CALLED ON NULL INPUT
12 | PARALLEL SAFE
13 | AS 'MODULE_PATHNAME';
14 |
15 | CREATE FUNCTION gtype_build_list()
16 | RETURNS gtype
17 | LANGUAGE c
18 | IMMUTABLE
19 | PARALLEL SAFE
20 | AS 'MODULE_PATHNAME', 'gtype_build_list_noargs';
21 |
22 |
23 | CREATE FUNCTION gtype_access_slice(gtype, gtype, gtype)
24 | RETURNS gtype
25 | LANGUAGE c
26 | IMMUTABLE
27 | PARALLEL SAFE AS 'MODULE_PATHNAME';
28 |
29 | CREATE FUNCTION gtype_in_operator(gtype, gtype)
30 | RETURNS bool
31 | LANGUAGE c
32 | IMMUTABLE
33 | PARALLEL SAFE
34 | AS 'MODULE_PATHNAME';
35 |
36 | CREATE OPERATOR @= (
37 | FUNCTION = gtype_in_operator,
38 | LEFTARG = gtype,
39 | RIGHTARG = gtype,
40 | NEGATOR = !@=,
41 | RESTRICT = eqsel,
42 | JOIN = eqjoinsel,
43 | HASHES,
44 | MERGES
45 | );
46 |
47 | --
48 | -- Scalar Functions
49 | --
50 | CREATE FUNCTION head (gtype)
51 | RETURNS gtype
52 | LANGUAGE c
53 | IMMUTABLE
54 | RETURNS NULL ON NULL INPUT
55 | PARALLEL SAFE
56 | AS 'MODULE_PATHNAME', 'gtype_head';
57 |
58 | CREATE FUNCTION last (gtype)
59 | RETURNS gtype
60 | LANGUAGE c
61 | IMMUTABLE
62 | RETURNS NULL ON NULL INPUT
63 | PARALLEL SAFE
64 | AS 'MODULE_PATHNAME', 'gtype_last';
65 |
66 | CREATE FUNCTION size (gtype)
67 | RETURNS gtype
68 | LANGUAGE c
69 | IMMUTABLE
70 | RETURNS NULL ON NULL INPUT
71 | PARALLEL SAFE
72 | AS 'MODULE_PATHNAME', 'gtype_size';
73 |
74 | --
75 | -- list functions (reverse is defined in string functions)
76 | --
77 |
78 | -- keys
79 | CREATE FUNCTION keys (gtype)
80 | RETURNS gtype
81 | LANGUAGE c
82 | IMMUTABLE
83 | RETURNS NULL ON NULL INPUT
84 | PARALLEL SAFE
85 | AS 'MODULE_PATHNAME', 'gtype_keys';
86 |
87 | --range
88 | CREATE FUNCTION range (gtype, gtype)
89 | RETURNS gtype
90 | LANGUAGE c
91 | IMMUTABLE
92 | PARALLEL SAFE
93 | RETURNS NULL ON NULL INPUT
94 | AS 'MODULE_PATHNAME', 'gtype_range';
95 |
96 | CREATE FUNCTION range (gtype, gtype, gtype)
97 | RETURNS gtype
98 | LANGUAGE c
99 | IMMUTABLE
100 | PARALLEL SAFE
101 | RETURNS NULL ON NULL INPUT
102 | AS 'MODULE_PATHNAME', 'gtype_range_w_skip';
--------------------------------------------------------------------------------
/sql/postgraph-range.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | --
19 | -- Range Functions
20 | --
21 | CREATE FUNCTION intrange(gtype, gtype)
22 | RETURNS gtype
23 | LANGUAGE c
24 | IMMUTABLE
25 | CALLED ON NULL INPUT
26 | PARALLEL SAFE
27 | AS 'MODULE_PATHNAME', 'gtype_intrange';
28 |
29 | CREATE FUNCTION intrange(gtype, gtype, gtype)
30 | RETURNS gtype
31 | LANGUAGE c
32 | IMMUTABLE
33 | CALLED ON NULL INPUT
34 | PARALLEL SAFE
35 | AS 'MODULE_PATHNAME', 'gtype_intrange';
36 |
37 | CREATE FUNCTION numrange(gtype, gtype)
38 | RETURNS gtype
39 | LANGUAGE c
40 | IMMUTABLE
41 | CALLED ON NULL INPUT
42 | PARALLEL SAFE
43 | AS 'MODULE_PATHNAME', 'gtype_numrange';
44 |
45 | CREATE FUNCTION numrange(gtype, gtype, gtype)
46 | RETURNS gtype
47 | LANGUAGE c
48 | IMMUTABLE
49 | CALLED ON NULL INPUT
50 | PARALLEL SAFE
51 | AS 'MODULE_PATHNAME', 'gtype_numrange';
52 |
53 | CREATE FUNCTION tsrange(gtype, gtype)
54 | RETURNS gtype
55 | LANGUAGE c
56 | IMMUTABLE
57 | CALLED ON NULL INPUT
58 | PARALLEL SAFE
59 | AS 'MODULE_PATHNAME', 'gtype_tsrange';
60 |
61 | CREATE FUNCTION tsrange(gtype, gtype, gtype)
62 | RETURNS gtype
63 | LANGUAGE c
64 | IMMUTABLE
65 | CALLED ON NULL INPUT
66 | PARALLEL SAFE
67 | AS 'MODULE_PATHNAME', 'gtype_tsrange';
68 |
69 | CREATE FUNCTION tstzrange(gtype, gtype)
70 | RETURNS gtype
71 | LANGUAGE c
72 | IMMUTABLE
73 | CALLED ON NULL INPUT
74 | PARALLEL SAFE
75 | AS 'MODULE_PATHNAME', 'gtype_tstzrange';
76 |
77 | CREATE FUNCTION tstzrange(gtype, gtype, gtype)
78 | RETURNS gtype
79 | LANGUAGE c
80 | IMMUTABLE
81 | CALLED ON NULL INPUT
82 | PARALLEL SAFE
83 | AS 'MODULE_PATHNAME', 'gtype_tstzrange';
84 |
85 | CREATE FUNCTION daterange(gtype, gtype)
86 | RETURNS gtype
87 | LANGUAGE c
88 | IMMUTABLE
89 | CALLED ON NULL INPUT
90 | PARALLEL SAFE
91 | AS 'MODULE_PATHNAME', 'gtype_daterange';
92 |
93 | CREATE FUNCTION daterange(gtype, gtype, gtype)
94 | RETURNS gtype
95 | LANGUAGE c
96 | IMMUTABLE
97 | CALLED ON NULL INPUT
98 | PARALLEL SAFE
99 | AS 'MODULE_PATHNAME', 'gtype_daterange';
100 |
101 |
--------------------------------------------------------------------------------
/sql/postgraph-temporal.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | --
19 | -- Temporal Functions
20 | --
21 | CREATE FUNCTION age(gtype, gtype)
22 | RETURNS gtype
23 | LANGUAGE c
24 | IMMUTABLE
25 | RETURNS NULL ON NULL INPUT
26 | PARALLEL SAFE
27 | AS 'MODULE_PATHNAME', 'gtype_age_w2args';
28 |
29 | CREATE FUNCTION age(gtype)
30 | RETURNS gtype
31 | LANGUAGE c
32 | STABLE
33 | RETURNS NULL ON NULL INPUT
34 | PARALLEL SAFE
35 | AS 'MODULE_PATHNAME', 'gtype_age_today';
36 |
37 | CREATE FUNCTION "extract"(gtype, gtype)
38 | RETURNS gtype
39 | LANGUAGE c
40 | IMMUTABLE
41 | RETURNS NULL ON NULL INPUT
42 | PARALLEL SAFE
43 | AS 'MODULE_PATHNAME', 'gtype_extract';
44 |
45 | CREATE FUNCTION date_part(gtype, gtype)
46 | RETURNS gtype
47 | LANGUAGE c
48 | IMMUTABLE
49 | RETURNS NULL ON NULL INPUT
50 | PARALLEL SAFE
51 | AS 'MODULE_PATHNAME', 'gtype_date_part';
52 |
53 | CREATE FUNCTION date_bin(gtype, gtype, gtype)
54 | RETURNS gtype
55 | LANGUAGE c
56 | IMMUTABLE
57 | RETURNS NULL ON NULL INPUT
58 | PARALLEL SAFE
59 | AS 'MODULE_PATHNAME', 'gtype_date_bin';
60 |
61 | CREATE FUNCTION date_trunc(gtype, gtype)
62 | RETURNS gtype
63 | LANGUAGE c
64 | IMMUTABLE
65 | RETURNS NULL ON NULL INPUT
66 | PARALLEL SAFE
67 | AS 'MODULE_PATHNAME', 'gtype_date_trunc';
68 |
69 | CREATE FUNCTION date_trunc(gtype, gtype, gtype)
70 | RETURNS gtype
71 | LANGUAGE c
72 | IMMUTABLE
73 | RETURNS NULL ON NULL INPUT
74 | PARALLEL SAFE
75 | AS 'MODULE_PATHNAME', 'gtype_date_trunc_zone';
76 |
77 | CREATE FUNCTION overlaps(gtype, gtype, gtype, gtype)
78 | RETURNS gtype
79 | LANGUAGE c
80 | IMMUTABLE
81 | RETURNS NULL ON NULL INPUT
82 | PARALLEL SAFE
83 | AS 'MODULE_PATHNAME', 'gtype_overlaps';
84 |
85 | CREATE FUNCTION isfinite(gtype)
86 | RETURNS gtype
87 | LANGUAGE c
88 | IMMUTABLE
89 | RETURNS NULL ON NULL INPUT
90 | PARALLEL SAFE
91 | AS 'MODULE_PATHNAME', 'gtype_isfinite';
92 |
93 | CREATE FUNCTION justify_hours(gtype)
94 | RETURNS gtype
95 | LANGUAGE c
96 | IMMUTABLE
97 | RETURNS NULL ON NULL INPUT
98 | PARALLEL SAFE
99 | AS 'MODULE_PATHNAME', 'gtype_justify_hours';
100 |
101 | CREATE FUNCTION justify_days(gtype)
102 | RETURNS gtype
103 | LANGUAGE c
104 | IMMUTABLE
105 | RETURNS NULL ON NULL INPUT
106 | PARALLEL SAFE
107 | AS 'MODULE_PATHNAME', 'gtype_justify_days';
108 |
109 | CREATE FUNCTION justify_interval(gtype)
110 | RETURNS gtype
111 | LANGUAGE c
112 | IMMUTABLE
113 | RETURNS NULL ON NULL INPUT
114 | PARALLEL SAFE
115 | AS 'MODULE_PATHNAME', 'gtype_justify_interval';
116 |
117 | CREATE FUNCTION make_date(gtype, gtype, gtype)
118 | RETURNS gtype
119 | LANGUAGE c
120 | IMMUTABLE
121 | PARALLEL SAFE
122 | AS 'MODULE_PATHNAME', 'gtype_make_date';
123 |
124 | CREATE FUNCTION make_time(gtype, gtype, gtype)
125 | RETURNS gtype
126 | LANGUAGE c
127 | IMMUTABLE
128 | PARALLEL SAFE
129 | AS 'MODULE_PATHNAME', 'gtype_make_time';
130 |
131 | CREATE FUNCTION make_timestamp(gtype, gtype, gtype, gtype, gtype, gtype)
132 | RETURNS gtype
133 | LANGUAGE c
134 | IMMUTABLE
135 | PARALLEL SAFE
136 | AS 'MODULE_PATHNAME', 'gtype_make_timestamp';
137 |
138 | CREATE FUNCTION make_timestamptz(gtype, gtype, gtype, gtype, gtype, gtype)
139 | RETURNS gtype
140 | LANGUAGE c
141 | STABLE
142 | PARALLEL SAFE
143 | AS 'MODULE_PATHNAME', 'gtype_make_timestamptz';
144 |
145 | CREATE FUNCTION make_timestamptz(gtype, gtype, gtype, gtype, gtype, gtype, gtype)
146 | RETURNS gtype
147 | LANGUAGE c
148 | STABLE
149 | PARALLEL SAFE
150 | AS 'MODULE_PATHNAME','gtype_make_timestamptz_wtimezone';
151 |
152 |
--------------------------------------------------------------------------------
/sql/postgraph-traversal.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 |
19 | --
20 | -- traversal - equality operators (=, <>, >)
21 | --
22 | CREATE FUNCTION traversal_eq(traversal, traversal) RETURNS boolean
23 | LANGUAGE c
24 | IMMUTABLE
25 | RETURNS NULL ON NULL INPUT
26 | PARALLEL SAFE
27 | AS 'MODULE_PATHNAME';
28 |
29 | CREATE OPERATOR = (
30 | FUNCTION = traversal_eq,
31 | LEFTARG = traversal,
32 | RIGHTARG = traversal,
33 | COMMUTATOR = =,
34 | NEGATOR = <>,
35 | RESTRICT = eqsel,
36 | JOIN = eqjoinsel,
37 | HASHES
38 | );
39 |
40 | CREATE FUNCTION traversal_ne(traversal, traversal) RETURNS boolean
41 | LANGUAGE c
42 | IMMUTABLE
43 | RETURNS NULL ON NULL INPUT
44 | PARALLEL SAFE
45 | AS 'MODULE_PATHNAME';
46 |
47 | CREATE OPERATOR <> (
48 | FUNCTION = traversal_ne,
49 | LEFTARG = traversal,
50 | RIGHTARG = traversal,
51 | COMMUTATOR = <>,
52 | NEGATOR = =,
53 | RESTRICT = neqsel,
54 | JOIN = neqjoinsel,
55 | HASHES
56 | );
57 |
58 | CREATE FUNCTION traversal_gt(traversal, traversal) RETURNS boolean
59 | LANGUAGE c
60 | IMMUTABLE
61 | RETURNS NULL ON NULL INPUT
62 | PARALLEL SAFE
63 | AS 'MODULE_PATHNAME';
64 |
65 | CREATE OPERATOR > (
66 | FUNCTION = traversal_gt,
67 | LEFTARG = traversal,
68 | RIGHTARG = traversal,
69 | COMMUTATOR = >,
70 | NEGATOR = <=,
71 | RESTRICT = scalargtsel,
72 | JOIN = scalargtjoinsel
73 | );
74 |
75 | CREATE FUNCTION traversal_ge(traversal, traversal) RETURNS boolean
76 | LANGUAGE c
77 | IMMUTABLE
78 | RETURNS NULL ON NULL INPUT
79 | PARALLEL SAFE
80 | AS 'MODULE_PATHNAME';
81 |
82 | CREATE OPERATOR >= (
83 | FUNCTION = traversal_ge,
84 | LEFTARG = traversal,
85 | RIGHTARG = traversal,
86 | COMMUTATOR = >=,
87 | NEGATOR = <,
88 | RESTRICT = scalargesel,
89 | JOIN = scalargejoinsel
90 | );
91 |
92 |
93 | CREATE FUNCTION traversal_lt(traversal, traversal) RETURNS boolean
94 | LANGUAGE c
95 | IMMUTABLE
96 | RETURNS NULL ON NULL INPUT
97 | PARALLEL SAFE
98 | AS 'MODULE_PATHNAME';
99 |
100 | CREATE OPERATOR < (
101 | FUNCTION = traversal_lt,
102 | LEFTARG = traversal,
103 | RIGHTARG = traversal,
104 | COMMUTATOR = <,
105 | NEGATOR = >=,
106 | RESTRICT = scalarltsel,
107 | JOIN = scalarltjoinsel
108 | );
109 |
110 | CREATE FUNCTION traversal_le(traversal, traversal) RETURNS boolean
111 | LANGUAGE c
112 | IMMUTABLE
113 | RETURNS NULL ON NULL INPUT
114 | PARALLEL SAFE
115 | AS 'MODULE_PATHNAME';
116 |
117 | CREATE OPERATOR <= (
118 | FUNCTION = traversal_le,
119 | LEFTARG = traversal,
120 | RIGHTARG = traversal,
121 | COMMUTATOR = <=,
122 | NEGATOR = >,
123 | RESTRICT = scalarlesel,
124 | JOIN = scalarlejoinsel
125 | );
126 |
127 | --
128 | -- traversal - B-tree support functions
129 | --
130 | -- comparison support
131 | CREATE FUNCTION traversal_btree_cmp(traversal, traversal)
132 | RETURNS int
133 | LANGUAGE c
134 | IMMUTABLE
135 | RETURNS NULL ON NULL INPUT
136 | PARALLEL SAFE
137 | AS 'MODULE_PATHNAME';
138 |
139 | -- sort support
140 | CREATE FUNCTION traversal_btree_sort(internal)
141 | RETURNS void
142 | LANGUAGE c
143 | IMMUTABLE
144 | RETURNS NULL ON NULL INPUT
145 | PARALLEL SAFE AS 'MODULE_PATHNAME';
146 |
147 | --
148 | -- define operator classes for graphid
149 | --
150 | CREATE OPERATOR CLASS traversal_ops
151 | DEFAULT FOR TYPE traversal
152 | USING btree AS
153 | OPERATOR 1 <,
154 | OPERATOR 2 <=,
155 | OPERATOR 3 =,
156 | OPERATOR 4 >=,
157 | OPERATOR 5 >,
158 | FUNCTION 1 traversal_btree_cmp (traversal, traversal),
159 | FUNCTION 2 traversal_btree_sort (internal);
160 |
161 | --
162 | -- traversal functions
163 | --
164 | CREATE FUNCTION relationships(traversal) RETURNS edge[]
165 | LANGUAGE c
166 | IMMUTABLE
167 | RETURNS NULL ON NULL INPUT
168 | PARALLEL SAFE
169 | AS 'MODULE_PATHNAME', 'traversal_edges';
170 |
171 | CREATE FUNCTION nodes(traversal) RETURNS vertex[]
172 | LANGUAGE c
173 | IMMUTABLE
174 | RETURNS NULL ON NULL INPUT
175 | PARALLEL SAFE
176 | AS 'MODULE_PATHNAME', 'traversal_nodes';
177 |
178 | CREATE FUNCTION size(traversal) RETURNS gtype
179 | LANGUAGE c
180 | IMMUTABLE
181 | RETURNS NULL ON NULL INPUT
182 | PARALLEL SAFE
183 | AS 'MODULE_PATHNAME', 'traversal_size';
184 |
185 | CREATE FUNCTION length(traversal) RETURNS gtype
186 | LANGUAGE c
187 | IMMUTABLE
188 | RETURNS NULL ON NULL INPUT
189 | PARALLEL SAFE
190 | AS 'MODULE_PATHNAME', 'traversal_length';
191 |
192 | CREATE OPERATOR @-@ (
193 | FUNCTION = length,
194 | RIGHTARG = traversal
195 | );
196 |
--------------------------------------------------------------------------------
/sql/postgraph-tsearch.sql.in:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | --
19 | -- Text Search Operators
20 | --
21 |
22 | CREATE FUNCTION gtype_tsquery_or(gtype, gtype)
23 | RETURNS gtype
24 | LANGUAGE c
25 | IMMUTABLE
26 | RETURNS NULL ON NULL INPUT
27 | PARALLEL SAFE
28 | AS 'MODULE_PATHNAME', 'gtype_tsquery_or';
29 |
30 | CREATE OPERATOR || (FUNCTION = gtype_tsquery_or, LEFTARG = gtype, RIGHTARG = gtype);
31 |
32 | CREATE FUNCTION gtype_tsquery_not(gtype)
33 | RETURNS gtype
34 | LANGUAGE c
35 | IMMUTABLE
36 | RETURNS NULL ON NULL INPUT
37 | PARALLEL SAFE
38 | AS 'MODULE_PATHNAME', 'gtype_tsquery_not';
39 |
40 | CREATE OPERATOR !! (FUNCTION = gtype_tsquery_not, RIGHTARG = gtype);
41 |
42 |
43 | --
44 | -- Text Search Functions
45 | --
46 | CREATE FUNCTION ts_delete(gtype, gtype)
47 | RETURNS gtype
48 | LANGUAGE c
49 | IMMUTABLE
50 | RETURNS NULL ON NULL INPUT
51 | PARALLEL SAFE
52 | AS 'MODULE_PATHNAME', 'gtype_ts_delete';
53 |
54 | CREATE FUNCTION strip(gtype)
55 | RETURNS gtype
56 | LANGUAGE c
57 | IMMUTABLE
58 | RETURNS NULL ON NULL INPUT
59 | PARALLEL SAFE
60 | AS 'MODULE_PATHNAME', 'gtype_ts_strip';
61 |
62 | CREATE FUNCTION tsquery_phrase(gtype, gtype)
63 | RETURNS gtype
64 | LANGUAGE c
65 | IMMUTABLE
66 | RETURNS NULL ON NULL INPUT
67 | PARALLEL SAFE
68 | AS 'MODULE_PATHNAME', 'gtype_tsquery_phrase';
69 |
70 | CREATE FUNCTION tsquery_phrase(gtype, gtype, gtype)
71 | RETURNS gtype
72 | LANGUAGE c
73 | IMMUTABLE
74 | RETURNS NULL ON NULL INPUT
75 | PARALLEL SAFE
76 | AS 'MODULE_PATHNAME', 'gtype_tsquery_phrase_distance';
77 |
78 | CREATE FUNCTION plainto_tsquery(gtype)
79 | RETURNS gtype
80 | LANGUAGE c
81 | IMMUTABLE
82 | RETURNS NULL ON NULL INPUT
83 | PARALLEL SAFE
84 | AS 'MODULE_PATHNAME', 'gtype_plainto_tsquery';
85 |
86 | CREATE FUNCTION phraseto_tsquery(gtype)
87 | RETURNS gtype
88 | LANGUAGE c
89 | IMMUTABLE
90 | RETURNS NULL ON NULL INPUT
91 | PARALLEL SAFE
92 | AS 'MODULE_PATHNAME', 'gtype_phraseto_tsquery';
93 |
94 | CREATE FUNCTION websearch_to_tsquery(gtype)
95 | RETURNS gtype
96 | LANGUAGE c
97 | IMMUTABLE
98 | RETURNS NULL ON NULL INPUT
99 | PARALLEL SAFE
100 | AS 'MODULE_PATHNAME', 'gtype_websearch_to_tsquery';
101 |
102 |
103 |
--------------------------------------------------------------------------------
/src/backend/access/ivfflat/ivfvacuum.c:
--------------------------------------------------------------------------------
1 | #include "postgres.h"
2 |
3 | #include "commands/vacuum.h"
4 | #include "access/ivfflat.h"
5 | #include "storage/bufmgr.h"
6 |
7 | /*
8 | * Bulk delete tuples from the index
9 | */
10 | IndexBulkDeleteResult *
11 | ivfflatbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state) {
12 | Relation index = info->index;
13 | BlockNumber blkno = IVFFLAT_HEAD_BLKNO;
14 | BufferAccessStrategy bas = GetAccessStrategy(BAS_BULKREAD);
15 |
16 | if (stats == NULL)
17 | stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
18 |
19 | // Iterate over list pages
20 | while (BlockNumberIsValid(blkno)) {
21 | Buffer cbuf;
22 | Page cpage;
23 | OffsetNumber coffno;
24 | OffsetNumber cmaxoffno;
25 | BlockNumber startPages[MaxOffsetNumber];
26 | ListInfo listInfo;
27 |
28 | cbuf = ReadBuffer(index, blkno);
29 | LockBuffer(cbuf, BUFFER_LOCK_SHARE);
30 | cpage = BufferGetPage(cbuf);
31 |
32 | cmaxoffno = PageGetMaxOffsetNumber(cpage);
33 |
34 | // Iterate over lists
35 | for (coffno = FirstOffsetNumber; coffno <= cmaxoffno; coffno = OffsetNumberNext(coffno)) {
36 | IvfflatList list = (IvfflatList) PageGetItem(cpage, PageGetItemId(cpage, coffno));
37 |
38 | startPages[coffno - FirstOffsetNumber] = list->startPage;
39 | }
40 |
41 | listInfo.blkno = blkno;
42 | blkno = IvfflatPageGetOpaque(cpage)->nextblkno;
43 |
44 | UnlockReleaseBuffer(cbuf);
45 |
46 | for (coffno = FirstOffsetNumber; coffno <= cmaxoffno; coffno = OffsetNumberNext(coffno)) {
47 | BlockNumber searchPage = startPages[coffno - FirstOffsetNumber];
48 | BlockNumber insertPage = InvalidBlockNumber;
49 |
50 | // Iterate over entry pages
51 | while (BlockNumberIsValid(searchPage)) {
52 | Buffer buf;
53 | Page page;
54 | GenericXLogState *state;
55 | OffsetNumber offno;
56 | OffsetNumber maxoffno;
57 | OffsetNumber deletable[MaxOffsetNumber];
58 | int ndeletable;
59 |
60 | vacuum_delay_point();
61 |
62 | buf = ReadBufferExtended(index, MAIN_FORKNUM, searchPage, RBM_NORMAL, bas);
63 |
64 | /*
65 | * ambulkdelete cannot delete entries from pages that are
66 | * pinned by other backends
67 | *
68 | * https://www.postgresql.org/docs/current/index-locking.html
69 | */
70 | LockBufferForCleanup(buf);
71 |
72 | state = GenericXLogStart(index);
73 | page = GenericXLogRegisterBuffer(state, buf, 0);
74 |
75 | maxoffno = PageGetMaxOffsetNumber(page);
76 | ndeletable = 0;
77 |
78 | // Find deleted tuples
79 | for (offno = FirstOffsetNumber; offno <= maxoffno; offno = OffsetNumberNext(offno)) {
80 | IndexTuple itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offno));
81 | ItemPointer htup = &(itup->t_tid);
82 |
83 | if (callback(htup, callback_state)) {
84 | deletable[ndeletable++] = offno;
85 | stats->tuples_removed++;
86 | } else
87 | stats->num_index_tuples++;
88 | }
89 |
90 | // Set to first free page
91 | // Must be set before searchPage is updated
92 | if (!BlockNumberIsValid(insertPage) && ndeletable > 0)
93 | insertPage = searchPage;
94 |
95 | searchPage = IvfflatPageGetOpaque(page)->nextblkno;
96 |
97 | if (ndeletable > 0) {
98 | // Delete tuples
99 | PageIndexMultiDelete(page, deletable, ndeletable);
100 | MarkBufferDirty(buf);
101 | GenericXLogFinish(state);
102 | } else
103 | GenericXLogAbort(state);
104 |
105 | UnlockReleaseBuffer(buf);
106 | }
107 |
108 | /*
109 | * Update after all tuples deleted.
110 | *
111 | * We don't add or delete items from lists pages, so offset won't
112 | * change.
113 | */
114 | if (BlockNumberIsValid(insertPage)) {
115 | listInfo.offno = coffno;
116 | IvfflatUpdateList(index, listInfo, insertPage, InvalidBlockNumber, InvalidBlockNumber, MAIN_FORKNUM);
117 | }
118 | }
119 | }
120 |
121 | FreeAccessStrategy(bas);
122 |
123 | return stats;
124 | }
125 |
126 | /*
127 | * Clean up after a VACUUM operation
128 | */
129 | IndexBulkDeleteResult *
130 | ivfflatvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats) {
131 | Relation rel = info->index;
132 |
133 | if (info->analyze_only)
134 | return stats;
135 |
136 | // stats is NULL if ambulkdelete not called
137 | // OK to return NULL if index not changed
138 | if (stats == NULL)
139 | return NULL;
140 |
141 | stats->num_pages = RelationGetNumberOfBlocks(rel);
142 |
143 | return stats;
144 | }
145 |
--------------------------------------------------------------------------------
/src/backend/catalog/ag_namespace.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #include "postgraph.h"
21 |
22 | #include "catalog/namespace.h"
23 |
24 | #include "catalog/ag_namespace.h"
25 |
26 | Oid postgraph_namespace_id(void)
27 | {
28 | return get_namespace_oid(CATALOG_SCHEMA, false);
29 | }
30 |
31 | Oid pg_catalog_namespace_id(void)
32 | {
33 | return get_namespace_oid("pg_catalog", false);
34 | }
35 |
--------------------------------------------------------------------------------
/src/backend/parser/.gitignore:
--------------------------------------------------------------------------------
1 | ag_scanner.c
2 | cypher_gram.c
3 |
--------------------------------------------------------------------------------
/src/backend/parser/cypher_keywords.c:
--------------------------------------------------------------------------------
1 | /*
2 | * For PostgreSQL Database Management System:
3 | * (formerly known as Postgres, then as Postgres95)
4 | *
5 | * Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group
6 | *
7 | * Portions Copyright (c) 1994, The Regents of the University of California
8 | *
9 | * Permission to use, copy, modify, and distribute this software and its documentation for any purpose,
10 | * without fee, and without a written agreement is hereby granted, provided that the above copyright notice
11 | * and this paragraph and the following two paragraphs appear in all copies.
12 | *
13 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT,
14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16 | * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 | *
18 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 | *
21 | * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA
22 | * HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 | */
24 |
25 | #include "postgres.h"
26 |
27 | #include "access/attnum.h"
28 | #include "access/htup.h"
29 | #include "access/tupdesc.h"
30 | #include "catalog/pg_type.h"
31 | #include "common/keywords.h"
32 | #include "fmgr.h"
33 | #include "funcapi.h"
34 |
35 | #include "parser/cypher_gram.h"
36 | #include "parser/cypher_kwlist_d.h"
37 |
38 | /*
39 | * This list must be sorted by ASCII name, because binary search is used to
40 | * locate entries.
41 | */
42 | #define PG_KEYWORD(kwname, value, category) value,
43 |
44 | const uint16 CypherKeywordTokens[] = {
45 | #include "parser/cypher_kwlist.h"
46 | };
47 |
48 | #undef PG_KEYWORD
49 |
50 | #define PG_KEYWORD(kwname, value, category) category,
51 |
52 | const uint16 CypherKeywordCategories[] = {
53 | #include "parser/cypher_kwlist.h"
54 | };
55 |
56 | #undef PG_KEYWORD
57 |
58 | PG_FUNCTION_INFO_V1(get_cypher_keywords);
59 |
60 | // function to return the list of grammar keywords
61 | Datum get_cypher_keywords(PG_FUNCTION_ARGS)
62 | {
63 | FuncCallContext *func_ctx;
64 |
65 | if (SRF_IS_FIRSTCALL())
66 | {
67 | MemoryContext old_mem_ctx;
68 | TupleDesc tup_desc;
69 |
70 | func_ctx = SRF_FIRSTCALL_INIT();
71 | old_mem_ctx = MemoryContextSwitchTo(func_ctx->multi_call_memory_ctx);
72 |
73 | tup_desc = CreateTemplateTupleDesc(3);
74 | TupleDescInitEntry(tup_desc, (AttrNumber)1, "word", TEXTOID, -1, 0);
75 | TupleDescInitEntry(tup_desc, (AttrNumber)2, "catcode", CHAROID, -1, 0);
76 | TupleDescInitEntry(tup_desc, (AttrNumber)3, "catdesc", TEXTOID, -1, 0);
77 |
78 | func_ctx->attinmeta = TupleDescGetAttInMetadata(tup_desc);
79 |
80 | MemoryContextSwitchTo(old_mem_ctx);
81 | }
82 |
83 | func_ctx = SRF_PERCALL_SETUP();
84 |
85 | if (func_ctx->call_cntr < CypherKeyword.num_keywords)
86 | {
87 | char *values[3];
88 | HeapTuple tuple;
89 |
90 | // cast-away-const is ugly but alternatives aren't much better
91 | values[0] = (char *) GetScanKeyword((int) func_ctx->call_cntr,
92 | &CypherKeyword);
93 |
94 | switch (CypherKeywordCategories[func_ctx->call_cntr])
95 | {
96 | case UNRESERVED_KEYWORD:
97 | values[1] = "U";
98 | values[2] = "unreserved";
99 | break;
100 | case COL_NAME_KEYWORD:
101 | values[1] = "C";
102 | values[2] = "unreserved (cannot be function or type name)";
103 | break;
104 | case TYPE_FUNC_NAME_KEYWORD:
105 | values[1] = "T";
106 | values[2] = "reserved (can be function or type name)";
107 | break;
108 | case RESERVED_KEYWORD:
109 | values[1] = "R";
110 | values[2] = "reserved";
111 | break;
112 | default:
113 | // shouldn't be possible
114 | values[1] = NULL;
115 | values[2] = NULL;
116 | break;
117 | }
118 |
119 | tuple = BuildTupleFromCStrings(func_ctx->attinmeta, values);
120 |
121 | SRF_RETURN_NEXT(func_ctx, HeapTupleGetDatum(tuple));
122 | }
123 |
124 | SRF_RETURN_DONE(func_ctx);
125 | }
126 |
--------------------------------------------------------------------------------
/src/backend/parser/cypher_parse_node.c:
--------------------------------------------------------------------------------
1 | /*
2 | * For PostgreSQL Database Management System:
3 | * (formerly known as Postgres, then as Postgres95)
4 | *
5 | * Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group
6 | *
7 | * Portions Copyright (c) 1994, The Regents of the University of California
8 | *
9 | * Permission to use, copy, modify, and distribute this software and its documentation for any purpose,
10 | * without fee, and without a written agreement is hereby granted, provided that the above copyright notice
11 | * and this paragraph and the following two paragraphs appear in all copies.
12 | *
13 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT,
14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16 | * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 | *
18 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 | *
21 | * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA
22 | * HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 | */
24 |
25 | #include "postgres.h"
26 |
27 | #include "mb/pg_wchar.h"
28 | #include "nodes/primnodes.h"
29 | #include "parser/parse_node.h"
30 |
31 | #include "parser/cypher_parse_node.h"
32 |
33 | static void errpos_ecb(void *arg);
34 |
35 | // NOTE: sync the logic with make_parsestate()
36 | cypher_parsestate *make_cypher_parsestate(cypher_parsestate *parent_cpstate)
37 | {
38 | ParseState *parent_pstate = (ParseState *)parent_cpstate;
39 | cypher_parsestate *cpstate;
40 | ParseState *pstate;
41 |
42 | cpstate = palloc0(sizeof(*cpstate));
43 |
44 | pstate = (ParseState *)cpstate;
45 |
46 | /* Fill in fields that don't start at null/false/zero */
47 | pstate->parentParseState = parent_pstate;
48 | pstate->p_next_resno = 1;
49 | pstate->p_resolve_unknowns = true;
50 |
51 | if (parent_cpstate)
52 | {
53 | pstate->p_sourcetext = parent_pstate->p_sourcetext;
54 | pstate->p_queryEnv = parent_pstate->p_queryEnv;
55 | pstate->p_pre_columnref_hook = parent_pstate->p_pre_columnref_hook;
56 | pstate->p_post_columnref_hook = parent_pstate->p_post_columnref_hook;
57 | pstate->p_paramref_hook = parent_pstate->p_paramref_hook;
58 | pstate->p_coerce_param_hook = parent_pstate->p_coerce_param_hook;
59 | pstate->p_ref_hook_state = parent_pstate->p_ref_hook_state;
60 |
61 | cpstate->graph_name = parent_cpstate->graph_name;
62 | cpstate->graph_oid = parent_cpstate->graph_oid;
63 | cpstate->params = parent_cpstate->params;
64 | }
65 |
66 | return cpstate;
67 | }
68 |
69 | void free_cypher_parsestate(cypher_parsestate *cpstate)
70 | {
71 | free_parsestate((ParseState *)cpstate);
72 | }
73 |
74 | void setup_errpos_ecb(errpos_ecb_state *ecb_state, ParseState *pstate,
75 | int query_loc)
76 | {
77 | ecb_state->ecb.previous = error_context_stack;
78 | ecb_state->ecb.callback = errpos_ecb;
79 | ecb_state->ecb.arg = ecb_state;
80 | ecb_state->pstate = pstate;
81 | ecb_state->query_loc = query_loc;
82 |
83 | error_context_stack = &ecb_state->ecb;
84 | }
85 |
86 | void cancel_errpos_ecb(errpos_ecb_state *ecb_state)
87 | {
88 | error_context_stack = ecb_state->ecb.previous;
89 | }
90 |
91 | /*
92 | * adjust the current error position by adding the position of the current
93 | * query which is a subquery of a parent query
94 | */
95 | static void errpos_ecb(void *arg)
96 | {
97 | errpos_ecb_state *ecb_state = arg;
98 | int query_pos;
99 |
100 | if (geterrcode() == ERRCODE_QUERY_CANCELED)
101 | return;
102 |
103 | Assert(ecb_state->query_loc > -1);
104 | query_pos = pg_mbstrlen_with_len(ecb_state->pstate->p_sourcetext,
105 | ecb_state->query_loc);
106 | errposition(query_pos + geterrposition());
107 | }
108 |
109 | /*
110 | * Generates a default alias name for when a query needs on and the parse
111 | * state does not provide one.
112 | */
113 | char *get_next_default_alias(cypher_parsestate *cpstate)
114 | {
115 | char *alias_name;
116 | int nlen = 0;
117 |
118 | /* get the length of the combinded string */
119 | nlen = snprintf(NULL, 0, "%s%d", AGE_DEFAULT_ALIAS_PREFIX,
120 | cpstate->default_alias_num);
121 |
122 | /* allocate the space */
123 | alias_name = palloc0(nlen + 1);
124 |
125 | /* create the name */
126 | snprintf(alias_name, nlen + 1, "%s%d", AGE_DEFAULT_ALIAS_PREFIX,
127 | cpstate->default_alias_num);
128 |
129 | /* increment the default alias number */
130 | cpstate->default_alias_num++;
131 |
132 | return alias_name;
133 | }
134 |
--------------------------------------------------------------------------------
/src/backend/parser/cypher_transform_entity.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #include "postgres.h"
21 |
22 | #include "parser/cypher_transform_entity.h"
23 |
24 | // creates a transform entity
25 | transform_entity *make_transform_entity(cypher_parsestate *cpstate,
26 | enum transform_entity_type type,
27 | Node *node, Expr *expr, char *alias)
28 | {
29 | transform_entity *entity;
30 |
31 | entity = palloc0(sizeof(transform_entity));
32 |
33 | entity->type = type;
34 | if (type == ENT_VERTEX)
35 | entity->entity.node = (cypher_node *)node;
36 | else if (entity->type == ENT_EDGE || entity->type == ENT_VLE_EDGE)
37 | entity->entity.rel = (cypher_relationship *)node;
38 | else if (type == ENT_FUNC_CALL)
39 | entity->entity.rel = NULL;
40 | else
41 | ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
42 | errmsg("unknown entity type")));
43 |
44 | entity->alias = alias;
45 | entity->declared_in_current_clause = true;
46 | entity->expr = expr;
47 | entity->in_join_tree = expr != NULL;
48 |
49 | return entity;
50 | }
51 |
52 | enum transform_entity_type find_transform_entity_type(cypher_parsestate *cpstate, char *name)
53 | {
54 | ListCell *lc;
55 |
56 | foreach(lc, cpstate->entities)
57 | {
58 | transform_entity *entity = lfirst(lc);
59 |
60 | if (entity->type == ENT_VERTEX && entity->entity.node->name != NULL && !strcmp(entity->entity.node->name, name))
61 | return ENT_VERTEX;
62 | else if (entity->type == ENT_EDGE && entity->entity.node->name != NULL && !strcmp(entity->entity.rel->name, name))
63 | return ENT_EDGE;
64 | else if (entity->type == ENT_VLE_EDGE && entity->entity.node->name != NULL && !strcmp(entity->entity.rel->name, name))
65 | return ENT_VLE_EDGE;
66 |
67 | }
68 |
69 | return -1;
70 | }
71 |
72 |
73 | /*
74 | * Finds the transform_entity in the cypher_parstate for a the given name and
75 | * type.
76 | */
77 | transform_entity *find_transform_entity(cypher_parsestate *cpstate,
78 | char *name,
79 | enum transform_entity_type type)
80 | {
81 | ListCell *lc;
82 |
83 | foreach(lc, cpstate->entities)
84 | {
85 | transform_entity *entity = lfirst(lc);
86 |
87 |
88 | if (type == ENT_VERTEX && entity->entity.node->name)
89 | {
90 | if (!strcmp(entity->entity.node->name, name))
91 | return entity;
92 | }
93 | else if (type == ENT_EDGE || type == ENT_VLE_EDGE)
94 | {
95 | if (entity->entity.node->name && !strcmp(entity->entity.rel->name, name))
96 | return entity;
97 | }
98 | }
99 |
100 | return NULL;
101 | }
102 |
103 | /*
104 | * Iterate through the cypher_parsestate's transform_entities and returns
105 | * the entity with name passed by name variable.
106 | */
107 | transform_entity *find_variable(cypher_parsestate *cpstate, char *name)
108 | {
109 | ListCell *lc;
110 |
111 | foreach (lc, cpstate->entities)
112 | {
113 | transform_entity *entity = lfirst(lc);
114 | char *entity_name;
115 |
116 | if (entity->type == ENT_VERTEX) {
117 | entity_name = entity->entity.node->name;
118 | } else if (entity->type == ENT_EDGE || entity->type == ENT_VLE_EDGE) {
119 | entity_name = entity->entity.rel->name;
120 | } else if (entity->type == ENT_FUNC_CALL) {
121 | entity_name = entity->alias;
122 | }else {
123 | ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
124 | errmsg("unknown entity type")));
125 | }
126 |
127 | if (entity_name != NULL && !strcmp(name, entity_name))
128 | {
129 | return entity;
130 | }
131 | }
132 |
133 | return NULL;
134 | }
135 |
136 | // helper function that extracts the name associated with the transform_entity.
137 | char *get_entity_name(transform_entity *entity)
138 | {
139 | if (entity->type == ENT_EDGE || entity->type == ENT_VLE_EDGE)
140 | {
141 | return entity->entity.rel->name;
142 | }
143 | else if (entity->type == ENT_VERTEX)
144 | {
145 | return entity->entity.node->name;
146 | }
147 | else
148 | {
149 | ereport(ERROR,
150 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
151 | errmsg("cannot get entity name from transform_entity type %i",
152 | entity->type)));
153 | }
154 |
155 | return NULL;
156 | }
157 |
--------------------------------------------------------------------------------
/src/backend/postgraph.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #include "postgres.h"
21 |
22 | #include "fmgr.h"
23 |
24 | #include "access/ivfflat.h"
25 | #include "catalog/ag_catalog.h"
26 | #include "nodes/ag_nodes.h"
27 | #include "optimizer/cypher_paths.h"
28 | #include "parser/cypher_analyze.h"
29 |
30 | PG_MODULE_MAGIC;
31 |
32 | void _PG_init(void);
33 |
34 | void _PG_init(void)
35 | {
36 | register_ag_nodes();
37 | set_rel_pathlist_init();
38 | //object_access_hook_init();
39 | //process_utility_hook_init();
40 | parse_analyze_init();
41 | parse_init();
42 | IvfflatInit();
43 | }
44 |
45 | void _PG_fini(void);
46 |
47 | void _PG_fini(void)
48 | {
49 | //process_utility_hook_fini();
50 | //object_access_hook_fini();
51 | set_rel_pathlist_fini();
52 | parse_analyze_fini();
53 | parse_fini();
54 | }
55 |
--------------------------------------------------------------------------------
/src/backend/utils/adt/cypher_funcs.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #include "postgres.h"
21 |
22 | #include "fmgr.h"
23 |
24 | #include "utils/gtype.h"
25 | #include "utils/gtype_typecasting.h"
26 |
27 | PG_FUNCTION_INFO_V1(cypher);
28 |
29 | Datum cypher(PG_FUNCTION_ARGS)
30 | {
31 | const char *s;
32 |
33 | s = PG_ARGISNULL(0) ? "NULL" : PG_GETARG_CSTRING(0);
34 |
35 | ereport(ERROR, (errmsg_internal("unhandled cypher(cstring) function call"),
36 | errdetail_internal("%s", s)));
37 |
38 | PG_RETURN_NULL();
39 | }
40 |
41 | PG_FUNCTION_INFO_V1(_cypher_create_clause);
42 |
43 | Datum _cypher_create_clause(PG_FUNCTION_ARGS)
44 | {
45 | PG_RETURN_NULL();
46 | }
47 |
48 | PG_FUNCTION_INFO_V1(_cypher_set_clause);
49 |
50 | Datum _cypher_set_clause(PG_FUNCTION_ARGS)
51 | {
52 | PG_RETURN_NULL();
53 | }
54 |
55 | PG_FUNCTION_INFO_V1(_cypher_delete_clause);
56 |
57 | Datum _cypher_delete_clause(PG_FUNCTION_ARGS)
58 | {
59 | PG_RETURN_NULL();
60 | }
61 |
62 | PG_FUNCTION_INFO_V1(_cypher_merge_clause);
63 |
64 | Datum _cypher_merge_clause(PG_FUNCTION_ARGS)
65 | {
66 | PG_RETURN_NULL();
67 | }
68 |
69 | PG_FUNCTION_INFO_V1(throw_error);
70 |
71 | Datum throw_error(PG_FUNCTION_ARGS)
72 | {
73 | char *str = GT_ARG_TO_STRING_DATUM(0);
74 |
75 | ereport(ERROR, (errmsg_internal("%s", str)));
76 |
77 | PG_RETURN_NULL();
78 | }
79 |
80 |
--------------------------------------------------------------------------------
/src/backend/utils/ag_func.c:
--------------------------------------------------------------------------------
1 | /*
2 | * For PostgreSQL Database Management System:
3 | * (formerly known as Postgres, then as Postgres95)
4 | *
5 | * Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group
6 | *
7 | * Portions Copyright (c) 1994, The Regents of the University of California
8 | *
9 | * Permission to use, copy, modify, and distribute this software and its documentation for any purpose,
10 | * without fee, and without a written agreement is hereby granted, provided that the above copyright notice
11 | * and this paragraph and the following two paragraphs appear in all copies.
12 | *
13 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT,
14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16 | * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 | *
18 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 | *
21 | * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA
22 | * HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 | */
24 |
25 | #include "postgraph.h"
26 |
27 | #include "access/htup.h"
28 | #include "access/htup_details.h"
29 | #include "catalog/pg_proc.h"
30 | #include "utils/builtins.h"
31 | #include "utils/lsyscache.h"
32 | #include "utils/syscache.h"
33 |
34 | #include "catalog/ag_namespace.h"
35 | #include "utils/ag_func.h"
36 |
37 | // checks that func_oid is of func_name function in CATALOG_SCHEMA
38 | bool is_oid_ag_func(Oid func_oid, const char *func_name)
39 | {
40 | HeapTuple proctup;
41 | Form_pg_proc proc;
42 | Oid nspid;
43 | const char *nspname;
44 |
45 | AssertArg(OidIsValid(func_oid));
46 | AssertArg(func_name);
47 |
48 | proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_oid));
49 | Assert(HeapTupleIsValid(proctup));
50 | proc = (Form_pg_proc)GETSTRUCT(proctup);
51 | if (strncmp(NameStr(proc->proname), func_name, NAMEDATALEN) != 0)
52 | {
53 | ReleaseSysCache(proctup);
54 | return false;
55 | }
56 |
57 | nspid = proc->pronamespace;
58 | ReleaseSysCache(proctup);
59 |
60 | nspname = get_namespace_name_or_temp(nspid);
61 | Assert(nspname);
62 | return (strcmp(nspname, CATALOG_SCHEMA) == 0);
63 | }
64 |
65 | // gets the function OID that matches with func_name and argument types
66 | Oid get_ag_func_oid(const char *func_name, const int nargs, ...)
67 | {
68 | Oid oids[FUNC_MAX_ARGS];
69 | va_list ap;
70 | int i;
71 | oidvector *arg_types;
72 | Oid func_oid;
73 |
74 | AssertArg(func_name);
75 | AssertArg(nargs >= 0 && nargs <= FUNC_MAX_ARGS);
76 |
77 | va_start(ap, nargs);
78 | for (i = 0; i < nargs; i++)
79 | oids[i] = va_arg(ap, Oid);
80 | va_end(ap);
81 |
82 | arg_types = buildoidvector(oids, nargs);
83 |
84 | func_oid = GetSysCacheOid3(PROCNAMEARGSNSP, Anum_pg_proc_oid,
85 | CStringGetDatum(func_name),
86 | PointerGetDatum(arg_types),
87 | ObjectIdGetDatum(postgraph_namespace_id()));
88 | if (!OidIsValid(func_oid))
89 | {
90 | ereport(ERROR, (errmsg_internal("ag function does not exist"),
91 | errdetail_internal("%s(%d)", func_name, nargs)));
92 | }
93 |
94 | return func_oid;
95 | }
96 |
97 | Oid get_pg_func_oid(const char *func_name, const int nargs, ...)
98 | {
99 | Oid oids[FUNC_MAX_ARGS];
100 | va_list ap;
101 | int i;
102 | oidvector *arg_types;
103 | Oid func_oid;
104 |
105 | AssertArg(func_name);
106 | AssertArg(nargs >= 0 && nargs <= FUNC_MAX_ARGS);
107 |
108 | va_start(ap, nargs);
109 | for (i = 0; i < nargs; i++)
110 | oids[i] = va_arg(ap, Oid);
111 | va_end(ap);
112 |
113 | arg_types = buildoidvector(oids, nargs);
114 |
115 | func_oid = GetSysCacheOid3(PROCNAMEARGSNSP, Anum_pg_proc_oid,
116 | CStringGetDatum(func_name),
117 | PointerGetDatum(arg_types),
118 | ObjectIdGetDatum(pg_catalog_namespace_id()));
119 | if (!OidIsValid(func_oid))
120 | {
121 | ereport(ERROR, (errmsg_internal("pg function does not exist"),
122 | errdetail_internal("%s(%d)", func_name, nargs)));
123 | }
124 |
125 | return func_oid;
126 | }
127 |
--------------------------------------------------------------------------------
/src/include/catalog/ag_catalog.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_AG_CATALOG_H
21 | #define AG_AG_CATALOG_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "utils/gtype.h"
26 | #include "utils/graphid.h"
27 |
28 | void object_access_hook_init(void);
29 | void object_access_hook_fini(void);
30 |
31 | void process_utility_hook_init(void);
32 | void process_utility_hook_fini(void);
33 |
34 | Oid ag_relation_id(const char *name, const char *kind);
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/src/include/catalog/ag_graph.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_AG_GRAPH_H
21 | #define AG_AG_GRAPH_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "catalog/ag_catalog.h"
26 |
27 | #define Anum_ag_graph_oid 1
28 | #define Anum_ag_graph_name 2
29 | #define Anum_ag_graph_namespace 3
30 |
31 | #define Natts_ag_graph 3
32 |
33 |
34 | #define session_graph_use() ag_relation_id("session_graph_use", "table")
35 | #define session_graph_use_index() \
36 | ag_relation_id("session_graph_use_index", "index")
37 |
38 | #define ag_graph_relation_id() ag_relation_id("ag_graph", "table")
39 | #define ag_graph_name_index_id() ag_relation_id("ag_graph_name_index", "index")
40 | #define ag_graph_namespace_index_id() \
41 | ag_relation_id("ag_graph_namespace_index", "index")
42 |
43 | void insert_graph(const Name graph_name, const Oid nsp_id);
44 | void delete_graph(const Name graph_name);
45 | void update_graph_name(const Name graph_name, const Name new_name);
46 |
47 | uint32 get_graph_oid(const char *graph_name);
48 | char *get_graph_namespace_name(const char *graph_name);
49 |
50 | List *get_graphnames(void);
51 | void drop_graphs(List *graphnames);
52 |
53 | #define graph_exists(graph_name) OidIsValid(get_graph_oid(graph_name))
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/include/catalog/ag_label.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_AG_LABEL_H
21 | #define AG_AG_LABEL_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "nodes/execnodes.h"
26 |
27 | #include "catalog/ag_catalog.h"
28 |
29 | #define Anum_ag_label_vertex_table_id 1
30 | #define Anum_ag_label_vertex_table_properties 2
31 |
32 | #define Anum_ag_label_edge_table_id 1
33 | #define Anum_ag_label_edge_table_start_id 2
34 | #define Anum_ag_label_edge_table_end_id 3
35 | #define Anum_ag_label_edge_table_properties 4
36 |
37 | #define vertex_tuple_id Anum_ag_label_vertex_table_id - 1
38 | #define vertex_tuple_properties Anum_ag_label_vertex_table_properties - 1
39 |
40 | #define edge_tuple_id Anum_ag_label_edge_table_id - 1
41 | #define edge_tuple_start_id Anum_ag_label_edge_table_start_id - 1
42 | #define edge_tuple_end_id Anum_ag_label_edge_table_end_id - 1
43 | #define edge_tuple_properties Anum_ag_label_edge_table_properties - 1
44 |
45 |
46 |
47 | #define Anum_ag_label_name 1
48 | #define Anum_ag_label_graph 2
49 | #define Anum_ag_label_id 3
50 | #define Anum_ag_label_kind 4
51 | #define Anum_ag_label_relation 5
52 | #define Anum_ag_label_label_path 6
53 |
54 | #define Natts_ag_label 6
55 |
56 | #define ag_label_relation_id() ag_relation_id("ag_label", "table")
57 | #define ag_label_name_graph_index_id() \
58 | ag_relation_id("ag_label_name_graph_index", "index")
59 | #define ag_label_graph_oid_index_id() \
60 | ag_relation_id("ag_label_graph_oid_index", "index")
61 | #define ag_label_relation_index_id() \
62 | ag_relation_id("ag_label_relation_index", "index")
63 | #define ag_label_label_index_id() \
64 | ag_relation_id("ag_label_ltree_index", "index")
65 |
66 | #define LABEL_ID_SEQ_NAME "_label_id_seq"
67 |
68 | #define LABEL_KIND_VERTEX 'v'
69 | #define LABEL_KIND_EDGE 'e'
70 |
71 | void insert_label(const char *label_name, Oid graph_oid, int32 label_id,
72 | char label_kind, Oid label_relation, const char *ltree);
73 | void delete_label(Oid relation);
74 |
75 | int32 get_label_id(const char *label_name, Oid graph_oid);
76 | Oid get_label_relation(const char *label_name, Oid graph_oid);
77 | char *get_label_relation_name(const char *label_name, Oid graph_oid);
78 |
79 | bool label_id_exists(Oid graph_oid, int32 label_id);
80 | RangeVar *get_label_range_var(char *graph_name, Oid graph_oid,
81 | char *label_name);
82 |
83 | List *get_all_edge_labels_per_graph(EState *estate, Oid graph_oid);
84 |
85 | #define label_exists(label_name, label_graph) \
86 | OidIsValid(get_label_id(label_name, label_graph))
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/src/include/catalog/ag_namespace.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_AG_NAMESPACE_H
21 | #define AG_AG_NAMESPACE_H
22 |
23 | #include "postgres.h"
24 |
25 | Oid postgraph_namespace_id(void);
26 | Oid pg_catalog_namespace_id(void);
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/src/include/commands/label_commands.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_LABEL_COMMANDS_H
21 | #define AG_LABEL_COMMANDS_H
22 |
23 | #include "postgres.h"
24 |
25 | #define LABEL_TYPE_VERTEX 'v'
26 | #define LABEL_TYPE_EDGE 'e'
27 |
28 | #define AG_DEFAULT_LABEL_EDGE "_ag_label_edge"
29 | #define AG_DEFAULT_LABEL_VERTEX "_ag_label_vertex"
30 |
31 | #define AG_VERTEX_COLNAME_ID "id"
32 | #define AG_VERTEX_COLNAME_PROPERTIES "properties"
33 |
34 | #define AG_ACCESS_FUNCTION_ID "id"
35 |
36 | #define AG_VERTEX_ACCESS_FUNCTION_ID "id"
37 | #define AG_VERTEX_ACCESS_FUNCTION_PROPERTIES "properties"
38 |
39 | #define AG_EDGE_COLNAME_ID "id"
40 | #define AG_EDGE_COLNAME_START_ID "start_id"
41 | #define AG_EDGE_COLNAME_END_ID "end_id"
42 | #define AG_EDGE_COLNAME_PROPERTIES "properties"
43 |
44 | #define AG_EDGE_ACCESS_FUNCTION_ID "id"
45 | #define AG_EDGE_ACCESS_FUNCTION_START_ID "start_id"
46 | #define AG_EDGE_ACCESS_FUNCTION_END_ID "end_id"
47 | #define AG_EDGE_ACCESS_FUNCTION_PROPERTIES "properties"
48 |
49 | #define IS_DEFAULT_LABEL_EDGE(str) \
50 | (str != NULL && strcmp(AG_DEFAULT_LABEL_EDGE, str) == 0)
51 | #define IS_DEFAULT_LABEL_VERTEX(str) \
52 | (str != NULL && strcmp(AG_DEFAULT_LABEL_VERTEX, str) == 0)
53 |
54 | #define IS_AG_DEFAULT_LABEL(x) \
55 | (IS_DEFAULT_LABEL_EDGE(x) || IS_DEFAULT_LABEL_VERTEX(x))
56 |
57 | void create_label(char *graph_name, char *label_name, char label_type,
58 | List *parents, char *ltree);
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/src/include/executor/cypher_executor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 |
21 | #ifndef AG_CYPHER_EXECUTOR_H
22 | #define AG_CYPHER_EXECUTOR_H
23 |
24 | #include "nodes/extensible.h"
25 | #include "nodes/nodes.h"
26 | #include "nodes/plannodes.h"
27 |
28 | #define DELETE_SCAN_STATE_NAME "Cypher Delete"
29 | #define SET_SCAN_STATE_NAME "Cypher Set"
30 | #define CREATE_SCAN_STATE_NAME "Cypher Create"
31 | #define MERGE_SCAN_STATE_NAME "Cypher Merge"
32 |
33 | Node *create_cypher_create_plan_state(CustomScan *cscan);
34 | extern const CustomExecMethods cypher_create_exec_methods;
35 |
36 | Node *create_cypher_set_plan_state(CustomScan *cscan);
37 | extern const CustomExecMethods cypher_set_exec_methods;
38 |
39 | Node *create_cypher_delete_plan_state(CustomScan *cscan);
40 | extern const CustomExecMethods cypher_delete_exec_methods;
41 |
42 | Node *create_cypher_merge_plan_state(CustomScan *cscan);
43 | extern const CustomExecMethods cypher_merge_exec_methods;
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/include/executor/cypher_utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 | #ifndef AG_CYPHER_UTILS_H
21 | #define AG_CYPHER_UTILS_H
22 |
23 | #include "access/heapam.h"
24 | #include "access/table.h"
25 | #include "access/tableam.h"
26 | #include "nodes/execnodes.h"
27 | #include "nodes/extensible.h"
28 | #include "nodes/nodes.h"
29 | #include "nodes/plannodes.h"
30 |
31 | #include "nodes/cypher_nodes.h"
32 | #include "utils/gtype.h"
33 |
34 | // declaration of a useful postgres macro that isn't in a header file
35 | #define DatumGetItemPointer(X) ((ItemPointer) DatumGetPointer(X))
36 | #define ItemPointerGetDatum(X) PointerGetDatum(X)
37 |
38 | /*
39 | * When executing the children of the CREATE, SET, REMOVE, and
40 | * DELETE clasues, we need to alter the command id in the estate
41 | * and the snapshot. That way we can hide the modified tuples from
42 | * the sub clauses that should not know what their parent clauses are
43 | * doing.
44 | */
45 | #define Increment_Estate_CommandId(estate) \
46 | estate->es_output_cid++; \
47 | estate->es_snapshot->curcid++;
48 |
49 | #define Decrement_Estate_CommandId(estate) \
50 | estate->es_output_cid--; \
51 | estate->es_snapshot->curcid--;
52 |
53 | typedef struct cypher_create_custom_scan_state
54 | {
55 | CustomScanState css;
56 | CustomScan *cs;
57 | List *pattern;
58 | List *path_values;
59 | uint32 flags;
60 | TupleTableSlot *slot;
61 | Oid graph_oid;
62 | } cypher_create_custom_scan_state;
63 |
64 | typedef struct cypher_set_custom_scan_state
65 | {
66 | CustomScanState css;
67 | CustomScan *cs;
68 | cypher_update_information *set_list;
69 | int flags;
70 | Oid graph_oid;
71 | } cypher_set_custom_scan_state;
72 |
73 | typedef struct cypher_delete_custom_scan_state
74 | {
75 | CustomScanState css;
76 | CustomScan *cs;
77 | cypher_delete_information *delete_data;
78 | int flags;
79 | List *edge_labels;
80 | Oid graph_oid;
81 | } cypher_delete_custom_scan_state;
82 |
83 | typedef struct cypher_merge_custom_scan_state
84 | {
85 | CustomScanState css;
86 | CustomScan *cs;
87 | cypher_merge_information *merge_information;
88 | int flags;
89 | cypher_create_path *path;
90 | List *path_values;
91 | Oid graph_oid;
92 | AttrNumber merge_function_attr;
93 | bool created_new_path;
94 | bool found_a_path;
95 | CommandId base_currentCommandId;
96 | } cypher_merge_custom_scan_state;
97 |
98 | TupleTableSlot *populate_vertex_tts(TupleTableSlot *elemTupleSlot,
99 | gtype_value *id, gtype_value *properties);
100 | TupleTableSlot *populate_edge_tts(
101 | TupleTableSlot *elemTupleSlot, gtype_value *id, gtype_value *startid,
102 | gtype_value *endid, gtype_value *properties);
103 |
104 | ResultRelInfo *create_entity_result_rel_info(EState *estate, char *graph_name,
105 | char *label_name);
106 | void destroy_entity_result_rel_info(ResultRelInfo *result_rel_info);
107 |
108 | bool entity_exists(EState *estate, Oid graph_oid, graphid id);
109 | HeapTuple insert_entity_tuple(ResultRelInfo *resultRelInfo,
110 | TupleTableSlot *elemTupleSlot,
111 | EState *estate);
112 | HeapTuple insert_entity_tuple_cid(ResultRelInfo *resultRelInfo,
113 | TupleTableSlot *elemTupleSlot,
114 | EState *estate, CommandId cid);
115 |
116 | #endif
117 |
--------------------------------------------------------------------------------
/src/include/nodes/ag_nodes.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 |
21 | #ifndef AG_AG_NODES_H
22 | #define AG_AG_NODES_H
23 |
24 | #include "postgres.h"
25 |
26 | #include "nodes/extensible.h"
27 | #include "nodes/nodes.h"
28 |
29 | // This list must match node_names and node_methods.
30 | typedef enum ag_node_tag
31 | {
32 | ag_node_invalid_t = 0,
33 |
34 | // projection
35 | cypher_group_by_t,
36 | cypher_return_t,
37 | cypher_with_t,
38 | cypher_call_t,
39 | // reading clause
40 | cypher_match_t,
41 | // updating clause
42 | cypher_create_t,
43 | cypher_set_t,
44 | cypher_set_item_t,
45 | cypher_delete_t,
46 | cypher_unwind_t,
47 | cypher_merge_t,
48 | cypher_load_csv_t,
49 | // pattern
50 | cypher_path_t,
51 | cypher_node_t,
52 | cypher_relationship_t,
53 | // expression
54 | cypher_bool_const_t,
55 | cypher_inet_const_t,
56 | cypher_param_t,
57 | cypher_map_t,
58 | cypher_list_t,
59 | // string match
60 | cypher_string_match_t,
61 | // typecast
62 | cypher_typecast_t,
63 | // integer constant
64 | cypher_integer_const_t,
65 | // sub patterns
66 | cypher_sub_pattern_t,
67 | // create data structures
68 | cypher_create_target_nodes_t,
69 | cypher_create_path_t,
70 | cypher_target_node_t,
71 | // set/remove data structures
72 | cypher_update_information_t,
73 | cypher_update_item_t,
74 | // delete data structures
75 | cypher_delete_information_t,
76 | cypher_delete_item_t,
77 | cypher_merge_information_t,
78 | // CREATE GRAPH ident
79 | cypher_create_graph_t,
80 | // USE GRAPH ident
81 | cypher_use_graph_t,
82 | // DROP GRAPH ident
83 | cypher_drop_graph_t,
84 | cypher_label_tree_node_t
85 | } ag_node_tag;
86 |
87 | void register_ag_nodes(void);
88 |
89 | ExtensibleNode *_new_ag_node(Size size, ag_node_tag tag);
90 |
91 | #define new_ag_node(size, tag) \
92 | ( \
93 | AssertMacro((size) >= sizeof(ExtensibleNode)), \
94 | AssertMacro(tag != ag_node_invalid_t), \
95 | _new_ag_node(size, tag) \
96 | )
97 |
98 | #define make_ag_node(type) \
99 | ((type *)new_ag_node(sizeof(type), CppConcat(type, _t)))
100 |
101 | static inline bool _is_ag_node(Node *node, const char *extnodename)
102 | {
103 | ExtensibleNode *extnode;
104 |
105 | if (!IsA(node, ExtensibleNode))
106 | return false;
107 |
108 | extnode = (ExtensibleNode *)node;
109 | if (strcmp(extnode->extnodename, extnodename) == 0)
110 | return true;
111 |
112 | return false;
113 | }
114 |
115 | #define is_ag_node(node, type) _is_ag_node((Node *)(node), CppAsString(type))
116 |
117 | #endif
118 |
--------------------------------------------------------------------------------
/src/include/nodes/cypher_copyfuncs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 |
21 | #ifndef AG_CYPHER_COPYFUNCS_H
22 | #define AG_CYPHER_COPYFUNCS_H
23 |
24 | #include "postgres.h"
25 |
26 | #include "nodes/nodes.h"
27 |
28 | /*
29 | * Functions that let AGE's ExtensibleNodes be compatible with
30 | * Postgres' copyObject. We assign each node to its copy function
31 | * in the DEFINE_NODE_METHODS and DEFINE_NODE_METHODS_EXTENDED
32 | * macros in ag_nodes.c
33 | */
34 |
35 | void copy_ag_node(ExtensibleNode *newnode,
36 | const ExtensibleNode *oldnode);
37 |
38 | // create data structures
39 | void copy_cypher_create_target_nodes(ExtensibleNode *newnode, const ExtensibleNode *from);
40 | void copy_cypher_create_path(ExtensibleNode *newnode, const ExtensibleNode *from);
41 | void copy_cypher_target_node(ExtensibleNode *newnode, const ExtensibleNode *from);
42 |
43 | // set/remove data structures
44 | void copy_cypher_update_information(ExtensibleNode *newnode, const ExtensibleNode *from);
45 | void copy_cypher_update_item(ExtensibleNode *newnode, const ExtensibleNode *from);
46 |
47 | // delete data structures
48 | void copy_cypher_delete_information(ExtensibleNode *newnode, const ExtensibleNode *from);
49 | void copy_cypher_delete_item(ExtensibleNode *newnode, const ExtensibleNode *from);
50 |
51 | // merge data structure
52 | void copy_cypher_merge_information(ExtensibleNode *newnode, const ExtensibleNode *from);
53 | #endif
54 |
--------------------------------------------------------------------------------
/src/include/nodes/cypher_outfuncs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 |
21 | #ifndef AG_CYPHER_OUTFUNCS_H
22 | #define AG_CYPHER_OUTFUNCS_H
23 |
24 | #include "postgres.h"
25 |
26 | #include "nodes/extensible.h"
27 | #include "nodes/nodes.h"
28 |
29 | // clauses
30 | void out_cypher_group_by(StringInfo str, const ExtensibleNode *node);
31 | void out_cypher_return(StringInfo str, const ExtensibleNode *node);
32 | void out_cypher_with(StringInfo str, const ExtensibleNode *node);
33 | void out_cypher_call(StringInfo str, const ExtensibleNode *node);
34 | void out_cypher_match(StringInfo str, const ExtensibleNode *node);
35 | void out_cypher_create(StringInfo str, const ExtensibleNode *node);
36 | void out_cypher_set(StringInfo str, const ExtensibleNode *node);
37 | void out_cypher_set_item(StringInfo str, const ExtensibleNode *node);
38 | void out_cypher_delete(StringInfo str, const ExtensibleNode *node);
39 | void out_cypher_unwind(StringInfo str, const ExtensibleNode *node);
40 | void out_cypher_merge(StringInfo str, const ExtensibleNode *node);
41 | void out_cypher_load_csv(StringInfo str, const ExtensibleNode *node);
42 |
43 | // pattern
44 | void out_cypher_path(StringInfo str, const ExtensibleNode *node);
45 | void out_cypher_node(StringInfo str, const ExtensibleNode *node);
46 | void out_cypher_relationship(StringInfo str, const ExtensibleNode *node);
47 |
48 | // expression
49 | void out_cypher_bool_const(StringInfo str, const ExtensibleNode *node);
50 | void out_cypher_inet_const(StringInfo str, const ExtensibleNode *node);
51 | void out_cypher_param(StringInfo str, const ExtensibleNode *node);
52 | void out_cypher_map(StringInfo str, const ExtensibleNode *node);
53 | void out_cypher_list(StringInfo str, const ExtensibleNode *node);
54 |
55 | // string match
56 | void out_cypher_string_match(StringInfo str, const ExtensibleNode *node);
57 |
58 | // typecast
59 | void out_cypher_typecast(StringInfo str, const ExtensibleNode *node);
60 |
61 | // integer constant
62 | void out_cypher_integer_const(StringInfo str, const ExtensibleNode *node);
63 |
64 | // sub pattern
65 | void out_cypher_sub_pattern(StringInfo str, const ExtensibleNode *node);
66 |
67 | // create private data structures
68 | void out_cypher_create_target_nodes(StringInfo str, const ExtensibleNode *node);
69 | void out_cypher_create_path(StringInfo str, const ExtensibleNode *node);
70 | void out_cypher_target_node(StringInfo str, const ExtensibleNode *node);
71 |
72 | // set/remove private data structures
73 | void out_cypher_update_information(StringInfo str, const ExtensibleNode *node);
74 | void out_cypher_update_item(StringInfo str, const ExtensibleNode *node);
75 |
76 | // delete private data structures
77 | void out_cypher_delete_information(StringInfo str, const ExtensibleNode *node);
78 | void out_cypher_delete_item(StringInfo str, const ExtensibleNode *node);
79 |
80 | // merge private data structures
81 | void out_cypher_merge_information(StringInfo str, const ExtensibleNode *node);
82 |
83 | // ddl utils
84 | void out_cypher_create_graph(StringInfo str, const ExtensibleNode *node);
85 | void out_cypher_use_graph(StringInfo str, const ExtensibleNode *node);
86 | void out_cypher_drop_graph(StringInfo str, const ExtensibleNode *node);
87 |
88 | // internal label tree nodes
89 | void out_cypher_label_tree_node(StringInfo str, const ExtensibleNode *node);
90 |
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/src/include/nodes/cypher_readfuncs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | * Portions Copyright (c) 1996-2010, Bitnine Global
19 | */
20 | #ifndef AG_CYPHER_READFUNCS_H
21 | #define AG_CYPHER_READFUNCS_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "nodes/extensible.h"
26 | #include "nodes/nodes.h"
27 |
28 | /*
29 | * Deserialization functions for AGE's ExtensibleNodes. We assign
30 | * each node to its deserialization functionin the DEFINE_NODE_METHODS
31 | * and DEFINE_NODE_METHODS_EXTENDED macros in ag_nodes.c.
32 |
33 | *
34 | * All functions are dependent on the pg_strtok function. We do not
35 | * setup pg_strtok. That is for the the caller to do. By default that
36 | * is the responsibility of Postgres' nodeRead function. We assume
37 | * that was setup correctly.
38 | */
39 |
40 | void read_ag_node(ExtensibleNode *node);
41 |
42 | // create data structures
43 | void read_cypher_create_target_nodes(struct ExtensibleNode *node);
44 | void read_cypher_create_path(struct ExtensibleNode *node);
45 | void read_cypher_target_node(struct ExtensibleNode *node);
46 |
47 | // set/remove data structures
48 | void read_cypher_update_information(struct ExtensibleNode *node);
49 | void read_cypher_update_item(struct ExtensibleNode *node);
50 |
51 | // delete data structures
52 | void read_cypher_delete_information(struct ExtensibleNode *node);
53 | void read_cypher_delete_item(struct ExtensibleNode *node);
54 |
55 | void read_cypher_merge_information(struct ExtensibleNode *node);
56 |
57 | void read_cypher_create_graph(struct ExtensibleNode *node);
58 | void read_cypher_use_graph(struct ExtensibleNode *node);
59 | void read_cypher_drop_graph(struct ExtensibleNode *node);
60 |
61 | #endif
62 |
--------------------------------------------------------------------------------
/src/include/optimizer/cypher_createplan.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_CREATEPLAN_H
21 | #define AG_CYPHER_CREATEPLAN_H
22 |
23 | #include "nodes/pg_list.h"
24 | #include "nodes/plannodes.h"
25 |
26 | Plan *plan_cypher_create_path(PlannerInfo *root, RelOptInfo *rel,
27 | CustomPath *best_path, List *tlist,
28 | List *clauses, List *custom_plans);
29 |
30 | Plan *plan_cypher_set_path(PlannerInfo *root, RelOptInfo *rel,
31 | CustomPath *best_path, List *tlist,
32 | List *clauses, List *custom_plans);
33 |
34 | Plan *plan_cypher_delete_path(PlannerInfo *root, RelOptInfo *rel,
35 | CustomPath *best_path, List *tlist,
36 | List *clauses, List *custom_plans);
37 |
38 | Plan *plan_cypher_merge_path(PlannerInfo *root, RelOptInfo *rel,
39 | CustomPath *best_path, List *tlist,
40 | List *clauses, List *custom_plans);
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/src/include/optimizer/cypher_pathnode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_PATHNODE_H
21 | #define AG_CYPHER_PATHNODE_H
22 |
23 | #include "nodes/pg_list.h"
24 |
25 | #define CREATE_PATH_NAME "Cypher Create"
26 | #define SET_PATH_NAME "Cypher Set"
27 | #define DELETE_PATH_NAME "Cypher Delete"
28 | #define MERGE_PATH_NAME "Cypher Merge"
29 |
30 | CustomPath *create_cypher_create_path(PlannerInfo *root, RelOptInfo *rel,
31 | List *custom_private);
32 | CustomPath *create_cypher_set_path(PlannerInfo *root, RelOptInfo *rel,
33 | List *custom_private);
34 | CustomPath *create_cypher_delete_path(PlannerInfo *root, RelOptInfo *rel,
35 | List *custom_private);
36 | CustomPath *create_cypher_merge_path(PlannerInfo *root, RelOptInfo *rel,
37 | List *custom_private);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/src/include/optimizer/cypher_paths.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_PATHS_H
21 | #define AG_CYPHER_PATHS_H
22 |
23 | void set_rel_pathlist_init(void);
24 | void set_rel_pathlist_fini(void);
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/src/include/parser/.gitignore:
--------------------------------------------------------------------------------
1 | cypher_gram_def.h
2 | cypher_kwlist_d.h
3 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_analyze.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_ANALYZE_H
21 | #define AG_CYPHER_ANALYZE_H
22 |
23 | #include "parser/cypher_parse_node.h"
24 |
25 | void parse_init(void);
26 | void parse_fini(void);
27 |
28 | void parse_analyze_init(void);
29 | void parse_analyze_fini(void);
30 |
31 | List *transform_cypher_order_by(cypher_parsestate *cpstate, List *sort_items, List **target_list, ParseExprKind expr_kind);
32 | ParseNamespaceItem *find_pnsi(cypher_parsestate *cpstate, char *varname);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_clause.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_CLAUSE_H
21 | #define AG_CYPHER_CLAUSE_H
22 |
23 | #include "nodes/parsenodes.h"
24 | #include "nodes/pg_list.h"
25 | #include "parser/parse_node.h"
26 |
27 | #include "parser/cypher_parse_node.h"
28 |
29 | typedef struct cypher_clause cypher_clause;
30 |
31 | struct cypher_clause
32 | {
33 | cypher_clause *next; //next clause
34 | Node *self;
35 | cypher_clause *prev; // previous clause
36 | };
37 |
38 | Query *transform_cypher_clause(cypher_parsestate *cpstate,
39 | cypher_clause *clause);
40 |
41 | Query *cypher_parse_sub_analyze(Node *parseTree,
42 | cypher_parsestate *cpstate,
43 | CommonTableExpr *parentCTE,
44 | bool locked_from_parent,
45 | bool resolve_unknowns);
46 | #endif
47 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_expr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * For PostgreSQL Database Management System:
3 | * (formerly known as Postgres, then as Postgres95)
4 | *
5 | * Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group
6 | *
7 | * Portions Copyright (c) 1994, The Regents of the University of California
8 | *
9 | * Permission to use, copy, modify, and distribute this software and its documentation for any purpose,
10 | * without fee, and without a written agreement is hereby granted, provided that the above copyright notice
11 | * and this paragraph and the following two paragraphs appear in all copies.
12 | *
13 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT,
14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16 | * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 | *
18 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 | *
21 | * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA
22 | * HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 | */
24 |
25 | #ifndef AG_CYPHER_EXPR_H
26 | #define AG_CYPHER_EXPR_H
27 |
28 | #include "nodes/nodes.h"
29 | #include "parser/parse_node.h"
30 |
31 | #include "parser/cypher_parse_node.h"
32 |
33 | Node *transform_cypher_expr(cypher_parsestate *cpstate, Node *expr,
34 | ParseExprKind expr_kind);
35 | Node *
36 | sql_transform_expr(ParseState *pstate, Node *expr, ParseExprKind exprKind) ;
37 | List *
38 | expand_NS_Item_Attrs(ParseState *pstate, ParseNamespaceItem *nsitem,
39 | int sublevels_up, int location);
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_gram.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | /*
21 | * NOTE: this file is only meant to be included in the Cypher parsing files,
22 | * i.e., cypher_gram.y, cypher_keywords.c, and cypher_parser.c.
23 | * Definitions that are needed outside the Cypher parser should be in
24 | * cypher_parser.h.
25 | */
26 |
27 | #ifndef AG_CYPHER_GRAM_H
28 | #define AG_CYPHER_GRAM_H
29 |
30 | #include "nodes/nodes.h"
31 | #include "nodes/pg_list.h"
32 |
33 | #include "parser/ag_scanner.h"
34 |
35 | // override the default data type of locations (yylloc)
36 | #define YYLTYPE int
37 |
38 | /*
39 | * Extra data that is passed to the generated parser.
40 | * The resulting abstract syntax tree is stored in result field.
41 | */
42 | typedef struct cypher_yy_extra
43 | {
44 | /* state variables for literal-lexing warnings */
45 | bool warn_on_first_escape;
46 | bool saw_non_ascii;
47 | List *result;
48 | } cypher_yy_extra;
49 |
50 | /*
51 | * cypher_gram_def.h is generated by Bison.
52 | *
53 | * nodes/nodes.h and nodes/pg_list.h must be included before this due to the
54 | * use of Node and List in YYSTYPE.
55 | *
56 | * ag_scanner.h must be included before this because ag_scanner_t is one of the
57 | * parameters of cypher_yyparse() which is generated by Bison.
58 | *
59 | * YYLTYPE must be defined before this. (see above)
60 | *
61 | * cypher_yy_extra must be defined before this because it is another parameter
62 | * of cypher_yyparse().
63 | */
64 | #include "parser/cypher_gram_def.h"
65 |
66 | // cypher_parser.c
67 | int cypher_yylex(YYSTYPE *lvalp, YYLTYPE *llocp, ag_scanner_t scanner, ag_yy_extra *extra);
68 | void cypher_yyerror(YYLTYPE *llocp, ag_scanner_t scanner,
69 | cypher_yy_extra *extra, const char *msg);
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_item.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_ITEM_H
21 | #define AG_CYPHER_ITEM_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "nodes/nodes.h"
26 | #include "nodes/pg_list.h"
27 | #include "nodes/primnodes.h"
28 | #include "parser/parse_node.h"
29 |
30 | #include "parser/cypher_parse_node.h"
31 |
32 | TargetEntry *transform_cypher_item(cypher_parsestate *cpstate, Node *node,
33 | Node *expr, ParseExprKind expr_kind,
34 | char *colname, bool resjunk);
35 | List *transform_cypher_item_list(cypher_parsestate *cpstate, List *item_list,
36 | List **groupClause, ParseExprKind expr_kind);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_keywords.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_KEYWORDS_H
21 | #define AG_KEYWORDS_H
22 |
23 | #include "common/kwlookup.h"
24 |
25 | extern const ScanKeywordList CypherKeyword;
26 | extern const uint16 CypherKeywordTokens[];
27 | extern const uint16 CypherKeywordCategories[];
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_parse_agg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * For PostgreSQL Database Management System:
3 | * (formerly known as Postgres, then as Postgres95)
4 | *
5 | * Portions Copyright (c) 1996-2010, The PostgreSQL Global Development Group
6 | *
7 | * Portions Copyright (c) 1994, The Regents of the University of California
8 | *
9 | * Permission to use, copy, modify, and distribute this software and its documentation for any purpose,
10 | * without fee, and without a written agreement is hereby granted, provided that the above copyright notice
11 | * and this paragraph and the following two paragraphs appear in all copies.
12 | *
13 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT,
14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY
16 | * OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 | *
18 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 | *
21 | * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA
22 | * HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 | */
24 |
25 | #ifndef CYPHER_PARSE_AGG_H
26 | #define CYPHER_PARSE_AGG_H
27 |
28 | #include "parser/parse_node.h"
29 |
30 | extern void parse_check_aggregates(ParseState *pstate, Query *qry);
31 |
32 | #endif /* CYPHER_PARSE_AGG_H */
33 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_parse_node.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_PARSE_NODE_H
21 | #define AG_CYPHER_PARSE_NODE_H
22 |
23 | #include "nodes/primnodes.h"
24 | #include "parser/parse_node.h"
25 |
26 | #include "nodes/cypher_nodes.h"
27 |
28 | #define AGE_DEFAULT_ALIAS_PREFIX "_age_default_alias_"
29 | #define AGE_DEFAULT_VARNAME_PREFIX "_age_varname_"
30 |
31 | typedef struct cypher_parsestate
32 | {
33 | ParseState pstate;
34 | char *graph_name;
35 | uint32 graph_oid;
36 | Param *params;
37 | int default_alias_num;
38 | List *entities;
39 | List *property_constraint_quals;
40 | /*
41 | * To flag when an aggregate has been found in an expression during an
42 | * expression transform. This is used during the return_item list transform
43 | * to know which expressions are group by keys (not an aggregate or a
44 | * composite expression with an aggregate), and which aren't (everything
45 | * else). It is only used by transform_cypher_item_list.
46 | */
47 | bool exprHasAgg;
48 | bool p_opt_match;
49 | Node *prop_node;
50 | Node *prop_name;
51 | } cypher_parsestate;
52 |
53 | typedef struct errpos_ecb_state
54 | {
55 | ErrorContextCallback ecb;
56 | ParseState *pstate; // ParseState of query that has subquery being parsed
57 | int query_loc; // location of subquery starting from p_sourcetext
58 | } errpos_ecb_state;
59 |
60 | cypher_parsestate *make_cypher_parsestate(cypher_parsestate *parent_cpstate);
61 | void free_cypher_parsestate(cypher_parsestate *cpstate);
62 | #define get_parse_state(cpstate) ((ParseState *)(cpstate))
63 |
64 | void setup_errpos_ecb(errpos_ecb_state *ecb_state, ParseState *pstate,
65 | int query_loc);
66 | void cancel_errpos_ecb(errpos_ecb_state *ecb_state);
67 | char *get_next_default_alias(cypher_parsestate *cpstate);
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_parser.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_PARSER_H
21 | #define AG_CYPHER_PARSER_H
22 |
23 | #include "nodes/pg_list.h"
24 |
25 | List *parse_cypher(const char *s);
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/src/include/parser/cypher_transform_entity.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_CYPHER_TRANSFORM_ENTITY_H
21 | #define AG_CYPHER_TRANSFORM_ENTITY_H
22 |
23 | #include "nodes/primnodes.h"
24 | #include "parser/parse_node.h"
25 |
26 | #include "nodes/cypher_nodes.h"
27 | #include "parser/cypher_parse_node.h"
28 |
29 | enum transform_entity_type
30 | {
31 | ENT_VERTEX = 0x0,
32 | ENT_EDGE,
33 | ENT_VLE_EDGE,
34 | ENT_FUNC_CALL
35 | };
36 |
37 | enum transform_entity_join_side
38 | {
39 | JOIN_SIDE_LEFT = 0x0,
40 | JOIN_SIDE_RIGHT
41 | };
42 |
43 | /*
44 | * In the transformation stage, we need to track
45 | * where a variable came from. When moving between
46 | * clauses, Postgres parsestate and Query data structures
47 | * are insufficient for some of the information we
48 | * need.
49 | */
50 | typedef struct
51 | {
52 | // denotes whether this entity is a vertex or edge
53 | enum transform_entity_type type;
54 |
55 | /*
56 | * MATCH clauses are transformed into a select * FROM ... JOIN, etc
57 | * We need to know wheter the table that this entity represents is
58 | * part of the join tree. If a cypher_node does not meet the conditions
59 | * set in INCLUDE_NODE_IN_JOIN_TREE. Then we can skip the node when
60 | * constructing our join tree. The entities around this particular entity
61 | * need to know this for the join to get properly constructed.
62 | */
63 | bool in_join_tree;
64 |
65 | /*
66 | * The parse data structure will be transformed into an Expr that represents
67 | * the entity. When contructing the join tree, we need to know what it was
68 | * turned into. If the entity was originally created in a previous clause,
69 | * this will be a Var that we need to reference to extract the id, startid,
70 | * endid for the join. If the entity was created in the current clause, then
71 | * this will be a FuncExpr that we can reference to get the id, startid, and
72 | * endid.
73 | */
74 | Expr *expr;
75 |
76 | char *alias;
77 | /*
78 | * tells each clause whether this variable was
79 | * declared by itself or a previous clause.
80 | */
81 | bool declared_in_current_clause;
82 | // The parse data structure that we transformed
83 | union
84 | {
85 | cypher_node *node;
86 | cypher_relationship *rel;
87 | } entity;
88 | } transform_entity;
89 |
90 | transform_entity *find_variable(cypher_parsestate *cpstate, char *name);
91 | transform_entity *find_transform_entity(cypher_parsestate *cpstate,
92 | char *name,
93 | enum transform_entity_type type);
94 | transform_entity *make_transform_entity(cypher_parsestate *cpstate,
95 | enum transform_entity_type type,
96 | Node *node, Expr *expr, char *alias);
97 | char *get_entity_name(transform_entity *entity);
98 | enum transform_entity_type find_transform_entity_type(cypher_parsestate *cpstate, char *name);
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/src/include/postgraph.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 | #ifndef POSTGRAPH_H
18 | #define POSTGRAPH_H
19 |
20 | #include "postgres.h"
21 |
22 | #define CATALOG_SCHEMA "postgraph"
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/include/utils/ag_cache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 |
20 | #ifndef AG_AG_CACHE_H
21 | #define AG_AG_CACHE_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "ltree.h"
26 |
27 | // graph_cache_data contains the same fields that ag_graph catalog table has
28 | typedef struct graph_cache_data
29 | {
30 | Oid oid;
31 | NameData name;
32 | Oid namespace;
33 | bool directed;
34 | } graph_cache_data;
35 |
36 | // label_cache_data contains the same fields that ag_label catalog table has
37 | typedef struct label_cache_data
38 | {
39 | NameData name;
40 | Oid graph;
41 | int32 id;
42 | char kind;
43 | Oid relation;
44 | ltree *label_tree;
45 | } label_cache_data;
46 |
47 | // callers of these functions must not modify the returned struct
48 | graph_cache_data *search_graph_name_cache(const char *name);
49 | graph_cache_data *search_graph_namespace_cache(Oid namespace);
50 | label_cache_data *search_label_oid_cache(Oid oid);
51 | label_cache_data *search_label_name_graph_cache(const char *name, Oid graph);
52 | label_cache_data *search_label_graph_oid_cache(Oid graph, int32 id);
53 | label_cache_data *search_label_relation_cache(Oid relation);
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/src/include/utils/ag_func.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef AG_AG_FUNC_H
19 | #define AG_AG_FUNC_H
20 |
21 | #include "postgres.h"
22 |
23 | #define CREATE_CLAUSE_FUNCTION_NAME "_cypher_create_clause"
24 | #define SET_CLAUSE_FUNCTION_NAME "_cypher_set_clause"
25 | #define DELETE_CLAUSE_FUNCTION_NAME "_cypher_delete_clause"
26 | #define MERGE_CLAUSE_FUNCTION_NAME "_cypher_merge_clause"
27 |
28 | bool is_oid_ag_func(Oid func_oid, const char *func_name);
29 | Oid get_ag_func_oid(const char *func_name, const int nargs, ...);
30 | Oid get_pg_func_oid(const char *func_name, const int nargs, ...);
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/src/include/utils/edge.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | /*
19 | * Declarations for edge data type support.
20 | */
21 | #ifndef AG_EDGE_H
22 | #define AG_EDGE_H
23 |
24 | #include "access/htup_details.h"
25 | #include "fmgr.h"
26 | #include "lib/stringinfo.h"
27 | #include "nodes/pg_list.h"
28 | #include "utils/array.h"
29 | #include "utils/numeric.h"
30 | #include "utils/syscache.h"
31 | #include "utils/fmgrprotos.h"
32 | #include "utils/varlena.h"
33 |
34 | #include "catalog/ag_namespace.h"
35 | #include "catalog/pg_type.h"
36 | #include "utils/graphid.h"
37 | #include "utils/gtype.h"
38 |
39 | /* Convenience macros */
40 | #define DATUM_GET_EDGE(d) ((edge *)PG_DETOAST_DATUM(d))
41 | #define EDGE_GET_DATUM(p) PointerGetDatum(p)
42 | #define AG_GET_ARG_EDGE(x) DATUM_GET_EDGE(PG_GETARG_DATUM(x))
43 | #define AG_RETURN_EDGE(x) PG_RETURN_POINTER(x)
44 |
45 |
46 | typedef uint32 eentry;
47 |
48 |
49 | #define EXTRACT_EDGE_ID(e) \
50 | (*((int64 *)(&((edge *)e)->children[0])))
51 |
52 | #define EXTRACT_EDGE_STARTID(e) \
53 | (*((int64 *)(&((edge *)e)->children[2])))
54 |
55 | #define EXTRACT_EDGE_ENDID(e) \
56 | (*((int64 *)(&((edge *)e)->children[4])))
57 |
58 | #define EXTRACT_EDGE_GRAPH_OID(v) \
59 | (*((Oid *)(&((edge *)v)->children[6])))
60 |
61 |
62 | /*
63 | * An edge, within an gtype Datum.
64 | *
65 | * An array has one child for each element, stored in array order.
66 | */
67 | typedef struct
68 | {
69 | int32 vl_len_;
70 | eentry children[FLEXIBLE_ARRAY_MEMBER];
71 | } edge;
72 |
73 | void append_edge_to_string(StringInfoData *buffer, edge *v);
74 | char *extract_edge_label(edge *v);
75 | gtype *extract_edge_properties(edge *v);
76 | Datum build_edge(PG_FUNCTION_ARGS);
77 | edge *create_edge(graphid id,graphid start_id,graphid end_id, Oid graph_oid, gtype *properties);
78 | int extract_edge_label_length(edge *v);
79 |
80 | #define EDGEOID \
81 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("edge"), ObjectIdGetDatum(postgraph_namespace_id())))
82 |
83 | #define EDGEARRAYOID \
84 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("_edge"), ObjectIdGetDatum(postgraph_namespace_id())))
85 |
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/src/include/utils/global_graph.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef POSTGRAPH_GLOBAL_GRAPH_H
19 | #define POSTGRAPH_GLOBAL_GRAPH_H
20 |
21 | #include "utils/graphid.h"
22 | #include "utils/queue.h"
23 |
24 | typedef struct vertex_entry vertex_entry;
25 | typedef struct edge_entry edge_entry;
26 | typedef struct graph_context graph_context;
27 |
28 | // GRAPH global context functions
29 | graph_context *manage_graph_contexts(char *graph_name, Oid graph_oid);
30 | graph_context *find_graph_context(Oid graph_oid);
31 | bool is_ggctx_invalid(graph_context *ggctx);
32 | // GRAPH retrieval functions
33 | Queue *get_graph_vertices(graph_context *ggctx);
34 | vertex_entry *get_vertex_entry(graph_context *ggctx, graphid vertex_id);
35 | edge_entry *get_edge_entry(graph_context *ggctx, graphid edge_id);
36 | // vertex entry accessor functions
37 | graphid get_vertex_entry_id(vertex_entry *ve);
38 | Queue *get_vertex_entry_edges_in(vertex_entry *ve);
39 | Queue *get_vertex_entry_edges_out(vertex_entry *ve);
40 | Queue *get_vertex_entry_edges_self(vertex_entry *ve);
41 | Oid get_vertex_entry_label_table_oid(vertex_entry *ve);
42 | Datum get_vertex_entry_properties(vertex_entry *ve);
43 | // edge entry accessor functions
44 | graphid get_edge_entry_id(edge_entry *ee);
45 | Oid get_edge_entry_label_table_oid(edge_entry *ee);
46 | Datum get_edge_entry_properties(edge_entry *ee);
47 | graphid get_start_id(edge_entry *ee);
48 | graphid get_end_id(edge_entry *ee);
49 | #endif
50 |
--------------------------------------------------------------------------------
/src/include/utils/graphid.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef AG_GRAPHID_H
19 | #define AG_GRAPHID_H
20 |
21 | #include "postgres.h"
22 |
23 | #include "fmgr.h"
24 | #include "utils/fmgroids.h"
25 | #include "utils/syscache.h"
26 |
27 | #include "catalog/ag_namespace.h"
28 | #include "catalog/pg_type.h"
29 |
30 | typedef int64 graphid;
31 | #define F_GRAPHIDEQ F_INT8EQ
32 |
33 | #define LABEL_ID_MIN 1
34 | #define LABEL_ID_MAX PG_UINT16_MAX
35 | #define INVALID_LABEL_ID 0
36 |
37 | #define label_id_is_valid(id) (id >= LABEL_ID_MIN && id <= LABEL_ID_MAX)
38 |
39 | #define ENTRY_ID_MIN INT64CONST(1)
40 | #define ENTRY_ID_MAX INT64CONST(281474976710655) // 0x0000ffffffffffff
41 | #define INVALID_ENTRY_ID INT64CONST(0)
42 |
43 | #define entry_id_is_valid(id) (id >= ENTRY_ID_MIN && id <= ENTRY_ID_MAX)
44 |
45 | #define ENTRY_ID_BITS (32 + 16)
46 | #define ENTRY_ID_MASK INT64CONST(0x0000ffffffffffff)
47 |
48 | #define DATUM_GET_GRAPHID(d) DatumGetInt64(d)
49 | #define GRAPHID_GET_DATUM(x) Int64GetDatum(x)
50 |
51 | #define AG_GETARG_GRAPHID(a) DATUM_GET_GRAPHID(PG_GETARG_DATUM(a))
52 | #define AG_RETURN_GRAPHID(x) return GRAPHID_GET_DATUM(x)
53 |
54 | // Oid accessors for GRAPHID
55 | #define GRAPHIDOID \
56 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("graphid"), ObjectIdGetDatum(postgraph_namespace_id())))
57 | #define GRAPHIDARRAYOID \
58 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("_graphid"), ObjectIdGetDatum(postgraph_namespace_id())))
59 |
60 |
61 | #define GET_LABEL_ID(id) \
62 | (((uint64)id) >> ENTRY_ID_BITS)
63 |
64 | graphid make_graphid(const int32 label_id, const int64 entry_id);
65 | int32 get_graphid_label_id(const graphid gid);
66 | int64 get_graphid_entry_id(const graphid gid);
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/src/include/utils/graphid_ds.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef POSTGRAPH_GRAPHID_DS_H
19 | #define POSTGRAPH_GRAPHID_DS_H
20 |
21 | #include "utils/graphid.h"
22 |
23 | #define IS_GRAPHID_STACK_EMPTY(queue) \
24 | get_queue_size(queue) == 0
25 | #define PEEK_GRAPHID_STACK(queue) \
26 | (graphid) get_graphid(peek_queue_head(queue))
27 |
28 | /*
29 | * We declare the GRAPHID data structures here, and in this way, so that they
30 | * may be used elsewhere. However, we keep the contents private by defining them
31 | * in graphid_ds.c
32 | */
33 |
34 | /* declare the GraphIdNode */
35 | typedef struct GraphIdNode GraphIdNode;
36 |
37 | /* declare the ListGraphId container */
38 | typedef struct ListGraphId ListGraphId;
39 |
40 | /* GraphIdNode access functions */
41 | GraphIdNode *next_GraphIdNode(GraphIdNode *node);
42 | graphid get_graphid(GraphIdNode *node);
43 |
44 | /* graphid queue functions */
45 | /* create a new ListGraphId queue */
46 | ListGraphId *new_graphid_queue(void);
47 | /* free a ListGraphId queue */
48 | void free_graphid_queue(ListGraphId *queue);
49 | /* push a graphid onto a ListGraphId queue */
50 | void push_graphid_queue(ListGraphId *queue, graphid id);
51 | /* pop (remove) a GraphIdNode from the top of the queue */
52 | graphid pop_graphid_queue(ListGraphId *queue);
53 | /* peek (doesn't remove) at the head entry of a ListGraphId queue */
54 | GraphIdNode *peek_queue_head(ListGraphId *queue);
55 | /* peek (doesn't remove) at the tail entry of a ListGraphId queue */
56 | GraphIdNode *peek_queue_tail(ListGraphId *queue);
57 | /* return the size of a ListGraphId queue */
58 | int64 get_queue_size(ListGraphId *queue);
59 |
60 | /* graphid list functions */
61 | /*
62 | * Helper function to add a graphid to the end of a ListGraphId container.
63 | * If the container is NULL, it creates the container with the entry.
64 | */
65 | ListGraphId *append_graphid(ListGraphId *container, graphid id);
66 | /* free a ListGraphId container */
67 | void free_ListGraphId(ListGraphId *container);
68 | /* return a reference to the head entry of a list */
69 | GraphIdNode *get_list_head(ListGraphId *list);
70 | /* get the size of the passed list */
71 | int64 get_list_size(ListGraphId *list);
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/src/include/utils/gtype_ext.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef AG_GTYPE_EXT_H
19 | #define AG_GTYPE_EXT_H
20 |
21 | #include "postgres.h"
22 |
23 | #include "utils/gtype.h"
24 |
25 | /*
26 | * Function serializes the data into the buffer provided.
27 | * Returns false if the type is not defined. Otherwise, true.
28 | */
29 | bool ag_serialize_extended_type(StringInfo buffer, gtentry *gtentry,
30 | gtype_value *scalar_val);
31 |
32 | /*
33 | * Function deserializes the data from the buffer pointed to by base_addr.
34 | * NOTE: This function writes to the error log and exits for any UNKNOWN
35 | * AGT_HEADER type.
36 | */
37 | void ag_deserialize_extended_type(char *base_addr, uint32 offset,
38 | gtype_value *result);
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/src/include/utils/gtype_temporal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Used to support gtype temporal values.
3 | *
4 | * Copyright (C) 2023 PostGraphDB
5 | *
6 | * This program is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU Affero General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU Affero General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Affero General Public License
17 | * along with this program. If not, see .
18 | */
19 |
20 | #ifndef PGRAPH_GTYPE_TEMPORAL_H
21 | #define PGRAPH_GTYPE_TEMPORAL_H
22 |
23 | #include "utils/timestamp.h"
24 |
25 | int timetz_cmp_internal(TimeTzADT *time1, TimeTzADT *time2);
26 | int interval_cmp_internal(Interval *interval1, Interval *interval2);
27 | //TimestampTz timestamp2timestamptz(Timestamp timestamp);
28 |
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/include/utils/path_finding.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2020-2023, Apache Software Foundation
18 | */
19 |
20 | #ifndef AG_GTYPE_VLE_H
21 | #define AG_GTYPE_VLE_H
22 |
23 | #include "utils/gtype.h"
24 | #include "utils/global_graph.h"
25 |
26 | /*
27 | * We declare the path_container here, and in this way, so that it may be
28 | * used elsewhere. However, we keep the contents private by defining it in
29 | * gtype_vle.c
30 | */
31 | typedef struct path_container path_container;
32 |
33 | /*
34 | * Function to take a AGTV_BINARY path_container and return a path as an
35 | * gtype_value.
36 | */
37 | gtype_value *agtv_materialize_vle_path(gtype *agt_arg_vpc);
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/src/include/utils/queue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | #ifndef POSTGRAPH_GRAPHID_DS_H
19 | #define POSTGRAPH_GRAPHID_DS_H
20 |
21 | #include "utils/graphid.h"
22 |
23 | #define IS_GRAPHID_STACK_EMPTY(queue) \
24 | queue_size(queue) == 0
25 | #define PEEK_GRAPHID_STACK(queue) \
26 | (graphid) get_graphid(peek_queue_head(queue))
27 |
28 | // declare the QueueNode
29 | typedef struct QueueNode QueueNode;
30 |
31 | // declare the Queue container
32 | typedef struct Queue Queue;
33 |
34 | // QueueNode access functions
35 | QueueNode *next_queue_node(QueueNode *queuenode);
36 | graphid get_graphid(QueueNode *queuenode);
37 |
38 | // graphid queue functions
39 | // create a new Queue queue
40 | Queue *new_graphid_queue(void);
41 | // free a Queue queue
42 | void free_graphid_queue(Queue *queue);
43 | // push a graphid onto a Queue queue
44 | void push_graphid_queue(Queue *queue, graphid id);
45 | // pop (remove) a QueueNode from the top of the queue
46 | graphid pop_graphid_queue(Queue *queue);
47 | // peek (doesn't remove) at the head entry of a Queue queue
48 | QueueNode *peek_queue_head(Queue *queue);
49 | // peek (doesn't remove) at the tail entry of a Queue queue
50 | QueueNode *peek_queue_tail(Queue *queue);
51 | // return the size of a Queue queue
52 | int64 queue_size(Queue *queue);
53 |
54 | // graphid list functions
55 | /*
56 | * Helper function to add a graphid to the end of a Queue container.
57 | * If the container is NULL, it creates the container with the entry.
58 | */
59 | Queue *append_graphid(Queue *container, graphid id);
60 | // free a Queue container
61 | void free_queue(Queue *container);
62 | // return a reference to the head entry of a list
63 | QueueNode *get_list_head(Queue *list);
64 | // get the size of the passed list
65 | int64 get_list_size(Queue *list);
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/src/include/utils/traversal.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | */
18 |
19 | /*
20 | * Declarations for gtype data type support.
21 | */
22 |
23 | #ifndef POSTGRAPH_TRAVERSAL_H
24 | #define POSTGRAPH_TRAVERSAL_H
25 |
26 | #include "access/htup_details.h"
27 | #include "fmgr.h"
28 | #include "lib/stringinfo.h"
29 | #include "nodes/pg_list.h"
30 | #include "utils/array.h"
31 | #include "utils/numeric.h"
32 | #include "utils/syscache.h"
33 |
34 | #include "catalog/ag_namespace.h"
35 | #include "catalog/pg_type.h"
36 | #include "utils/graphid.h"
37 |
38 | /* Convenience macros */
39 | #define DATUM_GET_TRAVERSAL(d) ((vertex *)PG_DETOAST_DATUM(d))
40 | #define TRAVERSAL_GET_DATUM(p) PointerGetDatum(p)
41 | #define AG_GET_ARG_TRAVERSAL(x) DATUM_GET_TRAVERSAL(PG_GETARG_DATUM(x))
42 | #define AG_RETURN_TRAVERSAL(x) PG_RETURN_POINTER(x)
43 |
44 | #define TRAVERSAL_GET_FIRST_ENTITY(ptr) \
45 | (&((traversal *)lhs)->children[1])
46 |
47 | typedef uint32 pentry;
48 |
49 | /*
50 | * An vertex, within an gtype Datum.
51 | *
52 | * An array has one child for each element, stored in array order.
53 | */
54 | typedef struct
55 | {
56 | int32 vl_len_; // varlena header (do not touch directly!)
57 | pentry children[FLEXIBLE_ARRAY_MEMBER];
58 | } traversal;
59 |
60 | #define TRAVERSALOID \
61 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("traversal"), ObjectIdGetDatum(postgraph_namespace_id())))
62 |
63 | #define TRAVERSALARRAYOID \
64 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("_traversal"), ObjectIdGetDatum(postgraph_namespace_id())))
65 |
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/src/include/utils/variable_edge.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | */
18 |
19 | /*
20 | * Declarations for gtype data type support.
21 | */
22 |
23 | #ifndef POSTGRAPH_VARIABLE_EDGE_H
24 | #define POSTGRAPH_VARIABLE_EDGE_H
25 |
26 | #include "access/htup_details.h"
27 | #include "fmgr.h"
28 | #include "lib/stringinfo.h"
29 | #include "nodes/pg_list.h"
30 | #include "utils/array.h"
31 | #include "utils/numeric.h"
32 | #include "utils/syscache.h"
33 |
34 | #include "catalog/ag_namespace.h"
35 | #include "catalog/pg_type.h"
36 | #include "utils/graphid.h"
37 |
38 | /* Convenience macros */
39 | #define DATUM_GET_VARIABLE_EDGE(d) ((vertex *)PG_DETOAST_DATUM(d))
40 | #define VARIABLE_EDGE_GET_DATUM(p) PointerGetDatum(p)
41 | #define AG_GET_ARG_VARIABLE_EDGE(x) DATUM_GET_VARIABLE_EDGE(PG_GETARG_DATUM(x))
42 | #define AG_RETURN_VARIABLE_EDGE(x) PG_RETURN_POINTER(x)
43 |
44 |
45 | typedef uint32 prentry;
46 |
47 | /*
48 | * An vertex, within an gtype Datum.
49 | *
50 | * An array has one child for each element, stored in array order.
51 | */
52 | typedef struct
53 | {
54 | int32 vl_len_; // varlena header (do not touch directly!)
55 | prentry children[FLEXIBLE_ARRAY_MEMBER];
56 | } VariableEdge;
57 |
58 | #define VARIABLEEDGEOID \
59 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("variable_edge"), ObjectIdGetDatum(postgraph_namespace_id())))
60 |
61 | #define VARIABLEEDGEARRAYOID \
62 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("_variable_edge"), ObjectIdGetDatum(postgraph_namespace_id())))
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/src/include/utils/vector.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | *
17 | * Portions Copyright (c) 2021-2023, pgvector
18 | */
19 |
20 | #ifndef VECTOR_H
21 | #define VECTOR_H
22 |
23 | #include "postgres.h"
24 |
25 | #include "utils/gtype.h"
26 |
27 | #define VECTOR_MAX_DIM 16000
28 |
29 | #define VECTOR_SIZE(_dim) (sizeof(uint32) + sizeof(uint32) + (_dim * sizeof(float8)) + sizeof(uint32))
30 | #define DatumGetVector(x) ((Vector *) PG_DETOAST_DATUM(x))
31 | /*
32 | typedef struct Vector
33 | {
34 | uint16 dim; // number of dimensions
35 | float8 *x;
36 | } Vector;
37 | */
38 | gtype_value *gtype_vector_in(char *str, int32 typmod);
39 | gtype_value *InitVectorGType(int dim);
40 | gtype_value *gtype_vector_add(gtype *lhs, gtype *rhs);
41 | gtype_value *gtype_vector_sub(gtype *lhs, gtype *rhs);
42 | gtype_value *gtype_vector_mul(gtype *lhs, gtype *rhs);
43 |
44 | static inline Vector *
45 | InitVector(int dim)
46 | {
47 | int size = VECTOR_SIZE(dim);
48 |
49 | Vector *result = (Vector *) palloc0(size);
50 |
51 | result->dim = dim;
52 |
53 | return result;
54 | }
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/src/include/utils/vertex.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 PostGraphDB
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Affero General Public License as
6 | * published by the Free Software Foundation, either version 3 of the
7 | * License, or (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU Affero General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU Affero General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | /*
19 | * Declarations for gtype data type support.
20 | */
21 |
22 | #ifndef AG_VERTEX_H
23 | #define AG_VERTEX_H
24 |
25 | #include "access/htup_details.h"
26 | #include "fmgr.h"
27 | #include "lib/stringinfo.h"
28 | #include "nodes/pg_list.h"
29 | #include "utils/array.h"
30 | #include "utils/numeric.h"
31 | #include "utils/syscache.h"
32 |
33 | #include "catalog/ag_namespace.h"
34 | #include "catalog/pg_type.h"
35 | #include "utils/graphid.h"
36 | #include "utils/gtype.h"
37 |
38 | /* Convenience macros */
39 | #define DATUM_GET_VERTEX(d) ((vertex *)PG_DETOAST_DATUM(d))
40 | #define VERTEX_GET_DATUM(p) PointerGetDatum(p)
41 | #define AG_GET_ARG_VERTEX(x) DATUM_GET_VERTEX(PG_GETARG_DATUM(x))
42 | #define AG_RETURN_VERTEX(x) PG_RETURN_POINTER(x)
43 |
44 |
45 | typedef uint32 ventry;
46 |
47 | #define EXTRACT_VERTEX_ID(v) \
48 | (*((int64 *)(&((vertex *)v)->children[0])))
49 |
50 | #define EXTRACT_VERTEX_GRAPH_OID(v) \
51 | (*((Oid *)(&((vertex *)v)->children[2])))
52 |
53 | /*
54 | * An vertex, within an gtype Datum.
55 | *
56 | * An array has one child for each element, stored in array order.
57 | */
58 | typedef struct
59 | {
60 | int32 vl_len_; // varlena header (do not touch directly!)
61 | ventry children[FLEXIBLE_ARRAY_MEMBER];
62 | } vertex;
63 |
64 | void append_vertex_to_string(StringInfoData *buffer, vertex *v);
65 | char *extract_vertex_label(vertex *v);
66 | gtype *extract_vertex_properties(vertex *v);
67 | Datum build_vertex(PG_FUNCTION_ARGS);
68 | vertex *create_vertex(graphid id, Oid graph_oid, gtype *properties);
69 | int extract_vertex_label_length(vertex *v);
70 |
71 | #define VERTEXOID \
72 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("vertex"), ObjectIdGetDatum(postgraph_namespace_id())))
73 |
74 | #define VERTEXARRAYOID \
75 | (GetSysCacheOid2(TYPENAMENSP, Anum_pg_type_oid, CStringGetDatum("_vertex"), ObjectIdGetDatum(postgraph_namespace_id())))
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/tools/git/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | #
20 | # This script checks the commit log message.
21 |
22 | if [ ! -s "$1" ] || ! grep -v '^#' "$1" | grep -q '[^[:space:]]'; then
23 | echo "Aborting commit due to empty commit message." >&2
24 | exit 1
25 | fi
26 |
27 | # Separate subject from body with a blank line
28 | line2=$(sed '2q;d' "$1")
29 | if [ -n "$line2" ] && echo "$line2" | grep -qv '^#'; then
30 | echo "FAIL: put a blank line to separate subject from body" >&2
31 | head -n 2 "$1" >&2
32 | exit 1
33 | fi
34 |
35 | # Limit the subject line to 50 characters
36 | subject=$(head -n 1 "$1")
37 | subject_len=$(printf "$subject" | wc -m)
38 | if [ $subject_len -gt 72 ]; then
39 | echo "FAIL: subject lines cannot be longer than 72 characters" >&2
40 | echo "$subject" >&2
41 | exit 1
42 | elif [ $subject_len -gt 50 ]; then
43 | echo "Subject lines less than or equal to 50 characters are preferred."
44 | fi
45 |
46 | # Capitalize the subject line
47 | if echo "$subject" | grep -qv '^[[:upper:]]'; then
48 | echo "FAIL: begin the subject line with a capital letter" >&2
49 | echo "$subject" >&2
50 | exit 1
51 | fi
52 |
53 | # Do not end the subject line with a period
54 | if echo "$subject" | grep -q '\.$'; then
55 | echo "FAIL: trailing punctuation is unnecessary in subject lines" >&2
56 | echo "$subject" >&2
57 | exit 1
58 | fi
59 |
60 | # Wrap the body at 72 characters
61 | lines=$(grep -nE '.{73,}' "$1")
62 | if [ -n "$lines" ]; then
63 | echo "FAIL: wrap the body at 72 characters" >&2
64 | echo "$lines" >&2
65 | exit 1
66 | fi
67 |
--------------------------------------------------------------------------------