Complex queries containing SCALAR EMITS UDFs with no arguments may crash

Details

Detail name Value
Changelog Number 12889
Type Bug
Status Resolved
Affected Versions Exasol 7.0.0, Exasol 7.1.0
Fix Versions Exasol 8.21.0
Resolution Date 2023-08-04

Description

An 'Internal server error' is thrown when the following conditions are met:

  • A SCALAR EMITS UDF is created with no arguments
  • A query contains a subselect directly (ie in FROM clause)
  • This SCALAR EMITS UDF is used in this subselect
  • The outer query contains an aggregation (ie GROUP BY or aggregation functions)

In some cases, the error might also appear in queries where the UDF is not directly contained due to query optimizations. 

Preparation

-- SCALAR EMITS UDF without arguments
--/
CREATE OR REPLACE LUA SCALAR SCRIPT test.s() EMITS (c INT) AS
function run(ctx)
 ctx.emit(decimal(1) )
end
/

Example

SELECT min(c) c FROM SELECT 1, s();

Workaround

Add an argument to the UDF, even if it is not used anywhere.

-- same UDF with one (unused) argument
--/
CREATE OR REPLACE LUA SCALAR SCRIPT test.s(x int) EMITS (c INT) AS
function run(ctx)
 ctx.emit(decimal(1) )
end
/

-- works
SELECT min(c) c FROM SELECT 1, s(1);

Fix

The query will run as expected.