Lua UDF with EMIT does not work with LIMIT if limit-value is smaller than number of emitted rows

Details

Detail name Value
Changelog Number 9636
Type Bug
Status Resolved
Affected Versions EXASOL 6.0.0, Exasol 6.1.0, Exasol 6.2.0, Exasol 7.0.0
Fix Versions Exasol 7.0.0
Resolution Date 2020-09-11

Background

This is the same bug as EXASOL-2465 but for Lua which was not covered by that fix.

Problem

A Lua UDF with EMIT does not work with LIMIT if the number of rows the result is limited to is smaller than the number of emitted rows per input row:

create or replace lua scalar script
test_scalaremit(a varchar(100)) emits(b varchar(100)) as

function run(ctx)
  ctx.emit(ctx.a)
  ctx.emit(ctx.a)
end
/

This query works fine:

select test_scalaremit(a) from values 0 as t(a) limit 2;

This fails:

select test_scalaremit(a) from values 0 as t(a) limit 1;
-- [Code: 0, SQL State: 22001]  Exception in script computing

Workaround

Use ORDER BY LIMIT:

select test_scalaremit(a) from values 0 as t(a) order by 1 limit 1;