Skip to content

Commit

Permalink
Merge pull request #64 from cwida/58-fix-test-cases-with-092-update
Browse files Browse the repository at this point in the history
58 fix test cases with 092 update
  • Loading branch information
Dtenwolde authored Dec 12, 2023
2 parents f642fb4 + 95afcf0 commit d4c4dbf
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 65 deletions.
4 changes: 2 additions & 2 deletions duckpgq/include/duckpgq/functions/tablefunctions/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

namespace duckdb {

struct MatchFunction : public TableFunction {
struct PGQMatchFunction : public TableFunction {
public:
MatchFunction() {
PGQMatchFunction() {
name = "duckpgq_match";
bind_replace = MatchBindReplace;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +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);
}
}

for (auto &edge_table : info->edge_tables) {
Expand Down
55 changes: 30 additions & 25 deletions duckpgq/src/duckpgq/functions/tablefunctions/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
namespace duckdb {

shared_ptr<PropertyGraphTable>
MatchFunction::FindGraphTable(const string &label,
PGQMatchFunction::FindGraphTable(const string &label,
CreatePropertyGraphInfo &pg_table) {
auto graph_table_entry = pg_table.label_map.find(label);
if (graph_table_entry == pg_table.label_map.end()) {
Expand All @@ -39,7 +39,7 @@ MatchFunction::FindGraphTable(const string &label,
return graph_table_entry->second;
}

void MatchFunction::CheckInheritance(
void PGQMatchFunction::CheckInheritance(
shared_ptr<PropertyGraphTable> &tableref, PathElement *element,
vector<unique_ptr<ParsedExpression>> &conditions) {
if (tableref->main_label == element->label) {
Expand Down Expand Up @@ -79,7 +79,7 @@ void MatchFunction::CheckInheritance(
conditions.push_back(std::move(subset_compare));
}

void MatchFunction::CheckEdgeTableConstraints(
void PGQMatchFunction::CheckEdgeTableConstraints(
const string &src_reference, const string &dst_reference,
const shared_ptr<PropertyGraphTable> &edge_table) {
if (src_reference != edge_table->source_reference) {
Expand All @@ -94,7 +94,7 @@ void MatchFunction::CheckEdgeTableConstraints(
}
}

unique_ptr<ParsedExpression> MatchFunction::CreateMatchJoinExpression(
unique_ptr<ParsedExpression> PGQMatchFunction::CreateMatchJoinExpression(
vector<string> vertex_keys, vector<string> edge_keys,
const string &vertex_alias, const string &edge_alias) {
vector<unique_ptr<ParsedExpression>> conditions;
Expand Down Expand Up @@ -125,7 +125,7 @@ unique_ptr<ParsedExpression> MatchFunction::CreateMatchJoinExpression(
return where_clause;
}

PathElement *MatchFunction::GetPathElement(
PathElement *PGQMatchFunction::GetPathElement(
unique_ptr<PathReference> &path_reference,
vector<unique_ptr<ParsedExpression>> &conditions) {
if (path_reference->path_reference_type ==
Expand All @@ -151,7 +151,7 @@ PathElement *MatchFunction::GetPathElement(
}

unique_ptr<SubqueryExpression>
MatchFunction::GetCountTable(const shared_ptr<PropertyGraphTable> &edge_table,
PGQMatchFunction::GetCountTable(const shared_ptr<PropertyGraphTable> &edge_table,
const string &prev_binding) {
// SELECT count(s.id) FROM src s
auto select_count = make_uniq<SelectStatement>();
Expand All @@ -176,7 +176,7 @@ MatchFunction::GetCountTable(const shared_ptr<PropertyGraphTable> &edge_table,
}

unique_ptr<JoinRef>
MatchFunction::GetJoinRef(const shared_ptr<PropertyGraphTable> &edge_table,
PGQMatchFunction::GetJoinRef(const shared_ptr<PropertyGraphTable> &edge_table,
const string &edge_binding,
const string &prev_binding,
const string &next_binding) {
Expand Down Expand Up @@ -217,7 +217,7 @@ MatchFunction::GetJoinRef(const shared_ptr<PropertyGraphTable> &edge_table,
return first_join_ref;
}

unique_ptr<SubqueryRef> MatchFunction::CreateCountCTESubquery() {
unique_ptr<SubqueryRef> PGQMatchFunction::CreateCountCTESubquery() {
//! BEGIN OF (SELECT count(cte1.temp) as temp * 0 from cte1) __x

auto temp_cte_select_node = make_uniq<SelectNode>();
Expand Down Expand Up @@ -252,7 +252,7 @@ unique_ptr<SubqueryRef> MatchFunction::CreateCountCTESubquery() {
}

unique_ptr<CommonTableExpressionInfo>
MatchFunction::CreateCSRCTE(const shared_ptr<PropertyGraphTable> &edge_table,
PGQMatchFunction::CreateCSRCTE(const shared_ptr<PropertyGraphTable> &edge_table,
const string &edge_binding,
const string &prev_binding,
const string &next_binding) {
Expand Down Expand Up @@ -375,37 +375,42 @@ MatchFunction::CreateCSRCTE(const shared_ptr<PropertyGraphTable> &edge_table,
return info;
}

void MatchFunction::EdgeTypeAny(
void PGQMatchFunction::EdgeTypeAny(
shared_ptr<PropertyGraphTable> &edge_table, const string &edge_binding,
const string &prev_binding, const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions) {
// (a) src.key = edge.src
auto src_left_expr = CreateMatchJoinExpression(
edge_table->source_pk, edge_table->source_fk, prev_binding, edge_binding);
auto dst_left_expr = CreateMatchJoinExpression(edge_table->destination_pk,
edge_table->destination_fk,
next_binding, edge_binding);

edge_table->source_pk, edge_table->source_fk,
prev_binding, edge_binding);
// (b) dst.key = edge.dst
auto dst_left_expr = CreateMatchJoinExpression(
edge_table->destination_pk,edge_table->destination_fk,
next_binding, edge_binding);
// (a) AND (b)
auto combined_left_expr = make_uniq<ConjunctionExpression>(
ExpressionType::CONJUNCTION_AND, std::move(src_left_expr),
std::move(dst_left_expr));

// (c) src.key = edge.dst
auto src_right_expr = CreateMatchJoinExpression(edge_table->source_pk,
edge_table->destination_fk,
prev_binding, edge_binding);
// (d) dst.key = edge.src
auto dst_right_expr = CreateMatchJoinExpression(edge_table->destination_pk,
edge_table->source_fk,
next_binding, edge_binding);
// (c) AND (d)
auto combined_right_expr = make_uniq<ConjunctionExpression>(
ExpressionType::CONJUNCTION_AND, std::move(src_right_expr),
std::move(dst_right_expr));

// ((a) AND (b)) OR ((c) AND (d))
auto combined_expr = make_uniq<ConjunctionExpression>(
ExpressionType::CONJUNCTION_OR, std::move(combined_left_expr),
std::move(combined_right_expr));
conditions.push_back(std::move(combined_expr));
}

void MatchFunction::EdgeTypeLeft(
void PGQMatchFunction::EdgeTypeLeft(
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,
Expand All @@ -419,7 +424,7 @@ void MatchFunction::EdgeTypeLeft(
prev_binding, edge_binding));
}

void MatchFunction::EdgeTypeRight(
void PGQMatchFunction::EdgeTypeRight(
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,
Expand All @@ -433,7 +438,7 @@ void MatchFunction::EdgeTypeRight(
next_binding, edge_binding));
}

void MatchFunction::EdgeTypeLeftRight(
void PGQMatchFunction::EdgeTypeLeftRight(
shared_ptr<PropertyGraphTable> &edge_table, const string &edge_binding,
const string &prev_binding, const string &next_binding,
vector<unique_ptr<ParsedExpression>> &conditions,
Expand Down Expand Up @@ -470,7 +475,7 @@ void MatchFunction::EdgeTypeLeftRight(
conditions.push_back(std::move(combined_expr));
}

PathElement *MatchFunction::HandleNestedSubPath(
PathElement *PGQMatchFunction::HandleNestedSubPath(
unique_ptr<PathReference> &path_reference,
vector<unique_ptr<ParsedExpression>> &conditions, idx_t element_idx) {
auto subpath = reinterpret_cast<SubPath *>(path_reference.get());
Expand All @@ -492,7 +497,7 @@ CreateWhereClause(vector<unique_ptr<ParsedExpression>> &conditions) {
return where_clause;
}

unique_ptr<FunctionExpression> MatchFunction::CreatePathFindingFunction(
unique_ptr<FunctionExpression> PGQMatchFunction::CreatePathFindingFunction(
const string &prev_binding, const string &next_binding,
shared_ptr<PropertyGraphTable> &edge_table,
const string &path_finding_udf) {
Expand All @@ -511,9 +516,9 @@ unique_ptr<FunctionExpression> MatchFunction::CreatePathFindingFunction(
std::move(pathfinding_children));
}

unique_ptr<TableRef> MatchFunction::MatchBindReplace(ClientContext &context,
unique_ptr<TableRef> PGQMatchFunction::MatchBindReplace(ClientContext &context,
TableFunctionBindInput &) {
auto data = make_uniq<MatchFunction::MatchBindData>();
auto data = make_uniq<PGQMatchFunction::MatchBindData>();
auto duckpgq_state_entry = context.registered_state.find("duckpgq");
auto duckpgq_state = (DuckPGQState *)duckpgq_state_entry->second.get();

Expand Down Expand Up @@ -821,7 +826,7 @@ unique_ptr<TableRef> MatchFunction::MatchBindReplace(ClientContext &context,
return std::move(result);
}

unique_ptr<SubqueryRef> MatchFunction::GenerateSubpathPatternSubquery(
unique_ptr<SubqueryRef> PGQMatchFunction::GenerateSubpathPatternSubquery(
unique_ptr<PathPattern> &path_pattern, CreatePropertyGraphInfo *pg_table,
vector<unique_ptr<ParsedExpression>> &column_list,
unordered_set<string> &named_subpaths) {
Expand Down
3 changes: 1 addition & 2 deletions duckpgq/src/duckpgq_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ inline void DuckpgqScalarFun(DataChunk &args, ExpressionState &state,
name_vector, result, args.size(), [&](string_t name) {
return StringVector::AddString(result,
"Duckpgq " + name.GetString() + " 🐥");
;
});
}

Expand All @@ -42,7 +41,7 @@ static void LoadInternal(DatabaseInstance &instance) {

auto &catalog = Catalog::GetSystemCatalog(*con.context);

MatchFunction match_pg_function;
PGQMatchFunction match_pg_function;
CreateTableFunctionInfo match_pg_info(match_pg_function);
catalog.CreateTableFunction(*con.context, match_pg_info);

Expand Down
2 changes: 1 addition & 1 deletion test/sql/create_pg/create_property_graph.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Pet
statement ok
INSERT INTO know VALUES (0,1, 10), (0,2, 11), (0,3, 12), (1,2, 14), (1,3, 15), (2,3, 16);

# vertex table with alias
# Vertex table with alias
statement ok
-CREATE PROPERTY GRAPH pg
VERTEX TABLES (
Expand Down
8 changes: 4 additions & 4 deletions test/sql/duckpgq.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ SELECT duckpgq('Sam');
----
Duckpgq Sam 🐥

query I
SELECT duckpgq_openssl_version('Michael');
----
<REGEX>:Duckpgq Michael, my linked OpenSSL version is OpenSSL.*
#query I
#SELECT duckpgq_openssl_version('Michael');
#----
#<REGEX>:Duckpgq Michael, my linked OpenSSL version is OpenSSL.*
5 changes: 4 additions & 1 deletion test/sql/explain_duckpgq.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ statement ok
import database 'duckdb-pgq/data/SNB0.003'

#IC 2
statement ok
# EXPLAIN queries are not yet supported (https://github.com/cwida/duckpgq-extension/issues/61)
statement error
-EXPLAIN FROM GRAPH_TABLE (snb
MATCH (a:Person WHERE a.id = 17592186044461)-[k:knows]-(b:Person)<-[au:hasAuthor]-(m:message WHERE m.creationDate < '2010-10-16')
COLUMNS (a.id, a.firstName, a.lastName, m.id as messageId, coalesce(m.imageFile, m.content), m.creationDate)
) tmp
ORDER BY creationDate DESC, Messageid ASC
LIMIT 20
----
Binder Error: Unknown DuckPGQ query encountered
23 changes: 12 additions & 11 deletions test/sql/path-finding/shortest_path.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,25 @@ query IIII
MATCH
p = ANY SHORTEST (a:Person)-[k:knows]->{1,3}(b:Person)
COLUMNS (path_length(p), p, a.name as name, b.name as b_name)
) study;
) study
order by study.name, study.b_name;
----
1 [0, 0, 1] Daniel Tavneet
1 [0, 1, 2] Daniel Gabor
1 [0, 2, 3] Daniel Peter
2 [1, 5, 3, 3, 0] Tavneet Daniel
1 [1, 4, 2] Tavneet Gabor
1 [1, 5, 3] Tavneet Peter
1 [0, 0, 1] Daniel Tavneet
2 [4, 7, 3, 3, 0] David Daniel
3 [4, 7, 3, 3, 0, 1, 2] David Gabor
1 [4, 7, 3] David Peter
3 [4, 7, 3, 3, 0, 0, 1] David Tavneet
2 [2, 6, 3, 3, 0] Gabor Daniel
3 [2, 6, 3, 3, 0, 0, 1] Gabor Tavneet
1 [2, 6, 3] Gabor Peter
3 [2, 6, 3, 3, 0, 0, 1] Gabor Tavneet
1 [3, 3, 0] Peter Daniel
2 [3, 3, 0, 0, 1] Peter Tavneet
2 [3, 3, 0, 1, 2] Peter Gabor
2 [4, 7, 3, 3, 0] David Daniel
3 [4, 7, 3, 3, 0, 0, 1] David Tavneet
3 [4, 7, 3, 3, 0, 1, 2] David Gabor
1 [4, 7, 3] David Peter
2 [3, 3, 0, 0, 1] Peter Tavneet
2 [1, 5, 3, 3, 0] Tavneet Daniel
1 [1, 4, 2] Tavneet Gabor
1 [1, 5, 3] Tavneet Peter


statement error
Expand Down
34 changes: 18 additions & 16 deletions test/sql/pattern-matching/basic_match.test
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,21 @@ Peter Tavneet
Peter Gabor
Peter David

query II
-SELECT study.a_name, study.b_name
FROM GRAPH_TABLE (pg
MATCH
(a:Person)-[k:Knows]-(b:Person)
WHERE a.name = 'Peter'
COLUMNS (a.name as a_name, b.name as b_name)
) study;
----
Peter Daniel
Peter Tavneet
Peter Gabor
Peter David
# Disabled, see https://github.com/cwida/duckpgq-extension/issues/60
#query II
#-SELECT study.a_name, study.b_name
#FROM GRAPH_TABLE (pg
# MATCH
# (a:Person)-[k:Knows]-(b:Person)
# WHERE a.name = 'Peter'
# COLUMNS (a.name as a_name, b.name as b_name)
# ) study
# ORDER BY a_name, b_name;
#----
#Peter Daniel
#Peter David
#Peter Gabor
#Peter Tavneet

query II
-SELECT study.a_name, study.b_name
Expand All @@ -165,13 +167,13 @@ FROM GRAPH_TABLE (pg
COLUMNS (a.name as a_name, b.name as b_name)
) study
GROUP BY study.a_name
ORDER BY count(study.b_name) DESC;
ORDER BY count(study.b_name) DESC, study.a_name;
----
Daniel 3
Tavneet 2
Peter 1
Gabor 1
David 1
Gabor 1
Peter 1

query III
-SELECT study.a_name, study.b_name, study.c_name
Expand Down
4 changes: 2 additions & 2 deletions test/sql/snb/snb.test
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,5 @@ query IIIII
COLUMNS (c.id,c.content,c.creationDate, replyAuthor.id % 10, replyAuthor.firstName || replyAuthor.lastName)
) tmp;
----
962072674306 thanks 2012-07-08 20:32:03.239+00 24189255811081 AlimGuliyev
962072674305 yes 2012-07-08 23:48:41.63+00 24189255811081 AlimGuliyev
962072674305 yes 2012-07-08 23:48:41.63+00 1 AlimGuliyev
962072674306 thanks 2012-07-08 20:32:03.239+00 1 AlimGuliyev

0 comments on commit d4c4dbf

Please sign in to comment.