@@ -69,6 +69,7 @@ TRAMPOLINE(app_define_table, define_table)
6969TRAMPOLINE(app_get_bbox, get_bbox)
7070TRAMPOLINE(table_name, name)
7171TRAMPOLINE(table_schema, schema)
72+ TRAMPOLINE(table_cluster, cluster)
7273TRAMPOLINE(table_add_row, add_row)
7374TRAMPOLINE(table_columns, columns)
7475TRAMPOLINE(table_tostring, __tostring)
@@ -771,6 +772,28 @@ flex_table_t &output_flex_t::create_flex_table()
771772 }
772773 lua_pop (lua_state (), 1 );
773774
775+ // optional "cluster" field
776+ lua_getfield (lua_state (), -1 , " cluster" );
777+ int const cluster_type = lua_type (lua_state (), -1 );
778+ if (cluster_type == LUA_TSTRING) {
779+ std::string const cluster = lua_tostring (lua_state (), -1 );
780+ if (cluster == " auto" ) {
781+ new_table.set_cluster_by_geom (true );
782+ } else if (cluster == " no" ) {
783+ new_table.set_cluster_by_geom (false );
784+ } else {
785+ throw std::runtime_error{
786+ " Unknown value '{}' for 'cluster' table option"
787+ " (use 'auto' or 'no')." _format (cluster)};
788+ }
789+ } else if (cluster_type == LUA_TNIL) {
790+ // ignore
791+ } else {
792+ throw std::runtime_error{
793+ " Unknown value for 'cluster' table option: Must be string." };
794+ }
795+ lua_pop (lua_state (), 1 );
796+
774797 // optional "data_tablespace" field
775798 lua_getfield (lua_state (), -1 , " data_tablespace" );
776799 if (lua_isstring (lua_state (), -1 )) {
@@ -1058,6 +1081,13 @@ int output_flex_t::table_schema()
10581081 return 1 ;
10591082}
10601083
1084+ int output_flex_t::table_cluster ()
1085+ {
1086+ auto const &table = get_table_from_param ();
1087+ lua_pushboolean (lua_state (), table.cluster_by_geom ());
1088+ return 1 ;
1089+ }
1090+
10611091static std::unique_ptr<geom_transform_t >
10621092get_transform (lua_State *lua_state, flex_table_column_t const &column)
10631093{
@@ -1615,6 +1645,7 @@ void output_flex_t::init_lua(std::string const &filename)
16151645 luaX_add_table_func (lua_state (), " add_row" , lua_trampoline_table_add_row);
16161646 luaX_add_table_func (lua_state (), " name" , lua_trampoline_table_name);
16171647 luaX_add_table_func (lua_state (), " schema" , lua_trampoline_table_schema);
1648+ luaX_add_table_func (lua_state (), " cluster" , lua_trampoline_table_cluster);
16181649 luaX_add_table_func (lua_state (), " columns" , lua_trampoline_table_columns);
16191650
16201651 // Clean up stack
0 commit comments