Class: Nanoarrow::CMaterializedArrayStream

Inherits:
Object
  • Object
show all
Defined in:
ext/nanoarrow/mat_array_stream.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_c_array(array) ⇒ Object



76
77
78
79
80
# File 'ext/nanoarrow/mat_array_stream.c', line 76

static VALUE mat_array_stream_from_c_array(VALUE klass, VALUE array)
{
    VALUE schema = rb_funcall(array, rb_intern("schema"), 0);
    return mat_array_stream_from_c_arrays(klass, rb_ary_new3(1, array), schema, Qfalse);
}

.from_c_array_stream(stream) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'ext/nanoarrow/mat_array_stream.c', line 82

static VALUE mat_array_stream_from_c_array_stream(VALUE klass, VALUE stream)
{
    VALUE arrays = rb_ary_new();
    while (true)
    {
        VALUE v = rb_funcall(stream, rb_intern("get_next"), 0);
        if (NIL_P(v))
            break;
        rb_ary_push(arrays, v);
    }

    VALUE schema = rb_funcall(stream, rb_intern("get_cached_schema"), 0);
    return mat_array_stream_from_c_arrays(klass, arrays, schema, Qfalse);
}

.from_c_arrays(arrays, schema, validate) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'ext/nanoarrow/mat_array_stream.c', line 40

static VALUE mat_array_stream_from_c_arrays(VALUE klass, VALUE arrays, VALUE schema, VALUE validate)
{
    mat_array_stream_t* out_ptr;
    VALUE out = mat_array_stream_allocate(klass);
    GetMatArrayStream(out, out_ptr);

    Check_Type(arrays, T_ARRAY);

    for (long i = 0; i < RARRAY_LEN(arrays); i++)
    {
        VALUE array = rb_ary_entry(arrays, i);

        if (!rb_obj_is_instance_of(array, cCArray))
            rb_raise(rb_eTypeError, "Expected CArray");

        int64_t len = NUM2LL(rb_funcall(array, rb_intern("length"), 0));
        if (len == 0)
            continue;

        if (RTEST(validate))
        {
            array_t* array_ptr;
            GetArray(array, array_ptr);
            assert_type_equal(array_ptr->schema, schema, Qfalse);
        }

        out_ptr->total_length += len;

        rb_ary_push(out_ptr->arrays, array);
    }

    out_ptr->schema = schema;

    return out;
}

Instance Method Details

#array(idx) ⇒ Object



113
114
115
116
117
118
119
# File 'ext/nanoarrow/mat_array_stream.c', line 113

static VALUE mat_array_stream_array(VALUE self, VALUE idx)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    return rb_funcall(stream->arrays, rb_intern("fetch"), 1, idx);
}

#arraysObject



130
131
132
133
134
135
136
# File 'ext/nanoarrow/mat_array_stream.c', line 130

static VALUE mat_array_stream_arrays(VALUE self)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    return stream->arrays;
}

#arrow_c_streamObject



138
139
140
141
142
143
144
145
# File 'ext/nanoarrow/mat_array_stream.c', line 138

static VALUE mat_array_stream_arrow_c_stream(VALUE self)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    VALUE stream_ptr = rb_funcall(cCArrayStream, rb_intern("from_c_arrays"), 3, stream->arrays, stream->schema, Qfalse);
    return rb_funcall(stream_ptr, rb_intern("arrow_c_stream"), 0);
}

#child(idx) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'ext/nanoarrow/mat_array_stream.c', line 147

static VALUE mat_array_stream_child(VALUE self, VALUE idx)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    mat_array_stream_t* out_ptr;
    VALUE out = mat_array_stream_allocate(cCMatArrayStream);
    GetMatArrayStream(out, out_ptr);

    out_ptr->schema = rb_funcall(stream->schema, rb_intern("child"), 1, idx);

    Check_Type(stream->arrays, T_ARRAY);
    long arrays_len = RARRAY_LEN(stream->arrays);
    out_ptr->arrays = rb_ary_new_capa(arrays_len);

    for (long i = 0; i < arrays_len; i++)
    {
        VALUE child = rb_funcall(rb_ary_entry(stream->arrays, i), rb_intern("child"), 1, idx);
        out_ptr->total_length += NUM2LL(rb_funcall(child, rb_intern("length"), 0));
        rb_ary_push(out_ptr->arrays, child);
    }

    return out;
}

#lengthObject



105
106
107
108
109
110
111
# File 'ext/nanoarrow/mat_array_stream.c', line 105

static VALUE mat_array_stream_length(VALUE self)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    return LL2NUM(stream->total_length);
}

#n_arraysObject



121
122
123
124
125
126
127
128
# File 'ext/nanoarrow/mat_array_stream.c', line 121

static VALUE mat_array_stream_n_arrays(VALUE self)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    Check_Type(stream->arrays, T_ARRAY);
    return LONG2NUM(RARRAY_LEN(stream->arrays));
}

#schemaObject



97
98
99
100
101
102
103
# File 'ext/nanoarrow/mat_array_stream.c', line 97

static VALUE mat_array_stream_schema(VALUE self)
{
    mat_array_stream_t* stream;
    GetMatArrayStream(self, stream);

    return stream->schema;
}