Skip to content

Commit 066b964

Browse files
authored
Export numeric interface to public (#392)
CBDB not allow building pg numeric from other formats. Numeric objects can only be constructed from string, which means that the caller needs to convert its own data into a specific format string, then convert the string into numeric. This is a very inefficient method. In order to better convert data of other structures into pg numeric, The current changes will expose the main structures and methods defined in numeric.c to numeric.h
1 parent f8a6bf8 commit 066b964

8 files changed

Lines changed: 557 additions & 523 deletions

File tree

contrib/btree_gist/btree_numeric.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ gbt_numeric_penalty(PG_FUNCTION_ARGS)
186186
NumericGetDatum(us),
187187
NumericGetDatum(os)));
188188

189-
if (numeric_is_nan(us))
189+
if (NUMERIC_IS_NAN(us))
190190
{
191-
if (numeric_is_nan(os))
191+
if (NUMERIC_IS_NAN(os))
192192
*result = 0.0;
193193
else
194194
*result = 1.0;

contrib/jsonb_plpython/jsonb_plpython.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,11 @@ PLyNumber_ToJsonbValue(PyObject *obj, JsonbValue *jbvNum)
390390
* jsonb doesn't allow NaN or infinity (per JSON specification), so we
391391
* have to reject those here explicitly.
392392
*/
393-
if (numeric_is_nan(num))
393+
if (NUMERIC_IS_NAN(num))
394394
ereport(ERROR,
395395
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
396396
errmsg("cannot convert NaN to jsonb")));
397-
if (numeric_is_inf(num))
397+
if (NUMERIC_IS_INF(num))
398398
ereport(ERROR,
399399
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
400400
errmsg("cannot convert infinity to jsonb")));

src/backend/cdb/cdblegacyhash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ cdblegacyhash_numeric(PG_FUNCTION_ARGS)
377377
size_t len; /* length for the data buffer */
378378
uint32 hash;
379379

380-
if (numeric_is_nan(num))
380+
if (NUMERIC_IS_NAN(num))
381381
{
382382
static const uint32 nanbuf = NAN_VAL;
383383

@@ -387,8 +387,8 @@ cdblegacyhash_numeric(PG_FUNCTION_ARGS)
387387
else
388388
/* not a nan */
389389
{
390-
buf = numeric_digits(num);
391-
len = numeric_len(num);
390+
buf = NUMERIC_DIGITS(num);
391+
len = NUMERIC_NDIGITS(num) * sizeof(NumericDigit);
392392
}
393393

394394
/* do the hash using the selected algorithm */

src/backend/gpopt/gpdbwrappers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ gpdb::NumericIsNan(Numeric num)
17171717
{
17181718
GP_WRAP_START;
17191719
{
1720-
return numeric_is_nan(num);
1720+
return NUMERIC_IS_NAN(num);
17211721
}
17221722
GP_WRAP_END;
17231723
return false;

src/backend/utils/adt/complex_type.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ numeric2complex(PG_FUNCTION_ARGS)
13131313
Numeric num = PG_GETARG_NUMERIC(0);
13141314
double float_num;
13151315

1316-
if (numeric_is_nan(num))
1316+
if (NUMERIC_IS_NAN(num))
13171317
{
13181318
float_num = get_float8_nan();
13191319
}

0 commit comments

Comments
 (0)