Skip to content

Aliases being set inside bind_replace are overwritten #16052

@Dtenwolde

Description

@Dtenwolde

What happens?

When setting the alias of a TableRef inside a bind_replace function, it is overwritten by the ref.alias even if this ref.alias is empty.
Specifically here:

auto new_plan = table_function.bind_replace(context, bind_input);
if (new_plan) {
new_plan->alias = ref.alias;
new_plan->column_name_alias = ref.column_name_alias;
return CreatePlan(*Bind(*new_plan));
} else if (!table_function.bind) {

I can set the ref.alias earlier like this: https://github.com/cwida/duckpgq-extension/blob/8de232b5ba4df00afdaf7e1f3c0870dfee21c54f/src/core/parser/duckpgq_parser.cpp#L50, but that means I need to check for every possible bind_replace function I have during the initial bind phase, which feels quite hacky. I think the ability to set the alias during the bind_replace and it not being overwritten is a better solution.

Perhaps I am missing something regarding the ref.alias, if that's the case please let me know :)

To Reproduce

To reproduce:

git clone --recurse-submodules git@github.com:cwida/duckpgq-extension.git
make GEN=ninja

CREATE TABLE Student(id BIGINT, name VARCHAR);INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Peter'), (4, 'David');
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);
-CREATE PROPERTY GRAPH pg
VERTEX TABLES (
    Student,
    Foo
    )
EDGE TABLES (
    know    SOURCE KEY ( src ) REFERENCES Student ( id )
            DESTINATION KEY ( dst ) REFERENCES Student ( id )
    );

select a.id, a.name, local_clustering_coefficient from local_clustering_coefficient(pg, student, know), student a where a.id = lcc.id;
Binder Error: Referenced table "lcc" not found!
Candidate tables: "a"

OS:

macOS

DuckDB Version:

v1.2-histrionicus

DuckDB Client:

CLI

Hardware:

No response

Full Name:

Daniel ten Wolde

Affiliation:

Centrum Wiskunde & Informatica

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a source build

Did you include all relevant data sets for reproducing the issue?

Yes

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions