[ 
https://issues.apache.org/jira/browse/IGNITE-24336?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vladimir Steshin updated IGNITE-24336:
--------------------------------------
    Description: 
We should implement user-defined table functions. They also have a 
implementation in Calcite, `_TableFunctionImpl_`. And we also have user-defined 
scalar functions.

Table functions should be described similarly to the existing configuration of 
scalar functions, via `_CacheConfiguration#setSqlFunctionClasses()_` and 
annotation `_@QuerySqlTableFunction_`. Or we might use another annotation. The 
annotation should describe the returned columns and their data types.

*Example:*
{code:java}
public static final class TableFunctions {
    @QuerySqlFunction(tableColumnTypes = {Integer.class, String.class}, 
tableColumnNames = {"INT_COL", "STR_COL"})
    public static Iterable table_fun(int i) {
        return Arrays.asList(
            new Object[]{i, "code_" + i},
            new Object[]{i * 10, "code_" + (i * 10)}
        );
    }
}

IgniteCache<?, ?> emp = ignite.getOrCreateCache(new 
CacheConfiguration("test_cache")
         .setSqlFunctionClasses(TableFunctions.class)
);

sql("select STR_COL from TABLE_FUN(1) where INT_COL>1")
{code}

Table function implementation must return an `Iterable` representing table 
rows. Each its element is an `_Object[]_` or an `_Iterable_` representing a 
table row. The number of row elements must match the number of the defined 
columns. 

*Known limitations:*
Only _Calcite_ engine will support table functions first.

  was:
We should implement user-defined table functions. They also have a 
implementation in Calcite, `_TableFunctionImpl_`. And we also have user-defined 
scalar functions.

Table functions should be described similarly to the existing configuration of 
scalar functions, via `_CacheConfiguration#setSqlFunctionClasses()_` and 
annotation `_@QuerySqlTableFunction_`. Or we might use another annotation. The 
annotation should describe the returned columns and their data types.

*Example:*
{code:java}
public static final class IncorrectTableFunctionsLibrary {
    @QuerySqlFunction(tableColumnTypes = {Integer.class, String.class}, 
tableColumnNames = {"INT_COL", "STR_COL"})
    public static Iterable table_fun(int i) {
        return Arrays.asList(
            new Object[]{i, "code_" + i},
            new Object[]{i * 10, "code_" + (i * 10)}
        );
    }
}

sql("select STR_COL from TABLE_FUN(1) where INT_COL>1")
{code}

Table function implementation must return an `Iterable` representing table 
rows. Each its element is an `_Object[]_` or an `_Iterable_` representing a 
table row. The number of row elements must match the number of the defined 
columns. 

*Known limitations:*
Only _Calcite_ engine will support table functions first.


> Calcite. Add support of user-defined table functions.
> -----------------------------------------------------
>
>                 Key: IGNITE-24336
>                 URL: https://issues.apache.org/jira/browse/IGNITE-24336
>             Project: Ignite
>          Issue Type: Improvement
>            Reporter: Vladimir Steshin
>            Assignee: Vladimir Steshin
>            Priority: Major
>              Labels: calcite, ignite-2, ise, sql
>
> We should implement user-defined table functions. They also have a 
> implementation in Calcite, `_TableFunctionImpl_`. And we also have 
> user-defined scalar functions.
> Table functions should be described similarly to the existing configuration 
> of scalar functions, via `_CacheConfiguration#setSqlFunctionClasses()_` and 
> annotation `_@QuerySqlTableFunction_`. Or we might use another annotation. 
> The annotation should describe the returned columns and their data types.
> *Example:*
> {code:java}
> public static final class TableFunctions {
>     @QuerySqlFunction(tableColumnTypes = {Integer.class, String.class}, 
> tableColumnNames = {"INT_COL", "STR_COL"})
>     public static Iterable table_fun(int i) {
>         return Arrays.asList(
>             new Object[]{i, "code_" + i},
>             new Object[]{i * 10, "code_" + (i * 10)}
>         );
>     }
> }
> IgniteCache<?, ?> emp = ignite.getOrCreateCache(new 
> CacheConfiguration("test_cache")
>          .setSqlFunctionClasses(TableFunctions.class)
> );
> sql("select STR_COL from TABLE_FUN(1) where INT_COL>1")
> {code}
> Table function implementation must return an `Iterable` representing table 
> rows. Each its element is an `_Object[]_` or an `_Iterable_` representing a 
> table row. The number of row elements must match the number of the defined 
> columns. 
> *Known limitations:*
> Only _Calcite_ engine will support table functions first.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to