Commit 848a1a61 authored by Olivier Bertrand's avatar Olivier Bertrand

Fix decimal problems in bson udf's

parent 7edd4294
......@@ -1511,12 +1511,8 @@ double BJSON::GetDouble(PBVAL vp)
d = (double)vlp->N;
break;
case TYPE_FLOAT:
{ char buf[32];
int n = (vlp->Nd) ? vlp->Nd : 5;
sprintf(buf, "%.*f", n, vlp->F);
d = atof(buf);
} break;
d = (double)vlp->F;
break;
case TYPE_DTM:
case TYPE_STRG:
d = atof(MZP(vlp->To_Val));
......
......@@ -116,7 +116,7 @@ BJNX::BJNX(PGLOBAL g) : BDOC(g)
Value = NULL;
MulVal = NULL;
Jpath = NULL;
Buf_Type = TYPE_NULL;
Buf_Type = TYPE_STRING;
Long = len;
Prec = 0;
Nod = 0;
......@@ -171,10 +171,9 @@ BJNX::BJNX(PGLOBAL g, PBVAL row, int type, int len, int prec, my_bool wr) : BDOC
my_bool BJNX::SetJpath(PGLOBAL g, char* path, my_bool jb)
{
// Check Value was allocated
if (!Value)
return true;
if (Value)
Value->SetNullable(true);
Jpath = path;
// Parse the json path
......@@ -697,8 +696,10 @@ PVAL BJNX::GetCalcValue(PGLOBAL g, PBVAL bap, int n)
if (IsTypeChar(Buf_Type)) {
type = TYPE_DOUBLE;
prec = 2;
} else
} else {
type = Buf_Type;
prec = GetPrecision();
} // endif Buf_Type
break;
case OP_MIN:
......@@ -711,7 +712,7 @@ PVAL BJNX::GetCalcValue(PGLOBAL g, PBVAL bap, int n)
type = TYPE_STRING;
if (IsTypeChar(Buf_Type)) {
lng = Long;
lng = (Long) ? Long : 512;
prec = GetPrecision();
} else
lng = 512;
......@@ -740,6 +741,7 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
vp->Reset();
xtrc(1, "CalculateArray size=%d op=%d\n", ars, op);
try {
for (i = 0; i < ars; i++) {
bvrp = GetArrayValue(bap, i);
xtrc(1, "i=%d nv=%d\n", i, nv);
......@@ -814,6 +816,13 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
} // endif Op
} catch (int n) {
xtrc(1, "Exception %d: %s\n", n, g->Message);
PUSH_WARNING(g->Message);
} catch (const char* msg) {
strcpy(g->Message, msg);
} // end catch
return vp;
} // end of CalculateArray
......@@ -4024,8 +4033,8 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
char *p, *path;
double d;
PBVAL jsp, jvp;
PBJNX bxp = NULL;
PGLOBAL g = (PGLOBAL)initid->ptr;
BJNX bnx(g);
if (g->N) {
if (!g->Activityp) {
......@@ -4044,8 +4053,6 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
*is_null = 1;
return 0.0;
} else {
BJNX bnx(g);
jvp = bnx.MakeValue(args, 0);
if ((p = bnx.GetString(jvp))) {
......@@ -4068,21 +4075,22 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
jsp = (PBVAL)g->Xchk;
path = MakePSZ(g, args, 1);
bxp = new(g) BJNX(g, jsp, TYPE_DOUBLE);
//bxp = new(g) BJNX(g, jsp, TYPE_DOUBLE, 32, jsp->Nd);
if (bxp->SetJpath(g, path)) {
if (bnx.SetJpath(g, path)) {
PUSH_WARNING(g->Message);
*is_null = 1;
return 0.0;
} else
bxp->ReadValue(g);
jvp = bnx.GetRowValue(g, jsp, 0);
if (bxp->GetValue()->IsNull()) {
if (!jvp || bnx.IsValueNull(jvp)) {
*is_null = 1;
return 0.0;
} // endif IsNull
d = bxp->GetValue()->GetFloatValue();
} else if (args->arg_count == 2) {
d = atof(bnx.GetString(jvp));
} else
d = bnx.GetDouble(jvp);
if (initid->const_item) {
// Keep result of constant function
......
......@@ -279,7 +279,7 @@ SELECT * FROM t1;
WHO WEEKS SUMS SUM AVGS SUMAVG AVGSUM AVGAVG AVERAGE
Joe 3, 4, 5 69.00+83.00+26.00 178.00 17.25+16.60+13.00 46.85 59.33 15.62 16.18
Beth 3, 4, 5 16.00+32.00+32.00 80.00 16.00+16.00+16.00 48.00 26.67 16.00 16.00
Janet 3, 4, 5 55.00+17.00+57.00 129.00 18.33+17.00+14.25 49.58 43.00 16.53 16.13
Janet 3, 4, 5 55.00+17.00+57.00 129.00 18.33+17.00+14.25 49.58 43.00 16.53 16.12
DROP TABLE t1;
#
# Expand expense in 3 one week tables
......
......@@ -606,14 +606,12 @@ Bson_File('test/fx.json', 0)
[{"_id":5,"type":"food","item":"beer","taste":"light","price":5.65,"ratings":[5,8,9]},{"_id":6,"type":"car","item":"roadster","mileage":56000,"ratings":[6,9]},{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4]},{"_id":8,"type":"furniture","item":"table","size":{"W":60,"L":80,"H":40},"ratings":[5,8,7]}]
SELECT Bson_File('test/fx.json', '0');
Bson_File('test/fx.json', '0')
NULL
Warnings:
Warning 1105
{"_id":5,"type":"food","item":"beer","taste":"light","price":5.65,"ratings":[5,8,9]}
SELECT Bson_File('test/fx.json', '[?]');
Bson_File('test/fx.json', '[?]')
NULL
Warnings:
Warning 1105
Warning 1105 Invalid function specification ?
SELECT BsonGet_String(Bson_File('test/fx.json'), '1.*');
BsonGet_String(Bson_File('test/fx.json'), '1.*')
{"_id":6,"type":"car","item":"roadster","mileage":56000,"ratings":[6,9]}
......@@ -628,57 +626,33 @@ Price
5.65
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings');
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings')
NULL
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4,6]}
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 1, 'ratings');
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 1, 'ratings')
NULL
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,6,4]}
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings', 1);
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings', 1)
NULL
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,6,4]}
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2.ratings'), 6, 0);
Bson_Array_Add(Bson_File('test/fx.json', '2.ratings'), 6, 0)
[6,null]
Warnings:
Warning 1105
[6,2,4]
SELECT Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1);
Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1)
NULL
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2]}
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin);
Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin)
NULL
Warnings:
Warning 1105
Warning 1105 First argument target is not an object
{"_id":7,"type":"food","item":"meat","origin":"france","ratings":[2,4]}
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 70 H, 'size');
Bson_Object_Add(Bson_File('test/fx.json', '2'), 70 H, 'size')
NULL
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4]}
Warnings:
Warning 1105
Warning 1105 No sub-item at 'size'
SELECT Bson_Object_Add(Bson_File('test/fx.json', '3'), 70 H, 'size');
Bson_Object_Add(Bson_File('test/fx.json', '3'), 70 H, 'size')
NULL
Warnings:
Warning 1105
Warning 1105 No sub-item at 'size'
{"_id":8,"type":"furniture","item":"table","size":{"W":60,"L":80,"H":70},"ratings":[5,8,7]}
SELECT Bson_Object_List(Bson_File('test/fx.json', '3.size'));
Bson_Object_List(Bson_File('test/fx.json', '3.size'))
NULL
Warnings:
Warning 1105
Warning 1105 First argument is not an object
["W","L","H"]
#
# Testing new functions
#
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment