From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: introduce DECIMAL to SQL built-in functions
Date: Fri, 19 Nov 2021 11:14:23 +0300 [thread overview]
Message-ID: <20211119081423.GA48713@tarantool.org> (raw)
In-Reply-To: <330552df-201e-82ac-a841-4dbb55c2a9d6@tarantool.org>
Hi! Thank you the review! My answer and diff below.
On Mon, Nov 15, 2021 at 10:39:38PM +0100, Vladislav Shpilevoy wrote:
> Hi! Thanks for the patch!
>
> > diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> > index 5abaf490d..684fcc275 100644
> > --- a/src/box/sql/func.c
> > +++ b/src/box/sql/func.c
> > @@ -258,6 +258,20 @@ func_abs_double(struct sql_context *ctx, int argc, const struct Mem *argv)
> > mem_set_double(ctx->pOut, arg->u.r < 0 ? -arg->u.r : arg->u.r);
> > }
> >
> > +static void
> > +func_abs_dec(struct sql_context *ctx, int argc, const struct Mem *argv)
> > +{
> > + assert(argc == 1);
> > + (void)argc;
> > + const struct Mem *arg = &argv[0];
> > + if (mem_is_null(arg))
> > + return;
> > + assert(mem_is_dec(arg));
> > + decimal_t dec;
> > + decimal_abs(&dec, &arg->u.d);
> > + mem_set_dec(ctx->pOut, &dec);
>
> You should be able to use the same argument both for in and out
> values:
>
> decimal_abs(&arg->u.d, &arg->u.d);
>
> In the 'documentation' of decNumber it is said to be allowed.
> See the comment on the function 'decNumberAbs()'.
Fixed. Although we still need to copy from arg to pOut.
Diff:
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 684fcc275..e3ce6c18e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -267,9 +267,8 @@ func_abs_dec(struct sql_context *ctx, int argc, const struct Mem *argv)
if (mem_is_null(arg))
return;
assert(mem_is_dec(arg));
- decimal_t dec;
- decimal_abs(&dec, &arg->u.d);
- mem_set_dec(ctx->pOut, &dec);
+ mem_set_dec(ctx->pOut, &arg->u.d);
+ decimal_abs(&ctx->pOut->u.d, &ctx->pOut->u.d);
}
/** Implementation of the CHAR_LENGTH() function. */
next prev parent reply other threads:[~2021-11-19 8:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-12 11:40 Mergen Imeev via Tarantool-patches
2021-11-15 21:39 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-19 8:14 ` Mergen Imeev via Tarantool-patches [this message]
2021-11-21 15:21 ` Vladislav Shpilevoy via Tarantool-patches
2021-11-22 7:41 Mergen Imeev via Tarantool-patches
2021-11-22 12:31 ` Kirill Yukhin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211119081423.GA48713@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=imeevma@tarantool.org \
--cc=v.shpilevoy@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: introduce DECIMAL to SQL built-in functions' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox