[Tarantool-patches] [PATCH v5 52/52] sql: introduce mem_get_agg()
imeevma at tarantool.org
imeevma at tarantool.org
Sat Apr 10 00:08:30 MSK 2021
This patch introduces mem_get_agg(). This function is used to receive
address of memory allocated for accumulation structure of the aggregate
function.
Closes #5818
---
src/box/sql/mem.c | 9 +++++++++
src/box/sql/mem.h | 7 +++++++
src/box/sql/vdbeapi.c | 5 ++++-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 3e9544cae..c7220190c 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -1357,6 +1357,15 @@ mem_get_bytes_len(const struct Mem *mem, uint32_t *len)
return 0;
}
+int
+mem_get_agg(const struct Mem *mem, void **accum)
+{
+ if ((mem->flags & MEM_Agg) == 0)
+ return -1;
+ *accum = mem->z;
+ return 0;
+}
+
int
mem_copy(struct Mem *to, const struct Mem *from)
{
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index 9c6d18e1f..9ba7ef066 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -605,6 +605,13 @@ mem_get_bin(const struct Mem *mem, const char **s);
int
mem_get_bytes_len(const struct Mem *mem, uint32_t *len);
+/**
+ * Return address of memory allocated for accumulation structure of the
+ * aggregate function.
+ */
+int
+mem_get_agg(const struct Mem *mem, void **accum);
+
/**
* Simple type to str convertor. It is used to simplify
* error reporting.
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index b0334f3ed..a9a7dc97a 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -416,7 +416,10 @@ sql_aggregate_context(sql_context * p, int nByte)
assert(p->func->def->aggregate == FUNC_AGGREGATE_GROUP);
if (!mem_is_agg(p->pMem) && mem_set_agg(p->pMem, p->func, nByte) != 0)
return NULL;
- return p->pMem->z;
+ void *accum;
+ if (mem_get_agg(p->pMem, &accum) != 0)
+ return NULL;
+ return accum;
}
/*
--
2.25.1
More information about the Tarantool-patches
mailing list