Looking at the code that turns a logical CalcRel into a BeamCalcRel I do
not see any obvious cause for this:
https://github.com/apache/beam/blob/b3aa2e89489898f8c760294ba4dba2310ac53e70/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rule/BeamCalcRule.java#L69

I don't like to guess that upstream libraries have the bug, but in this
case I wonder if the alias is lost in the Calcite optimizer rule for
merging the projects and filters into a Calc.

Kenn

On Mon, Jan 23, 2023 at 10:13 AM Kenneth Knowles <k...@apache.org> wrote:

> I am not sure I understand the question, but I do see an issue.
>
> Context: "CalcRel" is an optimized relational operation that is somewhat
> like ParDo, with a small snippet of a single-assignment DSL embedded in it.
> Calcite will choose to merge all the projects and filters into the node,
> and then generates Java bytecode to directly execute the DSL.
>
> Problem: it looks like the CalcRel has output columns with aliases "id"
> and "v" where it should have output columns with aliases "id" and "value".
>
> Kenn
>
> On Thu, Jan 19, 2023 at 6:01 PM Ahmet Altay <al...@google.com> wrote:
>
>> Adding: @Andrew Pilloud <apill...@google.com> @Kenneth Knowles
>> <k...@google.com>
>>
>> On Thu, Jan 12, 2023 at 12:31 PM Talat Uyarer via user <
>> user@beam.apache.org> wrote:
>>
>>> Hi All,
>>>
>>> I am using Beam 2.43 with Calcite SQL with Java.
>>>
>>> I have a query with a WITH clause and some aliasing. Looks like Beam
>>> Query optimizer after optimizing my query, it drops Select statement's
>>> aliases. Can you help me to identify where the problem is ?
>>>
>>> This is my query
>>> INFO: SQL:
>>> WITH `tempTable` (`id`, `v`) AS (SELECT
>>> `PCOLLECTION`.`f_nestedRow`.`f_nestedInt` AS `id`,
>>> `PCOLLECTION`.`f_nestedRow`.`f_nestedString` AS `v`
>>> FROM `beam`.`PCOLLECTION` AS `PCOLLECTION`) (SELECT `tempTable`.`id` AS
>>> `id`, `tempTable`.`v` AS `value`
>>> FROM `tempTable` AS `tempTable`
>>> WHERE `tempTable`.`v` <> '11')
>>>
>>> This is Calcite Plan look at LogicalProject(id=[$0], value=[$1]) in SQL
>>> plan.
>>>
>>> Jan 12, 2023 12:19:08 PM
>>> org.apache.beam.sdk.extensions.sql.impl.CalciteQueryPlanner convertToBeamRel
>>> INFO: SQLPlan>
>>> LogicalProject(id=[$0], value=[$1])
>>>   LogicalFilter(condition=[<>($1, '11')])
>>>     LogicalProject(id=[$1.f_nestedInt], v=[$1.f_nestedString])
>>>       BeamIOSourceRel(table=[[beam, PCOLLECTION]])
>>>
>>> But Beam Plan does not have a LogicalProject(id=[$0], value=[$1]) or
>>> similar.
>>>
>>> Jan 12, 2023 12:19:08 PM
>>> org.apache.beam.sdk.extensions.sql.impl.CalciteQueryPlanner convertToBeamRel
>>> INFO: BEAMPlan>
>>> BeamCalcRel(expr#0..1=[{inputs}], expr#2=[$t1.f_nestedInt],
>>> expr#3=[$t1.f_nestedString], expr#4=['11':VARCHAR], expr#5=[<>($t3, $t4)],
>>> id=[$t2], v=[$t3], $condition=[$t5])
>>>   BeamIOSourceRel(table=[[beam, PCOLLECTION]])
>>>
>>>
>>> Thanks
>>>
>>

Reply via email to