Skip to content

Commit

Permalink
Merge pull request #194 from cwida/56-make-columns-clause-optional
Browse files Browse the repository at this point in the history
56 make columns clause optional
  • Loading branch information
Dtenwolde authored Mar 4, 2024
2 parents f0a7160 + bb9b820 commit e55aa6d
Show file tree
Hide file tree
Showing 12 changed files with 16,167 additions and 16,134 deletions.
10 changes: 9 additions & 1 deletion scripts/generate_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def get_file_contents(fpath, add_line_numbers=False):
exit(1)
pgq_unreserved_dict[pur] = True


def add_to_other_keywords(kw, list_name):
global unreserved_dict
global pgq_unreserved_dict
Expand All @@ -226,6 +227,7 @@ def add_to_other_keywords(kw, list_name):
exit(1)
other_dict[kw] = True


for cr in colname_keywords:
add_to_other_keywords(cr, "colname")

Expand All @@ -241,7 +243,12 @@ def add_to_other_keywords(kw, list_name):
type_func_name_keywords = list(type_func_name_dict.keys())
type_func_name_keywords.sort()

all_keywords = list(reserved_dict.keys()) + list(unreserved_dict.keys()) + list(pgq_unreserved_dict.keys()) + list(other_dict.keys())
all_keywords = (
list(reserved_dict.keys())
+ list(unreserved_dict.keys())
+ list(pgq_unreserved_dict.keys())
+ list(other_dict.keys())
)
all_keywords.sort()

other_keyword = list(other_dict.keys())
Expand All @@ -258,6 +265,7 @@ def add_to_other_keywords(kw, list_name):
kw_definitions += "pgq_col_name_keyword: " + " | ".join(pgq_colname_keywords) + "\n"
text = text.replace("{{{ KEYWORD_DEFINITIONS }}}", kw_definitions)


# types
def concat_dir(dname, extension, add_line_numbers=False):
result = ""
Expand Down
1 change: 0 additions & 1 deletion src/include/duckdb/parser/property_graph_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ class PropertyGraphTable {
bool hasTableNameAlias() {
return !table_name_alias.empty();
}

};
} // namespace duckdb
5 changes: 3 additions & 2 deletions src/include/duckdb/parser/transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,14 @@ class Transformer {
//! Transform a node/edge table create (SQL/PGQ)
shared_ptr<PropertyGraphTable> TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable *node,
case_insensitive_set_t &global_label_set,
case_insensitive_map_t<string> &table_alias_map);
case_insensitive_map_t<string> &table_alias_map);
//! Transform a path pattern (SQL/PGQ)
unique_ptr<PathPattern> TransformPath(duckdb_libpgquery::PGPathPattern *root);
//! Transform a path element (SQL/PGQ)
static unique_ptr<PathElement> TransformPathElement(duckdb_libpgquery::PGPathElement *element);
//! Transform a subpath (SQL/PGQ)
unique_ptr<SubPath> TransformSubPathElement(duckdb_libpgquery::PGSubPath *element, unique_ptr<PathPattern> &path_pattern);
unique_ptr<SubPath> TransformSubPathElement(duckdb_libpgquery::PGSubPath *element,
unique_ptr<PathPattern> &path_pattern);

//! Transform a Postgres duckdb_libpgquery::T_PGDropPropertyGraphStmt node into a Drop[Table,Schema]Statement
unique_ptr<SQLStatement> TransformDropPropertyGraph(duckdb_libpgquery::PGDropPropertyGraphStmt &node);
Expand Down
8 changes: 4 additions & 4 deletions src/optimizer/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ unique_ptr<LogicalOperator> Optimizer::Optimize(unique_ptr<LogicalOperator> plan
});

// compress data based on statistics for materializing operators
// RunOptimizer(OptimizerType::COMPRESSED_MATERIALIZATION, [&]() {
// CompressedMaterialization compressed_materialization(context, binder, std::move(statistics_map));
// compressed_materialization.Compress(plan);
// });
// RunOptimizer(OptimizerType::COMPRESSED_MATERIALIZATION, [&]() {
// CompressedMaterialization compressed_materialization(context, binder, std::move(statistics_map));
// compressed_materialization.Compress(plan);
// });

// transform ORDER BY + LIMIT to TopN
RunOptimizer(OptimizerType::TOP_N, [&]() {
Expand Down
13 changes: 5 additions & 8 deletions src/parser/parsed_data/create_property_graph_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ unique_ptr<CreateInfo> CreatePropertyGraphInfo::Copy() const {
void CreatePropertyGraphInfo::Serialize(Serializer &serializer) const {
serializer.WriteProperty<string>(100, "property_graph_name", property_graph_name);
serializer.WriteList(101, "vertex_tables", vertex_tables.size(), [&](Serializer::List &list, idx_t i) {
auto &entry = vertex_tables[i];
list.WriteObject([&](Serializer &obj) { entry->Serialize(obj);
});
auto &entry = vertex_tables[i];
list.WriteObject([&](Serializer &obj) { entry->Serialize(obj); });
});
serializer.WriteList(102, "edge_tables", edge_tables.size(), [&](Serializer::List &list, idx_t i) {
auto &entry = edge_tables[i];
list.WriteObject([&](Serializer &obj) { entry->Serialize(obj); });
auto &entry = edge_tables[i];
list.WriteObject([&](Serializer &obj) { entry->Serialize(obj); });
});
serializer.WriteProperty(103, "label_map", label_map);
}
Expand All @@ -55,9 +54,7 @@ unique_ptr<CreateInfo> CreatePropertyGraphInfo::Deserialize(Deserializer &deseri
deserializer.ReadProperty<string>(100, "property_graph_name", result->property_graph_name);

deserializer.ReadList(101, "vertex_tables", [&](Deserializer::List &list, idx_t i) {
list.ReadObject([&](Deserializer &obj) {
result->vertex_tables[i]->Deserialize(obj);
});
list.ReadObject([&](Deserializer &obj) { result->vertex_tables[i]->Deserialize(obj); });
});

deserializer.ReadProperty(103, "label_map", result->label_map);
Expand Down
7 changes: 2 additions & 5 deletions src/parser/property_graph_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ void PropertyGraphTable::Serialize(Serializer &serializer) const {
}
}


shared_ptr<PropertyGraphTable> PropertyGraphTable::Deserialize(Deserializer &deserializer) {
auto pg_table = make_shared<PropertyGraphTable>();
deserializer.ReadProperty(100, "table_name", pg_table->table_name);
Expand Down Expand Up @@ -301,9 +300,7 @@ shared_ptr<PropertyGraphTable> PropertyGraphTable::Copy() const {

} // namespace duckdb



//void PropertyGraphTable::Serialize(Serializer &serializer) const {
// void PropertyGraphTable::Serialize(Serializer &serializer) const {
// FieldWriter writer(serializer);
// writer.WriteString(table_name);
//
Expand All @@ -326,4 +323,4 @@ shared_ptr<PropertyGraphTable> PropertyGraphTable::Copy() const {
// writer.WriteString(destination_reference);
// }
// writer.Finalize();
//}
//}
1 change: 0 additions & 1 deletion src/parser/subpath_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ string SubPath::ToString() const {
default:
throw InternalException("Unknown PathReferenceType found.");
}

}
if (lower != upper) {
result += "{" + std::to_string(lower) + "," + std::to_string(upper) + "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace duckdb {
shared_ptr<PropertyGraphTable>
Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable *graph_table,
case_insensitive_set_t &global_label_set,
case_insensitive_map_t<string> &table_alias_map) {
case_insensitive_map_t<string> &table_alias_map) {
vector<string> column_names;
vector<string> except_list;
case_insensitive_set_t label_set;
Expand Down Expand Up @@ -68,8 +68,7 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
label_names.emplace_back(label_str);
}

auto pg_table = make_shared<PropertyGraphTable>(graph_table_name, table_name_alias,
column_names, label_names);
auto pg_table = make_shared<PropertyGraphTable>(graph_table_name, table_name_alias, column_names, label_names);

pg_table->is_vertex_table = graph_table->is_vertex_table;
pg_table->except_columns = std::move(except_list);
Expand Down
16 changes: 6 additions & 10 deletions src/parser/transform/tableref/transform_match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ unique_ptr<PathElement> Transformer::TransformPathElement(duckdb_libpgquery::PGP
return result;
}

unique_ptr<SubPath> Transformer::TransformSubPathElement(duckdb_libpgquery::PGSubPath *root, unique_ptr<PathPattern> &path_pattern) {
unique_ptr<SubPath> Transformer::TransformSubPathElement(duckdb_libpgquery::PGSubPath *root,
unique_ptr<PathPattern> &path_pattern) {
auto result = make_uniq<SubPath>(PGQPathReferenceType::SUBPATH);

result->where_clause = TransformExpression(root->where_clause);
Expand Down Expand Up @@ -72,10 +73,10 @@ unique_ptr<SubPath> Transformer::TransformSubPathElement(duckdb_libpgquery::PGSu
if (result->path_mode > PGQPathMode::WALK) {
throw NotImplementedException("Path modes other than WALK have not been implemented yet.");
}
if (result->upper == 1<<30 && path_pattern->all && result->path_mode <= PGQPathMode::WALK) {
if (result->upper == 1 << 30 && path_pattern->all && result->path_mode <= PGQPathMode::WALK) {
throw ConstraintException("ALL unbounded with path mode WALK is not possible as this "
"could lead to infinite results. Consider specifying an upper bound or"
" path mode other than WALK");
"could lead to infinite results. Consider specifying an upper bound or"
" path mode other than WALK");
}

//! Path sequence
Expand Down Expand Up @@ -147,12 +148,7 @@ unique_ptr<TableRef> Transformer::TransformMatch(duckdb_libpgquery::PGMatchClaus
match_info->path_patterns.push_back(std::move(transformed_path));
}

for (auto node = root.columns->head; node != nullptr; node = lnext(node)) {
auto column = reinterpret_cast<duckdb_libpgquery::PGList *>(node->data.ptr_value);
auto target = reinterpret_cast<duckdb_libpgquery::PGResTarget *>(column->head->next->data.ptr_value);
auto res_target = TransformResTarget(*target);
match_info->column_list.push_back(std::move(res_target));
}
TransformExpressionList(*root.columns, match_info->column_list);

auto children = vector<unique_ptr<ParsedExpression>>();
children.push_back(std::move(match_info));
Expand Down
20 changes: 16 additions & 4 deletions third_party/libpg_query/grammar/statements/pgq.y
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,20 @@ GraphTableNameOptional:
/* EMPTY */ { $$ = NULL; }
;

ColumnsOptional:
COLUMNS '(' target_list_opt_comma ')' { $$ = $3; }
|
/* EMPTY */
{
PGAStar *star = makeNode(PGAStar);
$$ = list_make1(star);
}
;


GraphTableStmt:
'(' PGQ_IDENT MATCH PathPatternList KeepOptional GraphTableWhereOptional
COLUMNS '(' ColumnList ')' ')' GraphTableNameOptional
ColumnsOptional ')' GraphTableNameOptional
{
PGMatchClause *n = makeNode(PGMatchClause);
n->pg_name = $2;
Expand All @@ -271,21 +282,22 @@ GraphTableStmt:
}
}
n->where_clause = $6;
n->columns = $9;
n->graph_table = $12;
n->columns = $7;
n->graph_table = $9;
$$ = (PGNode *) n;
}
;

/*
ColumnSpec:
target_el { $$ = list_make2(makeInteger(PG_COLUMNSPEC_EXPR), $1); }
;

ColumnList:
ColumnSpec { $$ = list_make1($1); }
|
ColumnList ',' ColumnSpec { $$ = lappend($1, $3); }
;
*/

KeepOptional:
KEEP PathPrefix { $$ = $2; }
Expand Down
1 change: 1 addition & 0 deletions third_party/libpg_query/grammar/types/pgq.yh
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
%type <str> LabelOptional
%type <list> EdgeTablesClauseOptional
%type <range> GraphTableNameOptional
%type <list> ColumnsOptional
Loading

0 comments on commit e55aa6d

Please sign in to comment.