Hi all,

I'd like to propose allowing user-defined SQL functions to be called without 
parentheses in the Calcite query engine.

Several DBMSs support this syntax for built-in functions, such as CURRENT_USER 
in PostgreSQL and CURRENT_TIMESTAMP in SQL Server. 
Oracle also supports calls without parentheses for parameterless UDFs.

This could be useful for functions exposing session or application context, 
such as the current tenant, application user, or session identifier.

I propose adding an opt-in parameter to 
org.apache.ignite.cache.query.annotations.QuerySqlFunction:

boolean allowWithoutParentheses() default false;

For example:

@QuerySqlFunction(
    alias = "CURRENT_TENANT",
    allowWithoutParentheses = true
)
public String currentTenant() {
    return sessionContextProvider.getSessionContext()
        .getAttribute("tenant");
}

After registering the function through 
CacheConfiguration.setSqlFunctionClasses, it could be used as follows:

SELECT * FROM orders WHERE tenant_id = CURRENT_TENANT;
SELECT * FROM orders WHERE tenant_id = CURRENT_TENANT();

This option would be supported only by the Calcite query engine. 
The default value would preserve existing behavior. 
Enabling it for a function with parameters would result in a registration error.

WDYT?

Reply via email to