Changeset: 35ac3cab49dd for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=35ac3cab49dd Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 sql/backends/monet5/sql.c sql/backends/monet5/sql.h sql/backends/monet5/sql.mal sql/storage/store.c Branch: Nov2019 Log Message:
Simplify diffs (truncated from 448 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -8973,9 +8973,9 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "diff", "pattern batsql.diff(b:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "diff", "pattern batsql.diff(p:bat[:bit], b:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "first_value", "pattern batsql.first_value(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLfirst_value;", "return the first value of groups" ] +[ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:str):bat[:lng] ", "mvc_bat_get_value;", "return the current value of the sequence" ] -[ "batsql", "get_value", "pattern batsql.get_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_schema_sequences_get_value;", "return the current value of sequences" ] -[ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_schemas_sequences_get_value;", "return the current value of sequences" ] +[ "batsql", "get_value", "pattern batsql.get_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, d:any_1, p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or 'd' if non existent" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, d:bat[:any_1], p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or 'd' if non existent" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or NULL if non existent" ] @@ -8993,9 +8993,9 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "lead", "pattern batsql.lead(b:bat[:any_1], p:any_3, o:any_4):bat[:any_1] ", "SQLlead;", "return the value in the next row in the partition or NULL if non existent" ] [ "batsql", "max", "pattern batsql.max(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLmax;", "return the maximum of groups" ] [ "batsql", "min", "pattern batsql.min(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLmin;", "return the minimum of groups" ] +[ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] [ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:str):bat[:lng] ", "mvc_bat_next_value;", "return the next value of the sequence" ] -[ "batsql", "next_value", "pattern batsql.next_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_schema_sequences_next_value;", "return the next value of sequences" ] -[ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_schemas_sequences_next_value;", "return the next value of sequences" ] +[ "batsql", "next_value", "pattern batsql.next_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] [ "batsql", "nth_value", "pattern batsql.nth_value(b:bat[:any_1], n:any_2, s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(b:bat[:any_1], n:bat[:any_2], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "ntile", "pattern batsql.ntile(b:bat[:any_1], n:any_2, p:any_3, o:any_4):bat[:any_2] ", "SQLntile;", "return the groups divided as equally as possible" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -12695,9 +12695,9 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "diff", "pattern batsql.diff(b:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "diff", "pattern batsql.diff(p:bat[:bit], b:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "first_value", "pattern batsql.first_value(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLfirst_value;", "return the first value of groups" ] +[ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:str):bat[:lng] ", "mvc_bat_get_value;", "return the current value of the sequence" ] -[ "batsql", "get_value", "pattern batsql.get_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_schema_sequences_get_value;", "return the current value of sequences" ] -[ "batsql", "get_value", "pattern batsql.get_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_schemas_sequences_get_value;", "return the current value of sequences" ] +[ "batsql", "get_value", "pattern batsql.get_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, d:any_1, p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or 'd' if non existent" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, d:bat[:any_1], p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or 'd' if non existent" ] [ "batsql", "lag", "pattern batsql.lag(b:bat[:any_1], l:any_2, p:any_3, o:any_4):bat[:any_1] ", "SQLlag;", "return the value in the previous 'l' row in the partition or NULL if non existent" ] @@ -12715,9 +12715,9 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "lead", "pattern batsql.lead(b:bat[:any_1], p:any_3, o:any_4):bat[:any_1] ", "SQLlead;", "return the value in the next row in the partition or NULL if non existent" ] [ "batsql", "max", "pattern batsql.max(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLmax;", "return the maximum of groups" ] [ "batsql", "min", "pattern batsql.min(b:bat[:any_1], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLmin;", "return the minimum of groups" ] +[ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] [ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:str):bat[:lng] ", "mvc_bat_next_value;", "return the next value of the sequence" ] -[ "batsql", "next_value", "pattern batsql.next_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_schema_sequences_next_value;", "return the next value of sequences" ] -[ "batsql", "next_value", "pattern batsql.next_value(sname:bat[:str], sequence:bat[:str]):bat[:lng] ", "mvc_bat_schemas_sequences_next_value;", "return the next value of sequences" ] +[ "batsql", "next_value", "pattern batsql.next_value(sname:str, sequence:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] [ "batsql", "nth_value", "pattern batsql.nth_value(b:bat[:any_1], n:any_2, s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(b:bat[:any_1], n:bat[:any_2], s:bat[:lng], e:bat[:lng]):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "ntile", "pattern batsql.ntile(b:bat[:any_1], n:any_2, p:any_3, o:any_4):bat[:any_2] ", "SQLntile;", "return the groups divided as equally as possible" ] diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -802,226 +802,87 @@ mvc_get_value(Client cntxt, MalBlkPtr mb } static str -mvc_bat_sequence_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int (*bulk_func)(seqbulk *, lng *), const char* call) +mvc_bat_next_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int (*bulk_func)(seqbulk *, lng *), const char *call, const char *action) { mvc *m = NULL; - str msg = MAL_SUCCEED; - BAT *b = NULL, *r = NULL; + str msg = MAL_SUCCEED, sname = NULL, seqname = NULL; + BAT *b = NULL, *c = NULL, *r = NULL, *it; BUN p, q; sql_schema *s = NULL; sql_sequence *seq = NULL; seqbulk *sb = NULL; - BATiter bi; + BATiter bi, ci; bat *res = getArgReference_bat(stk, pci, 0); - bat sid = *getArgReference_bat(stk, pci, 1); - const char *seqname = *getArgReference_str(stk, pci, 2); - - if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) - return msg; - if ((msg = checkSQLContext(cntxt)) != NULL) - return msg; - - if ((b = BATdescriptor(sid)) == NULL) - throw(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); - - if (!(r = COLnew(b->hseqbase, TYPE_lng, BATcount(b), TRANSIENT))) { - msg = createException(SQL, call, SQLSTATE(HY001) MAL_MALLOC_FAIL); - goto bailout; - } - - if (!BATcount(b)) - goto bailout; /* Success case */ - - bi = bat_iterator(b); - BATloop(b, p, q) { - str sname = BUNtvar(bi, p); - lng l; - - if (!s || strcmp(s->base.name, sname) != 0) { - if (sb) { - seqbulk_destroy(sb); - sb = NULL; - } - s = mvc_bind_schema(m, sname); - seq = NULL; - if (!s || !(seq = find_sql_sequence(s, seqname)) || !(sb = seqbulk_create(seq, BATcount(b)))) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot find the sequence %s.%s", sname, seqname); - goto bailout; - } - } - if (!bulk_func(sb, &l)) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot generate next sequence value %s.%s", sname, seqname); - goto bailout; - } - if (BUNappend(r, &l, false) != GDK_SUCCEED) { - msg = createException(SQL, call, SQLSTATE(HY001) MAL_MALLOC_FAIL); - goto bailout; - } - } - -bailout: - if (sb) - seqbulk_destroy(sb); - if (b) - BBPunfix(b->batCacheid); - if (msg) - BBPreclaim(r); + bat schid = 0, seqid = 0; + + if (isaBatType(getArgType(mb, pci, 1))) + schid = *getArgReference_bat(stk, pci, 1); else - BBPkeepref(*res = r->batCacheid); - return msg; -} - -str -mvc_bat_next_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_sequence_value(cntxt, mb, stk, pci, seqbulk_next_value, "sql.next_value"); -} - -str -mvc_bat_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_sequence_value(cntxt, mb, stk, pci, seqbulk_get_value, "sql.get_value"); -} - -static str -mvc_bat_schema_sequences_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int (*bulk_func)(seqbulk *, lng *), const char* call) -{ - mvc *m = NULL; - str msg = MAL_SUCCEED; - BAT *b = NULL, *r = NULL; - BUN p, q; - sql_schema *s = NULL; - sql_sequence *seq = NULL; - seqbulk *sb = NULL; - BATiter bi; - bat *res = getArgReference_bat(stk, pci, 0); - const char *sname = *getArgReference_str(stk, pci, 1); - bat sid = *getArgReference_bat(stk, pci, 2); + sname = *getArgReference_str(stk, pci, 1); + if (isaBatType(getArgType(mb, pci, 2))) + seqid = *getArgReference_bat(stk, pci, 2); + else + seqname = *getArgReference_str(stk, pci, 2); if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) return msg; if ((msg = checkSQLContext(cntxt)) != NULL) return msg; - if ((b = BATdescriptor(sid)) == NULL) - throw(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); - - if (!(r = COLnew(b->hseqbase, TYPE_lng, BATcount(b), TRANSIENT))) { + if (schid && !(b = BATdescriptor(schid))) { + msg = createException(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); + goto bailout; + } + if (seqid && !(c = BATdescriptor(seqid))) { + msg = createException(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); + goto bailout; + } + assert(b || c); + it = b ? b : c; /* Either b or c must be set */ + + if (!(r = COLnew(it->hseqbase, TYPE_lng, BATcount(it), TRANSIENT))) { msg = createException(SQL, call, SQLSTATE(HY001) MAL_MALLOC_FAIL); goto bailout; } - if (!(s = mvc_bind_schema(m, sname))) { - msg = createException(SQL, call, SQLSTATE(3F000) "Cannot find the schema %s", sname); - goto bailout; - } - - if (!BATcount(b)) + if (!BATcount(it)) goto bailout; /* Success case */ - bi = bat_iterator(b); - BATloop(b, p, q) { - str seqname = BUNtvar(bi, p); + if (b) + bi = bat_iterator(b); + if (c) + ci = bat_iterator(c); + + BATloop(it, p, q) { + str nsname, nseqname; lng l; - if (!seq || strcmp(seq->base.name, seqname) != 0) { + if (b) + nsname = BUNtvar(bi, p); + else + nsname = sname; + if (c) + nseqname = BUNtvar(ci, p); + else + nseqname = seqname; + + if (!s || strcmp(s->base.name, nsname) != 0 || !seq || strcmp(seq->base.name, nseqname) != 0) { if (sb) { seqbulk_destroy(sb); sb = NULL; } - if (!(seq = find_sql_sequence(s, seqname)) || !(sb = seqbulk_create(seq, BATcount(b)))) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot find the sequence %s.%s", sname, seqname); + seq = NULL; + if ((!s || strcmp(s->base.name, nsname) != 0) && !(s = mvc_bind_schema(m, nsname))) { + msg = createException(SQL, call, SQLSTATE(3F000) "Cannot find the schema %s", nsname); + goto bailout; + } + if (!(seq = find_sql_sequence(s, nseqname)) || !(sb = seqbulk_create(seq, BATcount(it)))) { + msg = createException(SQL, call, SQLSTATE(HY050) "Cannot find the sequence %s.%s", nsname, nseqname); goto bailout; } } if (!bulk_func(sb, &l)) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot generate next sequence value %s.%s", sname, seqname); - goto bailout; - } - if (BUNappend(r, &l, false) != GDK_SUCCEED) { - msg = createException(SQL, call, SQLSTATE(HY001) MAL_MALLOC_FAIL); - goto bailout; - } - } - -bailout: - if (sb) - seqbulk_destroy(sb); - if (b) - BBPunfix(b->batCacheid); - if (msg) - BBPreclaim(r); - else - BBPkeepref(*res = r->batCacheid); - return msg; -} - -str -mvc_bat_schema_sequences_next_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_schema_sequences_value(cntxt, mb, stk, pci, seqbulk_next_value, "sql.next_value"); -} - -str -mvc_bat_schema_sequences_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_schema_sequences_value(cntxt, mb, stk, pci, seqbulk_get_value, "sql.get_value"); -} - -static str -mvc_bat_schemas_sequences_values(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int (*bulk_func)(seqbulk *, lng *), const char* call) -{ - mvc *m = NULL; - str msg = MAL_SUCCEED; - BAT *b = NULL, *c = NULL, *r = NULL; - BUN p1, p2, q1, q2; - sql_schema *s = NULL; - sql_sequence *seq = NULL; - seqbulk *sb = NULL; - BATiter bi, ci; - bat *res = getArgReference_bat(stk, pci, 0); - bat schid = *getArgReference_bat(stk, pci, 1); - bat seqid = *getArgReference_bat(stk, pci, 2); - - if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) - return msg; - if ((msg = checkSQLContext(cntxt)) != NULL) - return msg; - - if (!(b = BATdescriptor(schid)) || !(c = BATdescriptor(seqid))) { - msg = createException(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); - goto bailout; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list