diff options
author | Olivier Bertrand <bertrandop@gmail.com> | 2021-01-28 01:02:29 +0100 |
---|---|---|
committer | Olivier Bertrand <bertrandop@gmail.com> | 2021-01-28 01:02:29 +0100 |
commit | 7edd4294be4e59c19539167620ff140e3f5e7f58 (patch) | |
tree | 9496c7f8fcd309d5594b2ac8f6da3abc1519736d | |
parent | 9a07f30ba296c1431cc51fe6123bc31dd6aad05d (diff) | |
download | mariadb-git-7edd4294be4e59c19539167620ff140e3f5e7f58.tar.gz |
- Continue BSON development
modified: storage/connect/bson.cpp
modified: storage/connect/bson.h
modified: storage/connect/bsonudf.cpp
modified: storage/connect/bsonudf.h
modified: storage/connect/ha_connect.cc
modified: storage/connect/jsonudf.cpp
modified: storage/connect/mysql-test/connect/r/bson.result
modified: storage/connect/mysql-test/connect/r/bson_udf.result
modified: storage/connect/mysql-test/connect/t/bson_udf.inc
modified: storage/connect/mysql-test/connect/t/bson_udf.test
modified: storage/connect/mysql-test/connect/t/bson_udf2.inc
modified: storage/connect/tabbson.cpp
modified: storage/connect/tabbson.h
-rw-r--r-- | storage/connect/bson.cpp | 30 | ||||
-rw-r--r-- | storage/connect/bson.h | 2 | ||||
-rw-r--r-- | storage/connect/bsonudf.cpp | 215 | ||||
-rw-r--r-- | storage/connect/bsonudf.h | 12 | ||||
-rw-r--r-- | storage/connect/ha_connect.cc | 16 | ||||
-rw-r--r-- | storage/connect/jsonudf.cpp | 4 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/r/bson.result | 2 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/r/bson_udf.result | 51 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/bson_udf.inc | 2 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/bson_udf.test | 1 | ||||
-rw-r--r-- | storage/connect/mysql-test/connect/t/bson_udf2.inc | 2 | ||||
-rw-r--r-- | storage/connect/tabbson.cpp | 128 | ||||
-rw-r--r-- | storage/connect/tabbson.h | 7 |
13 files changed, 341 insertions, 131 deletions
diff --git a/storage/connect/bson.cpp b/storage/connect/bson.cpp index fc58303a73f..5731ce9eac5 100644 --- a/storage/connect/bson.cpp +++ b/storage/connect/bson.cpp @@ -37,6 +37,8 @@ #undef SE_CATCH // Does not work for Linux #endif +int GetJsonDefPrec(void); + #if defined(SE_CATCH) /**************************************************************************/ /* This is the support of catching C interrupts to prevent crashes. */ @@ -1722,14 +1724,22 @@ void BJSON::SetBigint(PBVAL vlp, longlong ll) /***********************************************************************/ /* Set the Value's value as the given DOUBLE. */ /***********************************************************************/ -void BJSON::SetFloat(PBVAL vlp, double d, int nd) +void BJSON::SetFloat(PBVAL vlp, double d, int prec) { - double* dp = (double*)BsonSubAlloc(sizeof(double)); + int nd = MY_MIN((prec < 0) ? GetJsonDefPrec() : prec, 16); + + if (nd < 6 && d >= FLT_MIN && d <= FLT_MAX) { + vlp->F = (float)d; + vlp->Type = TYPE_FLOAT; + } else { + double* dp = (double*)BsonSubAlloc(sizeof(double)); - *dp = d; - vlp->To_Val = MOF(dp); - vlp->Nd = MY_MIN(nd, 16); - vlp->Type = TYPE_DBL; + *dp = d; + vlp->To_Val = MOF(dp); + vlp->Type = TYPE_DBL; + } // endif nd + + vlp->Nd = nd; } // end of SetFloat /***********************************************************************/ @@ -1746,13 +1756,7 @@ void BJSON::SetFloat(PBVAL vlp, PSZ s) for (--p; *p == '0'; nd--, p--); } // endif p - if (nd < 6 && d >= FLT_MIN && d <= FLT_MAX) { - vlp->F = (float)d; - vlp->Nd = nd; - vlp->Type = TYPE_FLOAT; - } else - SetFloat(vlp, d, nd); - + SetFloat(vlp, d, nd); } // end of SetFloat /***********************************************************************/ diff --git a/storage/connect/bson.h b/storage/connect/bson.h index 6eb6c019c1a..32a9c49b00a 100644 --- a/storage/connect/bson.h +++ b/storage/connect/bson.h @@ -149,7 +149,7 @@ public: void SetString(PBVAL vlp, PSZ s, int ci = 0); void SetInteger(PBVAL vlp, int n); void SetBigint(PBVAL vlp, longlong ll); - void SetFloat(PBVAL vlp, double f, int nd = 16); + void SetFloat(PBVAL vlp, double f, int nd = -1); void SetFloat(PBVAL vlp, PSZ s); void SetBool(PBVAL vlp, bool b); void Clear(PBVAL vlp) { vlp->N = 0; vlp->Nd = 0; vlp->Next = 0; } diff --git a/storage/connect/bsonudf.cpp b/storage/connect/bsonudf.cpp index 719b7d7509a..dd9f95bc4ba 100644 --- a/storage/connect/bsonudf.cpp +++ b/storage/connect/bsonudf.cpp @@ -27,12 +27,21 @@ #endif #define M 6 +int JsonDefPrec = -1; +int GetDefaultPrec(void); int IsArgJson(UDF_ARGS* args, uint i); void SetChanged(PBSON bsp); /* --------------------------------- JSON UDF ---------------------------------- */ /*********************************************************************************/ +/* Replaces GetJsonGrpSize not usable when CONNECT is not installed. */ +/*********************************************************************************/ +int GetJsonDefPrec(void) { + return (JsonDefPrec < 0) ? GetDefaultPrec() : JsonDefPrec; +} /* end of GetJsonDefPrec */ + +/*********************************************************************************/ /* Program for saving the status of the memory pools. */ /*********************************************************************************/ inline void JsonMemSave(PGLOBAL g) { @@ -262,6 +271,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm) return true; } // endif's +#if 0 // For calculated arrays, a local Value must be used switch (jnp->Op) { case OP_NUM: @@ -293,6 +303,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm) if (jnp->Valp) MulVal = AllocateValue(g, jnp->Valp); +#endif // 0 return false; } // end of SetArrayOptions @@ -376,7 +387,7 @@ my_bool BJNX::ParseJpath(PGLOBAL g) } // endfor i, p Nod = i; - MulVal = AllocateValue(g, Value); +//MulVal = AllocateValue(g, Value); if (trace(1)) for (i = 0; i < Nod; i++) @@ -433,20 +444,42 @@ PSZ BJNX::MakeKey(UDF_ARGS *args, int i) } // end of MakeKey /*********************************************************************************/ -/* MakeJson: Serialize the json item and set value to it. */ +/* MakeJson: Make the Json tree to serialize. */ /*********************************************************************************/ -PVAL BJNX::MakeJson(PGLOBAL g, PBVAL bvp) +PBVAL BJNX::MakeJson(PGLOBAL g, PBVAL bvp, int n) { - if (Value->IsTypeNum()) { - strcpy(g->Message, "Cannot make Json for a numeric value"); - Value->Reset(); - } else if (bvp->Type != TYPE_JAR && bvp->Type != TYPE_JOB) { - strcpy(g->Message, "Target is not an array or object"); - Value->Reset(); - } else - Value->SetValue_psz(Serialize(g, bvp, NULL, 0)); + PBVAL vlp, jvp = bvp; - return Value; + if (n < Nod -1) { + if (bvp->Type == TYPE_JAR) { + int ars = GetArraySize(bvp); + PJNODE jnp = &Nodes[n]; + + jvp = NewVal(TYPE_JAR); + jnp->Op = OP_EQ; + + for (int i = 0; i < ars; i++) { + jnp->Rank = i; + vlp = GetRowValue(g, bvp, n); + AddArrayValue(jvp, DupVal(vlp)); + } // endfor i + + jnp->Op = OP_XX; + jnp->Rank = 0; + } else if(bvp->Type == TYPE_JOB) { + jvp = NewVal(TYPE_JOB); + + for (PBPR prp = GetObject(bvp); prp; prp = GetNext(prp)) { + vlp = GetRowValue(g, GetVlp(prp), n + 1); + SetKeyValue(jvp, vlp, MZP(prp->Key)); + } // endfor prp + + } // endif Type + + } // endif n + + Jb = true; + return jvp; } // end of MakeJson /*********************************************************************************/ @@ -459,15 +492,18 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp) if (Jb) { vp->SetValue_psz(Serialize(g, vlp, NULL, 0)); + Jb = false; } else switch (vlp->Type) { case TYPE_DTM: case TYPE_STRG: vp->SetValue_psz(GetString(vlp)); break; case TYPE_INTG: - case TYPE_BINT: vp->SetValue(GetInteger(vlp)); break; + case TYPE_BINT: + vp->SetValue(GetBigint(vlp)); + break; case TYPE_DBL: case TYPE_FLOAT: if (vp->IsTypeNum()) @@ -532,7 +568,7 @@ PVAL BJNX::GetColumnValue(PGLOBAL g, PBVAL row, int i) /*********************************************************************************/ /* GetRowValue: */ /*********************************************************************************/ -PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b) +PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i) { my_bool expd = false; PBVAL bap; @@ -544,9 +580,7 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b) vlp = NewVal(Value); return vlp; } else if (Nodes[i].Op == OP_XX) { - Jb = b; - // return DupVal(g, row); - return row; // or last line ??? + return MakeJson(g, row, i); } else if (Nodes[i].Op == OP_EXP) { PUSH_WARNING("Expand not supported by this function"); return NULL; @@ -611,14 +645,95 @@ PVAL BJNX::ExpandArray(PGLOBAL g, PBVAL arp, int n) } // end of ExpandArray /*********************************************************************************/ -/* CalculateArray: NIY */ +/* Get the value used for calculating the array. */ +/*********************************************************************************/ +PVAL BJNX::GetCalcValue(PGLOBAL g, PBVAL bap, int n) +{ + // For calculated arrays, a local Value must be used + int lng = 0; + short type, prec = 0; + bool b = n < Nod - 1; + PVAL valp; + PBVAL vlp, vp; + OPVAL op = Nodes[n].Op; + + switch (op) { + case OP_NUM: + type = TYPE_INT; + break; + case OP_ADD: + case OP_MULT: + if (!IsTypeNum(Buf_Type)) { + type = TYPE_INT; + prec = 0; + + for (vlp = GetArray(bap); vlp; vlp = GetNext(vlp)) { + vp = (b && IsJson(vlp)) ? GetRowValue(g, vlp, n + 1) : vlp; + + switch (vp->Type) { + case TYPE_BINT: + if (type == TYPE_INT) + type = TYPE_BIGINT; + + break; + case TYPE_DBL: + case TYPE_FLOAT: + type = TYPE_DOUBLE; + prec = MY_MAX(prec, vp->Nd); + break; + default: + break; + } // endswitch Type + + } // endfor vlp + + } else { + type = Buf_Type; + prec = GetPrecision(); + } // endif Buf_Type + + break; + case OP_SEP: + if (IsTypeChar(Buf_Type)) { + type = TYPE_DOUBLE; + prec = 2; + } else + type = Buf_Type; + + break; + case OP_MIN: + case OP_MAX: + type = Buf_Type; + lng = Long; + prec = GetPrecision(); + break; + case OP_CNC: + type = TYPE_STRING; + + if (IsTypeChar(Buf_Type)) { + lng = Long; + prec = GetPrecision(); + } else + lng = 512; + + break; + default: + break; + } // endswitch Op + + return valp = AllocateValue(g, type, lng, prec); +} // end of GetCalcValue + +/*********************************************************************************/ +/* CalculateArray */ /*********************************************************************************/ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n) { int i, ars = GetArraySize(bap), nv = 0; bool err; OPVAL op = Nodes[n].Op; - PVAL val[2], vp = Nodes[n].Valp; + PVAL val[2], vp = GetCalcValue(g, bap, n); + PVAL mulval = AllocateValue(g, vp); PBVAL bvrp, bvp; BVAL bval; @@ -647,9 +762,9 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n) SetJsonValue(g, vp, bvp); continue; } else - SetJsonValue(g, MulVal, bvp); + SetJsonValue(g, mulval, bvp); - if (!MulVal->IsNull()) { + if (!mulval->IsNull()) { switch (op) { case OP_CNC: if (Nodes[n].CncVal) { @@ -657,18 +772,18 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n) err = vp->Compute(g, val, 1, op); } // endif CncVal - val[0] = MulVal; + val[0] = mulval; err = vp->Compute(g, val, 1, op); break; // case OP_NUM: case OP_SEP: - val[0] = Nodes[n].Valp; - val[1] = MulVal; + val[0] = vp; + val[1] = mulval; err = vp->Compute(g, val, 2, OP_ADD); break; default: - val[0] = Nodes[n].Valp; - val[1] = MulVal; + val[0] = vp; + val[1] = mulval; err = vp->Compute(g, val, 2, op); } // endswitch Op @@ -690,9 +805,9 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n) if (op == OP_SEP) { // Calculate average - MulVal->SetValue(nv); + mulval->SetValue(nv); val[0] = vp; - val[1] = MulVal; + val[1] = mulval; if (vp->Compute(g, val, 2, OP_DIV)) vp->Reset(); @@ -2701,6 +2816,45 @@ void bson_object_values_deinit(UDF_INIT* initid) /*********************************************************************************/ /* Set the value of JsonGrpSize. */ /*********************************************************************************/ +my_bool bsonset_def_prec_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) { + strcpy(message, "This function must have 1 integer argument"); + return true; + } else + return false; + +} // end of bsonset_def_prec_init + +long long bsonset_def_prec(UDF_INIT *initid, UDF_ARGS *args, char *, char *) +{ + long long n = *(long long*)args->args[0]; + + JsonDefPrec = (int)n; + return (long long)GetJsonDefPrec(); +} // end of bsonset_def_prec + +/*********************************************************************************/ +/* Get the value of JsonGrpSize. */ +/*********************************************************************************/ +my_bool bsonget_def_prec_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count != 0) { + strcpy(message, "This function must have no arguments"); + return true; + } else + return false; + +} // end of bsonget_def_prec_init + +long long bsonget_def_prec(UDF_INIT *initid, UDF_ARGS *args, char *, char *) +{ + return (long long)GetJsonDefPrec(); +} // end of bsonget_def_prec + +/*********************************************************************************/ +/* Set the value of JsonGrpSize. */ +/*********************************************************************************/ my_bool bsonset_grp_size_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { if (args->arg_count != 1 || args->arg_type[0] != INT_RESULT) { @@ -4714,7 +4868,8 @@ char *bson_serialize(UDF_INIT *initid, UDF_ARGS *args, char *result, BJNX bnx(bsp->G); PBVAL bvp = (args->arg_count == 1) ? (PBVAL)bsp->Jsp : (PBVAL)bsp->Top; - if (!(str = bnx.Serialize(g, bvp, bsp->Filename, bsp->Pretty))) +// if (!(str = bnx.Serialize(g, bvp, bsp->Filename, bsp->Pretty))) + if (!(str = bnx.Serialize(g, bvp, NULL, 0))) str = strcpy(result, g->Message); // Keep result of constant function @@ -5513,7 +5668,7 @@ void bbin_object_values_deinit(UDF_INIT* initid) my_bool bbin_get_item_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { return bson_get_item_init(initid, args, message); -} // end of bbin_get_item_init +} // end of bbin_get_item_init char *bbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error) diff --git a/storage/connect/bsonudf.h b/storage/connect/bsonudf.h index 01b9b9d55d5..bbfd1ceed80 100644 --- a/storage/connect/bsonudf.h +++ b/storage/connect/bsonudf.h @@ -81,6 +81,7 @@ typedef struct _jpn { extern uint JsonGrpSize; uint GetJsonGroupSize(void); + typedef class BJNX* PBJNX; /*********************************************************************************/ @@ -102,7 +103,7 @@ public: my_bool SetJpath(PGLOBAL g, char* path, my_bool jb = false); my_bool ParseJpath(PGLOBAL g); void ReadValue(PGLOBAL g); - PBVAL GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b = true); + PBVAL GetRowValue(PGLOBAL g, PBVAL row, int i); PBVAL GetJson(PGLOBAL g); my_bool CheckPath(PGLOBAL g); my_bool CheckPath(PGLOBAL g, UDF_ARGS* args, PBVAL jsp, PBVAL& jvp, int n); @@ -123,7 +124,8 @@ protected: PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i); PVAL ExpandArray(PGLOBAL g, PBVAL arp, int n); PVAL CalculateArray(PGLOBAL g, PBVAL arp, int n); - PVAL MakeJson(PGLOBAL g, PBVAL bvp); + PVAL GetCalcValue(PGLOBAL g, PBVAL bap, int n); + PBVAL MakeJson(PGLOBAL g, PBVAL bvp, int n); void SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp); PBVAL GetRow(PGLOBAL g); PBVAL MoveVal(PBVAL vlp); @@ -259,6 +261,12 @@ extern "C" { DllExport double bsonget_real(UDF_INIT*, UDF_ARGS*, char*, char*); DllExport void bsonget_real_deinit(UDF_INIT*); + DllExport my_bool bsonset_def_prec_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport long long bsonset_def_prec(UDF_INIT*, UDF_ARGS*, char*, char*); + + DllExport my_bool bsonget_def_prec_init(UDF_INIT*, UDF_ARGS*, char*); + DllExport long long bsonget_def_prec(UDF_INIT*, UDF_ARGS*, char*, char*); + DllExport my_bool bsonset_grp_size_init(UDF_INIT*, UDF_ARGS*, char*); DllExport long long bsonset_grp_size(UDF_INIT*, UDF_ARGS*, char*, char*); diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 9b40b5c9a13..69646e22e30 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -170,7 +170,7 @@ #define JSONMAX 10 // JSON Default max grp size extern "C" { - char version[]= "Version 1.07.0002 December 25, 2020"; + char version[]= "Version 1.07.0002 January 27, 2021"; #if defined(__WIN__) char compver[]= "Version 1.07.0002 " __DATE__ " " __TIME__; char slash= '\\'; @@ -255,6 +255,7 @@ USETEMP UseTemp(void); int GetConvSize(void); TYPCONV GetTypeConv(void); int GetDefaultDepth(void); +int GetDefaultPrec(void); bool JsonAllPath(void); char *GetJsonNull(void); uint GetJsonGrpSize(void); @@ -420,9 +421,15 @@ static MYSQL_THDVAR_INT(default_depth, "Default depth used by Json, XML and Mongo discovery", NULL, NULL, 5, -1, 16, 1); // Defaults to 5 +// Default precision for doubles +static MYSQL_THDVAR_INT(default_prec, + PLUGIN_VAR_RQCMDARG, + "Default precision used for doubles", + NULL, NULL, 6, 0, 16, 1); // Defaults to 6 + // Estimate max number of rows for JSON aggregate functions static MYSQL_THDVAR_UINT(json_grp_size, - PLUGIN_VAR_RQCMDARG, // opt + PLUGIN_VAR_RQCMDARG, // opt "max number of rows for JSON aggregate functions.", NULL, NULL, JSONMAX, 1, INT_MAX, 1); @@ -495,6 +502,7 @@ TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);} char *GetJsonNull(void) {return connect_hton ? THDVAR(current_thd, json_null) : NULL;} int GetDefaultDepth(void) {return THDVAR(current_thd, default_depth);} +int GetDefaultPrec(void) {return THDVAR(current_thd, default_prec);} uint GetJsonGrpSize(void) {return connect_hton ? THDVAR(current_thd, json_grp_size) : 10;} size_t GetWorkSize(void) {return (size_t)THDVAR(current_thd, work_size);} @@ -4834,6 +4842,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type) lock.cc by lock_external() and unlock_external() in lock.cc; the section "locking functions for mysql" in lock.cc; copy_data_between_tables() in sql_table.cc. + */ int ha_connect::external_lock(THD *thd, int lock_type) { @@ -7445,7 +7454,8 @@ static struct st_mysql_sys_var* connect_system_variables[]= { MYSQL_SYSVAR(json_null), MYSQL_SYSVAR(json_all_path), MYSQL_SYSVAR(default_depth), - MYSQL_SYSVAR(json_grp_size), + MYSQL_SYSVAR(default_prec), + MYSQL_SYSVAR(json_grp_size), #if defined(JAVA_SUPPORT) MYSQL_SYSVAR(jvm_path), MYSQL_SYSVAR(class_path), diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index 53818cbe00b..49a36407cec 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -354,9 +354,11 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val) vp->SetValue_psz(val->GetString(g)); break; case TYPE_INTG: - case TYPE_BINT: vp->SetValue(val->GetInteger()); break; + case TYPE_BINT: + vp->SetValue(val->GetBigint()); + break; case TYPE_DBL: if (vp->IsTypeNum()) vp->SetValue(val->GetFloat()); diff --git a/storage/connect/mysql-test/connect/r/bson.result b/storage/connect/mysql-test/connect/r/bson.result index fd15e020aac..98abdbb8744 100644 --- a/storage/connect/mysql-test/connect/r/bson.result +++ b/storage/connect/mysql-test/connect/r/bson.result @@ -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.12 +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 DROP TABLE t1; # # Expand expense in 3 one week tables diff --git a/storage/connect/mysql-test/connect/r/bson_udf.result b/storage/connect/mysql-test/connect/r/bson_udf.result index a0b93f2e547..14b3629e4b1 100644 --- a/storage/connect/mysql-test/connect/r/bson_udf.result +++ b/storage/connect/mysql-test/connect/r/bson_udf.result @@ -176,6 +176,9 @@ Value List # # Test UDF's with column arguments # +SELECT Bsonset_Def_Prec(2); +Bsonset_Def_Prec(2) +2 CREATE TABLE t2 ( ISBN CHAR(15), @@ -213,7 +216,7 @@ SALARY DOUBLE(8,2) NOT NULL FLAG=52 ) ENGINE=CONNECT TABLE_TYPE=FIX BLOCK_SIZE=8 FILE_NAME='employee.dat' ENDING=1; SELECT Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY) FROM t3 WHERE NAME = 'MERCHANT'; Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY) -{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.0000000000000000} +{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.00} SELECT DEPARTMENT, Bson_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT; DEPARTMENT Bson_Array_Grp(NAME) 0021 ["STRONG","SHORTSIGHT"] @@ -249,30 +252,30 @@ Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES) {"DEPARTMENT":"2452","NAMES":["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"]} SELECT Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY)) json_EMPLOYES) FROM t3 GROUP BY DEPARTMENT; Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY)) json_EMPLOYES) -{"DEPARTMENT":"0021","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","TITLE":"DIRECTOR","SALARY":23000.0000000000000000},{"SERIALNO":"22222","NAME":"SHORTSIGHT","TITLE":"SECRETARY","SALARY":5500.0000000000000000}]} -{"DEPARTMENT":"0318","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","TITLE":"SALESMAN","SALARY":9600.0000000000000000},{"SERIALNO":"24888","NAME":"PLUMHEAD","TITLE":"TYPIST","SALARY":2800.0000000000000000},{"SERIALNO":"27845","NAME":"HONEY","TITLE":"SECRETARY","SALARY":4900.0000000000000000},{"SERIALNO":"73452","NAME":"TONGHO","TITLE":"ENGINEER","SALARY":6800.0000000000000000},{"SERIALNO":"74234","NAME":"WALTER","TITLE":"ENGINEER","SALARY":7400.0000000000000000},{"SERIALNO":"77777","NAME":"SHRINKY","TITLE":"ADMINISTRATOR","SALARY":7500.0000000000000000},{"SERIALNO":"70012","NAME":"WERTHER","TITLE":"DIRECTOR","SALARY":14500.0000000000000000},{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.0000000000000000},{"SERIALNO":"73111","NAME":"WHEELFOR","TITLE":"SALESMAN","SALARY":10030.0000000000000000}]} -{"DEPARTMENT":"0319","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","TITLE":"SALESMAN","SALARY":14800.0000000000000000},{"SERIALNO":"40567","NAME":"QUINN","TITLE":"DIRECTOR","SALARY":14000.0000000000000000},{"SERIALNO":"00137","NAME":"BROWNY","TITLE":"ENGINEER","SALARY":10500.0000000000000000},{"SERIALNO":"12345","NAME":"KITTY","TITLE":"TYPIST","SALARY":3000.4499999999998181},{"SERIALNO":"33333","NAME":"MONAPENNY","TITLE":"SECRETARY","SALARY":3800.0000000000000000},{"SERIALNO":"00023","NAME":"MARTIN","TITLE":"ENGINEER","SALARY":10000.0000000000000000},{"SERIALNO":"07654","NAME":"FUNNIGUY","TITLE":"ADMINISTRATOR","SALARY":8500.0000000000000000},{"SERIALNO":"45678","NAME":"BUGHAPPY","TITLE":"PROGRAMMER","SALARY":8500.0000000000000000},{"SERIALNO":"56789","NAME":"FODDERMAN","TITLE":"SALESMAN","SALARY":7000.0000000000000000},{"SERIALNO":"55555","NAME":"MESSIFUL","TITLE":"SECRETARY","SALARY":5000.5000000000000000},{"SERIALNO":"98765","NAME":"GOOSEPEN","TITLE":"ADMINISTRATOR","SALARY":4700.0000000000000000}]} -{"DEPARTMENT":"2452","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","TITLE":"SCIENTIST","SALARY":8000.0000000000000000},{"SERIALNO":"31416","NAME":"ORELLY","TITLE":"ENGINEER","SALARY":13400.0000000000000000},{"SERIALNO":"36666","NAME":"BIGHORN","TITLE":"SCIENTIST","SALARY":11000.0000000000000000},{"SERIALNO":"02345","NAME":"SMITH","TITLE":"ENGINEER","SALARY":9000.0000000000000000},{"SERIALNO":"11111","NAME":"CHERRY","TITLE":"SECRETARY","SALARY":4500.0000000000000000}]} +{"DEPARTMENT":"0021","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","TITLE":"DIRECTOR","SALARY":23000.00},{"SERIALNO":"22222","NAME":"SHORTSIGHT","TITLE":"SECRETARY","SALARY":5500.00}]} +{"DEPARTMENT":"0318","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","TITLE":"SALESMAN","SALARY":9600.00},{"SERIALNO":"24888","NAME":"PLUMHEAD","TITLE":"TYPIST","SALARY":2800.00},{"SERIALNO":"27845","NAME":"HONEY","TITLE":"SECRETARY","SALARY":4900.00},{"SERIALNO":"73452","NAME":"TONGHO","TITLE":"ENGINEER","SALARY":6800.00},{"SERIALNO":"74234","NAME":"WALTER","TITLE":"ENGINEER","SALARY":7400.00},{"SERIALNO":"77777","NAME":"SHRINKY","TITLE":"ADMINISTRATOR","SALARY":7500.00},{"SERIALNO":"70012","NAME":"WERTHER","TITLE":"DIRECTOR","SALARY":14500.00},{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.00},{"SERIALNO":"73111","NAME":"WHEELFOR","TITLE":"SALESMAN","SALARY":10030.00}]} +{"DEPARTMENT":"0319","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","TITLE":"SALESMAN","SALARY":14800.00},{"SERIALNO":"40567","NAME":"QUINN","TITLE":"DIRECTOR","SALARY":14000.00},{"SERIALNO":"00137","NAME":"BROWNY","TITLE":"ENGINEER","SALARY":10500.00},{"SERIALNO":"12345","NAME":"KITTY","TITLE":"TYPIST","SALARY":3000.45},{"SERIALNO":"33333","NAME":"MONAPENNY","TITLE":"SECRETARY","SALARY":3800.00},{"SERIALNO":"00023","NAME":"MARTIN","TITLE":"ENGINEER","SALARY":10000.00},{"SERIALNO":"07654","NAME":"FUNNIGUY","TITLE":"ADMINISTRATOR","SALARY":8500.00},{"SERIALNO":"45678","NAME":"BUGHAPPY","TITLE":"PROGRAMMER","SALARY":8500.00},{"SERIALNO":"56789","NAME":"FODDERMAN","TITLE":"SALESMAN","SALARY":7000.00},{"SERIALNO":"55555","NAME":"MESSIFUL","TITLE":"SECRETARY","SALARY":5000.50},{"SERIALNO":"98765","NAME":"GOOSEPEN","TITLE":"ADMINISTRATOR","SALARY":4700.00}]} +{"DEPARTMENT":"2452","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","TITLE":"SCIENTIST","SALARY":8000.00},{"SERIALNO":"31416","NAME":"ORELLY","TITLE":"ENGINEER","SALARY":13400.00},{"SERIALNO":"36666","NAME":"BIGHORN","TITLE":"SCIENTIST","SALARY":11000.00},{"SERIALNO":"02345","NAME":"SMITH","TITLE":"ENGINEER","SALARY":9000.00},{"SERIALNO":"11111","NAME":"CHERRY","TITLE":"SECRETARY","SALARY":4500.00}]} SELECT Bson_Make_Object(DEPARTMENT, TITLE, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, SALARY)) json_EMPLOYES) FROM t3 GROUP BY DEPARTMENT, TITLE; Bson_Make_Object(DEPARTMENT, TITLE, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, SALARY)) json_EMPLOYES) -{"DEPARTMENT":"0021","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","SALARY":23000.0000000000000000}]} -{"DEPARTMENT":"0021","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"22222","NAME":"SHORTSIGHT","SALARY":5500.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"77777","NAME":"SHRINKY","SALARY":7500.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"70012","NAME":"WERTHER","SALARY":14500.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"73452","NAME":"TONGHO","SALARY":6800.0000000000000000},{"SERIALNO":"74234","NAME":"WALTER","SALARY":7400.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","SALARY":9600.0000000000000000},{"SERIALNO":"78943","NAME":"MERCHANT","SALARY":8700.0000000000000000},{"SERIALNO":"73111","NAME":"WHEELFOR","SALARY":10030.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"27845","NAME":"HONEY","SALARY":4900.0000000000000000}]} -{"DEPARTMENT":"0318","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"24888","NAME":"PLUMHEAD","SALARY":2800.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"98765","NAME":"GOOSEPEN","SALARY":4700.0000000000000000},{"SERIALNO":"07654","NAME":"FUNNIGUY","SALARY":8500.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"40567","NAME":"QUINN","SALARY":14000.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"00023","NAME":"MARTIN","SALARY":10000.0000000000000000},{"SERIALNO":"00137","NAME":"BROWNY","SALARY":10500.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"PROGRAMMER","EMPLOYES":[{"SERIALNO":"45678","NAME":"BUGHAPPY","SALARY":8500.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","SALARY":14800.0000000000000000},{"SERIALNO":"56789","NAME":"FODDERMAN","SALARY":7000.0000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"33333","NAME":"MONAPENNY","SALARY":3800.0000000000000000},{"SERIALNO":"55555","NAME":"MESSIFUL","SALARY":5000.5000000000000000}]} -{"DEPARTMENT":"0319","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"12345","NAME":"KITTY","SALARY":3000.4499999999998181}]} -{"DEPARTMENT":"2452","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"31416","NAME":"ORELLY","SALARY":13400.0000000000000000},{"SERIALNO":"02345","NAME":"SMITH","SALARY":9000.0000000000000000}]} -{"DEPARTMENT":"2452","TITLE":"SCIENTIST","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","SALARY":8000.0000000000000000},{"SERIALNO":"36666","NAME":"BIGHORN","SALARY":11000.0000000000000000}]} -{"DEPARTMENT":"2452","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"11111","NAME":"CHERRY","SALARY":4500.0000000000000000}]} +{"DEPARTMENT":"0021","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","SALARY":23000.00}]} +{"DEPARTMENT":"0021","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"22222","NAME":"SHORTSIGHT","SALARY":5500.00}]} +{"DEPARTMENT":"0318","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"77777","NAME":"SHRINKY","SALARY":7500.00}]} +{"DEPARTMENT":"0318","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"70012","NAME":"WERTHER","SALARY":14500.00}]} +{"DEPARTMENT":"0318","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"73452","NAME":"TONGHO","SALARY":6800.00},{"SERIALNO":"74234","NAME":"WALTER","SALARY":7400.00}]} +{"DEPARTMENT":"0318","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","SALARY":9600.00},{"SERIALNO":"78943","NAME":"MERCHANT","SALARY":8700.00},{"SERIALNO":"73111","NAME":"WHEELFOR","SALARY":10030.00}]} +{"DEPARTMENT":"0318","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"27845","NAME":"HONEY","SALARY":4900.00}]} +{"DEPARTMENT":"0318","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"24888","NAME":"PLUMHEAD","SALARY":2800.00}]} +{"DEPARTMENT":"0319","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"98765","NAME":"GOOSEPEN","SALARY":4700.00},{"SERIALNO":"07654","NAME":"FUNNIGUY","SALARY":8500.00}]} +{"DEPARTMENT":"0319","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"40567","NAME":"QUINN","SALARY":14000.00}]} +{"DEPARTMENT":"0319","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"00023","NAME":"MARTIN","SALARY":10000.00},{"SERIALNO":"00137","NAME":"BROWNY","SALARY":10500.00}]} +{"DEPARTMENT":"0319","TITLE":"PROGRAMMER","EMPLOYES":[{"SERIALNO":"45678","NAME":"BUGHAPPY","SALARY":8500.00}]} +{"DEPARTMENT":"0319","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","SALARY":14800.00},{"SERIALNO":"56789","NAME":"FODDERMAN","SALARY":7000.00}]} +{"DEPARTMENT":"0319","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"33333","NAME":"MONAPENNY","SALARY":3800.00},{"SERIALNO":"55555","NAME":"MESSIFUL","SALARY":5000.50}]} +{"DEPARTMENT":"0319","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"12345","NAME":"KITTY","SALARY":3000.45}]} +{"DEPARTMENT":"2452","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"31416","NAME":"ORELLY","SALARY":13400.00},{"SERIALNO":"02345","NAME":"SMITH","SALARY":9000.00}]} +{"DEPARTMENT":"2452","TITLE":"SCIENTIST","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","SALARY":8000.00},{"SERIALNO":"36666","NAME":"BIGHORN","SALARY":11000.00}]} +{"DEPARTMENT":"2452","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"11111","NAME":"CHERRY","SALARY":4500.00}]} SELECT Bson_Object_Grp(SALARY) FROM t3; ERROR HY000: Can't initialize function 'bson_object_grp'; This function requires 2 arguments (key, value) SELECT Bson_Object_Grp(NAME, SALARY) FROM t3; @@ -325,7 +328,7 @@ BsonGet_String(Bson_Make_Array(45,28,36,45,89),'3') 45 SELECT BsonGet_String(Bson_Make_Array(45,28,36,45,89),'["+"]') "list",'=' as "egal",BsonGet_String(Bson_Make_Array(45,28,36,45,89),'[+]') "sum"; list egal sum -45+28+36+45+89 = 243.00 +45+28+36+45+89 = 243 SELECT BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.0'); BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.0') 36 diff --git a/storage/connect/mysql-test/connect/t/bson_udf.inc b/storage/connect/mysql-test/connect/t/bson_udf.inc index 366f48e5861..c4722722ef7 100644 --- a/storage/connect/mysql-test/connect/t/bson_udf.inc +++ b/storage/connect/mysql-test/connect/t/bson_udf.inc @@ -22,6 +22,8 @@ if (!$HA_CONNECT_SO) { --eval CREATE FUNCTION bson_object_delete RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION bson_object_list RETURNS STRING SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION bson_object_values RETURNS STRING SONAME '$HA_CONNECT_SO'; +--eval CREATE FUNCTION bsonset_def_prec RETURNS INTEGER SONAME '$HA_CONNECT_SO'; +--eval CREATE FUNCTION bsonget_def_prec RETURNS INTEGER SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION bsonset_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO'; --eval CREATE FUNCTION bsonget_grp_size RETURNS INTEGER SONAME '$HA_CONNECT_SO'; --eval CREATE AGGREGATE FUNCTION bson_array_grp RETURNS STRING SONAME '$HA_CONNECT_SO'; diff --git a/storage/connect/mysql-test/connect/t/bson_udf.test b/storage/connect/mysql-test/connect/t/bson_udf.test index 84a3db6d061..0da2de38864 100644 --- a/storage/connect/mysql-test/connect/t/bson_udf.test +++ b/storage/connect/mysql-test/connect/t/bson_udf.test @@ -77,6 +77,7 @@ SELECT Bson_Object_Values('{"One":1,"Two":2,"Three":3}') "Value List"; --echo # --echo # Test UDF's with column arguments --echo # +SELECT Bsonset_Def_Prec(2); CREATE TABLE t2 ( ISBN CHAR(15), diff --git a/storage/connect/mysql-test/connect/t/bson_udf2.inc b/storage/connect/mysql-test/connect/t/bson_udf2.inc index ceddf8b0632..d06d7fac435 100644 --- a/storage/connect/mysql-test/connect/t/bson_udf2.inc +++ b/storage/connect/mysql-test/connect/t/bson_udf2.inc @@ -13,6 +13,8 @@ DROP FUNCTION bson_object_add; DROP FUNCTION bson_object_delete; DROP FUNCTION bson_object_list; DROP FUNCTION bson_object_values; +DROP FUNCTION bsonset_def_prec; +DROP FUNCTION bsonget_def_prec; DROP FUNCTION bsonset_grp_size; DROP FUNCTION bsonget_grp_size; DROP FUNCTION bson_array_grp; diff --git a/storage/connect/tabbson.cpp b/storage/connect/tabbson.cpp index ba4380c5f89..db63b8e78db 100644 --- a/storage/connect/tabbson.cpp +++ b/storage/connect/tabbson.cpp @@ -719,7 +719,10 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp) if (jvp) { vp->SetNull(false); - switch (jvp->Type) { + if (Jb) { + vp->SetValue_psz(Serialize(g, jvp, NULL, 0)); + Jb = false; + } else switch (jvp->Type) { case TYPE_STRG: case TYPE_INTG: case TYPE_BINT: @@ -727,29 +730,29 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp) case TYPE_DTM: case TYPE_FLOAT: switch (vp->GetType()) { - case TYPE_STRING: - case TYPE_DATE: - case TYPE_DECIM: - vp->SetValue_psz(GetString(jvp)); - break; - case TYPE_INT: - case TYPE_SHORT: - case TYPE_TINY: - vp->SetValue(GetInteger(jvp)); - break; - case TYPE_BIGINT: - vp->SetValue(GetBigint(jvp)); - break; - case TYPE_DOUBLE: - vp->SetValue(GetDouble(jvp)); + case TYPE_STRING: + case TYPE_DATE: + case TYPE_DECIM: + vp->SetValue_psz(GetString(jvp)); + break; + case TYPE_INT: + case TYPE_SHORT: + case TYPE_TINY: + vp->SetValue(GetInteger(jvp)); + break; + case TYPE_BIGINT: + vp->SetValue(GetBigint(jvp)); + break; + case TYPE_DOUBLE: + vp->SetValue(GetDouble(jvp)); - if (jvp->Type == TYPE_DBL || jvp->Type == TYPE_FLOAT) - vp->SetPrec(jvp->Nd); + if (jvp->Type == TYPE_DBL || jvp->Type == TYPE_FLOAT) + vp->SetPrec(jvp->Nd); - break; - default: - sprintf(G->Message, "Unsupported column type %d", vp->GetType()); - throw 888; + break; + default: + sprintf(G->Message, "Unsupported column type %d", vp->GetType()); + throw 888; } // endswitch Type break; @@ -780,53 +783,59 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp) /***********************************************************************/ /* MakeJson: Serialize the json item and set value to it. */ /***********************************************************************/ -PVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp) +PBVAL BCUTIL::MakeBson(PGLOBAL g, PBVAL jsp, int n) { - if (Cp->Value->IsTypeNum()) { - strcpy(g->Message, "Cannot make Json for a numeric column"); + PBVAL vlp, jvp = jsp; - if (!Cp->Warned) { - PushWarning(g, Tp); - Cp->Warned = true; - } // endif Warned + if (n < Cp->Nod - 1) { + if (jsp->Type == TYPE_JAR) { + int ars = GetArraySize(jsp); + PJNODE jnp = &Cp->Nodes[n]; - Cp->Value->Reset(); -#if 0 - } else if (Value->GetType() == TYPE_BIN) { - if ((unsigned)Value->GetClen() >= sizeof(BSON)) { - ulong len = Tjp->Lrecl ? Tjp->Lrecl : 500; - PBSON bsp = JbinAlloc(g, NULL, len, jsp); + jvp = NewVal(TYPE_JAR); + jnp->Op = OP_EQ; - strcat(bsp->Msg, " column"); - ((BINVAL*)Value)->SetBinValue(bsp, sizeof(BSON)); - } else { - strcpy(g->Message, "Column size too small"); - Value->SetValue_char(NULL, 0); - } // endif Clen -#endif // 0 - } else - Cp->Value->SetValue_psz(Serialize(g, jsp, NULL, 0)); + for (int i = 0; i < ars; i++) { + jnp->Rank = i; + vlp = GetRowValue(g, jsp, n); + AddArrayValue(jvp,DupVal(vlp)); + } // endfor i + + jnp->Op = OP_XX; + jnp->Rank = 0; + } else if (jsp->Type == TYPE_JOB) { + jvp = NewVal(TYPE_JOB); - return Cp->Value; -} // end of MakeJson + for (PBPR prp = GetObject(jsp); prp; prp = GetNext(prp)) { + vlp = GetRowValue(g, GetVlp(prp), n + 1); + SetKeyValue(jvp, vlp, MZP(prp->Key)); + } // endfor prp + + } // endif Type + + } // endif's + + Jb = true; + return jvp; +} // end of MakeBson /***********************************************************************/ -/* GetColumnValue: */ +/* GetRowValue: */ /***********************************************************************/ -PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) +PBVAL BCUTIL::GetRowValue(PGLOBAL g, PBVAL row, int i) { int nod = Cp->Nod, n = nod - 1; JNODE *nodes = Cp->Nodes; - PVAL value = Cp->Value; PBVAL arp; PBVAL bvp = NULL; for (; i < nod && row; i++) { if (nodes[i].Op == OP_NUM) { - value->SetValue(row->Type == TYPE_JAR ? GetSize(row) : 1); - return(value); + bvp = NewVal(TYPE_INT); + bvp->N = (row->Type == TYPE_JAR) ? GetSize(row) : 1; + return(bvp); } else if (nodes[i].Op == OP_XX) { - return MakeBson(g, row); + return MakeBson(g, row, i); } else switch (row->Type) { case TYPE_JOB: if (!nodes[i].Key) { @@ -847,9 +856,9 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) if (nodes[i].Op == OP_EQ) bvp = GetArrayValue(arp, nodes[i].Rank); else if (nodes[i].Op == OP_EXP) - return ExpandArray(g, arp, i); + return NewVal(ExpandArray(g, arp, i)); else - return CalculateArray(g, arp, i); + return NewVal(CalculateArray(g, arp, i)); } else { // Unexpected array, unwrap it as [0] @@ -871,6 +880,17 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) } // endfor i + return bvp; +} // end of GetColumnValue + +/***********************************************************************/ +/* GetColumnValue: */ +/***********************************************************************/ +PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i) +{ + PVAL value = Cp->Value; + PBVAL bvp = GetRowValue(g, row, i); + SetJsonValue(g, value, bvp); return value; } // end of GetColumnValue diff --git a/storage/connect/tabbson.h b/storage/connect/tabbson.h index bb3f32bd945..adb02dd28e4 100644 --- a/storage/connect/tabbson.h +++ b/storage/connect/tabbson.h @@ -127,11 +127,13 @@ protected: class BCUTIL : public BTUTIL { public: // Constructor - BCUTIL(PGLOBAL G, PBSCOL cp, TDBBSN* tp) : BTUTIL(G, tp) { Cp = cp; } + BCUTIL(PGLOBAL G, PBSCOL cp, TDBBSN* tp) : BTUTIL(G, tp) + { Cp = cp; Jb = false; } // Utility functions void SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp); - PVAL MakeBson(PGLOBAL g, PBVAL jsp); + PBVAL MakeBson(PGLOBAL g, PBVAL jsp, int n); + PBVAL GetRowValue(PGLOBAL g, PBVAL row, int i); PVAL GetColumnValue(PGLOBAL g, PBVAL row, int i); PVAL ExpandArray(PGLOBAL g, PBVAL arp, int n); PVAL CalculateArray(PGLOBAL g, PBVAL arp, int n); @@ -140,6 +142,7 @@ public: protected: // Member PBSCOL Cp; + bool Jb; }; // end of class BCUTIL /* -------------------------- TDBBSN class --------------------------- */ |