ext/duckdb/appender.c in duckdb-0.2.8.0 vs ext/duckdb/appender.c in duckdb-0.2.9.0
- old
+ new
@@ -22,10 +22,31 @@
static VALUE appender_append_double(VALUE self, VALUE val);
static VALUE appender_append_varchar(VALUE self, VALUE val);
static VALUE appender_append_varchar_length(VALUE self, VALUE val, VALUE len);
static VALUE appender_append_blob(VALUE self, VALUE val);
static VALUE appender_append_null(VALUE self);
+
+#ifdef HAVE_DUCKDB_APPEND_DATE
+static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VALUE dayval);
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_INTERVAL
+static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros);
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_TIME
+static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros);
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
+static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros);
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_HUGEINT
+static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper);
+#endif
+
static VALUE appender_flush(VALUE self);
static VALUE appender_close(VALUE self);
static void deallocate(void * ctx)
{
@@ -266,10 +287,110 @@
rb_raise(eDuckDBError, "failed to append");
}
return self;
}
+#ifdef HAVE_DUCKDB_APPEND_DATE
+static VALUE appender__append_date(VALUE self, VALUE yearval, VALUE monthval, VALUE dayval) {
+ duckdb_date_struct dt_struct;
+ duckdb_date dt;
+ rubyDuckDBAppender *ctx;
+
+ Data_Get_Struct(self, rubyDuckDBAppender, ctx);
+ dt_struct.year = NUM2INT(yearval);
+ dt_struct.month = NUM2INT(monthval);
+ dt_struct.day = NUM2INT(dayval);
+ dt = duckdb_to_date(dt_struct);
+
+ if (duckdb_append_date(ctx->appender, dt) == DuckDBError) {
+ rb_raise(eDuckDBError, "failed to append date");
+ }
+ return self;
+}
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_INTERVAL
+static VALUE appender__append_interval(VALUE self, VALUE months, VALUE days, VALUE micros) {
+ duckdb_interval interval;
+ rubyDuckDBAppender *ctx;
+
+ Data_Get_Struct(self, rubyDuckDBAppender, ctx);
+ interval.months = NUM2INT(months);
+ interval.days = NUM2INT(days);
+ interval.micros = NUM2LL(micros);
+
+ if (duckdb_append_interval(ctx->appender, interval) == DuckDBError) {
+ rb_raise(eDuckDBError, "failed to append interval");
+ }
+ return self;
+}
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_TIME
+static VALUE appender__append_time(VALUE self, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
+ duckdb_time_struct time_st;
+ duckdb_time time;
+ rubyDuckDBAppender *ctx;
+
+ Data_Get_Struct(self, rubyDuckDBAppender, ctx);
+ time_st.hour = NUM2INT(hour);
+ time_st.min = NUM2INT(min);
+ time_st.sec = NUM2INT(sec);
+ time_st.micros = NUM2INT(micros);
+
+ time = duckdb_to_time(time_st);
+
+ if (duckdb_append_time(ctx->appender, time) == DuckDBError) {
+ rb_raise(eDuckDBError, "failed to append time");
+ }
+ return self;
+}
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
+static VALUE appender__append_timestamp(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour, VALUE min, VALUE sec, VALUE micros) {
+ duckdb_timestamp_struct timestamp_st;
+ duckdb_timestamp timestamp;
+
+ rubyDuckDBAppender *ctx;
+
+ Data_Get_Struct(self, rubyDuckDBAppender, ctx);
+
+ timestamp_st.date.year = NUM2INT(year);
+ timestamp_st.date.month = NUM2INT(month);
+ timestamp_st.date.day = NUM2INT(day);
+ timestamp_st.time.hour = NUM2INT(hour);
+ timestamp_st.time.min = NUM2INT(min);
+ timestamp_st.time.sec = NUM2INT(sec);
+ timestamp_st.time.micros = NUM2INT(micros);
+
+ timestamp = duckdb_to_timestamp(timestamp_st);
+
+ if (duckdb_append_timestamp(ctx->appender, timestamp) == DuckDBError) {
+ rb_raise(eDuckDBError, "failed to append timestamp");
+ }
+ return self;
+}
+#endif
+
+#ifdef HAVE_DUCKDB_APPEND_HUGEINT
+static VALUE appender__append_hugeint(VALUE self, VALUE lower, VALUE upper) {
+ duckdb_hugeint hugeint;
+
+ hugeint.lower = NUM2ULL(lower);
+ hugeint.upper = NUM2LL(upper);
+
+ rubyDuckDBAppender *ctx;
+
+ Data_Get_Struct(self, rubyDuckDBAppender, ctx);
+ if (duckdb_append_hugeint(ctx->appender, hugeint) == DuckDBError) {
+ rb_raise(eDuckDBError, "failed to append hugeint");
+ }
+ return self;
+}
+#endif
+
static VALUE appender_flush(VALUE self) {
rubyDuckDBAppender *ctx;
Data_Get_Struct(self, rubyDuckDBAppender, ctx);
if (duckdb_appender_flush(ctx->appender) == DuckDBError) {
@@ -307,9 +428,24 @@
rb_define_method(cDuckDBAppender, "append_double", appender_append_double, 1);
rb_define_method(cDuckDBAppender, "append_varchar", appender_append_varchar, 1);
rb_define_method(cDuckDBAppender, "append_varchar_length", appender_append_varchar_length, 2);
rb_define_method(cDuckDBAppender, "append_blob", appender_append_blob, 1);
rb_define_method(cDuckDBAppender, "append_null", appender_append_null, 0);
+#ifdef HAVE_DUCKDB_APPEND_DATE
+ rb_define_private_method(cDuckDBAppender, "_append_date", appender__append_date, 3);
+#endif
+#ifdef HAVE_DUCKDB_APPEND_INTERVAL
+ rb_define_private_method(cDuckDBAppender, "_append_interval", appender__append_interval, 3);
+#endif
+#ifdef HAVE_DUCKDB_APPEND_TIME
+ rb_define_private_method(cDuckDBAppender, "_append_time", appender__append_time, 4);
+#endif
+#ifdef HAVE_DUCKDB_APPEND_TIMESTAMP
+ rb_define_private_method(cDuckDBAppender, "_append_timestamp", appender__append_timestamp, 7);
+#endif
+#ifdef HAVE_DUCKDB_APPEND_HUGEINT
+ rb_define_private_method(cDuckDBAppender, "_append_hugeint", appender__append_hugeint, 2);
+#endif
rb_define_method(cDuckDBAppender, "flush", appender_flush, 0);
rb_define_method(cDuckDBAppender, "close", appender_close, 0);
}
#endif /* HAVE_DUCKDB_APPENDER_CREATE */