Class: DuckDB::TableFunction::BindInfo

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

Overview

The DuckDB::TableFunction::BindInfo encapsulates information for the bind phase of table functions.

During the bind phase, you can:

  • Access parameters passed to the function
  • Define the output schema (columns)
  • Set performance hints (cardinality)
  • Report errors

Example:

table_function.bind do |bind_info|
# Get parameters
limit = bind_info.get_parameter(0).to_i

# Define output schema
bind_info.add_result_column('id', DuckDB::LogicalType::BIGINT)
bind_info.add_result_column('name', DuckDB::LogicalType::VARCHAR)

# Set cardinality hint
bind_info.set_cardinality(limit, true)
end

Instance Method Summary collapse

Instance Method Details

#add_result_column(name, type) ⇒ Object



29
30
31
# File 'lib/duckdb/table_function/bind_info.rb', line 29

def add_result_column(name, type)
  _add_result_column(name.to_s, DuckDB::LogicalType.resolve(type))
end

#bind_data=(data) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/duckdb/table_function_bind_info.c', line 181

static VALUE table_function_bind_info_set_bind_data(VALUE self, VALUE data) {
    rubyDuckDBBindInfo *ctx;
    void *handle;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    if (ctx->bind_data_handle != NULL) {
        rbduckdb_function_data_release(ctx->bind_data_handle);
    }
    handle = rbduckdb_function_data_register(data);
    ctx->bind_data_handle = handle;
    duckdb_bind_set_bind_data(ctx->bind_info, handle, rbduckdb_function_data_destroy);

    return self;
}

#get_named_parameter(name) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/duckdb/table_function_bind_info.c', line 101

static VALUE table_function_bind_info_get_named_parameter(VALUE self, VALUE name) {
    rubyDuckDBBindInfo *ctx;
    const char *param_name;
    duckdb_value param_value;
    VALUE result;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    param_name = StringValueCStr(name);
    param_value = duckdb_bind_get_named_parameter(ctx->bind_info, param_name);

    // If parameter not found, return nil
    if (!param_value) {
        return Qnil;
    }

    result = rbduckdb_duckdb_value_to_ruby(param_value);

    duckdb_destroy_value(&param_value);

    return result;
}

#get_parameter(index) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'ext/duckdb/table_function_bind_info.c', line 75

static VALUE table_function_bind_info_get_parameter(VALUE self, VALUE index) {
    rubyDuckDBBindInfo *ctx;
    idx_t idx;
    duckdb_value param_value;
    VALUE result;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    idx = NUM2ULL(index);
    param_value = duckdb_bind_get_parameter(ctx->bind_info, idx);

    result = rbduckdb_duckdb_value_to_ruby(param_value);

    duckdb_destroy_value(&param_value);

    return result;
}

#parameter_countObject



56
57
58
59
60
61
62
63
64
65
# File 'ext/duckdb/table_function_bind_info.c', line 56

static VALUE table_function_bind_info_parameter_count(VALUE self) {
    rubyDuckDBBindInfo *ctx;
    idx_t count;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    count = duckdb_bind_get_parameter_count(ctx->bind_info);

    return ULL2NUM(count);
}

#set_cardinality(cardinality, is_exact) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'ext/duckdb/table_function_bind_info.c', line 156

static VALUE table_function_bind_info_set_cardinality(VALUE self, VALUE cardinality, VALUE is_exact) {
    rubyDuckDBBindInfo *ctx;
    idx_t card;
    bool exact;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    card = NUM2ULL(cardinality);
    exact = RTEST(is_exact);

    duckdb_bind_set_cardinality(ctx->bind_info, card, exact);

    return self;
}

#set_error(error) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
# File 'ext/duckdb/table_function_bind_info.c', line 205

static VALUE table_function_bind_info_set_error(VALUE self, VALUE error) {
    rubyDuckDBBindInfo *ctx;
    const char *error_msg;

    TypedData_Get_Struct(self, rubyDuckDBBindInfo, &bind_info_data_type, ctx);

    error_msg = StringValueCStr(error);
    duckdb_bind_set_error(ctx->bind_info, error_msg);

    return self;
}