Class: DuckDB::AggregateFunction

Inherits:
Object
  • Object
show all
Includes:
FunctionTypeValidation
Defined in:
lib/duckdb/aggregate_function.rb,
ext/duckdb/aggregate_function.c

Overview

Note:

DuckDB::AggregateFunction is experimental. Phase 1.0 only supports set_init and set_finalize; update and combine are internal no-ops.

DuckDB::AggregateFunction encapsulates DuckDB’s aggregate function.

Constant Summary

Constants included from FunctionTypeValidation

FunctionTypeValidation::SUPPORTED_TYPES

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject



96
97
98
99
100
101
102
103
104
105
106
# File 'ext/duckdb/aggregate_function.c', line 96

static VALUE duckdb_aggregate_function_initialize(VALUE self) {
    rubyDuckDBAggregateFunction *p;
    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);
    p->aggregate_function = duckdb_create_aggregate_function();
    p->init_proc = Qnil;
    p->update_proc = Qnil;
    p->combine_proc = Qnil;
    p->finalize_proc = Qnil;
    p->special_handling = false;
    return self;
}

Class Method Details

._state_registry_sizeObject

Returns the number of Ruby states currently tracked in the registry.



766
767
768
769
# File 'ext/duckdb/aggregate_function.c', line 766

static VALUE aggregate_function_state_registry_size(VALUE klass) {
    (void)klass;
    return LONG2NUM((long)RHASH_SIZE(g_aggregate_state_registry));
}

Instance Method Details

#add_parameter(logical_type) ⇒ DuckDB::AggregateFunction

Adds a parameter to the aggregate function.

Parameters:

Returns:

Raises:



27
28
29
30
31
# File 'lib/duckdb/aggregate_function.rb', line 27

def add_parameter(logical_type)
  logical_type = check_supported_type!(logical_type)

  _add_parameter(logical_type)
end

#name=(name) ⇒ Object



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

static VALUE rbduckdb_aggregate_function_set_name(VALUE self, VALUE name) {
    rubyDuckDBAggregateFunction *p;
    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);

    const char *str = StringValuePtr(name);
    duckdb_aggregate_function_set_name(p->aggregate_function, str);

    return self;
}

#return_type=(logical_type) ⇒ DuckDB::AggregateFunction

Sets the return type for the aggregate function.

Parameters:

Returns:

Raises:



16
17
18
19
20
# File 'lib/duckdb/aggregate_function.rb', line 16

def return_type=(logical_type)
  logical_type = check_supported_type!(logical_type)

  _set_return_type(logical_type)
end

#set_combineObject

:nodoc:



725
726
727
728
729
730
731
732
733
734
735
736
737
738
# File 'ext/duckdb/aggregate_function.c', line 725

static VALUE rbduckdb_aggregate_function_set_combine(VALUE self) {
    rubyDuckDBAggregateFunction *p;

    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "block is required");
    }

    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);
    p->combine_proc = rb_block_proc();

    maybe_set_functions(p);

    return self;
}

#set_finalizeObject

:nodoc:



741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'ext/duckdb/aggregate_function.c', line 741

static VALUE rbduckdb_aggregate_function_set_finalize(VALUE self) {
    rubyDuckDBAggregateFunction *p;

    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "block is required");
    }

    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);
    p->finalize_proc = rb_block_proc();

    maybe_set_functions(p);

    return self;
}

#set_initObject

:nodoc:



693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'ext/duckdb/aggregate_function.c', line 693

static VALUE rbduckdb_aggregate_function_set_init(VALUE self) {
    rubyDuckDBAggregateFunction *p;

    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "block is required");
    }

    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);
    p->init_proc = rb_block_proc();

    maybe_set_functions(p);

    return self;
}

#set_special_handlingDuckDB::AggregateFunction

Sets special NULL handling for the aggregate function. By default DuckDB skips rows with NULL input values. Calling this method disables that behaviour so the update callback is invoked even when inputs are NULL, receiving nil for each NULL argument. This lets the function implement its own NULL semantics (e.g. counting NULLs).

Wraps duckdb_aggregate_function_set_special_handling.

Returns:



43
44
45
# File 'lib/duckdb/aggregate_function.rb', line 43

def set_special_handling
  _set_special_handling
end

#set_updateObject

:nodoc:



709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'ext/duckdb/aggregate_function.c', line 709

static VALUE rbduckdb_aggregate_function_set_update(VALUE self) {
    rubyDuckDBAggregateFunction *p;

    if (!rb_block_given_p()) {
        rb_raise(rb_eArgError, "block is required");
    }

    TypedData_Get_Struct(self, rubyDuckDBAggregateFunction, &aggregate_function_data_type, p);
    p->update_proc = rb_block_proc();

    maybe_set_functions(p);

    return self;
}