Emitting Lua script contains superfluous output column metadata

Details

Detail name Value
Changelog Number 6592
Type Bug
Status Resolved
Affected Versions EXASOL 6.0.0, Exasol 6.1.0, Exasol 6.2.0, Exasol 7.0.alpha1
Fix Versions Exasol 7.0.0, Exasol 6.2.5
Resolution Date 2020-03-11

Bug

For emitting Lua scripts the global metadata variables exa.meta.output_column_count and exa.meta.output_columns[] include all columns from the SELECT list, not just the emitted columns.

Notice

If the script call is the only element in the SELECT list, then it works correctly. The input columns, e.g. exa.meta.input_column_count, are always correct.

Example

CREATE OR REPLACE LUA SCALAR SCRIPT example() EMITS (...) AS
function run(ctx)
    for i = 1, exa.meta.output_column_count do
        ctx.emit(exa.meta.output_columns[i].name)
    end
end
/

The following SELECT should return one row containing the only output parameter EMITTED. Due to the bug it returns two rows: One for the unrelated column DUMMY and one for the output parameter EMITTED:

SELECT
    dummy,
    example() EMITS (emitted VARCHAR(100))
FROM dual;

Workaround

Either rewrite the SELECT so that the script call is the only element in the SELECT list, or move all other columns in the SELECT list behind the script call and add a parameter to the script containing the proper value for exa.meta.output_column_count:

CREATE OR REPLACE LUA SCALAR SCRIPT example(output_column_count_workaround DOUBLE) EMITS (...) AS
function run(ctx)
    for i = 1, ctx.output_column_count_workaround do
        ctx.emit(exa.meta.output_columns[i].name)
    end
end
/

SELECT
    example(1) EMITS (emitted VARCHAR(100)),
    dummy
FROM dual;