Commit 7edd4294 authored by Olivier Bertrand's avatar Olivier Bertrand

- 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
parent 9a07f30b
......@@ -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)
{
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;
} // 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);
} // end of SetFloat
/***********************************************************************/
......
......@@ -149,7 +149,7 @@ class BJSON : public BLOCK {
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; }
......
This diff is collapsed.
......@@ -81,6 +81,7 @@ typedef struct _jpn {
extern uint JsonGrpSize;
uint GetJsonGroupSize(void);
typedef class BJNX* PBJNX;
/*********************************************************************************/
......@@ -102,7 +103,7 @@ class BJNX : public BDOC {
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 @@ class BJNX : public BDOC {
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*);
......
......@@ -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,6 +421,12 @@ 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
......@@ -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,6 +7454,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(json_null),
MYSQL_SYSVAR(json_all_path),
MYSQL_SYSVAR(default_depth),
MYSQL_SYSVAR(default_prec),
MYSQL_SYSVAR(json_grp_size),
#if defined(JAVA_SUPPORT)
MYSQL_SYSVAR(jvm_path),
......
......@@ -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());
......
......@@ -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
......
......@@ -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';
......
......@@ -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),
......
......@@ -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;
......
......@@ -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:
......@@ -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);
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
return Cp->Value;
} // end of MakeJson
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
......
......@@ -127,11 +127,13 @@ class BTUTIL : public BDOC {
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 @@ class BCUTIL : public BTUTIL {
protected:
// Member
PBSCOL Cp;
bool Jb;
}; // end of class BCUTIL
/* -------------------------- TDBBSN class --------------------------- */
......
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