Class: DuckDB::TableFunction::InitInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/duckdb/table_function/init_info.rb,
ext/duckdb/table_function_init_info.c

Overview

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

Instance Method Summary collapse

Instance Method Details

#column_countInteger

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

Returns:

  • (Integer)


91
92
93
94
95
96
97
# File 'ext/duckdb/table_function_init_info.c', line 91

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));
}

#column_index(index) ⇒ Integer

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

Returns:

  • (Integer)


110
111
112
113
114
115
116
# File 'ext/duckdb/table_function_init_info.c', line 110

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)));
}

#set_max_threads(max_threads) ⇒ self #max_threads=(max_threads) ⇒ Object

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

Overloads:

  • #set_max_threads(max_threads) ⇒ self

    Returns:

    • (self)


71
72
73
74
75
76
77
78
79
# File 'ext/duckdb/table_function_init_info.c', line 71

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;
}

#set_error(error_message) ⇒ 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')

Returns:

  • (self)


48
49
50
51
52
53
54
55
56
57
58
# File 'ext/duckdb/table_function_init_info.c', line 48

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;
}

#set_max_threads(max_threads) ⇒ self #max_threads=(max_threads) ⇒ Object

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

Overloads:

  • #set_max_threads(max_threads) ⇒ self

    Returns:

    • (self)


71
72
73
74
75
76
77
78
79
# File 'ext/duckdb/table_function_init_info.c', line 71

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;
}