Changeset: 8a443018ce4d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8a443018ce4d
Branch: default
Log Message:
Merge with Dec2025 branch.
diffs (truncated from 793 to 300 lines):
diff --git a/clients/Tests/MAL-signatures-hge.test
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -45109,6 +45109,16 @@ pattern calc.timestamptz(X_0:str, X_1:in
str_2time_timestamptz
cast to timestamp and check for overflow
calc
+to_hex
+command calc.to_hex(X_0:int):str
+CALCto_hex_int
+convert to unsigned hexadecimal number representation
+calc
+to_hex
+command calc.to_hex(X_0:lng):str
+CALCto_hex_lng
+convert to unsigned hexadecimal number representation
+calc
url
command calc.url(X_0:str):url
URLnew
diff --git a/clients/Tests/MAL-signatures.test
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -33664,6 +33664,16 @@ pattern calc.timestamptz(X_0:str, X_1:in
str_2time_timestamptz
cast to timestamp and check for overflow
calc
+to_hex
+command calc.to_hex(X_0:int):str
+CALCto_hex_int
+convert to unsigned hexadecimal number representation
+calc
+to_hex
+command calc.to_hex(X_0:lng):str
+CALCto_hex_lng
+convert to unsigned hexadecimal number representation
+calc
url
command calc.url(X_0:str):url
URLnew
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -1810,7 +1810,11 @@ INET6toString(allocator *ma, str *retval
}
/* nils should never reach us here */
- assert(best_len < 8);
+ assert(best_len < 16);
+ if (best_len <= 2) {
+ best_len = 0;
+ best_start = 16;
+ }
/* Special case: IPv4-mapped IPv6 address */
if (best_start == 0 && best_len == 10 && value->hex[10] == 0xFF &&
value->hex[11] == 0xFF) {
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -106,10 +106,6 @@
#endif
#endif
-/* also see gdk.h for these */
-#define THRDMASK (1U)
-#define TEMMASK (1U<<10)
-
/*
* @- pthreads Includes and Definitions
*/
diff --git a/gdk/gdk_system_private.h b/gdk/gdk_system_private.h
--- a/gdk/gdk_system_private.h
+++ b/gdk/gdk_system_private.h
@@ -70,5 +70,5 @@ struct allocator {
exception_buffer eb;
MT_Lock lock; /* lock for thread-safe allocations */
bool use_lock;
- char name [MT_NAME_LEN]; /* Name (only for display!) */
+ char name[MT_NAME_LEN]; /* Name (only for display!) */
};
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -2092,7 +2092,7 @@ ma_alloc(allocator *sa, size_t sz)
{
assert(sa);
size_t nsize = sz + MA_HEADER_SIZE;
- char* r = (char*) _ma_alloc_internal(sa, nsize);
+ char *r = _ma_alloc_internal(sa, nsize);
return ma_fill_in_header(r, sz);
}
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -148,7 +148,7 @@ typedef struct CLIENT {
*/
MT_Sema s; /* sema to (de)activate
thread */
const char *mythread;
- str errbuf; /* location of GDK
exceptions */
+ char *errbuf; /* location of GDK
exceptions */
struct CLIENT *father;
/*
* Each client has a private entry point into the namespace and
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -48,7 +48,7 @@ isExceptionVariable(const char *nme)
return false;
}
-static char *M5OutOfMemory = MAL_MALLOC_FAIL;
+static char M5OutOfMemory[] = MAL_MALLOC_FAIL;
char *
concatErrors(allocator *ma, char *err1, const char *err2)
diff --git a/monetdb5/modules/mal/calc.c b/monetdb5/modules/mal/calc.c
--- a/monetdb5/modules/mal/calc.c
+++ b/monetdb5/modules/mal/calc.c
@@ -653,6 +653,39 @@ CALCmax(Client cntxt, MalBlkPtr mb, MalS
return MAL_SUCCEED;
}
+static str
+CALCto_hex_int(Client ctx, str *res, const int *n)
+{
+ allocator *ma = ctx->curprg->def->ma;
+ if (is_int_nil(*n)) {
+ *res = MA_STRDUP(ma, str_nil);
+ return MAL_SUCCEED;
+ }
+ const size_t size = 9; // 32 bits -> 8 hex digits + 1 NUL
+ str buf = ma_alloc(ma, size);
+ if (buf == NULL)
+ throw(MAL, "calc.to_hex", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ snprintf(buf, size, "%" PRIx32, (uint32_t)*n);
+ *res = buf;
+ return MAL_SUCCEED;
+}
+
+static str
+CALCto_hex_lng(Client ctx, str *res, const lng *n)
+{
+ allocator *ma = ctx->curprg->def->ma;
+ if (is_lng_nil(*n)) {
+ *res = MA_STRDUP(ma, str_nil);
+ return MAL_SUCCEED;
+ }
+ const size_t size = 17; // 64 bits -> 16 hex digits + 1 NUL
+ str buf = ma_alloc(ma, size);
+ if (buf == NULL)
+ throw(MAL, "calc.to_hex", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ snprintf(buf, size, "%" PRIx64, (uint64_t)*n);
+ *res = buf;
+ return MAL_SUCCEED;
+}
static str
CALCmax_no_nil(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
@@ -2580,6 +2613,8 @@ mel_func calc_init_funcs[] = {
command("calc", "ptr", CMDvarCONVERTptr, false, "Cast VALUE to ptr",
args(1,2, arg("",ptr),arg("v",ptr))),
pattern("calc", "ifthenelse", CALCswitchbit, false, "If VALUE is true return
MIDDLE else RIGHT", args(1,4,
argany("",1),arg("b",bit),argany("t",1),argany("f",1))),
command("calc", "length", CMDstrlength, false, "Length of STRING", args(1,2,
arg("",int),arg("s",str))),
+ command("calc", "to_hex", CALCto_hex_int, false, "convert to unsigned
hexadecimal number representation", args(1, 2, arg("", str), arg("n", int))),
+ command("calc", "to_hex", CALCto_hex_lng, false, "convert to unsigned
hexadecimal number representation", args(1, 2, arg("", str), arg("n", lng))),
pattern("aggr", "sum", CMDBATsum, false, "Calculate aggregate sum of B.",
args(1,2, arg("",bte),batarg("b",msk))),
pattern("aggr", "sum", CMDBATsum, false, "Calculate aggregate sum of B.",
args(1,3, arg("",bte),batarg("b",msk),arg("nil_if_empty",bit))),
pattern("aggr", "sum", CMDBATsum, false, "Calculate aggregate sum of B with
candidate list.", args(1,3, arg("",bte),batarg("b",msk),batarg("s",oid))),
diff --git a/sql/ChangeLog.Dec2025 b/sql/ChangeLog.Dec2025
--- a/sql/ChangeLog.Dec2025
+++ b/sql/ChangeLog.Dec2025
@@ -1,6 +1,10 @@
# ChangeLog file for sql
# This file is updated with Maddlog
+* Mon Nov 10 2025 Joeri van Ruth <[email protected]>
+- Add functions to_hex(int) and to_hex(bigint). They return the
+ unsigned hexadecimal string representation of their argument.
+
* Wed Nov 5 2025 Joeri van Ruth <[email protected]>
- COPY BINARY has been optimized to be much faster when many string columns
are involved.
diff --git a/sql/backends/monet5/sql_bincopyconvert.c
b/sql/backends/monet5/sql_bincopyconvert.c
--- a/sql/backends/monet5/sql_bincopyconvert.c
+++ b/sql/backends/monet5/sql_bincopyconvert.c
@@ -811,6 +811,9 @@ static struct type_record_t type_recs[]
{ "hge", "hge", .trivial_if_no_byteswap=true, .decoder=byteswap_hge,
.encoder=byteswap_hge, .validate=validate_hge },
#endif
+ { "inet4", "inet4", .encoder_trivial=true, .decoder_trivial=true, },
+ { "inet6", "inet6", .encoder_trivial=true, .decoder_trivial=true, },
+
{ "blob", "blob", .loader=load_blobs, .dumper=dump_blob },
// \0-terminated text records
diff --git a/sql/backends/monet5/sql_upgrades.c
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -5223,6 +5223,24 @@ sql_update_dec2025(Client c, mvc *sql, s
}
res_table_destroy(output);
output = NULL;
+ if (err)
+ return err;
+
+ sql_find_subtype(&tp, "bigint", 64, 0);
+ if (!sql_bind_func(sql, "sys", "to_hex", &tp, NULL, F_FUNC, true,
true)) {
+ sql->session->status = 0; /* if the function was not found
clean the error */
+ sql->errstr[0] = '\0';
+ const char query[] = "create function to_hex(n int)\n"
+ "returns text external name \"calc\".\"to_hex\";\n"
+ "grant execute on function to_hex(int) to public;\n"
+ "create function to_hex(n bigint)\n"
+ "returns text external name \"calc\".\"to_hex\";\n"
+ "grant execute on function to_hex(bigint) to public;\n"
+ "update sys.functions set system = true where not
system and schema_id = 2000 and name = 'to_hex' and type = 1;\n"; /* F_FUNC ==
1 */
+ printf("Running database upgrade commands:\n%s\n", query);
+ fflush(stdout);
+ err = SQLstatementIntern(c, query, "update", true, false, NULL);
+ }
return err;
}
diff --git a/sql/scripts/49_strings.sql b/sql/scripts/49_strings.sql
--- a/sql/scripts/49_strings.sql
+++ b/sql/scripts/49_strings.sql
@@ -94,3 +94,14 @@ grant execute on aggregate sha512 to pub
create aggregate ripemd160(val string)
returns string with order external name aggr.ripemd160;
grant execute on aggregate ripemd160 to public;
+
+-- to_hex returns the unsigned hexadecimal representation of the given number.
+-- Compatible with Postgres.
+
+create function to_hex(n int)
+returns text external name "calc"."to_hex";
+grant execute on function to_hex(int) to public;
+
+create function to_hex(n bigint)
+returns text external name "calc"."to_hex";
+grant execute on function to_hex(bigint) to public;
diff --git a/sql/test/2025/Tests/All b/sql/test/2025/Tests/All
--- a/sql/test/2025/Tests/All
+++ b/sql/test/2025/Tests/All
@@ -1,1 +1,2 @@
empty_bind_opt_on_sys_tables
+to_hex
diff --git a/sql/test/2025/Tests/to_hex.test b/sql/test/2025/Tests/to_hex.test
new file mode 100644
--- /dev/null
+++ b/sql/test/2025/Tests/to_hex.test
@@ -0,0 +1,93 @@
+# INT TESTS
+
+query T
+select to_hex(0)
+----
+0
+
+query T
+select to_hex(1)
+----
+1
+
+query T
+select to_hex(15)
+----
+f
+
+query T
+select to_hex(0x7fff_ffff)
+----
+7fffffff
+
+query T
+select to_hex(-1)
+----
+ffffffff
+
+query T
+select to_hex(-2_147_483_647)
+----
+80000001
+
+
+
+
+
+# BIGINT TESTS
+
+query T
+select to_hex(cast(0 as bigint))
+----
+0
+
+query T
+select to_hex(cast(1 as bigint))
+----
+1
+
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]