Skip to content

Commit

Permalink
Add check for subquery ref and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Jan 19, 2025
1 parent 4697869 commit 80dcaa4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/parser/duckpgq_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <duckpgq/core/functions/table/describe_property_graph.hpp>
#include <duckpgq/core/functions/table/drop_property_graph.hpp>
#include "duckdb/parser/query_node/cte_node.hpp"
#include "duckdb/parser/tableref/subqueryref.hpp"

namespace duckpgq {

Expand All @@ -34,6 +35,9 @@ ParserExtensionParseResult duckpgq_parse(ParserExtensionInfo *info,
std::move(parser.statements[0])));
}

ParserExtensionPlanResult
duckpgq_handle_statement(SQLStatement *statement, DuckPGQState &duckpgq_state);

void duckpgq_find_match_function(TableRef *table_ref,
DuckPGQState &duckpgq_state) {
if (auto table_function_ref = dynamic_cast<TableFunctionRef *>(table_ref)) {
Expand All @@ -54,6 +58,9 @@ void duckpgq_find_match_function(TableRef *table_ref,
// Handle JoinRef case
duckpgq_find_match_function(join_ref->left.get(), duckpgq_state);
duckpgq_find_match_function(join_ref->right.get(), duckpgq_state);
} else if (auto subquery_ref = dynamic_cast<SubqueryRef *>(table_ref)) {
// Handle SubqueryRef case
duckpgq_handle_statement(subquery_ref->subquery.get(), duckpgq_state);
}
}

Expand Down
32 changes: 32 additions & 0 deletions test/sql/nested_subquery.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


require duckpgq

statement ok
CREATE TABLE Student(id BIGINT, name VARCHAR);INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Peter'), (4, 'David');

statement ok
CREATE TABLE know(src BIGINT, dst BIGINT, createDate BIGINT);INSERT INTO know VALUES (0,1, 10), (0,2, 11), (0,3, 12), (3,0, 13), (1,2, 14), (1,3, 15), (2,3, 16), (4,3, 17);

statement ok
CREATE TABLE School(name VARCHAR, Id BIGINT, Kind VARCHAR);INSERT INTO School VALUES ('VU', 0, 'University'), ('UVA', 1, 'University');

statement ok
CREATE TABLE StudyAt(personId BIGINT, schoolId BIGINT);INSERT INTO StudyAt VALUES (0, 0), (1, 0), (2, 1), (3, 1), (4, 1);

statement ok
-CREATE PROPERTY GRAPH pg
VERTEX TABLES (
Student PROPERTIES ( id, name ) LABEL Person,
School LABEL SCHOOL
)
EDGE TABLES (
know SOURCE KEY ( src ) REFERENCES Student ( id )
DESTINATION KEY ( dst ) REFERENCES Student ( id ),
studyAt SOURCE KEY ( personId ) REFERENCES Student ( id )
DESTINATION KEY ( SchoolId ) REFERENCES School ( id )
);


statement ok
-select * from (select id, id_1 from graph_table ( pg match (p:person)-[k:know]->(p2:person) columns (p.id, p2.id)));

0 comments on commit 80dcaa4

Please sign in to comment.