Changeset: fcaf15f02545 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fcaf15f02545
Modified Files:
        monetdb5/modules/atoms/str.c
        monetdb5/modules/atoms/str.h
        monetdb5/modules/kernel/batstr.c
        sql/backends/monet5/rel_bin.c
        sql/common/sql_types.c
Branch: clean-candidates
Log Message:

Remove ambiguity by naming str module functions with the number of arguments to 
distinguish functions with the same name (this is also donw in mmath module)


diffs (truncated from 447 to 300 lines):

diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -3313,7 +3313,7 @@ STRlike(const char *s, const char *pat, 
 }
 
 static str
-STRlikewrap(bit *ret, const str *s, const str *pat, const str *esc)
+STRlikewrap3(bit *ret, const str *s, const str *pat, const str *esc)
 {
        if (strNil(*s) || strNil(*pat) || strNil(*esc))
                *ret = bit_nil;
@@ -3323,7 +3323,7 @@ STRlikewrap(bit *ret, const str *s, cons
 }
 
 static str
-STRlikewrap2(bit *ret, const str *s, const str *pat)
+STRlikewrap(bit *ret, const str *s, const str *pat)
 {
        if (strNil(*s) || strNil(*pat))
                *ret = bit_nil;
@@ -4275,7 +4275,7 @@ STRRpad(str *res, const str *arg1, const
 }
 
 str
-str_lpad2(str *buf, size_t *buflen, str s, int len, str s2)
+str_lpad3(str *buf, size_t *buflen, str s, int len, str s2)
 {
        return pad(buf, buflen, s, s2, len, 1, "str.lpad2");
 }
@@ -4288,7 +4288,7 @@ str_lpad2(str *buf, size_t *buflen, str 
  * Result: xyxhi
  */
 static str
-STRLpad2(str *res, const str *arg1, const int *len, const str *arg2)
+STRLpad3(str *res, const str *arg1, const int *len, const str *arg2)
 {
        str buf = NULL, msg = MAL_SUCCEED, s = *arg1, s2 = *arg2;
        int l = *len;
@@ -4301,7 +4301,7 @@ STRLpad2(str *res, const str *arg1, cons
                *res = NULL;
                if (!(buf = GDKmalloc(buflen)))
                        throw(MAL, "str.lpad2", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               if ((msg = str_lpad2(&buf, &buflen, s, l, s2)) != MAL_SUCCEED) {
+               if ((msg = str_lpad3(&buf, &buflen, s, l, s2)) != MAL_SUCCEED) {
                        GDKfree(buf);
                        return msg;
                }
@@ -4315,7 +4315,7 @@ STRLpad2(str *res, const str *arg1, cons
 }
 
 str
-str_rpad2(str *buf, size_t *buflen, str s, int len, str s2)
+str_rpad3(str *buf, size_t *buflen, str s, int len, str s2)
 {
        return pad(buf, buflen, s, s2, len, 0, "str.rpad2");
 }
@@ -4328,7 +4328,7 @@ str_rpad2(str *buf, size_t *buflen, str 
  * Result: hixyx
  */
 static str
-STRRpad2(str *res, const str *arg1, const int *len, const str *arg2)
+STRRpad3(str *res, const str *arg1, const int *len, const str *arg2)
 {
        str buf = NULL, msg = MAL_SUCCEED, s = *arg1, s2 = *arg2;
        int l = *len;
@@ -4341,7 +4341,7 @@ STRRpad2(str *res, const str *arg1, cons
                *res = NULL;
                if (!(buf = GDKmalloc(buflen)))
                        throw(MAL, "str.rpad2", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               if ((msg = str_rpad2(&buf, &buflen, s, l, s2)) != MAL_SUCCEED) {
+               if ((msg = str_rpad3(&buf, &buflen, s, l, s2)) != MAL_SUCCEED) {
                        GDKfree(buf);
                        return msg;
                }
@@ -4573,7 +4573,7 @@ str_locate2(str needle, str haystack, in
 }
 
 static str
-STRlocate2(int *ret, const str *needle, const str *haystack, const int *start)
+STRlocate3(int *ret, const str *needle, const str *haystack, const int *start)
 {
        str s = *needle, s2 = *haystack;
        int st = *start;
@@ -4729,7 +4729,7 @@ STRspace(str *res, const int *ll)
 mel_func str_init_funcs[] = {
  command("str", "str", STRtostr, false, "Noop routine.", args(1,2, 
arg("",str),arg("s",str))),
  command("str", "string", STRTail, false, "Return the tail s[offset..n]\nof a 
string s[0..n].", args(1,3, arg("",str),arg("s",str),arg("offset",int))),
- command("str", "string", STRSubString, false, "Return substring 
s[offset..offset+count] of a string s[0..n]", args(1,4, 
arg("",str),arg("s",str),arg("offset",int),arg("count",int))),
+ command("str", "string3", STRSubString, false, "Return substring 
s[offset..offset+count] of a string s[0..n]", args(1,4, 
arg("",str),arg("s",str),arg("offset",int),arg("count",int))),
  command("str", "length", STRLength, false, "Return the length of a string.", 
args(1,2, arg("",int),arg("s",str))),
  command("str", "nbytes", STRBytes, false, "Return the string length in 
bytes.", args(1,2, arg("",int),arg("s",str))),
  command("str", "unicodeAt", STRWChrAt, false, "get a unicode character\n(as 
an int) from a string position.", args(1,3, 
arg("",int),arg("s",str),arg("index",int))),
@@ -4744,25 +4744,25 @@ mel_func str_init_funcs[] = {
  command("str", "trim", STRStrip, false, "Strip whitespaces around a string.", 
args(1,2, arg("",str),arg("s",str))),
  command("str", "ltrim", STRLtrim, false, "Strip whitespaces from start of a 
string.", args(1,2, arg("",str),arg("s",str))),
  command("str", "rtrim", STRRtrim, false, "Strip whitespaces from end of a 
string.", args(1,2, arg("",str),arg("s",str))),
- command("str", "trim", STRStrip2, false, "Remove the longest string 
containing only characters from the second string around the first string.", 
args(1,3, arg("",str),arg("s",str),arg("s2",str))),
- command("str", "ltrim", STRLtrim2, false, "Remove the longest string 
containing only characters from the second string from the start of the first 
string.", args(1,3, arg("",str),arg("s",str),arg("s2",str))),
- command("str", "rtrim", STRRtrim2, false, "Remove the longest string 
containing only characters from the second string from the end of the first 
string.", args(1,3, arg("",str),arg("s",str),arg("s2",str))),
+ command("str", "trim2", STRStrip2, false, "Remove the longest string 
containing only characters from the second string around the first string.", 
args(1,3, arg("",str),arg("s",str),arg("s2",str))),
+ command("str", "ltrim2", STRLtrim2, false, "Remove the longest string 
containing only characters from the second string from the start of the first 
string.", args(1,3, arg("",str),arg("s",str),arg("s2",str))),
+ command("str", "rtrim2", STRRtrim2, false, "Remove the longest string 
containing only characters from the second string from the end of the first 
string.", args(1,3, arg("",str),arg("s",str),arg("s2",str))),
  command("str", "lpad", STRLpad, false, "Fill up a string to the given length 
prepending the whitespace character.", args(1,3, 
arg("",str),arg("s",str),arg("len",int))),
  command("str", "rpad", STRRpad, false, "Fill up a string to the given length 
appending the whitespace character.", args(1,3, 
arg("",str),arg("s",str),arg("len",int))),
- command("str", "lpad", STRLpad2, false, "Fill up the first string to the 
given length prepending characters of the second string.", args(1,4, 
arg("",str),arg("s",str),arg("len",int),arg("s2",str))),
- command("str", "rpad", STRRpad2, false, "Fill up the first string to the 
given length appending characters of the second string.", args(1,4, 
arg("",str),arg("s",str),arg("len",int),arg("s2",str))),
+ command("str", "lpad3", STRLpad3, false, "Fill up the first string to the 
given length prepending characters of the second string.", args(1,4, 
arg("",str),arg("s",str),arg("len",int),arg("s2",str))),
+ command("str", "rpad3", STRRpad3, false, "Fill up the first string to the 
given length appending characters of the second string.", args(1,4, 
arg("",str),arg("s",str),arg("len",int),arg("s2",str))),
  command("str", "substitute", STRSubstitute, false, "Substitute first 
occurrence of 'src' by\n'dst'.  Iff repeated = true this is\nrepeated while 
'src' can be found in the\nresult string. In order to prevent\nrecursion and 
result strings of unlimited\nsize, repeating is only done iff src is\nnot a 
substring of dst.", args(1,5, 
arg("",str),arg("s",str),arg("src",str),arg("dst",str),arg("rep",bit))),
- command("str", "like", STRlikewrap2, false, "SQL pattern match function", 
args(1,3, arg("",bit),arg("s",str),arg("pat",str))),
- command("str", "like", STRlikewrap, false, "SQL pattern match function", 
args(1,4, arg("",bit),arg("s",str),arg("pat",str),arg("esc",str))),
+ command("str", "like", STRlikewrap, false, "SQL pattern match function", 
args(1,3, arg("",bit),arg("s",str),arg("pat",str))),
+ command("str", "like3", STRlikewrap3, false, "SQL pattern match function", 
args(1,4, arg("",bit),arg("s",str),arg("pat",str),arg("esc",str))),
  command("str", "ascii", STRascii, false, "Return unicode of head of string", 
args(1,2, arg("",int),arg("s",str))),
  command("str", "substring", STRsubstringTail, false, "Extract the tail of a 
string", args(1,3, arg("",str),arg("s",str),arg("start",int))),
- command("str", "substring", STRsubstring, false, "Extract a substring from 
str starting at start, for length len", args(1,4, 
arg("",str),arg("s",str),arg("start",int),arg("len",int))),
+ command("str", "substring3", STRsubstring, false, "Extract a substring from 
str starting at start, for length len", args(1,4, 
arg("",str),arg("s",str),arg("start",int),arg("len",int))),
  command("str", "prefix", STRprefix, false, "Extract the prefix of a given 
length", args(1,3, arg("",str),arg("s",str),arg("l",int))),
  command("str", "suffix", STRsuffix, false, "Extract the suffix of a given 
length", args(1,3, arg("",str),arg("s",str),arg("l",int))),
  command("str", "stringleft", STRprefix, false, "", args(1,3, 
arg("",str),arg("s",str),arg("l",int))),
  command("str", "stringright", STRsuffix, false, "", args(1,3, 
arg("",str),arg("s",str),arg("l",int))),
  command("str", "locate", STRlocate, false, "Locate the start position of a 
string", args(1,3, arg("",int),arg("s1",str),arg("s2",str))),
- command("str", "locate", STRlocate2, false, "Locate the start position of a 
string", args(1,4, arg("",int),arg("s1",str),arg("s2",str),arg("start",int))),
+ command("str", "locate3", STRlocate3, false, "Locate the start position of a 
string", args(1,4, arg("",int),arg("s1",str),arg("s2",str),arg("start",int))),
  command("str", "insert", STRinsert, false, "Insert a string into another", 
args(1,5, 
arg("",str),arg("s",str),arg("start",int),arg("l",int),arg("s2",str))),
  command("str", "replace", STRreplace, false, "Insert a string into another", 
args(1,4, arg("",str),arg("s",str),arg("pat",str),arg("s2",str))),
  command("str", "repeat", STRrepeat, false, "", args(1,3, 
arg("",str),arg("s2",str),arg("c",int))),
diff --git a/monetdb5/modules/atoms/str.h b/monetdb5/modules/atoms/str.h
--- a/monetdb5/modules/atoms/str.h
+++ b/monetdb5/modules/atoms/str.h
@@ -34,7 +34,7 @@
 
 mal_export int str_utf8_length(str s); /* this function looks for NULL values 
of s, returning int_nil on those */
 
-mal_export bool batstr_func_has_candidates(char *func, int args);
+mal_export bool batstr_func_has_candidates(const char *func);
 
 /* For str returning functions, the result is passed as the input parameter 
buf. The returned str indicates
    if the function succeeded (ie malloc failure or invalid unicode character). 
str_wchr_at function also
@@ -91,9 +91,9 @@ extern str str_lpad(str *buf, size_t *bu
 __attribute__((__visibility__("hidden")));
 extern str str_rpad(str *buf, size_t *buflen, str s, int len)
 __attribute__((__visibility__("hidden")));
-extern str str_lpad2(str *buf, size_t *buflen, str s, int len, str s2)
+extern str str_lpad3(str *buf, size_t *buflen, str s, int len, str s2)
 __attribute__((__visibility__("hidden")));
-extern str str_rpad2(str *buf, size_t *buflen, str s, int len, str s2)
+extern str str_rpad3(str *buf, size_t *buflen, str s, int len, str s2)
 __attribute__((__visibility__("hidden")));
 
 extern int str_search(str s, str s2)
diff --git a/monetdb5/modules/kernel/batstr.c b/monetdb5/modules/kernel/batstr.c
--- a/monetdb5/modules/kernel/batstr.c
+++ b/monetdb5/modules/kernel/batstr.c
@@ -25,29 +25,16 @@
 #include "mal_exception.h"
 #include "str.h"
 
-/* In order to make avaialble a bulk version of a string function with 
candidates, all possible combinations of scalar/vector 
+/* In order to make avaialble a bulk version of a string function with 
candidates, all possible combinations of scalar/vector
        version of each argument must be avaiable for the function. Obviously 
this won't scale for functions with a large number of
-       arguments, so we keep a blacklist for functions without candidate 
versions.  */
-static struct functions_with_no_cands {
-       char *name;
-       int nargs; /*here nargs represent the total number of arguments */
-} functions_list[8] = {
-       { "lpad", 4 },
-       { "rpad", 4 },
-       { "splitpart", 4 },
-       { "substitute", 5 },
-       { "locate", 4 },
-       { "insert", 5 },
-       { "replace", 4 },
-       { NULL, 0 }
-};
-
-bool batstr_func_has_candidates(char *func, int args)
+       arguments, so we keep a blacklist for functions without candidate 
versions. */
+static const char* batstr_funcs_with_no_cands[8] = 
{"lpad3","rpad3","splitpart","substitute","locate3","insert","replace",NULL};
+
+bool
+batstr_func_has_candidates(const char *func)
 {
-       size_t number_valid_types = sizeof(functions_list) / 
sizeof(functions_list[0]);
-
-       for (size_t i = 0 ; i < number_valid_types ; i++)
-               if (functions_list[i].name && strcmp(functions_list[i].name, 
func) == 0 && functions_list[i].nargs == args)
+       for (size_t i = 0; batstr_funcs_with_no_cands[i]; i++)
+               if (strcmp(batstr_funcs_with_no_cands[i], func) == 0)
                        return false;
        return true;
 }
@@ -1533,51 +1520,51 @@ STRbatRpad_bat(Client cntxt, MalBlkPtr m
 }
 
 static str
-STRbatLpad2_const_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+STRbatLpad3_const_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
-       return do_batstr_constint_conststr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad2);
+       return do_batstr_constint_conststr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad3);
 }
 
 static str
-STRbatRpad2_const_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+STRbatRpad3_const_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
-       return do_batstr_constint_conststr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad2);
+       return do_batstr_constint_conststr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad3);
 }
 
 static str
-STRbatLpad2_bat_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatLpad3_bat_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_batint_conststr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad2);
+       return do_batstr_batint_conststr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad3);
 }
 
 static str
-STRbatRpad2_bat_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatRpad3_bat_const(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_batint_conststr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad2);
+       return do_batstr_batint_conststr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad3);
 }
 
 static str
-STRbatLpad2_const_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatLpad3_const_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_constint_batstr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad2);
+       return do_batstr_constint_batstr_str(cntxt, mb, stk, pci, 
"batstr.lpad", str_lpad3);
 }
 
 static str
-STRbatRpad2_const_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatRpad3_const_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_constint_batstr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad2);
+       return do_batstr_constint_batstr_str(cntxt, mb, stk, pci, 
"batstr.rpad", str_rpad3);
 }
 
 static str
-STRbatLpad2_bat_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatLpad3_bat_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_batint_batstr_str(cntxt, mb, stk, pci, "batstr.lpad", 
str_lpad2);
+       return do_batstr_batint_batstr_str(cntxt, mb, stk, pci, "batstr.lpad", 
str_lpad3);
 }
 
 static str
-STRbatRpad2_bat_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatRpad3_bat_bat(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
-       return do_batstr_batint_batstr_str(cntxt, mb, stk, pci, "batstr.rpad", 
str_rpad2);
+       return do_batstr_batint_batstr_str(cntxt, mb, stk, pci, "batstr.rpad", 
str_rpad3);
 }
 
 /*
@@ -4639,7 +4626,7 @@ bailout:
 }
 
 static str
-STRbatstrLocate2cst(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatstrLocate3cst(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        BATiter bi;
        BAT *bn = NULL, *b = NULL, *bs = NULL;
@@ -4703,7 +4690,7 @@ bailout:
 }
 
 static str
-STRbatstrLocate2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
+STRbatstrLocate3(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        BATiter lefti, righti;
        BAT *bn = NULL, *left = NULL, *ls = NULL, *right = NULL, *rs = NULL, 
*start = NULL, *ss = NULL;
@@ -4798,24 +4785,24 @@ mel_func batstr_init_funcs[] = {
  pattern("batstr", "ltrim", STRbatLtrim, false, "Strip whitespaces from start 
of a string.", args(1,3, batarg("",str),batarg("s",str),batarg("s",oid))),
  pattern("batstr", "rtrim", STRbatRtrim, false, "Strip whitespaces from end of 
a string.", args(1,2, batarg("",str),batarg("s",str))),
  pattern("batstr", "rtrim", STRbatRtrim, false, "Strip whitespaces from end of 
a string.", args(1,3, batarg("",str),batarg("s",str),batarg("s",oid))),
- pattern("batstr", "trim", STRbatStrip2_const, false, "Strip characters in the 
second string around the first strings.", args(1,3, 
batarg("",str),batarg("s",str),arg("s2",str))),
- pattern("batstr", "trim", STRbatStrip2_const, false, "Strip characters in the 
second string around the first strings.", args(1,4, 
batarg("",str),batarg("s",str),arg("s2",str),batarg("s",oid))),
- pattern("batstr", "trim", STRbatStrip2_1st_const, false, "Strip characters in 
the second string around the first strings.", args(1,3, 
batarg("",str),arg("s",str),batarg("s2",str))),
- pattern("batstr", "trim", STRbatStrip2_1st_const, false, "Strip characters in 
the second string around the first strings.", args(1,4, 
batarg("",str),arg("s",str),batarg("s2",str),batarg("s",oid))),
- pattern("batstr", "ltrim", STRbatLtrim2_const, false, "Strip characters in 
the second string from start of the first strings.", args(1,3, 
batarg("",str),batarg("s",str),arg("s2",str))),
- pattern("batstr", "ltrim", STRbatLtrim2_const, false, "Strip characters in 
the second string from start of the first strings.", args(1,4, 
batarg("",str),batarg("s",str),arg("s2",str),batarg("s",oid))),
- pattern("batstr", "ltrim", STRbatLtrim2_1st_const, false, "Strip characters 
in the second string from start of the first strings.", args(1,3, 
batarg("",str),arg("s",str),batarg("s2",str))),
- pattern("batstr", "ltrim", STRbatLtrim2_1st_const, false, "Strip characters 
in the second string from start of the first strings.", args(1,4, 
batarg("",str),arg("s",str),batarg("s2",str),batarg("s",oid))),
- pattern("batstr", "rtrim", STRbatRtrim2_const, false, "Strip characters in 
the second string from end of the first strings.", args(1,3, 
batarg("",str),batarg("s",str),arg("s2",str))),
- pattern("batstr", "rtrim", STRbatRtrim2_const, false, "Strip characters in 
the second string from end of the first strings.", args(1,4, 
batarg("",str),batarg("s",str),arg("s2",str),batarg("s",oid))),
- pattern("batstr", "rtrim", STRbatRtrim2_1st_const, false, "Strip characters 
in the second string from end of the first strings.", args(1,3, 
batarg("",str),arg("s",str),batarg("s2",str))),
- pattern("batstr", "rtrim", STRbatRtrim2_1st_const, false, "Strip characters 
in the second string from end of the first strings.", args(1,4, 
batarg("",str),arg("s",str),batarg("s2",str),batarg("s",oid))),
- pattern("batstr", "trim", STRbatStrip2_bat, false, "Strip characters in the 
second strings around the first strings.", args(1,3, 
batarg("",str),batarg("s",str),batarg("s2",str))),
- pattern("batstr", "trim", STRbatStrip2_bat, false, "Strip characters in the 
second strings around the first strings.", args(1,5, 
batarg("",str),batarg("s",str),batarg("s2",str),batarg("s1",oid),batarg("s2",oid))),
- pattern("batstr", "ltrim", STRbatLtrim2_bat, false, "Strip characters in the 
second strings from start of the first strings.", args(1,3, 
batarg("",str),batarg("s",str),batarg("s2",str))),
- pattern("batstr", "ltrim", STRbatLtrim2_bat, false, "Strip characters in the 
second strings from start of the first strings.", args(1,5, 
batarg("",str),batarg("s",str),batarg("s2",str),batarg("s1",oid),batarg("s2",oid))),
- pattern("batstr", "rtrim", STRbatRtrim2_bat, false, "Strip characters in the 
second strings from end of the first strings.", args(1,3, 
batarg("",str),batarg("s",str),batarg("s2",str))),
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to