Skip to content

Commit 05cd2fd

Browse files
committed
Revert changes to the transformer
1 parent 0b94a2d commit 05cd2fd

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

src/include/duckdb/parser/transformer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,12 @@ class Transformer {
339339
case_insensitive_set_t &global_label_set,
340340
case_insensitive_map_t<string> &table_alias_map);
341341
//! Transform a path pattern (SQL/PGQ)
342-
unique_ptr<PathPattern> TransformPath(duckdb_libpgquery::PGPathPattern *root, case_insensitive_map_t<idx_t>& anonymous_variable_map);
342+
unique_ptr<PathPattern> TransformPath(duckdb_libpgquery::PGPathPattern *root);
343343
//! Transform a path element (SQL/PGQ)
344-
static unique_ptr<PathElement> TransformPathElement(duckdb_libpgquery::PGPathElement *element, case_insensitive_map_t<idx_t>& anonymous_variable_map);
344+
static unique_ptr<PathElement> TransformPathElement(duckdb_libpgquery::PGPathElement *element);
345345
//! Transform a subpath (SQL/PGQ)
346346
unique_ptr<SubPath> TransformSubPathElement(duckdb_libpgquery::PGSubPath *element,
347-
unique_ptr<PathPattern> &path_pattern, case_insensitive_map_t<idx_t>& anonymous_variable_map);
347+
unique_ptr<PathPattern> &path_pattern);
348348

349349
//! Transform a Postgres duckdb_libpgquery::T_PGDropPropertyGraphStmt node into a Drop[Table,Schema]Statement
350350
unique_ptr<SQLStatement> TransformDropPropertyGraph(duckdb_libpgquery::PGDropPropertyGraphStmt &node);

src/parser/transform/tableref/transform_match.cpp

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace duckdb {
66

7-
unique_ptr<PathElement> Transformer::TransformPathElement(duckdb_libpgquery::PGPathElement *element, case_insensitive_map_t<idx_t>& anonymous_variable_map) {
7+
unique_ptr<PathElement> Transformer::TransformPathElement(duckdb_libpgquery::PGPathElement *element) {
88
//! Vertex or edge pattern
99
auto result = make_uniq<PathElement>(PGQPathReferenceType::PATH_ELEMENT);
1010
switch (element->match_type) {
@@ -33,32 +33,15 @@ unique_ptr<PathElement> Transformer::TransformPathElement(duckdb_libpgquery::PGP
3333
std::string label_name = StringUtil::Lower(label_expression->name);
3434
result->label = label_name;
3535
if (!element->element_var) {
36-
// Case: Anonymous node with label `:N`
37-
if (anonymous_variable_map.find(label_name) != anonymous_variable_map.end()) {
38-
throw ConstraintException("Ambiguous anonymous variable pattern detected for label '" + label_name + "'. "
39-
"Please provide an explicit variable name.");
40-
}
41-
anonymous_variable_map[label_name] = 1;
42-
result->variable_binding = label_name;
36+
result->variable_binding = "";
4337
} else {
44-
// Case: Explicitly named node (e.g., `n:N`)
45-
std::string variable_name = element->element_var;
46-
// Check if this label was already used as an anonymous variable
47-
if (anonymous_variable_map.find(variable_name) != anonymous_variable_map.end() &&
48-
anonymous_variable_map[variable_name] == 1) {
49-
throw ConstraintException("Conflicting variable bindings: anonymous node with variable '" + variable_name +
50-
"' was already assigned. Provide explicit variable names for all occurrences.");
51-
}
52-
anonymous_variable_map[variable_name] = 1;
53-
54-
// Register this explicitly named variable
55-
result->variable_binding = variable_name;
38+
result->variable_binding = element->element_var;
5639
}
5740
return result;
5841
}
5942

6043
unique_ptr<SubPath> Transformer::TransformSubPathElement(duckdb_libpgquery::PGSubPath *root,
61-
unique_ptr<PathPattern> &path_pattern, case_insensitive_map_t<idx_t>& anonymous_variable_map) {
44+
unique_ptr<PathPattern> &path_pattern) {
6245
auto result = make_uniq<SubPath>(PGQPathReferenceType::SUBPATH);
6346

6447
result->where_clause = TransformExpression(root->where_clause);
@@ -103,18 +86,18 @@ unique_ptr<SubPath> Transformer::TransformSubPathElement(duckdb_libpgquery::PGSu
10386
auto path_node = reinterpret_cast<duckdb_libpgquery::PGNode *>(node->data.ptr_value);
10487
if (path_node->type == duckdb_libpgquery::T_PGPathElement) {
10588
auto element = reinterpret_cast<duckdb_libpgquery::PGPathElement *>(path_node);
106-
auto path_element = TransformPathElement(element, anonymous_variable_map);
89+
auto path_element = TransformPathElement(element);
10790
result->path_list.push_back(std::move(path_element));
10891
} else if (path_node->type == duckdb_libpgquery::T_PGSubPath) {
10992
auto subpath = reinterpret_cast<duckdb_libpgquery::PGSubPath *>(path_node);
110-
auto subpath_element = TransformSubPathElement(subpath, path_pattern, anonymous_variable_map);
93+
auto subpath_element = TransformSubPathElement(subpath, path_pattern);
11194
result->path_list.push_back(std::move(subpath_element));
11295
}
11396
}
11497
return result;
11598
}
11699

117-
unique_ptr<PathPattern> Transformer::TransformPath(duckdb_libpgquery::PGPathPattern *root, case_insensitive_map_t<idx_t>& anonymous_variable_map) {
100+
unique_ptr<PathPattern> Transformer::TransformPath(duckdb_libpgquery::PGPathPattern *root) {
118101
auto result = make_uniq<PathPattern>();
119102
result->all = root->all;
120103
result->shortest = root->shortest;
@@ -135,11 +118,11 @@ unique_ptr<PathPattern> Transformer::TransformPath(duckdb_libpgquery::PGPathPatt
135118
auto path_node = reinterpret_cast<duckdb_libpgquery::PGNode *>(node->data.ptr_value);
136119
if (path_node->type == duckdb_libpgquery::T_PGPathElement) {
137120
auto element = reinterpret_cast<duckdb_libpgquery::PGPathElement *>(path_node);
138-
auto path_element = TransformPathElement(element, anonymous_variable_map);
121+
auto path_element = TransformPathElement(element);
139122
result->path_elements.push_back(std::move(path_element));
140123
} else if (path_node->type == duckdb_libpgquery::T_PGSubPath) {
141124
auto subpath = reinterpret_cast<duckdb_libpgquery::PGSubPath *>(path_node);
142-
auto subpath_element = TransformSubPathElement(subpath, result, anonymous_variable_map);
125+
auto subpath_element = TransformSubPathElement(subpath, result);
143126
result->path_elements.push_back(std::move(subpath_element));
144127
} else {
145128
throw NotImplementedException("Path node type " + NodetypeToString(path_node->type) + " not recognized");
@@ -153,7 +136,6 @@ unique_ptr<TableRef> Transformer::TransformMatch(duckdb_libpgquery::PGMatchClaus
153136
auto match_info = make_uniq<MatchExpression>();
154137
match_info->pg_name = root.pg_name; // Name of the property graph to bind to
155138
string alias_name;
156-
case_insensitive_map_t<idx_t> anonymous_variable_map; // Map of anonymous variables to their bound names
157139
if (root.graph_table) {
158140
alias_name = TransformQualifiedName(*root.graph_table).name;
159141
}
@@ -165,7 +147,7 @@ unique_ptr<TableRef> Transformer::TransformMatch(duckdb_libpgquery::PGMatchClaus
165147

166148
for (auto node = root.paths->head; node != nullptr; node = lnext(node)) {
167149
auto path = reinterpret_cast<duckdb_libpgquery::PGPathPattern *>(node->data.ptr_value);
168-
auto transformed_path = TransformPath(path, anonymous_variable_map);
150+
auto transformed_path = TransformPath(path);
169151
match_info->path_patterns.push_back(std::move(transformed_path));
170152
}
171153

0 commit comments

Comments
 (0)