Append an array of values to a BUN
Hi there,
Is there a way to append an array of values to a BUN, instead one value at
a time?
sql_table *tbl = mvc_bind_table(m, sch, "atable");
sql_column *col = mvc_bind_column(m, tbl, "acolumn");
BAT *tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT);
long long v_long[3] = {100000000009,100000000010,100000000011};
for (irow=0; irow
Ok to make it work I had to replace
for (irow=0; irow
Hi there,
Is there a way to append an array of values to a BUN, instead one value at a time?
sql_table *tbl = mvc_bind_table(m, sch, "atable"); sql_column *col = mvc_bind_column(m, tbl, "acolumn"); BAT *tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT); long long v_long[3] = {100000000009,100000000010,100000000011};
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Thanks, Anton
Though I wonder how to append an array of values to a BUN for TYPE_str
column?
sql_table *tbl = mvc_bind_table(m, sch, "atable");
sql_column *col1 = mvc_bind_column(m, tbl, "acolumn"); //char(1)
BAT *tmp1 = NULL;
int nrows = 3;
tmp1 = COLnew(0, TYPE_str, (BUN)nrows, TRANSIENT);
char v_char[3][2] = {"Y\0","N\0","Y\0"}; //char(1)
for (irow=0; irow
Ok to make it work I had to replace
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
with
memcpy(Tloc(tmp1, BUNlast(tmp1)), v_long, nrows*sizeof(long long));
BATsetcount(tmp1, BATcount(tmp1) + nrows);
Anton
On Fri, Nov 2, 2018 at 9:39 AM Anton Kravchenko < kravchenko.anton86@gmail.com> wrote:
Hi there,
Is there a way to append an array of values to a BUN, instead one value at a time?
sql_table *tbl = mvc_bind_table(m, sch, "atable"); sql_column *col = mvc_bind_column(m, tbl, "acolumn"); BAT *tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT); long long v_long[3] = {100000000009,100000000010,100000000011};
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Thanks, Anton
I tried char *v_char[] = {"Y\0N\0Y\0"}; // array of strings int v_char_off[] = {0, 2, 4}; // offsets for strings // append string heaps size_t toff = tmp3->batCount == 0 ? 0 : tmp3->tvheap->free; // make sure we get alignment right toff = (toff + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1); //create a heap of strings HEAPextend(tmp3->tvheap, toff + nrows*(sizeof(char)+1), 1); memcpy(tmp3->tvheap->base + toff, v_char, nrows*(sizeof(char)+1)); tmp3->tvheap->free = toff + nrows*(sizeof(char)+1); BATsetcount(tmp3, BATcount(tmp3) + nrows); //integers to point into a heap of strings memcpy(Tloc(tmp3, BUNlast(tmp3)), v_char_off, nrows*sizeof(int)); but output string column is empty. Anton On Fri, Nov 2, 2018 at 2:08 PM Anton Kravchenko < kravchenko.anton86@gmail.com> wrote:
Though I wonder how to append an array of values to a BUN for TYPE_str column?
sql_table *tbl = mvc_bind_table(m, sch, "atable");
sql_column *col1 = mvc_bind_column(m, tbl, "acolumn"); //char(1)
BAT *tmp1 = NULL;
int nrows = 3;
tmp1 = COLnew(0, TYPE_str, (BUN)nrows, TRANSIENT);
char v_char[3][2] = {"Y\0","N\0","Y\0"}; //char(1)
for (irow=0; irow
BUNappend(tmp1, &(v_char[irow]), FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Anton
On Fri, Nov 2, 2018 at 1:12 PM Anton Kravchenko < kravchenko.anton86@gmail.com> wrote:
Ok to make it work I had to replace
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
with
memcpy(Tloc(tmp1, BUNlast(tmp1)), v_long, nrows*sizeof(long long));
BATsetcount(tmp1, BATcount(tmp1) + nrows);
Anton
On Fri, Nov 2, 2018 at 9:39 AM Anton Kravchenko < kravchenko.anton86@gmail.com> wrote:
Hi there,
Is there a way to append an array of values to a BUN, instead one value at a time?
sql_table *tbl = mvc_bind_table(m, sch, "atable"); sql_column *col = mvc_bind_column(m, tbl, "acolumn"); BAT *tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT); long long v_long[3] = {100000000009,100000000010,100000000011};
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Thanks, Anton
Bad idea. The string heap (tvheap) is highly structured. Don't mess with it. On 02/11/2018 22.27, Anton Kravchenko wrote:
I tried
char *v_char[] = {"Y\0N\0Y\0"}; // array of strings int v_char_off[] = {0, 2, 4}; // offsets for strings
// append string heaps size_t toff = tmp3->batCount == 0 ? 0 : tmp3->tvheap->free; // make sure we get alignment right toff = (toff + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1); //create a heap of strings HEAPextend(tmp3->tvheap, toff + nrows*(sizeof(char)+1), 1); memcpy(tmp3->tvheap->base + toff, v_char, nrows*(sizeof(char)+1));
tmp3->tvheap->free = toff + nrows*(sizeof(char)+1); BATsetcount(tmp3, BATcount(tmp3) + nrows);
//integers to point into a heap of strings memcpy(Tloc(tmp3, BUNlast(tmp3)), v_char_off, nrows*sizeof(int));
but output string column is empty.
Anton
On Fri, Nov 2, 2018 at 2:08 PM Anton Kravchenko
mailto:kravchenko.anton86@gmail.com> wrote: Though I wonder how to append an array of values to a BUN for TYPE_str column?
sql_table *tbl = mvc_bind_table(m, sch, "atable");
sql_column *col1 = mvc_bind_column(m, tbl, "acolumn"); //char(1)
BAT *tmp1 = NULL;
int nrows = 3;
tmp1 = COLnew(0, TYPE_str, (BUN)nrows, TRANSIENT);
char v_char[3][2] = {"Y\0","N\0","Y\0"}; //char(1)
for (irow=0; irow
BUNappend(tmp1, &(v_char[irow]), FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Anton
On Fri, Nov 2, 2018 at 1:12 PM Anton Kravchenko
mailto:kravchenko.anton86@gmail.com> wrote: Ok to make it work I had to replace
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
with
memcpy(Tloc(tmp1, BUNlast(tmp1)), v_long, nrows*sizeof(long long));
BATsetcount(tmp1, BATcount(tmp1) + nrows);
Anton
On Fri, Nov 2, 2018 at 9:39 AM Anton Kravchenko
mailto:kravchenko.anton86@gmail.com> wrote: Hi there,
Is there a way to append an array of values to a BUN, instead one value at a time?
sql_table*tbl = mvc_bind_table(m, sch, "atable");
sql_column *col = mvc_bind_column(m, tbl, "acolumn"); BAT*tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT); longlong v_long[3] = {100000000009,100000000010,100000000011};
for(irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Thanks, Anton
_______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list
-- Sjoerd Mullender
You can use the macro bunfastapp. See the code base for examples. It's probably only a little faster than using BUNappend, but it does require more code around it (setting properties and such). The problem with strings is that the string need to be added to the string heap which is a relatively expensive operation. On 02/11/2018 22.08, Anton Kravchenko wrote:
Though I wonder how to append an array of values to a BUN for TYPE_str column?
sql_table *tbl = mvc_bind_table(m, sch, "atable");
sql_column *col1 = mvc_bind_column(m, tbl, "acolumn"); //char(1)
BAT *tmp1 = NULL;
int nrows = 3;
tmp1 = COLnew(0, TYPE_str, (BUN)nrows, TRANSIENT);
char v_char[3][2] = {"Y\0","N\0","Y\0"}; //char(1)
for (irow=0; irow
BUNappend(tmp1, &(v_char[irow]), FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Anton
On Fri, Nov 2, 2018 at 1:12 PM Anton Kravchenko
mailto:kravchenko.anton86@gmail.com> wrote: Ok to make it work I had to replace
for (irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
with
memcpy(Tloc(tmp1, BUNlast(tmp1)), v_long, nrows*sizeof(long long));
BATsetcount(tmp1, BATcount(tmp1) + nrows);
Anton
On Fri, Nov 2, 2018 at 9:39 AM Anton Kravchenko
mailto:kravchenko.anton86@gmail.com> wrote: Hi there,
Is there a way to append an array of values to a BUN, instead one value at a time?
sql_table*tbl = mvc_bind_table(m, sch, "atable");
sql_column *col = mvc_bind_column(m, tbl, "acolumn"); BAT*tmp1 = COLnew(0, TYPE_lng, (BUN)nrows, TRANSIENT); longlong v_long[3] = {100000000009,100000000010,100000000011};
for(irow=0; irow
BUNappend(tmp1, &v_long[irow], FALSE);
mvc_append_column(m->session->tr, col1, tmp1);
mvc_commit(m, 0, tr->name);
bat_destroy(tmp1);
Thanks, Anton
_______________________________________________ users-list mailing list users-list@monetdb.org https://www.monetdb.org/mailman/listinfo/users-list
-- Sjoerd Mullender
participants (2)
-
Anton Kravchenko
-
Sjoerd Mullender