Skip to content

Commit

Permalink
Merge pull request #173 from cwida/80-make-label-label-optional
Browse files Browse the repository at this point in the history
Adding LabelOptional rule
  • Loading branch information
Dtenwolde committed Feb 3, 2024
2 parents 57dd06f + b47a158 commit 3e2ceda
Show file tree
Hide file tree
Showing 4 changed files with 14,326 additions and 14,309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
vector<string> label_names;

auto table_name = reinterpret_cast<duckdb_libpgquery::PGRangeVar *>(graph_table->table->head->data.ptr_value);
auto graph_table_name = TransformQualifiedName(*table_name);
auto graph_table_name = TransformQualifiedName(*table_name).name;
string table_name_alias =
reinterpret_cast<duckdb_libpgquery::PGValue *>(graph_table->table->head->next->data.ptr_value)->val.str;
if (!table_name_alias.empty()) {
table_alias_map[table_name_alias] = graph_table_name.name;
table_alias_map[table_name_alias] = graph_table_name;
}

bool all_columns = false;
Expand Down Expand Up @@ -54,7 +54,12 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
label_element = label_element->next) {
auto label = reinterpret_cast<duckdb_libpgquery::PGValue *>(label_element->data.ptr_value);
D_ASSERT(label->type == duckdb_libpgquery::T_PGString);
std::string label_str = label->val.str;
std::string label_str;
if (label->val.str == nullptr) {
label_str = graph_table_name;
} else {
label_str = label->val.str;
}
label_str = StringUtil::Lower(label_str);
if (global_label_set.find(label_str) != label_set.end()) {
throw ConstraintException("Label %s is not unique, make sure all labels are unique", label_str);
Expand All @@ -63,7 +68,7 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
label_names.emplace_back(label_str);
}

auto pg_table = make_shared<PropertyGraphTable>(graph_table_name.name, table_name_alias,
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;
Expand Down
21 changes: 13 additions & 8 deletions third_party/libpg_query/grammar/statements/pgq.y
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ LabelList:
| LabelList ',' PGQ_IDENT { $$ = lappend($1, makeString($3)); }
;

LabelOptional:
LABEL PGQ_IDENT { $$ = $2; }
| /* EMPTY */ { $$ = NULL; }
;

Discriminator:
IN_P qualified_name '(' LabelList ')'
{
Expand All @@ -129,14 +134,14 @@ Discriminator:

VertexTableDefinition:
/* qualified name is an BIGINT column with 64 bits: a maximum of 64 labels can be set */
QualifiednameOptionalAs PropertiesClause LABEL PGQ_IDENT Discriminator
QualifiednameOptionalAs PropertiesClause LabelOptional Discriminator
{
PGPropertyGraphTable *n = (PGPropertyGraphTable*) $5;
PGPropertyGraphTable *n = (PGPropertyGraphTable*) $4;
n->table = $1;
n->properties = $2;
/* Xth label in list is set iff discriminator Xth-bit==1 */
if (n->labels) n->labels = lappend(n->labels,makeString($4));
else n->labels = list_make1(makeString($4));
if (n->labels) n->labels = lappend(n->labels,makeString($3));
else n->labels = list_make1(makeString($3));
n->is_vertex_table = true;
$$ = (PGNode *) n;
}
Expand All @@ -153,9 +158,9 @@ EdgeTableDefinition:
QualifiednameOptionalAs
SOURCE KeyReference qualified_name KeySpecification
DESTINATION KeyReference qualified_name KeySpecification
PropertiesClause LABEL PGQ_IDENT Discriminator
PropertiesClause LabelOptional Discriminator
{
PGPropertyGraphTable *n = (PGPropertyGraphTable*) $13;
PGPropertyGraphTable *n = (PGPropertyGraphTable*) $12;
n->table = $1;
n->is_vertex_table = false;
n->src_fk = $3;
Expand All @@ -166,8 +171,8 @@ EdgeTableDefinition:
n->dst_pk = $9;
n->properties = $10;
/* Xth label in list is set iff discriminator Xth-bit==1 */
if (n->labels) n->labels = lappend(n->labels,makeString($12));
else n->labels = list_make1(makeString($12));
if (n->labels) n->labels = lappend(n->labels,makeString($11));
else n->labels = list_make1(makeString($11));
$$ = (PGNode *) n;
}
;
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 @@ -53,3 +53,4 @@
%type <list> EdgePattern
%type <list> VertexPattern
%type <node> pgq_expr
%type <str> LabelOptional
Loading

0 comments on commit 3e2ceda

Please sign in to comment.