Inconsistency between `this` and `this.*`
What's up?
My assumption has been that this refers to the current relation at any given point in a pipeline, and that this.* is more precisely a tuple that contains references to all of the current columns at that point in the pipeline. However, I recently found some curious behavior - this seems to behave as I expect, while this.* reflects the known columns from the original source relation.
from foo
select { a, b, c = a + b }
select this
results in:
SELECT
a,
b,
a + b AS c
FROM
foo
-- Generated by PRQL compiler version:0.13.13 (https://prql-lang.org)
while:
from foo
select { a, b, c = a + b }
select this.*
results in:
SELECT
a,
b
FROM
foo
-- Generated by PRQL compiler version:0.13.13 (https://prql-lang.org)
Is there intentionally a distinction between this and this.*? Or is this a bug that results from the implementation of the .* wildcard handling on relations?
Thanks for the clear report — reproduced, and it's a bug, not an intended distinction.
this.* looks up this._self to find which columns to expand, but the lookup followed an input redirect to the first input's _self (this.foo._self), so the wildcard enumerated only that input's columns (a, b) and never saw the computed column c, which sits at the top level of the this frame. Bare this doesn't go through that lookup, which is why the two diverged.
I've opened #6045 with a fix: keep a frame's own _self instead of letting an input redirect shadow it, and flatten the per-input expansion into a flat column list. select this.* now matches select this, and sort this.* picks up computed columns too. A maintainer will review.