Class: DuckDB::Expression
- Inherits:
-
Object
- Object
- DuckDB::Expression
- Defined in:
- lib/duckdb/expression.rb,
ext/duckdb/expression.c
Overview
DuckDB::Expression represents a DuckDB expression object.
Instances are returned by DuckDB::ScalarFunction::BindInfo#get_argument during the bind phase of a scalar function.
Instance Method Summary collapse
-
#fold(client_context) ⇒ Object
Evaluates the expression at planning time and returns a DuckDB::Value holding the constant result.
-
#foldable? ⇒ Boolean
Returns
trueif the expression can be folded to a constant at query planning time (e.g. literals, constant arithmetic),falseotherwise (e.g. column references, non-deterministic functions).
Instance Method Details
#fold(client_context) ⇒ Object
Evaluates the expression at planning time and returns a DuckDB::Value holding the constant result. Raises DuckDB::Error if the expression is not foldable.
sf.set_bind do |bind_info|
expr = bind_info.get_argument(0)
client_context = bind_info.client_context
value = expr.fold(client_context) # => DuckDB::Value
end
18 19 20 21 22 |
# File 'lib/duckdb/expression.rb', line 18 def fold(client_context) raise DuckDB::Error, 'expression is not foldable' unless foldable? _fold(client_context) end |
#foldable? ⇒ Boolean
Returns true if the expression can be folded to a constant at query planning time (e.g. literals, constant arithmetic), false otherwise (e.g. column references, non-deterministic functions).
54 55 56 57 58 |
# File 'ext/duckdb/expression.c', line 54
static VALUE rbduckdb_expression_foldable_p(VALUE self) {
rubyDuckDBExpression *ctx;
TypedData_Get_Struct(self, rubyDuckDBExpression, &expression_data_type, ctx);
return duckdb_expression_is_foldable(ctx->expression) ? Qtrue : Qfalse;
}
|