Annotation Type QuerySqlTableFunction


  • @Documented
    @Retention(RUNTIME)
    @Target(METHOD)
    public @interface QuerySqlTableFunction
    Annotates public methods in classes to be used in SQL queries as custom table functions. Annotated class must be registered using CacheConfiguration.setSqlFunctionClasses(Class[]).

    Usage example:

         public class MyTableFunctions {
             @QuerySqlTableFunction(columnTypes = {Float.class, String.class}, columnNames = {"F_VAL", "S_VAL"})
             public static Iterable<Object[]> my_table(int i, Float f, String str) {
                 return Arrays.asList(
                     new Object[]{f, "code_" + (i * 10) + ": " + str},
                     new Object[]{null, "code_" + (i * 20) + ": " + str},
                     new Object[]{f,  "code_" + (i * 30) + ": " + str}
                 );
             }
         }
    
         // Register in CacheConfiguration.
         cacheCfg.setSqlFunctionClasses(MyTableFunctions.class);
    
         // And use in queries.
         cache.query(new SqlFieldsQuery("select S_VAL from MY_TABLE(1, 5.0f, "ext") where F_VAL is not null"));
     

    Table function must return an Iterable as a row set. Each row can be represented by an Object[] or by an Collection. Row length must match the defined number of column types. Row value types must match the defined column types or be able assigned to them.

    Note, the table functions are available currently only with Calcite.

    See Also:
    QuerySqlFunction, SessionContextProviderResource
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String[] columnNames
      Defines column names of the returned SQL table representation.
      Class<?>[] columnTypes
      Defines column types of the returned SQL table representation.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String alias
      Specifies alias for the table function name to be used form SQL queries.
    • Element Detail

      • columnTypes

        Class<?>[] columnTypes
        Defines column types of the returned SQL table representation. Number of the types must match number of columnNames().
        Returns:
        Table column types.
      • columnNames

        String[] columnNames
        Defines column names of the returned SQL table representation. Number of the names must match number of columnTypes().
        Returns:
        Table column names.
      • alias

        String alias
        Specifies alias for the table function name to be used form SQL queries. If no alias provided, the method name is used.
        Returns:
        Alias for table function name.
        Default:
        ""