Skip to content

Commit

Permalink
Merge pull request #69 from cwida/62-complex-patterns
Browse files Browse the repository at this point in the history
62 complex patterns
  • Loading branch information
Dtenwolde authored Jan 18, 2024
2 parents d4c4dbf + 511d2cb commit a751a9b
Show file tree
Hide file tree
Showing 18 changed files with 904 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
# Add commits/tags to build against other DuckDB versions
duckdb_version: [ 'v0.8.1' ]
duckdb_version: [ 'lattest' ]
arch: ['linux_amd64', 'linux_arm64', 'linux_amd64_gcc4']
include:
- arch: 'linux_amd64'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/MacOS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
# Add commits/tags to build against other DuckDB versions
duckdb_version: [ 'v0.8.1' ]
duckdb_version: [ 'latest' ]

env:
OSX_BUILD_UNIVERSAL: 1
Expand All @@ -39,7 +39,7 @@ jobs:
cd duckdb-pgq
git checkout ${{ matrix.duckdb_version }}
# Build extension
# Build extension
- name: Build extension
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
# Add commits/tags to build against other DuckDB versions
duckdb_version: [ 'v0.8.1' ]
duckdb_version: [ 'latest' ]

steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/_extension_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ on:
matrix_parse_script:
required: false
type: string
default: "./duckdb/scripts/modify_distribution_matrix.py"
default: "./duckdb-pgq/scripts/modify_distribution_matrix.py"

jobs:
generate_matrix:
Expand All @@ -63,13 +63,13 @@ jobs:

- name: Checkout DuckDB to version
run: |
cd duckdb
cd duckdb-pgq
git checkout ${{ inputs.duckdb_version }}
- id: parse-matrices
run: |
cat ./duckdb/.github/config/distribution_matrix.json > distribution_matrix.json
grep wasm distribution_matrix.json || (head -n -1 ./duckdb/.github/config/distribution_matrix.json > distribution_matrix.json && echo ',"wasm":{"include":[{"duckdb_arch":"wasm_mvp","vcpkg_triplet":"wasm32-emscripten"},{"duckdb_arch":"wasm_eh","vcpkg_triplet":"wasm32-emscripten"},{"duckdb_arch":"wasm_threads","vcpkg_triplet":"wasm32-emscripten"}]}}' >> distribution_matrix.json)
cat ./duckdb-pgq/.github/config/distribution_matrix.json > distribution_matrix.json
grep wasm distribution_matrix.json || (head -n -1 ./duckdb-pgq/.github/config/distribution_matrix.json > distribution_matrix.json && echo ',"wasm":{"include":[{"duckdb_arch":"wasm_mvp","vcpkg_triplet":"wasm32-emscripten"},{"duckdb_arch":"wasm_eh","vcpkg_triplet":"wasm32-emscripten"},{"duckdb_arch":"wasm_threads","vcpkg_triplet":"wasm32-emscripten"}]}}' >> distribution_matrix.json)
python3 ${{ inputs.matrix_parse_script }} --input distribution_matrix.json --deploy_matrix --output deploy_matrix.json --exclude "${{ inputs.exclude_archs }}" --pretty
deploy_matrix="`cat deploy_matrix.json`"
echo deploy_matrix=$deploy_matrix >> $GITHUB_OUTPUT
Expand All @@ -91,7 +91,7 @@ jobs:

- name: Checkout DuckDB to version
run: |
cd duckdb
cd duckdb-pgq
git checkout ${{ inputs.duckdb_version }}
- uses: actions/download-artifact@v2
Expand All @@ -112,7 +112,7 @@ jobs:
pwd
python3 -m pip install pip awscli
git config --global --add safe.directory '*'
cd duckdb
cd duckdb-pgq
git fetch --tags
export DUCKDB_VERSION=`git tag --points-at HEAD`
export DUCKDB_VERSION=${DUCKDB_VERSION:=`git log -1 --format=%h`}
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = duckdb-pgq
url = [email protected]:cwida/duckdb-pgq.git
branch = master
[submodule "duckdb"]
path = duckdb
url = [email protected]:duckdb/duckdb.git
branch = main
33 changes: 15 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
cmake_minimum_required(VERSION 2.8.12)

# Set extension name here
#<<<<<<< HEAD
#set(TARGET_NAME duckpgq)
# Set extension name here <<<<<<< HEAD set(TARGET_NAME duckpgq)
#
#set(EXTENSION_NAME ${TARGET_NAME}_extension)
#project(${TARGET_NAME})
#set(CMAKE_CXX_STANDARD 11)
# set(EXTENSION_NAME ${TARGET_NAME}_extension) project(${TARGET_NAME})
# set(CMAKE_CXX_STANDARD 11)
#
#include_directories(duckpgq/include)
#add_subdirectory(duckpgq/src)
# include_directories(duckpgq/include) add_subdirectory(duckpgq/src)
#
#include_directories(../duckdb-pgq/third_party/libpg_query/include)
# include_directories(../duckdb-pgq/third_party/libpg_query/include)
#
#add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
# add_library(${EXTENSION_NAME} STATIC ${EXTENSION_SOURCES})
#
#set(PARAMETERS "-warnings")
#build_loadable_extension(${TARGET_NAME} ${PARAMETERS} ${EXTENSION_SOURCES})
#=======
# set(PARAMETERS "-warnings") build_loadable_extension(${TARGET_NAME}
# ${PARAMETERS} ${EXTENSION_SOURCES})
# =======
set(TARGET_NAME duckpgq)
set(CMAKE_CXX_STANDARD 11)
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be added in ./vcpkg.json and then
# used in cmake with find_package. Feel free to remove or replace with other dependencies.
# Note that it should also be removed from vcpkg.json to prevent needlessly installing it..
# DuckDB's extension distribution supports vcpkg. As such, dependencies can be
# added in ./vcpkg.json and then used in cmake with find_package. Feel free to
# remove or replace with other dependencies. Note that it should also be removed
# from vcpkg.json to prevent needlessly installing it..
find_package(OpenSSL REQUIRED)

set(EXTENSION_NAME ${TARGET_NAME}_extension)
Expand All @@ -33,15 +30,15 @@ include_directories(duckpgq/include)
add_subdirectory(duckpgq/src)
include_directories(../duckdb-pgq/third_party/libpg_query/include)

#set(EXTENSION_SOURCES duckpgq/src/duckpgq_extension.cpp)
# set(EXTENSION_SOURCES duckpgq/src/duckpgq_extension.cpp)

build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})

# Link OpenSSL in both the static library as the loadable extension
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto)
#>>>>>>> template/main
# >>>>>>> template/main

install(
TARGETS ${EXTENSION_NAME}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test_release_python: release_python

#### Misc
format:
find src/ -iname *.hpp -o -iname *.cpp | xargs clang-format --sort-includes=0 -style=file -i
find duckpgq/ -iname *.hpp -o -iname *.cpp | xargs clang-format --sort-includes=0 -style=file -i
cmake-format -i CMakeLists.txt
update:
git submodule update --remote --merge
Expand Down
2 changes: 1 addition & 1 deletion duckdb-pgq
73 changes: 54 additions & 19 deletions duckpgq/include/duckpgq/functions/tablefunctions/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
//===----------------------------------------------------------------------===//

#pragma once
#include <duckdb/parser/parsed_data/create_pragma_function_info.hpp>

#include "duckdb/function/table_function.hpp"
#include "duckdb/parser/parsed_data/create_property_graph_info.hpp"
#include "duckdb/parser/path_element.hpp"
#include "duckdb/parser/subpath_element.hpp"
#include "duckdb/parser/path_pattern.hpp"

namespace duckdb {

struct PGQMatchFunction : public TableFunction {
public:
PGQMatchFunction() {
PGQMatchFunction() {
name = "duckpgq_match";
bind_replace = MatchBindReplace;
}

struct MatchBindData : public TableFunctionData {
bool done = false;
};

static shared_ptr<PropertyGraphTable>
FindGraphTable(const string &label, CreatePropertyGraphInfo &pg_table);

static void
CheckInheritance(shared_ptr<PropertyGraphTable> &tableref,
CheckInheritance(const shared_ptr<PropertyGraphTable> &tableref,
PathElement *element,
vector<unique_ptr<ParsedExpression>> &conditions);

Expand All @@ -42,8 +45,7 @@ struct PGQMatchFunction : public TableFunction {
const string &vertex_alias, const string &edge_alias);

static PathElement *
GetPathElement(unique_ptr<PathReference> &path_reference,
vector<unique_ptr<ParsedExpression>> &conditions);
GetPathElement(const unique_ptr<PathReference> &path_reference);

static unique_ptr<SubqueryExpression>
GetCountTable(const shared_ptr<PropertyGraphTable> &edge_table,
Expand All @@ -61,33 +63,35 @@ struct PGQMatchFunction : public TableFunction {
const string &edge_binding, const string &prev_binding,
const string &next_binding);

static void EdgeTypeAny(shared_ptr<PropertyGraphTable> &edge_table,
static void EdgeTypeAny(const shared_ptr<PropertyGraphTable> &edge_table,
const string &edge_binding,
const string &prev_binding,
const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions);

static void EdgeTypeLeft(shared_ptr<PropertyGraphTable> &edge_table,
static void EdgeTypeLeft(const shared_ptr<PropertyGraphTable> &edge_table,
const string &next_table_name,
const string &prev_table_name,
const string &edge_binding,
const string &prev_binding,
const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions);

static void EdgeTypeRight(shared_ptr<PropertyGraphTable> &edge_table,
static void EdgeTypeRight(const shared_ptr<PropertyGraphTable> &edge_table,
const string &next_table_name,
const string &prev_table_name,
const string &edge_binding,
const string &prev_binding,
const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions);

static void EdgeTypeLeftRight(
shared_ptr<PropertyGraphTable> &edge_table, const string &edge_binding,
const string &prev_binding, const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions,
unordered_map<string, string> &alias_map, int32_t &extra_alias_counter);
static void
EdgeTypeLeftRight(const shared_ptr<PropertyGraphTable> &edge_table,
const string &edge_binding, const string &prev_binding,
const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions,
unordered_map<string, string> &alias_map,
int32_t &extra_alias_counter);

static PathElement *
HandleNestedSubPath(unique_ptr<PathReference> &path_reference,
Expand All @@ -102,10 +106,41 @@ struct PGQMatchFunction : public TableFunction {
vector<unique_ptr<ParsedExpression>> &column_list,
unordered_set<string> &named_subpaths);

static unique_ptr<FunctionExpression>
CreatePathFindingFunction(const string &prev_binding,
const string &next_binding,
shared_ptr<PropertyGraphTable> &edge_table,
const string &path_finding_udf);
static unique_ptr<ParsedExpression>
CreatePathFindingFunction(vector<unique_ptr<PathReference>> &path_list,
CreatePropertyGraphInfo &pg_table);

static void AddPathFinding(const unique_ptr<SelectNode> &select_node,
unique_ptr<TableRef> &from_clause,
vector<unique_ptr<ParsedExpression>> &conditions,
const string &prev_binding,
const string &edge_binding,
const string &next_binding,
const shared_ptr<PropertyGraphTable> &edge_table,
const SubPath *subpath);

static void
AddEdgeJoins(const unique_ptr<SelectNode> &select_node,
const shared_ptr<PropertyGraphTable> &edge_table,
const shared_ptr<PropertyGraphTable> &previous_vertex_table,
const shared_ptr<PropertyGraphTable> &next_vertex_table,
PGQMatchType edge_type, const string &edge_binding,
const string &prev_binding, const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions,
unordered_map<string, string> &alias_map,
int32_t &extra_alias_counter);

static void ProcessPathList(
vector<unique_ptr<PathReference>> &path_pattern,
vector<unique_ptr<ParsedExpression>> &conditions,
unique_ptr<TableRef> &from_clause, unique_ptr<SelectNode> &select_node,
unordered_map<string, string> &alias_map,
CreatePropertyGraphInfo &pg_table, int32_t &extra_alias_counter,
vector<unique_ptr<ParsedExpression>> &column_list);

static void
CheckNamedSubpath(SubPath &subpath,
vector<unique_ptr<ParsedExpression>> &column_list,
CreatePropertyGraphInfo &pg_table);
};
} // namespace duckdb
} // namespace duckdb
4 changes: 2 additions & 2 deletions duckpgq/include/duckpgq/functions/tablefunctions/pgq_scan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ struct CSRScanPtrData : public TableFunctionData {
public:
static unique_ptr<FunctionData>
ScanCSRPtrBind(ClientContext &context, TableFunctionBindInput &input,
vector<LogicalType> &return_types, vector<string> &names) {
vector<LogicalType> &return_types, vector<string> &names) {
auto result = make_uniq<CSRScanPtrData>();
result->csr_id = input.inputs[0].GetValue<int32_t>();
return_types.emplace_back(LogicalType::UBIGINT);
names.emplace_back("ptr");
return std::move(result);
}
}

public:
int32_t csr_id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind(
CheckPropertyGraphTableLabels(vertex_table, table);

v_table_names.insert(vertex_table->table_name);
if (vertex_table->hasTableNameAlias()) {
v_table_names.insert(vertex_table->table_name_alias);
}
if (vertex_table->hasTableNameAlias()) {
v_table_names.insert(vertex_table->table_name_alias);
}
}

for (auto &edge_table : info->edge_tables) {
Expand Down
Loading

0 comments on commit a751a9b

Please sign in to comment.