Class: DuckDB::ScalarFunction::BindInfo

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

Overview

DuckDB::ScalarFunction::BindInfo encapsulates the bind phase of a scalar function.

An instance is passed to the block given to ScalarFunction#set_bind. The bind phase runs once at query planning time (before execution).

Example:

sf.set_bind do |bind_info|
  if bind_info.argument_count != 1
    bind_info.set_error('expected exactly 1 argument')
  end
end

Instance Method Summary collapse

Instance Method Details

#argument_countInteger

Returns the number of arguments declared for the scalar function.

bind_info.argument_count  # => 2

Returns:

  • (Integer)


49
50
51
52
53
# File 'ext/duckdb/scalar_function_bind_info.c', line 49

static VALUE rbduckdb_scalar_function_bind_info_argument_count(VALUE self) {
    rubyDuckDBScalarFunctionBindInfo *ctx;
    TypedData_Get_Struct(self, rubyDuckDBScalarFunctionBindInfo, &scalar_function_bind_info_data_type, ctx);
    return ULL2NUM(duckdb_scalar_function_bind_get_argument_count(ctx->bind_info));
}

#client_contextDuckDB::ClientContext

Returns the client context associated with the bind phase of the scalar function.



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

static VALUE rbduckdb_scalar_function_bind_info_client_context(VALUE self) {
    rubyDuckDBScalarFunctionBindInfo *ctx;
    duckdb_client_context client_context;
    TypedData_Get_Struct(self, rubyDuckDBScalarFunctionBindInfo, &scalar_function_bind_info_data_type, ctx);
    duckdb_scalar_function_get_client_context(ctx->bind_info, &client_context);
    return rbduckdb_client_context_new(client_context);
}

#get_argument(index) ⇒ Object

Returns the DuckDB::Expression for the argument at index. Raises ArgumentError if index is out of range.

sf.set_bind do |bind_info|
  expr = bind_info.get_argument(0)
end


25
26
27
28
29
30
31
32
# File 'lib/duckdb/scalar_function/bind_info.rb', line 25

def get_argument(index)
  if index.negative? || index >= argument_count
    raise ArgumentError,
          "index #{index} is out of range (argument_count: #{argument_count})"
  end

  _get_argument(index)
end

#set_error(message) ⇒ self

Reports an error during the bind phase. The error message will be propagated as a DuckDB::Error when the query is executed.

bind_info.set_error('invalid argument')

Returns:

  • (self)


64
65
66
67
68
69
# File 'ext/duckdb/scalar_function_bind_info.c', line 64

static VALUE rbduckdb_scalar_function_bind_info_set_error(VALUE self, VALUE error) {
    rubyDuckDBScalarFunctionBindInfo *ctx;
    TypedData_Get_Struct(self, rubyDuckDBScalarFunctionBindInfo, &scalar_function_bind_info_data_type, ctx);
    duckdb_scalar_function_bind_set_error(ctx->bind_info, StringValueCStr(error));
    return self;
}