ext/duckdb/result.c in duckdb-0.10.2.0 vs ext/duckdb/result.c in duckdb-1.0.0.0
- old
+ new
@@ -1,7 +1,12 @@
#include "ruby-duckdb.h"
+struct chunk_arg {
+ duckdb_data_chunk chunk;
+ idx_t col_count;
+};
+
static VALUE cDuckDBResult;
static ID id__to_date;
static ID id__to_time;
static ID id__to_time_from_duckdb_time;
static ID id__to_interval_from_vector;
@@ -25,14 +30,15 @@
static VALUE duckdb_result_column_count(VALUE oDuckDBResult);
static VALUE duckdb_result_row_count(VALUE oDuckDBResult);
static VALUE duckdb_result_rows_changed(VALUE oDuckDBResult);
static VALUE duckdb_result_columns(VALUE oDuckDBResult);
static VALUE duckdb_result_streaming_p(VALUE oDuckDBResult);
+static VALUE destroy_data_chunk(VALUE arg);
static VALUE duckdb_result_chunk_each(VALUE oDuckDBResult);
static VALUE duckdb_result__chunk_stream(VALUE oDuckDBResult);
-static void yield_rows(duckdb_data_chunk chunk, idx_t col_count);
+static VALUE yield_rows(VALUE arg);
static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx);
static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
static VALUE duckdb_result__to_smallint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
static VALUE duckdb_result__to_utinyint(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx);
@@ -91,64 +97,115 @@
TypedData_Get_Struct(obj, rubyDuckDBResult, &result_data_type, ctx);
return ctx;
}
static VALUE to_ruby_obj_boolean(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_boolean` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
bool bval = duckdb_value_boolean(result, col_idx, row_idx);
return bval ? Qtrue : Qfalse;
+#endif
}
static VALUE to_ruby_obj_smallint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_smallint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
int16_t i16val = duckdb_value_int16(result, col_idx, row_idx);
return INT2FIX(i16val);
+#endif
}
static VALUE to_ruby_obj_utinyint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_utinyint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
uint8_t ui8val = duckdb_value_uint8(result, col_idx, row_idx);
return UINT2NUM(ui8val);
+#endif
}
static VALUE to_ruby_obj_integer(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_integer` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
int32_t i32val = duckdb_value_int32(result, col_idx, row_idx);
return INT2NUM(i32val);
+#endif
}
static VALUE to_ruby_obj_bigint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_bigint` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
int64_t i64val = duckdb_value_int64(result, col_idx, row_idx);
return LL2NUM(i64val);
+#endif
}
static VALUE to_ruby_obj_hugeint(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `__to_hugeint_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
duckdb_hugeint hugeint = duckdb_value_hugeint(result, col_idx, row_idx);
return rb_ary_new3(2, ULL2NUM(hugeint.lower), LL2NUM(hugeint.upper));
+#endif
}
static VALUE to_ruby_obj_decimal(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `__to_decimal_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
duckdb_decimal decimal = duckdb_value_decimal(result, col_idx, row_idx);
return rb_ary_new3(4, ULL2NUM(decimal.value.lower), LL2NUM(decimal.value.upper), UINT2NUM(decimal.width), UINT2NUM(decimal.scale));
+#endif
}
static VALUE to_ruby_obj_float(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_float` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
float fval = duckdb_value_float(result, col_idx, row_idx);
return DBL2NUM(fval);
+#endif
}
static VALUE to_ruby_obj_double(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_double` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
double dval = duckdb_value_double(result, col_idx, row_idx);
return DBL2NUM(dval);
+#endif
}
static VALUE to_ruby_obj_blob(duckdb_result *result, idx_t col_idx, idx_t row_idx) {
+
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
VALUE str;
+ rb_warn("private method `_to_blob` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
duckdb_blob bval = duckdb_value_blob(result, col_idx, row_idx);
str = rb_str_new(bval.data, bval.size);
if (bval.data) {
duckdb_free(bval.data);
}
return str;
+#endif
}
/*
* call-seq:
* result.rows_changed -> integer
@@ -218,13 +275,19 @@
* end
* end
*
*/
static VALUE duckdb_result_row_count(VALUE oDuckDBResult) {
+
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
rubyDuckDBResult *ctx;
+ rb_warn("`row_count` will be deprecated in the future.");
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
return LL2NUM(duckdb_row_count(&(ctx->result)));
+#endif
}
/*
* call-seq:
* result.columns -> DuckDB::Column[]
@@ -254,72 +317,101 @@
* Returns true if the result is streaming, otherwise false.
*
*/
static VALUE duckdb_result_streaming_p(VALUE oDuckDBResult) {
rubyDuckDBResult *ctx;
+
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qtrue;
+#else
+ /* FIXME streaming is allways true. so this method is not useful and deprecated. */
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
return duckdb_result_is_streaming(ctx->result) ? Qtrue : Qfalse;
+#endif
}
+static VALUE destroy_data_chunk(VALUE arg) {
+ struct chunk_arg *p = (struct chunk_arg *)arg;
+ duckdb_destroy_data_chunk(&(p->chunk));
+ return Qnil;
+}
+
static VALUE duckdb_result_chunk_each(VALUE oDuckDBResult) {
+/*
+#ifdef HAVE_DUCKDB_H_GE_V1_0_0
+ return duckdb_result__chunk_stream(oDuckDBResult);
+#else
+*/
rubyDuckDBResult *ctx;
- idx_t col_count;
+ struct chunk_arg arg;
idx_t chunk_count;
idx_t chunk_idx;
- duckdb_data_chunk chunk;
+#ifdef DUCKDB_API_NO_DEPRECATED
+ //TODO: use duckdb_fetch_chunk instead of duckdb_result_chunk_count and duckdb_result_get_chunk.
+ // duckdb_result_chunk_count will be deprecated in the future.
+ // duckdb_result_get_chunk will be deprecated in the future.
+#else
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
- col_count = duckdb_column_count(&(ctx->result));
+ arg.col_count = duckdb_column_count(&(ctx->result));
chunk_count = duckdb_result_chunk_count(ctx->result);
RETURN_ENUMERATOR(oDuckDBResult, 0, 0);
for (chunk_idx = 0; chunk_idx < chunk_count; chunk_idx++) {
- chunk = duckdb_result_get_chunk(ctx->result, chunk_idx);
- yield_rows(chunk, col_count);
- duckdb_destroy_data_chunk(&chunk);
+ arg.chunk = duckdb_result_get_chunk(ctx->result, chunk_idx);
+ rb_ensure(yield_rows, (VALUE)&arg, destroy_data_chunk, (VALUE)&arg);
}
+#endif
return Qnil;
+/*
+#endif
+*/
}
static VALUE duckdb_result__chunk_stream(VALUE oDuckDBResult) {
rubyDuckDBResult *ctx;
- duckdb_data_chunk chunk;
- idx_t col_count;
+ struct chunk_arg arg;
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
RETURN_ENUMERATOR(oDuckDBResult, 0, 0);
- col_count = duckdb_column_count(&(ctx->result));
+ arg.col_count = duckdb_column_count(&(ctx->result));
- while((chunk = duckdb_stream_fetch_chunk(ctx->result)) != NULL) {
- yield_rows(chunk, col_count);
- duckdb_destroy_data_chunk(&chunk);
+#ifdef HAVE_DUCKDB_H_GE_V1_0_0
+ while((arg.chunk = duckdb_fetch_chunk(ctx->result)) != NULL) {
+#else
+ while((arg.chunk = duckdb_stream_fetch_chunk(ctx->result)) != NULL) {
+#endif
+ rb_ensure(yield_rows, (VALUE)&arg, destroy_data_chunk, (VALUE)&arg);
}
return Qnil;
}
-static void yield_rows(duckdb_data_chunk chunk, idx_t col_count) {
+static VALUE yield_rows(VALUE arg) {
idx_t row_count;
idx_t row_idx;
idx_t col_idx;
duckdb_vector vector;
VALUE row;
VALUE val;
- row_count = duckdb_data_chunk_get_size(chunk);
+ struct chunk_arg *p = (struct chunk_arg *)arg;
+
+ row_count = duckdb_data_chunk_get_size(p->chunk);
for (row_idx = 0; row_idx < row_count; row_idx++) {
- row = rb_ary_new2(col_count);
- for (col_idx = 0; col_idx < col_count; col_idx++) {
- vector = duckdb_data_chunk_get_vector(chunk, col_idx);
+ row = rb_ary_new2(p->col_count);
+ for (col_idx = 0; col_idx < p->col_count; col_idx++) {
+ vector = duckdb_data_chunk_get_vector(p->chunk, col_idx);
val = vector_value(vector, row_idx);
rb_ary_store(row, col_idx, val);
}
rb_yield(row);
}
+ return Qnil;
}
static VALUE duckdb_result__column_type(VALUE oDuckDBResult, VALUE col_idx) {
rubyDuckDBResult *ctx;
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
@@ -327,14 +419,19 @@
}
static VALUE duckdb_result__is_null(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
rubyDuckDBResult *ctx;
bool is_null;
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qfalse;
+#else
+ rb_warn("private method `_null?` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
is_null = duckdb_value_is_null(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
return is_null ? Qtrue : Qfalse;
+#endif
}
static VALUE duckdb_result__to_boolean(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
rubyDuckDBResult *ctx;
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
@@ -401,32 +498,42 @@
static VALUE duckdb_result__to_string(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
rubyDuckDBResult *ctx;
duckdb_string p;
VALUE obj;
+#ifdef DUCKDB_API_NO_DEPRECATED
+ return Qnil;
+#else
+ rb_warn("private method `_to_string` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
p = duckdb_value_string(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
if (p.data) {
obj = rb_utf8_str_new(p.data, p.size);
duckdb_free(p.data);
return obj;
}
+#endif
return Qnil;
}
static VALUE duckdb_result__to_string_internal(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
rubyDuckDBResult *ctx;
duckdb_string p;
VALUE obj;
+#ifdef DUCKDB_API_NO_DEPRECATED
+ // duckdb_value_string_internal will be deprecated in the future.
+#else
+ rb_warn("private method `_to_string_internal` will be deprecated in the future. Set DuckDB::Result#use_chunk_each to true.");
TypedData_Get_Struct(oDuckDBResult, rubyDuckDBResult, &result_data_type, ctx);
p = duckdb_value_string_internal(&(ctx->result), NUM2LL(col_idx), NUM2LL(row_idx));
if (p.data) {
obj = rb_utf8_str_new(p.data, p.size);
return obj;
}
+#endif
return Qnil;
}
static VALUE duckdb_result__to_blob(VALUE oDuckDBResult, VALUE row_idx, VALUE col_idx) {
rubyDuckDBResult *ctx;
@@ -803,29 +910,30 @@
id__to_uuid_from_vector = rb_intern("_to_uuid_from_vector");
rb_define_alloc_func(cDuckDBResult, allocate);
rb_define_method(cDuckDBResult, "column_count", duckdb_result_column_count, 0);
- rb_define_method(cDuckDBResult, "row_count", duckdb_result_row_count, 0);
+ rb_define_method(cDuckDBResult, "row_count", duckdb_result_row_count, 0); /* deprecated */
rb_define_method(cDuckDBResult, "rows_changed", duckdb_result_rows_changed, 0);
rb_define_method(cDuckDBResult, "columns", duckdb_result_columns, 0);
rb_define_method(cDuckDBResult, "streaming?", duckdb_result_streaming_p, 0);
rb_define_method(cDuckDBResult, "chunk_each", duckdb_result_chunk_each, 0);
rb_define_private_method(cDuckDBResult, "_chunk_stream", duckdb_result__chunk_stream, 0);
rb_define_private_method(cDuckDBResult, "_column_type", duckdb_result__column_type, 1);
- rb_define_private_method(cDuckDBResult, "_null?", duckdb_result__is_null, 2);
- rb_define_private_method(cDuckDBResult, "_to_boolean", duckdb_result__to_boolean, 2);
- rb_define_private_method(cDuckDBResult, "_to_smallint", duckdb_result__to_smallint, 2);
- rb_define_private_method(cDuckDBResult, "_to_utinyint", duckdb_result__to_utinyint, 2);
- rb_define_private_method(cDuckDBResult, "_to_integer", duckdb_result__to_integer, 2);
- rb_define_private_method(cDuckDBResult, "_to_bigint", duckdb_result__to_bigint, 2);
- rb_define_private_method(cDuckDBResult, "__to_hugeint_internal", duckdb_result___to_hugeint_internal, 2);
- rb_define_private_method(cDuckDBResult, "__to_decimal_internal", duckdb_result___to_decimal_internal, 2);
- rb_define_private_method(cDuckDBResult, "_to_float", duckdb_result__to_float, 2);
- rb_define_private_method(cDuckDBResult, "_to_double", duckdb_result__to_double, 2);
- rb_define_private_method(cDuckDBResult, "_to_string", duckdb_result__to_string, 2);
- rb_define_private_method(cDuckDBResult, "_to_string_internal", duckdb_result__to_string_internal, 2);
- rb_define_private_method(cDuckDBResult, "_to_blob", duckdb_result__to_blob, 2);
+
+ rb_define_private_method(cDuckDBResult, "_null?", duckdb_result__is_null, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_boolean", duckdb_result__to_boolean, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_smallint", duckdb_result__to_smallint, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_utinyint", duckdb_result__to_utinyint, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_integer", duckdb_result__to_integer, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_bigint", duckdb_result__to_bigint, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "__to_hugeint_internal", duckdb_result___to_hugeint_internal, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "__to_decimal_internal", duckdb_result___to_decimal_internal, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_float", duckdb_result__to_float, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_double", duckdb_result__to_double, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_string", duckdb_result__to_string, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_string_internal", duckdb_result__to_string_internal, 2); /* deprecated */
+ rb_define_private_method(cDuckDBResult, "_to_blob", duckdb_result__to_blob, 2); /* deprecated */
rb_define_private_method(cDuckDBResult, "_enum_internal_type", duckdb_result__enum_internal_type, 1);
rb_define_private_method(cDuckDBResult, "_enum_dictionary_size", duckdb_result__enum_dictionary_size, 1);
rb_define_private_method(cDuckDBResult, "_enum_dictionary_value", duckdb_result__enum_dictionary_value, 2);
}