Error when defining UDF in cube 'sql' parameter
Describe the bug SQL compilation error: syntax error line 4 at position 7 unexpected 'CREATE'.
Cube is unable to create a UDF as part of the sql parameter. This was tested on Snowflake but may affect other data sources.
On Cube Cloud in SQL Runner, the same SQL returns a permissions error, but the same user can execute it from the Snowflake Console
To Reproduce Steps to reproduce the behavior:
- create a cube (see data model below) that includes a 'CREATE FUNCTION' command in the sql parameter.
- In playground, add the measure and dimension and run
Expected behavior A clear and concise description of what you expected to happen.
Screenshots
Minimally reproducible Cube Schema This example is from Snowflakes UDF documentation. It works in the Snowflake console, running as this same user.
cubes:
- name: udf_test
sql: >
CREATE OR REPLACE FUNCTION addone(i int)
RETURNS INT
LANGUAGE PYTHON
RUNTIME_VERSION = '3.8'
HANDLER = 'addone_py'
as
$$
def addone_py(i):
return i+1
$$;
SELECT addone(3) as col1;
measures:
- name: count
type: count
dimensions:
- name: col1
sql: col1
type: numberVersion: 0.33.31
Additional Context: @igorlukanin noted there's a restriction on the Snowflake side - alternative implementations may be:
- introducing an option to run multi-statement queries against Snowflake
- allowing to run an arbitrary set of SQL statements after a driver connects to the data source: all UDFs might as well go there
Source: cube-js/cube