class DuckDB::TableFunction::InitInfo
The DuckDB::TableFunction::InitInfo provides context during table function initialization.
It is passed to the init callback to set up execution state.
Example:
table_function.init do |init_info| # Initialize execution state # Can report errors if initialization fails init_info.set_error('Initialization failed') end
rubocop:disable Lint/EmptyClass
Public Instance Methods
Returns the object stored during the bind phase with DuckDB::TableFunction::BindInfo#set_bind_data, or nil if none was set.
data = init_info.bind_data
Source
static VALUE table_function_init_info_column_count(VALUE self) {
rubyDuckDBInitInfo *ctx;
TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
return ULL2NUM(duckdb_init_get_column_count(ctx->info));
}
Returns the number of projected result columns for this scan. Without projection pushdown this equals the number of result columns added in the bind callback.
init_info.column_count # => 2
Source
static VALUE table_function_init_info_column_index(VALUE self, VALUE index) {
rubyDuckDBInitInfo *ctx;
TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
return ULL2NUM(duckdb_init_get_column_index(ctx->info, NUM2ULL(index)));
}
Returns the column index of the projected result column at index (0 <= index < column_count). Without projection pushdown the projected columns mirror the columns added in the bind callback, so this returns index itself.
init_info.column_index(0) # => 0
Source
static VALUE table_function_init_info_get_bind_data(VALUE self) {
rubyDuckDBInitInfo *ctx;
TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
return rbduckdb_function_data_lookup(duckdb_init_get_bind_data(ctx->info));
}
Returns the object stored during the bind phase with DuckDB::TableFunction::BindInfo#set_bind_data, or nil if none was set.
data = init_info.bind_data
Sets the maximum number of threads that can execute the table function concurrently. This is a hint to DuckDB’s scheduler; the actual number of threads is also bounded by the configured worker pool size (e.g., +SET threads+).
init_info.max_threads = 4
Source
static VALUE table_function_init_info_set_error(VALUE self, VALUE error) {
rubyDuckDBInitInfo *ctx;
const char *error_msg;
TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
error_msg = StringValueCStr(error);
duckdb_init_set_error(ctx->info, error_msg);
return self;
}
Sets an error message for the init phase. This will cause the query to fail with the specified error.
init_info.set_error('Invalid initialization')
Source
static VALUE table_function_init_info_set_max_threads(VALUE self, VALUE max_threads) {
rubyDuckDBInitInfo *ctx;
TypedData_Get_Struct(self, rubyDuckDBInitInfo, &init_info_data_type, ctx);
duckdb_init_set_max_threads(ctx->info, NUM2ULL(max_threads));
return self;
}
Sets the maximum number of threads that can execute the table function concurrently. This is a hint to DuckDB’s scheduler; the actual number of threads is also bounded by the configured worker pool size (e.g., +SET threads+).
init_info.max_threads = 4