Skip to content

Commit

Permalink
Creating a table from a graph_table works
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Jan 19, 2024
1 parent f54cd95 commit a7dfd00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 13 additions & 5 deletions duckpgq/src/duckpgq_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "duckdb/parser/parsed_data/create_table_function_info.hpp"
#include "duckdb/parser/query_node/select_node.hpp"
#include "duckdb/parser/statement/copy_statement.hpp"
#include "duckdb/parser/parsed_data/create_table_info.hpp"

#include "duckdb/parser/statement/extension_statement.hpp"

#include "duckpgq/functions/tablefunctions/drop_property_graph.hpp"
Expand Down Expand Up @@ -120,11 +122,17 @@ ParserExtensionPlanResult duckpgq_handle_statement(SQLStatement *statement, Duck
throw Exception("use duckpgq_bind instead");
}
if (statement->type == StatementType::CREATE_STATEMENT) {
ParserExtensionPlanResult result;
result.function = CreatePropertyGraphFunction();
result.requires_valid_transaction = true;
result.return_type = StatementReturnType::QUERY_RESULT;
return result;
auto &create_statement = statement->Cast<CreateStatement>();
auto create_property_graph = dynamic_cast<CreatePropertyGraphInfo*>(create_statement.info.get());
if (create_property_graph) {
ParserExtensionPlanResult result;
result.function = CreatePropertyGraphFunction();
result.requires_valid_transaction = true;
result.return_type = StatementReturnType::QUERY_RESULT;
return result;
}
auto create_table = reinterpret_cast<CreateTableInfo*>(create_statement.info.get());
duckpgq_handle_statement(create_table->query.get(), duckpgq_state);
}
if (statement->type == StatementType::DROP_STATEMENT) {
ParserExtensionPlanResult result;
Expand Down
13 changes: 12 additions & 1 deletion test/sql/copy_to_duckpgq.test
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ statement ok
COLUMNS(a.firstName, a.lastName, a.birthday, a.locationIP, a.browserUsed, a.LocationCityId, a.gender, a.creationDate)
) tmp) TO '__TEST_DIR__/is1.csv' (HEADER FALSE);

query IIIIIII
query IIIIIIII
SELECT * FROM '__TEST_DIR__/is1.csv';
----
Ali Abouba 1987-05-29 41.203.147.168 Internet Explorer 1264 male 2011-05-12 02:46:47.595

statement ok
-CREATE TABLE result as (FROM GRAPH_TABLE (snb
MATCH (a is person where a.id = 17592186044461)
COLUMNS(a.firstName, a.lastName, a.birthday, a.locationIP, a.browserUsed, a.LocationCityId, a.gender, a.creationDate)
) tmp);

query IIIIIIII
SELECT * FROM result;
----
Ali Abouba 1987-05-29 41.203.147.168 Internet Explorer 1264 male 2011-05-12 02:46:47.595+00

0 comments on commit a7dfd00

Please sign in to comment.