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

Details

Detail name Value
Changelog Number 7738
Type Bug
Status Resolved
Affected Versions Exasol 6.1.0
Fix Versions Exasol 6.1.3
Resolution Date 2020-02-28

Problem

An 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 python scalar script
test_scalaremit(a varchar(100)) emits(b varchar(100)) as

def run(ctx):
  ctx.emit(ctx.a)
  ctx.emit(ctx.a)
/

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: 22002]  VM error: GeneratorStageStopExecution

Workaround

Use ORDER BY LIMIT:

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

Limitation

The fix does not work for Lua scripts, see EXASOL-2634.