简体   繁体   English

从MonetdbLite C API使用monetdb_append

[英]Using monetdb_append from MonetdbLite C API

I am trying to use MonetDBLite C in an application. 我正在尝试在应用程序中使用MonetDBLiteC。 According to the PDF ( https://arxiv.org/pdf/1805.08520.pdf ), I would benefit from a boost in speed in loading massive amount of data using monetdb_append function. 根据PDF( https://arxiv.org/pdf/1805.08520.pdf )所述,我将受益于使用monetdb_append函数加载大量数据的速度提高。 From PDF: 从PDF:

In addition to issuing SQL queries, the embedded process can efficiently bulk append large amounts of data to the database using the monetdb_append function. 除了发出SQL查询之外,嵌入式过程还可以使用monetdb_append函数将大量数据有效地批量追加到数据库。 This function takes the schema and the name of a table to append to, and a reference to the data to append to the columns of the table. 该函数采用要添加到的表的模式和名称,以及要添加到表的列的对数据的引用。 This function allows for efficient bulk insertions, as there is significant overhead involved in parsing individual INSERT INTO statements, which becomes a bottleneck when the user wants to insert a large amount of data. 此功能可进行有效的大容量插入,因为解析单个INSERT INTO语句涉及大量开销,当用户要插入大量数据时,这将成为瓶颈。

This is the declaration in embedded.h 这是embedded.h中的声明

char* monetdb_append(monetdb_connection conn, const char* schema, const char* table, append_data *data, int ncols);

Has anybody an example how to use this function? 有没有人举个例子说明如何使用这个功能? I assume that batid of the append_data structure is the identification of a BAT structure. 我假设append_data结构的那BATID是BAT结构的识别。 But it is not clear how that can be used with the existing API. 但是尚不清楚如何将其与现有API一起使用。

The binary append indeed requires construction of as many BAT structures as you have columns to append. 二进制附加确实需要构造与要附加的列一样多的BAT结构。 Some additional MonetDBLite headers need to be included ( monetdb_config.h and gdk.h ). 需要包括一些其他的MonetDBLite标头( monetdb_config.hgdk.h )。 The important parts are: 重要的部分是:

  1. Create the BATs using COLnew with the correct type and count 使用COLnew使用正确的类型和数量创建COLnew
  2. Add some values to them, eg by pointer access (of the correct type length) to bat->theap.base[i] 向它们添加一些值,例如,通过对bat->theap.base[i]指针访问(具有正确的类型长度)
  3. Set BAT properties ( BATsetcount , BATsettrivprop and BBPkeepref ) for the append 为附加设置BAT属性( BATsetcountBATsettrivpropBBPkeepref
  4. Allocate and populate the append_data data structure. 分配并填充append_data数据结构。
  5. Call monetdb_append . 调用monetdb_append

Below is a short example how to append 42 values to a one-column table containing integers ( CREATE TABLE test (my_column INTEGER); ) 下面是一个简短的示例,如何将42个值附加到包含整数的单列表中( CREATE TABLE test (my_column INTEGER);

// startup, connect etc. before

size_t n = 42;
BAT* b = COLnew(0, TYPE_int, n, TRANSIENT);
for (size_t i = 0; i < n; i++) {
    ((int*)b->theap.base)[i] = i; // or whatever
}

BATsetcount(b, n);
BATsettrivprop(b);
BBPkeepref(b->batCacheid);

append_data *ad = NULL;
ad = malloc(1 * sizeof(append_data));
ad[0].colname = "my_column";
ad[0].batid = b->batCacheid;

if (monetdb_append(conn, "sys", "test", ad, 1) != NULL) { /* handle error */}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM