Commit 347bce02 authored by Olivier Bertrand's avatar Olivier Bertrand

- Remove static linkage to cpprestsdk when it is installed

  modified:   storage/connect/CMakeLists.txt

- Continue BSON development
  modified:   storage/connect/bson.cpp
  modified:   storage/connect/bson.h
  modified:   storage/connect/bsonudf.cpp
  modified:   storage/connect/bsonudf.h
  added:      storage/connect/mysql-test/connect/r/bson_udf.result
  added:      storage/connect/mysql-test/connect/t/bson_udf.inc
  added:      storage/connect/mysql-test/connect/t/bson_udf.test
  added:      storage/connect/mysql-test/connect/t/bson_udf2.inc
parent 70cfeb9b
...@@ -334,26 +334,26 @@ IF(CONNECT_WITH_REST) ...@@ -334,26 +334,26 @@ IF(CONNECT_WITH_REST)
# MESSAGE(STATUS "=====> REST support is ON") # MESSAGE(STATUS "=====> REST support is ON")
SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp tabrest.h) SET(CONNECT_SOURCES ${CONNECT_SOURCES} tabrest.cpp tabrest.h)
add_definitions(-DREST_SUPPORT) add_definitions(-DREST_SUPPORT)
FIND_PACKAGE(cpprestsdk QUIET) # FIND_PACKAGE(cpprestsdk QUIET)
IF (cpprestsdk_FOUND) # IF (cpprestsdk_FOUND)
IF(UNIX) # IF(UNIX)
# INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR}) ## INCLUDE_DIRECTORIES(${CPPRESTSDK_INCLUDE_DIR})
# If needed edit next line to set the path to libcpprest.so ## If needed edit next line to set the path to libcpprest.so
SET(REST_LIBRARY -lcpprest) # SET(REST_LIBRARY -lcpprest)
MESSAGE (STATUS ${REST_LIBRARY}) # MESSAGE (STATUS ${REST_LIBRARY})
ELSE(NOT UNIX) # ELSE(NOT UNIX)
# Next line sets debug compile mode matching cpprest_2_10d.dll ## Next line sets debug compile mode matching cpprest_2_10d.dll
# when it was binary installed (can be change later in Visual Studio) ## when it was binary installed (can be change later in Visual Studio)
# Comment it out if not needed depending on your cpprestsdk installation. ## Comment it out if not needed depending on your cpprestsdk installation.
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd") # SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
ENDIF(UNIX) # ENDIF(UNIX)
# IF(REST_LIBRARY) why this? how about Windows ## IF(REST_LIBRARY) why this? how about Windows
SET(CONNECT_SOURCES ${CONNECT_SOURCES} restget.cpp) # SET(CONNECT_SOURCES ${CONNECT_SOURCES} restget.cpp)
add_definitions(-DREST_SOURCE) # add_definitions(-DREST_SOURCE)
# ENDIF() ## ENDIF()
# ELSE(NOT cpprestsdk_FOUND) ##ELSE(NOT cpprestsdk_FOUND)
# MESSAGE(STATUS "=====> cpprestsdk package not found") ## MESSAGE(STATUS "=====> cpprestsdk package not found")
ENDIF (cpprestsdk_FOUND) # ENDIF (cpprestsdk_FOUND)
ENDIF(CONNECT_WITH_REST) ENDIF(CONNECT_WITH_REST)
# #
......
...@@ -631,7 +631,7 @@ PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty) ...@@ -631,7 +631,7 @@ PSZ BDOC::Serialize(PGLOBAL g, PBVAL bvp, char* fn, int pretty)
err = SerializeValue(MVP(bvp->To_Val)); err = SerializeValue(MVP(bvp->To_Val));
break; break;
default: default:
err = SerializeValue(bvp); err = SerializeValue(bvp, true);
} // endswitch Type } // endswitch Type
if (fs) { if (fs) {
...@@ -737,7 +737,7 @@ bool BDOC::SerializeObject(OFFSET obp) ...@@ -737,7 +737,7 @@ bool BDOC::SerializeObject(OFFSET obp)
/***********************************************************************/ /***********************************************************************/
/* Serialize a JSON Value. */ /* Serialize a JSON Value. */
/***********************************************************************/ /***********************************************************************/
bool BDOC::SerializeValue(PBVAL jvp) bool BDOC::SerializeValue(PBVAL jvp, bool b)
{ {
char buf[64]; char buf[64];
...@@ -750,7 +750,11 @@ bool BDOC::SerializeValue(PBVAL jvp) ...@@ -750,7 +750,11 @@ bool BDOC::SerializeValue(PBVAL jvp)
return jp->WriteStr(jvp->B ? "true" : "false"); return jp->WriteStr(jvp->B ? "true" : "false");
case TYPE_STRG: case TYPE_STRG:
case TYPE_DTM: case TYPE_DTM:
return jp->Escape(MZP(jvp->To_Val)); if (b) {
return jp->WriteStr(MZP(jvp->To_Val));
} else
return jp->Escape(MZP(jvp->To_Val));
case TYPE_INTG: case TYPE_INTG:
sprintf(buf, "%d", jvp->N); sprintf(buf, "%d", jvp->N);
return jp->WriteStr(buf); return jp->WriteStr(buf);
...@@ -1505,8 +1509,12 @@ double BJSON::GetDouble(PBVAL vp) ...@@ -1505,8 +1509,12 @@ double BJSON::GetDouble(PBVAL vp)
d = (double)vlp->N; d = (double)vlp->N;
break; break;
case TYPE_FLOAT: case TYPE_FLOAT:
d = (double)vlp->F; { char buf[32];
break; int n = (vlp->Nd) ? vlp->Nd : 5;
sprintf(buf, "%.*f", n, vlp->F);
d = atof(buf);
} break;
case TYPE_DTM: case TYPE_DTM:
case TYPE_STRG: case TYPE_STRG:
d = atof(MZP(vlp->To_Val)); d = atof(MZP(vlp->To_Val));
...@@ -1632,7 +1640,7 @@ PBVAL BJSON::SetValue(PBVAL vlp, PVAL valp) ...@@ -1632,7 +1640,7 @@ PBVAL BJSON::SetValue(PBVAL vlp, PVAL valp)
{ double d = valp->GetFloatValue(); { double d = valp->GetFloatValue();
int nd = (IsTypeNum(valp->GetType())) ? valp->GetValPrec() : 0; int nd = (IsTypeNum(valp->GetType())) ? valp->GetValPrec() : 0;
if (nd <= 6 && d >= FLT_MIN && d <= FLT_MAX) { if (nd > 0 && nd <= 6 && d >= FLT_MIN && d <= FLT_MAX) {
vlp->F = (float)valp->GetFloatValue(); vlp->F = (float)valp->GetFloatValue();
vlp->Type = TYPE_FLOAT; vlp->Type = TYPE_FLOAT;
} else { } else {
......
...@@ -193,7 +193,7 @@ class BDOC : public BJSON { ...@@ -193,7 +193,7 @@ class BDOC : public BJSON {
OFFSET ParseAsArray(int& i); OFFSET ParseAsArray(int& i);
bool SerializeArray(OFFSET arp, bool b); bool SerializeArray(OFFSET arp, bool b);
bool SerializeObject(OFFSET obp); bool SerializeObject(OFFSET obp);
bool SerializeValue(PBVAL vp); bool SerializeValue(PBVAL vp, bool b = false);
// Members used when parsing and serializing // Members used when parsing and serializing
JOUT* jp; // Used with serialize JOUT* jp; // Used with serialize
......
...@@ -36,7 +36,7 @@ void SetChanged(PBSON bsp); ...@@ -36,7 +36,7 @@ void SetChanged(PBSON bsp);
/* Program for saving the status of the memory pools. */ /* Program for saving the status of the memory pools. */
/*********************************************************************************/ /*********************************************************************************/
inline void JsonMemSave(PGLOBAL g) { inline void JsonMemSave(PGLOBAL g) {
g->Saved_Size = ((PPOOLHEADER)g->Sarea)->To_Free; g->Saved_Size = ((PPOOLHEADER)g->Sarea)->To_Free;
} /* end of JsonMemSave */ } /* end of JsonMemSave */
/*********************************************************************************/ /*********************************************************************************/
...@@ -854,12 +854,16 @@ my_bool BJNX::DeleteItem(PGLOBAL g, PBVAL row) ...@@ -854,12 +854,16 @@ my_bool BJNX::DeleteItem(PGLOBAL g, PBVAL row)
PUSH_WARNING("Only one expand can be handled"); PUSH_WARNING("Only one expand can be handled");
return b; return b;
} // endif loop } // endif loop
n++; n++;
loop = true;
} else } else
n = Nodes[i].Rank; n = Nodes[i].Rank;
vlp = GetArrayValue(rwp, n); vlp = GetArrayValue(rwp, n);
if (GetNext(vlp) && Nodes[i].Op == OP_EXP)
loop = true;
} else } else
vlp = NULL; vlp = NULL;
...@@ -1384,9 +1388,9 @@ PBVAL BJNX::MakeValue(UDF_ARGS *args, uint i, bool b, PBVAL *top) ...@@ -1384,9 +1388,9 @@ PBVAL BJNX::MakeValue(UDF_ARGS *args, uint i, bool b, PBVAL *top)
if (n) { if (n) {
if (n == 3) { if (n == 3) {
if (i == 0) { PBSON bsp = (PBSON)sap;
PBSON bsp = (PBSON)sap;
if (i == 0) {
if (top) if (top)
*top = (PBVAL)bsp->Top; *top = (PBVAL)bsp->Top;
...@@ -1394,8 +1398,9 @@ PBVAL BJNX::MakeValue(UDF_ARGS *args, uint i, bool b, PBVAL *top) ...@@ -1394,8 +1398,9 @@ PBVAL BJNX::MakeValue(UDF_ARGS *args, uint i, bool b, PBVAL *top)
G = bsp->G; G = bsp->G;
Base = G->Sarea; Base = G->Sarea;
} else { } else {
PUSH_WARNING("Only first argument can be binary"); BJNX bnx(bsp->G);
return jvp;
jvp = MoveJson(&bnx, (PBVAL)bsp->Jsp);
} // endelse i } // endelse i
} else { } else {
...@@ -1616,7 +1621,7 @@ char *BJNX::MakeResult(UDF_ARGS *args, PBVAL top, uint n) ...@@ -1616,7 +1621,7 @@ char *BJNX::MakeResult(UDF_ARGS *args, PBVAL top, uint n)
/*********************************************************************************/ /*********************************************************************************/
/* Make the binary result according to the first argument type. */ /* Make the binary result according to the first argument type. */
/*********************************************************************************/ /*********************************************************************************/
PBSON BJNX::MakeBinResult(PGLOBAL g, UDF_ARGS *args, PBVAL top, ulong len, int n) PBSON BJNX::MakeBinResult(UDF_ARGS *args, PBVAL top, ulong len, int n)
{ {
char* filename = NULL; char* filename = NULL;
int pretty = 2; int pretty = 2;
...@@ -1641,7 +1646,7 @@ PBSON BJNX::MakeBinResult(PGLOBAL g, UDF_ARGS *args, PBVAL top, ulong len, int n ...@@ -1641,7 +1646,7 @@ PBSON BJNX::MakeBinResult(PGLOBAL g, UDF_ARGS *args, PBVAL top, ulong len, int n
filename = (char*)args->args[0]; filename = (char*)args->args[0];
} // endif 2 } // endif 2
if ((bnp = BbinAlloc(g, len, top))) { if ((bnp = BbinAlloc(G, len, top))) {
bnp->Filename = filename; bnp->Filename = filename;
bnp->Pretty = pretty; bnp->Pretty = pretty;
strcpy(bnp->Msg, "Json Binary item"); strcpy(bnp->Msg, "Json Binary item");
...@@ -1650,6 +1655,114 @@ PBSON BJNX::MakeBinResult(PGLOBAL g, UDF_ARGS *args, PBVAL top, ulong len, int n ...@@ -1650,6 +1655,114 @@ PBSON BJNX::MakeBinResult(PGLOBAL g, UDF_ARGS *args, PBVAL top, ulong len, int n
return bnp; return bnp;
} // end of MakeBinResult } // end of MakeBinResult
/***********************************************************************/
/* Move a Json val block from one area to the current area. */
/***********************************************************************/
PBVAL BJNX::MoveVal(PBVAL vlp)
{
PBVAL nvp = NewVal(vlp->Type);
nvp->Nd = vlp->Nd;
return nvp;
} // end of MovedVal
/***********************************************************************/
/* Move a Json tree from one area to current area. */
/***********************************************************************/
PBVAL BJNX::MoveJson(PBJNX bxp, PBVAL jvp)
{
PBVAL res = NULL;
if (jvp)
switch (jvp->Type) {
case TYPE_JAR:
res = MoveArray(bxp, jvp);
break;
case TYPE_JOB:
res = MoveObject(bxp, jvp);
break;
default:
res = MoveValue(bxp, jvp);
break;
} // endswitch Type
return res;
} // end of MoveJson
/***********************************************************************/
/* Move an array. */
/***********************************************************************/
PBVAL BJNX::MoveArray(PBJNX bxp, PBVAL jap)
{
PBVAL vlp, vmp, jvp = NULL, jarp = MoveVal(jap);
for (vlp = bxp->GetArray(jap); vlp; vlp = bxp->GetNext(vlp)) {
vmp = MoveJson(bxp, vlp);
if (jvp)
jvp->Next = MOF(vmp);
else
jarp->To_Val = MOF(vmp);
jvp = vmp;
} // endfor vlp
return jarp;
} // end of MoveArray
/***********************************************************************/
/* Replace all object pointers by offsets. */
/***********************************************************************/
PBVAL BJNX::MoveObject(PBJNX bxp, PBVAL jop)
{
PBPR mpp, prp, ppp = NULL;
PBVAL vmp, jobp = MoveVal(jop);
for (prp = bxp->GetObject(jop); prp; prp = bxp->GetNext(prp)) {
vmp = MoveJson(bxp, GetVlp(prp));
mpp = NewPair(DupStr(bxp->MZP(prp->Key)));
SetPairValue(mpp, vmp);
if (ppp)
ppp->Vlp.Next = MOF(mpp);
else
jobp->To_Val = MOF(mpp);
ppp = mpp;
} // endfor vlp
return jobp;
} // end of MoffObject
/***********************************************************************/
/* Move a non json value. */
/***********************************************************************/
PBVAL BJNX::MoveValue(PBJNX bxp, PBVAL jvp)
{
double *dp;
PBVAL nvp = MoveVal(jvp);
switch (jvp->Type) {
case TYPE_STRG:
case TYPE_DTM:
nvp->To_Val = DupStr(bxp->MZP(jvp->To_Val));
break;
case TYPE_DBL:
dp = (double*)BsonSubAlloc(sizeof(double));
*dp = bxp->DBL(jvp->To_Val);
nvp->To_Val = MOF(dp);
break;
case TYPE_JVAL:
nvp->To_Val = MOF(MoveJson(bxp, bxp->MVP(jvp->To_Val)));
break;
default:
nvp->To_Val = jvp->To_Val;
break;
} // endswith Type
return nvp;
} // end of MoveValue
/* -----------------------------Utility functions ------------------------------ */ /* -----------------------------Utility functions ------------------------------ */
/*********************************************************************************/ /*********************************************************************************/
...@@ -1688,14 +1801,14 @@ int IsArgJson(UDF_ARGS *args, uint i) ...@@ -1688,14 +1801,14 @@ int IsArgJson(UDF_ARGS *args, uint i)
!strnicmp(args->attributes[i], "Json_", 5)) { !strnicmp(args->attributes[i], "Json_", 5)) {
if (!args->args[i] || strchr("[{ \t\r\n", *args->args[i])) if (!args->args[i] || strchr("[{ \t\r\n", *args->args[i]))
n = 1; // arg should be is a json item n = 1; // arg should be is a json item
else // else
n = 2; // A file name may have been returned // n = 2; // A file name may have been returned
} else if (!strnicmp(args->attributes[i], "Bbin_", 5)) { } else if (!strnicmp(args->attributes[i], "Bbin_", 5)) {
if (args->lengths[i] == sizeof(BSON)) if (args->lengths[i] == sizeof(BSON))
n = 3; // arg is a binary json item n = 3; // arg is a binary json item
else // else
n = 2; // A file name may have been returned // n = 2; // A file name may have been returned
} else if (!strnicmp(args->attributes[i], "Bfile_", 6) || } else if (!strnicmp(args->attributes[i], "Bfile_", 6) ||
!strnicmp(args->attributes[i], "Jfile_", 6)) { !strnicmp(args->attributes[i], "Jfile_", 6)) {
...@@ -1785,7 +1898,8 @@ void bsonvalue_deinit(UDF_INIT* initid) { ...@@ -1785,7 +1898,8 @@ void bsonvalue_deinit(UDF_INIT* initid) {
} // end of bsonvalue_deinit } // end of bsonvalue_deinit
/*********************************************************************************/ /*********************************************************************************/
/* Make a Bson array containing all the parameters. */ /* Make a Json array containing all the parameters. */
/* Note: jvp must be set before arp because it can be a binary argument. */
/*********************************************************************************/ /*********************************************************************************/
my_bool bson_make_array_init(UDF_INIT* initid, UDF_ARGS* args, char* message) my_bool bson_make_array_init(UDF_INIT* initid, UDF_ARGS* args, char* message)
{ {
...@@ -1804,10 +1918,13 @@ char* bson_make_array(UDF_INIT* initid, UDF_ARGS* args, char* result, ...@@ -1804,10 +1918,13 @@ char* bson_make_array(UDF_INIT* initid, UDF_ARGS* args, char* result,
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!CheckMemory(g, initid, args, args->arg_count, false)) {
BJNX bnx(g); BJNX bnx(g);
PBVAL bvp = NULL, arp = bnx.NewVal(TYPE_JAR); PBVAL jvp = bnx.MakeValue(args, 0);
PBVAL arp = bnx.NewVal(TYPE_JAR);
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count;) {
bnx.AddArrayValue(arp, bnx.MakeValue(args, i, true)); bnx.AddArrayValue(arp, jvp);
jvp = bnx.MakeValue(args, ++i);
} // endfor i
if (!(str = bnx.Serialize(g, arp, NULL, 0))) if (!(str = bnx.Serialize(g, arp, NULL, 0)))
str = strcpy(result, g->Message); str = strcpy(result, g->Message);
...@@ -2056,7 +2173,7 @@ char *bson_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -2056,7 +2173,7 @@ char *bson_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!CheckMemory(g, initid, args, 1, false, false, true)) { if (!CheckMemory(g, initid, args, 1, false, false, true)) {
int *x; int *x;
uint n = 1; uint n = 1;
BJNX bnx(g); BJNX bnx(g, NULL, TYPE_STRING);
PBVAL arp, top; PBVAL arp, top;
PBVAL jvp = bnx.MakeValue(args, 0, true, &top); PBVAL jvp = bnx.MakeValue(args, 0, true, &top);
...@@ -4621,6 +4738,7 @@ void bson_serialize_deinit(UDF_INIT* initid) ...@@ -4621,6 +4738,7 @@ void bson_serialize_deinit(UDF_INIT* initid)
/*********************************************************************************/ /*********************************************************************************/
/* Make and return a binary Json array containing all the parameters. */ /* Make and return a binary Json array containing all the parameters. */
/* Note: jvp must be set before arp because it can be a binary argument. */
/*********************************************************************************/ /*********************************************************************************/
my_bool bbin_make_array_init(UDF_INIT *initid, UDF_ARGS *args, char *message) my_bool bbin_make_array_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{ {
...@@ -4639,20 +4757,20 @@ char *bbin_make_array(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4639,20 +4757,20 @@ char *bbin_make_array(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!g->Xchk) { if (!g->Xchk) {
if (!CheckMemory(g, initid, args, args->arg_count, false)) { if (!CheckMemory(g, initid, args, args->arg_count, false)) {
BJNX bnx(g); BJNX bnx(g);
PBVAL arp; PBVAL jvp = bnx.MakeValue(args, 0);
PBVAL arp = bnx.NewVal(TYPE_JAR);
if ((arp = bnx.NewVal(TYPE_JAR))) { for (uint i = 0; i < args->arg_count;) {
for (uint i = 0; i < args->arg_count; i++) bnx.AddArrayValue(arp, jvp);
bnx.AddArrayValue(arp, bnx.MakeValue(args, i)); jvp = bnx.MakeValue(args, ++i);
} // endfor i
if ((bsp = BbinAlloc(g, initid->max_length, arp))) { if ((bsp = BbinAlloc(bnx.G, initid->max_length, arp))) {
strcat(bsp->Msg, " array"); strcat(bsp->Msg, " array");
// Keep result of constant function // Keep result of constant function
g->Xchk = (initid->const_item) ? bsp : NULL; g->Xchk = (initid->const_item) ? bsp : NULL;
} // endif bsp } // endif bsp
} // endif arp
} // endif CheckMemory } // endif CheckMemory
...@@ -4738,7 +4856,7 @@ char *bbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4738,7 +4856,7 @@ char *bbin_array_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (jarp) { if (jarp) {
bnx.AddArrayValue(jarp, bnx.MakeValue(args, 1), x); bnx.AddArrayValue(jarp, bnx.MakeValue(args, 1), x);
bnx.SetChanged(true); bnx.SetChanged(true);
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
if (initid->const_item) if (initid->const_item)
// Keep result of constant function // Keep result of constant function
...@@ -4795,7 +4913,7 @@ char* bbin_array_add_values(UDF_INIT* initid, UDF_ARGS* args, char* result, ...@@ -4795,7 +4913,7 @@ char* bbin_array_add_values(UDF_INIT* initid, UDF_ARGS* args, char* result,
bnx.AddArrayValue(arp, bnx.MakeValue(args, i)); bnx.AddArrayValue(arp, bnx.MakeValue(args, i));
bnx.SetChanged(true); bnx.SetChanged(true);
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
} // endif CheckMemory } // endif CheckMemory
// Keep result of constant function // Keep result of constant function
...@@ -4937,7 +5055,7 @@ char *bbin_make_object(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4937,7 +5055,7 @@ char *bbin_make_object(UDF_INIT *initid, UDF_ARGS *args, char *result,
for (uint i = 0; i < args->arg_count; i++) for (uint i = 0; i < args->arg_count; i++)
bnx.SetKeyValue(objp, bnx.MakeValue(args, i), bnx.MakeKey(args, i)); bnx.SetKeyValue(objp, bnx.MakeValue(args, i), bnx.MakeKey(args, i));
if ((bsp = BbinAlloc(g, initid->max_length, objp))) { if ((bsp = BbinAlloc(bnx.G, initid->max_length, objp))) {
strcat(bsp->Msg, " object"); strcat(bsp->Msg, " object");
// Keep result of constant function // Keep result of constant function
...@@ -4992,7 +5110,7 @@ char *bbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -4992,7 +5110,7 @@ char *bbin_object_nonull(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (!bnx.IsValueNull(jvp = bnx.MakeValue(args, i))) if (!bnx.IsValueNull(jvp = bnx.MakeValue(args, i)))
bnx.SetKeyValue(objp, jvp, bnx.MakeKey(args, i)); bnx.SetKeyValue(objp, jvp, bnx.MakeKey(args, i));
if ((bsp = BbinAlloc(g, initid->max_length, objp))) { if ((bsp = BbinAlloc(bnx.G, initid->max_length, objp))) {
strcat(bsp->Msg, " object"); strcat(bsp->Msg, " object");
// Keep result of constant function // Keep result of constant function
...@@ -5051,7 +5169,7 @@ char *bbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5051,7 +5169,7 @@ char *bbin_object_key(UDF_INIT *initid, UDF_ARGS *args, char *result,
for (uint i = 0; i < args->arg_count; i += 2) for (uint i = 0; i < args->arg_count; i += 2)
bnx.SetKeyValue(objp, bnx.MakeValue(args, i + 1), MakePSZ(g, args, i)); bnx.SetKeyValue(objp, bnx.MakeValue(args, i + 1), MakePSZ(g, args, i));
if ((bsp = BbinAlloc(g, initid->max_length, objp))) { if ((bsp = BbinAlloc(bnx.G, initid->max_length, objp))) {
strcat(bsp->Msg, " object"); strcat(bsp->Msg, " object");
// Keep result of constant function // Keep result of constant function
...@@ -5129,7 +5247,7 @@ char *bbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5129,7 +5247,7 @@ char *bbin_object_add(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif jobp } // endif jobp
// In case of error unchanged argument will be returned // In case of error unchanged argument will be returned
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
if (initid->const_item) if (initid->const_item)
// Keep result of constant function // Keep result of constant function
...@@ -5182,7 +5300,7 @@ char *bbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5182,7 +5300,7 @@ char *bbin_array_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
else if (arp && arp->Type == TYPE_JAR) { else if (arp && arp->Type == TYPE_JAR) {
bnx.SetChanged(bnx.DeleteValue(arp, *x)); bnx.SetChanged(bnx.DeleteValue(arp, *x));
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
} else { } else {
PUSH_WARNING("First argument target is not an array"); PUSH_WARNING("First argument target is not an array");
// if (g->Mrr) *error = 1; // if (g->Mrr) *error = 1;
...@@ -5259,7 +5377,7 @@ char *bbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5259,7 +5377,7 @@ char *bbin_object_delete(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif jvp } // endif jvp
// In case of error unchanged argument will be returned // In case of error unchanged argument will be returned
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
if (initid->const_item) if (initid->const_item)
// Keep result of constant function // Keep result of constant function
...@@ -5310,7 +5428,7 @@ char *bbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5310,7 +5428,7 @@ char *bbin_object_list(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif jsp type } // endif jsp type
// In case of error unchanged argument will be returned // In case of error unchanged argument will be returned
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
bsp->Jsp = (PJSON)jarp; bsp->Jsp = (PJSON)jarp;
} // endif CheckMemory } // endif CheckMemory
...@@ -5362,7 +5480,7 @@ char *bbin_object_values(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5362,7 +5480,7 @@ char *bbin_object_values(UDF_INIT *initid, UDF_ARGS *args, char *result,
} // endif jvp } // endif jvp
// In case of error unchanged argument will be returned // In case of error unchanged argument will be returned
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
bsp->Jsp = (PJSON)jarp; bsp->Jsp = (PJSON)jarp;
} // endif CheckMemory } // endif CheckMemory
...@@ -5414,7 +5532,7 @@ char *bbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5414,7 +5532,7 @@ char *bbin_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
if (bnx.CheckPath(g, args, jsp, jvp, 1)) if (bnx.CheckPath(g, args, jsp, jvp, 1))
PUSH_WARNING(g->Message); PUSH_WARNING(g->Message);
else if (jvp) { else if (jvp) {
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
bsp->Jsp = (PJSON)jvp; bsp->Jsp = (PJSON)jvp;
if (initid->const_item) if (initid->const_item)
...@@ -5495,7 +5613,7 @@ char *bbin_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5495,7 +5613,7 @@ char *bbin_item_merge(UDF_INIT *initid, UDF_ARGS *args, char *result,
bnx.MergeObject(jsp[0], jsp[1]); bnx.MergeObject(jsp[0], jsp[1]);
bnx.SetChanged(true); bnx.SetChanged(true);
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
} // endif CheckMemory } // endif CheckMemory
if (g->N) if (g->N)
...@@ -5592,7 +5710,7 @@ static char *bbin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5592,7 +5710,7 @@ static char *bbin_handle_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
bxp->SetChanged(true); bxp->SetChanged(true);
} // endfor i } // endfor i
if (!(bsp = bxp->MakeBinResult(g, args, top, initid->max_length))) if (!(bsp = bxp->MakeBinResult(args, top, initid->max_length)))
throw 4; throw 4;
if (g->N) if (g->N)
...@@ -5745,7 +5863,7 @@ char *bbin_delete_item(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5745,7 +5863,7 @@ char *bbin_delete_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
bnx.SetChanged(bnx.DeleteItem(g, jvp)); bnx.SetChanged(bnx.DeleteItem(g, jvp));
} // endfor i } // endfor i
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
if (args->arg_count == 1) if (args->arg_count == 1)
// Here Jsp was not a sub-item of top // Here Jsp was not a sub-item of top
...@@ -5815,7 +5933,7 @@ char *bbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -5815,7 +5933,7 @@ char *bbin_file(UDF_INIT *initid, UDF_ARGS *args, char *result,
// else if (pretty == 3) // else if (pretty == 3)
// pretty = pty; // pretty = pty;
if ((bsp = BbinAlloc(g, len, jsp))) { if ((bsp = BbinAlloc(bnx.G, len, jsp))) {
strcat(bsp->Msg, " file"); strcat(bsp->Msg, " file");
bsp->Filename = fn; bsp->Filename = fn;
bsp->Pretty = pretty; bsp->Pretty = pretty;
...@@ -5923,7 +6041,7 @@ char* bbin_locate_all(UDF_INIT* initid, UDF_ARGS* args, char* result, ...@@ -5923,7 +6041,7 @@ char* bbin_locate_all(UDF_INIT* initid, UDF_ARGS* args, char* result,
mx = (int)*(long long*)args->args[2]; mx = (int)*(long long*)args->args[2];
if ((path = bnx.LocateAll(g, bvp, bvp2, mx))) { if ((path = bnx.LocateAll(g, bvp, bvp2, mx))) {
bsp = bnx.MakeBinResult(g, args, top, initid->max_length); bsp = bnx.MakeBinResult(args, top, initid->max_length);
bsp->Jsp = (PJSON)bnx.ParseJson(g, path, strlen(path)); bsp->Jsp = (PJSON)bnx.ParseJson(g, path, strlen(path));
} // endif path } // endif path
......
...@@ -116,7 +116,7 @@ class BJNX : public BDOC { ...@@ -116,7 +116,7 @@ class BJNX : public BDOC {
JTYP type, PBVAL* top = NULL); JTYP type, PBVAL* top = NULL);
PBVAL ParseJsonFile(PGLOBAL g, char* fn, int& pty, size_t& len); PBVAL ParseJsonFile(PGLOBAL g, char* fn, int& pty, size_t& len);
char *MakeResult(UDF_ARGS* args, PBVAL top, uint n = 2); char *MakeResult(UDF_ARGS* args, PBVAL top, uint n = 2);
PBSON MakeBinResult(PGLOBAL g, UDF_ARGS* args, PBVAL top, ulong len, int n = 2); PBSON MakeBinResult(UDF_ARGS* args, PBVAL top, ulong len, int n = 2);
protected: protected:
my_bool SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm); my_bool SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm);
...@@ -126,6 +126,11 @@ class BJNX : public BDOC { ...@@ -126,6 +126,11 @@ class BJNX : public BDOC {
PVAL MakeJson(PGLOBAL g, PBVAL bvp); PVAL MakeJson(PGLOBAL g, PBVAL bvp);
void SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp); void SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp);
PBVAL GetRow(PGLOBAL g); PBVAL GetRow(PGLOBAL g);
PBVAL MoveVal(PBVAL vlp);
PBVAL MoveJson(PBJNX bxp, PBVAL jvp);
PBVAL MoveArray(PBJNX bxp, PBVAL jvp);
PBVAL MoveObject(PBJNX bxp, PBVAL jvp);
PBVAL MoveValue(PBJNX bxp, PBVAL jvp);
my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2); my_bool CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2);
my_bool LocateArray(PGLOBAL g, PBVAL jarp); my_bool LocateArray(PGLOBAL g, PBVAL jarp);
my_bool LocateObject(PGLOBAL g, PBVAL jobp); my_bool LocateObject(PGLOBAL g, PBVAL jobp);
...@@ -368,6 +373,10 @@ extern "C" { ...@@ -368,6 +373,10 @@ extern "C" {
DllExport char *bbin_get_item(UDF_EXEC_ARGS); DllExport char *bbin_get_item(UDF_EXEC_ARGS);
DllExport void bbin_get_item_deinit(UDF_INIT*); DllExport void bbin_get_item_deinit(UDF_INIT*);
DllExport my_bool bbin_item_merge_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char* bbin_item_merge(UDF_EXEC_ARGS);
DllExport void bbin_item_merge_deinit(UDF_INIT*);
DllExport my_bool bbin_set_item_init(UDF_INIT*, UDF_ARGS*, char*); DllExport my_bool bbin_set_item_init(UDF_INIT*, UDF_ARGS*, char*);
DllExport char *bbin_set_item(UDF_EXEC_ARGS); DllExport char *bbin_set_item(UDF_EXEC_ARGS);
DllExport void bbin_set_item_deinit(UDF_INIT*); DllExport void bbin_set_item_deinit(UDF_INIT*);
......
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=VIR BLOCK_SIZE=5;
#
# Test UDF's with constant arguments
#
SELECT BsonValue(56, 3.1416, 'foo', NULL);
ERROR HY000: Can't initialize function 'bsonvalue'; Cannot accept more than 1 argument
SELECT BsonValue(3.1416);
BsonValue(3.1416)
3.1416
SELECT BsonValue(-80);
BsonValue(-80)
-80
SELECT BsonValue('foo');
BsonValue('foo')
foo
SELECT BsonValue(9223372036854775807);
BsonValue(9223372036854775807)
9223372036854775807
SELECT BsonValue(NULL);
BsonValue(NULL)
null
SELECT BsonValue(TRUE);
BsonValue(TRUE)
true
SELECT BsonValue(FALSE);
BsonValue(FALSE)
false
SELECT BsonValue();
BsonValue()
null
SELECT BsonValue('[11, 22, 33]' json_) FROM t1;
BsonValue('[11, 22, 33]' json_)
[11,22,33]
[11,22,33]
[11,22,33]
[11,22,33]
[11,22,33]
SELECT Bson_Make_Array();
Bson_Make_Array()
[]
SELECT Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL);
Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL)
[56,3.1416,"My name is \"Foo\"",null]
SELECT Bson_Make_Array(Bson_Make_Array(56, 3.1416, 'foo'), TRUE);
Bson_Make_Array(Bson_Make_Array(56, 3.1416, 'foo'), TRUE)
[[56,3.1416,"foo"],true]
SELECT Bson_Array_Add(Bson_Make_Array(56, 3.1416, 'foo', NULL)) Array;
ERROR HY000: Can't initialize function 'bson_array_add'; This function must have at least 2 arguments
SELECT Bson_Array_Add(Bson_Make_Array(56, 3.1416, 'foo', NULL), 'One more') Array;
Array
[56,3.1416,"foo",null,"One more"]
SELECT Bson_Array_Add(BsonValue('one value'), 'One more');
Bson_Array_Add(BsonValue('one value'), 'One more')
["one value","One more"]
SELECT Bson_Array_Add('one value', 'One more');
Bson_Array_Add('one value', 'One more')
["one value","One more"]
SELECT Bson_Array_Add('one value' json_, 'One more');
Bson_Array_Add('one value' json_, 'One more')
["one value","One more"]
SELECT Bson_Array_Add(5 json_, 'One more');
Bson_Array_Add(5 json_, 'One more')
[5,"One more"]
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 0);
Bson_Array_Add('[5,3,8,7,9]' json_, 4, 0)
[4,5,3,8,7,9]
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 2) Array;
Array
[5,3,4,8,7,9]
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 9);
Bson_Array_Add('[5,3,8,7,9]' json_, 4, 9)
[5,3,8,7,9,4]
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), '[2]', 33, 1);
Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), '[2]', 33, 1)
[1,2,[11,22],"[2]"]
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, '[2]', 1);
Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, '[2]', 1)
[1,2,[11,33,22]]
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, 1, '[2]');
Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, 1, '[2]')
[1,2,[11,33,22]]
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin', NULL), 'One more', 'Two more') Array;
Array
[56,3.1416,"machin",null,"One more","Two more"]
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin'), 'One more', 'Two more') Array FROM t1;
Array
[56,3.1416,"machin","One more","Two more"]
[56,3.1416,"machin","One more","Two more"]
[56,3.1416,"machin","One more","Two more"]
[56,3.1416,"machin","One more","Two more"]
[56,3.1416,"machin","One more","Two more"]
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin'), n) Array FROM t1;
Array
[56,3.1416,"machin",1]
[56,3.1416,"machin",2]
[56,3.1416,"machin",3]
[56,3.1416,"machin",4]
[56,3.1416,"machin",5]
SELECT Bson_Array_Add_Values(Bson_Make_Array(n, 3.1416, 'machin'), n) Array FROM t1;
Array
[1,3.1416,"machin",1]
[2,3.1416,"machin",2]
[3,3.1416,"machin",3]
[4,3.1416,"machin",4]
[5,3.1416,"machin",5]
SELECT Bson_Array_Add_Values('[56]', 3.1416, 'machin') Array;
Array
[56,3.1416,"machin"]
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), 0);
Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), 0)
[3.1416,"My name is \"Foo\"",null]
SELECT Bson_Array_Delete(Bson_Make_Object(56, 3.1416, 'My name is Foo', NULL), 2);
Bson_Array_Delete(Bson_Make_Object(56, 3.1416, 'My name is Foo', NULL), 2)
{"56":56,"3.1416":3.1416,"My name is Foo":"My name is Foo","NULL":null}
Warnings:
Warning 1105 First argument target is not an array
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2');
Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2')
[56,3.1416,"My name is \"Foo\"",null]
Warnings:
Warning 1105 Missing or null array index
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2', 2);
Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2', 2)
[56,3.1416,"My name is \"Foo\"",null]
Warnings:
Warning 1105 First argument target is not an array
/* WARNING VOID */
#
SELECT Bson_Make_Object(56, 3.1416, 'foo', NULL);
Bson_Make_Object(56, 3.1416, 'foo', NULL)
{"56":56,"3.1416":3.1416,"foo":"foo","NULL":null}
SELECT Bson_Make_Object(56 qty, 3.1416 price, 'foo' truc, NULL garanty);
Bson_Make_Object(56 qty, 3.1416 price, 'foo' truc, NULL garanty)
{"qty":56,"price":3.1416,"truc":"foo","garanty":null}
SELECT Bson_Make_Object();
Bson_Make_Object()
{}
SELECT Bson_Make_Object(Bson_Make_Array(56, 3.1416, 'foo'), NULL);
Bson_Make_Object(Bson_Make_Array(56, 3.1416, 'foo'), NULL)
{"Make_Array(56, 3.1416, 'foo')":[56,3.1416,"foo"],"NULL":null}
SELECT Bson_Make_Array(Bson_Make_Object(56 "qty", 3.1416 "price", 'foo') ,NULL);
Bson_Make_Array(Bson_Make_Object(56 "qty", 3.1416 "price", 'foo') ,NULL)
[{"qty":56,"price":3.1416,"foo":"foo"},null]
SELECT Bson_Object_Key('qty', 56, 'price', 3.1416, 'truc', 'machin', 'garanty', NULL);
Bson_Object_Key('qty', 56, 'price', 3.1416, 'truc', 'machin', 'garanty', NULL)
{"qty":56,"price":3.1416,"truc":"machin","garanty":null}
SELECT Bson_Object_Key('qty', 56, 'price', 3.1416, 'truc', 'machin', 'garanty');
ERROR HY000: Can't initialize function 'bson_object_key'; This function must have an even number of arguments
SELECT Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'blue' color);
Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'blue' color)
{"qty":56,"price":3.1416,"truc":"machin","garanty":null,"color":"blue"}
SELECT Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 45.99 price);
Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 45.99 price)
{"qty":56,"price":45.99,"truc":"machin","garanty":null}
SELECT Bson_Object_Add(Bson_File('notexist.json'), 'cheese' item, '[1]', 1);
Bson_Object_Add(Bson_File('notexist.json'), 'cheese' item, '[1]', 1)
NULL
Warnings:
Warning 1105 Error 2 opening notexist.json
Warning 1105 No sub-item at '[1]'
SELECT Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'truc');
Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'truc')
{"qty":56,"price":3.1416,"garanty":null}
SELECT Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'chose');
Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'chose')
{"qty":56,"price":3.1416,"truc":"machin","garanty":null}
SELECT Bson_Object_List(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty)) "Key List";
Key List
["qty","price","truc","garanty"]
SELECT Bson_Object_List('{"qty":56, "price":3.1416, "truc":"machin", "garanty":null}') "Key List";
Key List
["qty","price","truc","garanty"]
SELECT Bson_Object_Values('{"One":1,"Two":2,"Three":3}') "Value List";
Value List
[1,2,3]
#
# Test UDF's with column arguments
#
CREATE TABLE t2
(
ISBN CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32),
AUTHOR CHAR(64),
TITLE CHAR(32),
TRANSLATION CHAR(32),
TRANSLATOR CHAR(80),
PUBLISHER CHAR(32),
DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT Bson_Make_Array(AUTHOR, TITLE, DATEPUB) FROM t2;
Bson_Make_Array(AUTHOR, TITLE, DATEPUB)
[" Jean-Christophe Bernadac, Franois Knab","Construire une application XML",1999]
["William J. Pardi","XML en Action",1999]
SELECT Bson_Make_Object(AUTHOR, TITLE, DATEPUB) FROM t2;
Bson_Make_Object(AUTHOR, TITLE, DATEPUB)
{"AUTHOR":" Jean-Christophe Bernadac, Franois Knab","TITLE":"Construire une application XML","DATEPUB":1999}
{"AUTHOR":"William J. Pardi","TITLE":"XML en Action","DATEPUB":1999}
SELECT Bson_Array_Grp(TITLE, DATEPUB) FROM t2;
ERROR HY000: Can't initialize function 'bson_array_grp'; This function can only accept 1 argument
SELECT Bson_Array_Grp(TITLE) FROM t2;
Bson_Array_Grp(TITLE)
["Construire une application XML","XML en Action"]
CREATE TABLE t3 (
SERIALNO CHAR(5) NOT NULL,
NAME VARCHAR(12) NOT NULL FLAG=6,
SEX SMALLINT(1) NOT NULL,
TITLE VARCHAR(15) NOT NULL FLAG=20,
MANAGER CHAR(5) DEFAULT NULL,
DEPARTMENT CHAr(4) NOT NULL FLAG=41,
SECRETARY CHAR(5) DEFAULT NULL FLAG=46,
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}
SELECT DEPARTMENT, Bson_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT;
DEPARTMENT Bson_Array_Grp(NAME)
0021 ["STRONG","SHORTSIGHT"]
0318 ["BANCROFT","PLUMHEAD","HONEY","TONGHO","WALTER","SHRINKY","WERTHER","MERCHANT","WHEELFOR"]
0319 ["BULLOZER","QUINN","BROWNY","KITTY","MONAPENNY","MARTIN","FUNNIGUY","BUGHAPPY","FODDERMAN","MESSIFUL"]
2452 ["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"]
Warnings:
Warning 1105 Result truncated to json_grp_size values
SELECT BsonSet_Grp_Size(30);
BsonSet_Grp_Size(30)
30
SELECT Bson_Make_Object(title, Bson_Array_Grp(name) `json_names`) from t3 GROUP BY title;
Bson_Make_Object(title, Bson_Array_Grp(name) `json_names`)
{"title":"ADMINISTRATOR","names":["GOOSEPEN","FUNNIGUY","SHRINKY"]}
{"title":"DIRECTOR","names":["QUINN","WERTHER","STRONG"]}
{"title":"ENGINEER","names":["BROWNY","ORELLY","MARTIN","TONGHO","WALTER","SMITH"]}
{"title":"PROGRAMMER","names":["BUGHAPPY"]}
{"title":"SALESMAN","names":["WHEELFOR","MERCHANT","BULLOZER","BANCROFT","FODDERMAN"]}
{"title":"SCIENTIST","names":["BIGHEAD","BIGHORN"]}
{"title":"SECRETARY","names":["MESSIFUL","HONEY","SHORTSIGHT","CHERRY","MONAPENNY"]}
{"title":"TYPIST","names":["KITTY","PLUMHEAD"]}
SELECT Bson_Make_Array(DEPARTMENT, Bson_Array_Grp(NAME)) FROM t3 GROUP BY DEPARTMENT;
Bson_Make_Array(DEPARTMENT, Bson_Array_Grp(NAME))
["0021",["STRONG","SHORTSIGHT"]]
["0318",["BANCROFT","PLUMHEAD","HONEY","TONGHO","WALTER","SHRINKY","WERTHER","MERCHANT","WHEELFOR"]]
["0319",["BULLOZER","QUINN","BROWNY","KITTY","MONAPENNY","MARTIN","FUNNIGUY","BUGHAPPY","FODDERMAN","MESSIFUL","GOOSEPEN"]]
["2452",["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"]]
SELECT Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES) FROM t3 GROUP BY DEPARTMENT;
Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES)
{"DEPARTMENT":"0021","NAMES":["STRONG","SHORTSIGHT"]}
{"DEPARTMENT":"0318","NAMES":["BANCROFT","PLUMHEAD","HONEY","TONGHO","WALTER","SHRINKY","WERTHER","MERCHANT","WHEELFOR"]}
{"DEPARTMENT":"0319","NAMES":["BULLOZER","QUINN","BROWNY","KITTY","MONAPENNY","MARTIN","FUNNIGUY","BUGHAPPY","FODDERMAN","MESSIFUL","GOOSEPEN"]}
{"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}]}
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}]}
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;
Bson_Object_Grp(NAME, SALARY)
{"":"MARTIN","ffffp@":"KITTY"}
SELECT Bson_Make_Object(DEPARTMENT, Bson_Object_Grp(NAME, SALARY) "Json_SALARIES") FROM t3 GROUP BY DEPARTMENT;
Bson_Make_Object(DEPARTMENT, Bson_Object_Grp(NAME, SALARY) "Json_SALARIES")
{"DEPARTMENT":"0021","SALARIES":{"":"SHORTSIGHT"}}
{"DEPARTMENT":"0318","SALARIES":{"":"WHEELFOR"}}
{"DEPARTMENT":"0319","SALARIES":{"":"GOOSEPEN","ffffp@":"KITTY"}}
{"DEPARTMENT":"2452","SALARIES":{"":"CHERRY"}}
SELECT Bson_Array_Grp(NAME) FROM t3;
Bson_Array_Grp(NAME)
["BANCROFT","SMITH","MERCHANT","FUNNIGUY","BUGHAPPY","BIGHEAD","SHRINKY","WALTER","FODDERMAN","TONGHO","SHORTSIGHT","MESSIFUL","HONEY","GOOSEPEN","CHERRY","MONAPENNY","KITTY","PLUMHEAD","STRONG","BULLOZER","WERTHER","QUINN","ORELLY","BIGHORN","BROWNY","WHEELFOR","MARTIN"]
SELECT Bson_Object_Key(name, title) FROM t3 WHERE DEPARTMENT = 318;
Bson_Object_Key(name, title)
{"BANCROFT":"SALESMAN"}
{"MERCHANT":"SALESMAN"}
{"SHRINKY":"ADMINISTRATOR"}
{"WALTER":"ENGINEER"}
{"TONGHO":"ENGINEER"}
{"HONEY":"SECRETARY"}
{"PLUMHEAD":"TYPIST"}
{"WERTHER":"DIRECTOR"}
{"WHEELFOR":"SALESMAN"}
SELECT Bson_Object_Grp(name, title) FROM t3 WHERE DEPARTMENT = 318;
Bson_Object_Grp(name, title)
{"SALESMAN":"WHEELFOR","ADMINISTRATOR":"SHRINKY","ENGINEER":"TONGHO","SECRETARY":"HONEY","TYPIST":"PLUMHEAD","DIRECTOR":"WERTHER"}
#
# Test value getting UDF's
#
SELECT BsonGet_String(Bson_Array_Grp(name),'[#]') FROM t3;
BsonGet_String(Bson_Array_Grp(name),'[#]')
27
SELECT BsonGet_String(Bson_Array_Grp(name),'[","]') FROM t3;
BsonGet_String(Bson_Array_Grp(name),'[","]')
BANCROFT,SMITH,MERCHANT,FUNNIGUY,BUGHAPPY,BIGHEAD,SHRINKY,WALTER,FODDERMAN,TONGHO,SHORTSIGHT,MESSIFUL,HONEY,GOOSEPEN,CHERRY,MONAPENNY,KITTY,PLUMHEAD,STRONG,BULLOZER,WERTHER,QUINN,ORELLY,BIGHORN,BROWNY,WHEELFOR,MARTIN
SELECT BsonGet_String(Bson_Array_Grp(name),'[>]') FROM t3;
BsonGet_String(Bson_Array_Grp(name),'[>]')
WHEELFOR
SET @j1 = '[45,28,36,45,89]';
SELECT BsonGet_String(@j1,'1');
BsonGet_String(@j1,'1')
28
SELECT BsonGet_String(@j1 json_,'3');
BsonGet_String(@j1 json_,'3')
45
SELECT BsonGet_String(Bson_Make_Array(45,28,36,45,89),'3');
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
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
SELECT BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.*');
BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.*')
[36,45,89]
SELECT BsonGet_String(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'truc');
BsonGet_String(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'truc')
machin
SET @j2 = '{"qty":56,"price":3.141600,"truc":"machin","garanty":null}';
SELECT BsonGet_String(@j2 json_,'truc');
BsonGet_String(@j2 json_,'truc')
machin
SELECT BsonGet_String(@j2,'truc');
BsonGet_String(@j2,'truc')
machin
SELECT BsonGet_String(@j2,'chose');
BsonGet_String(@j2,'chose')
NULL
SELECT BsonGet_String(NULL json_, NULL);
BsonGet_String(NULL json_, NULL)
NULL
Warnings:
Warning 1105
/* NULL WARNING */
SELECT department, BsonGet_String(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
department Sumsal
0021 28500.00
0318 72230.00
0319 89800.95
2452 45900.00
SELECT BsonGet_Int(@j1, '4');
BsonGet_Int(@j1, '4')
89
SELECT BsonGet_Int(@j1, '[#]');
BsonGet_Int(@j1, '[#]')
5
SELECT BsonGet_Int(@j1, '[+]');
BsonGet_Int(@j1, '[+]')
243
SELECT BsonGet_Int(@j1 json_, '3');
BsonGet_Int(@j1 json_, '3')
45
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '3');
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '3')
45
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '["+"]');
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '["+"]')
45
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[+]');
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[+]')
243
SELECT BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0');
BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0')
36
SELECT BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '0.1');
BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '0.1')
28
SELECT BsonGet_Int(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'qty');
BsonGet_Int(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'qty')
56
SELECT BsonGet_Int(@j2 json_, 'price');
BsonGet_Int(@j2 json_, 'price')
3
SELECT BsonGet_Int(@j2, 'qty');
BsonGet_Int(@j2, 'qty')
56
SELECT BsonGet_Int('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose');
BsonGet_Int('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose')
NULL
SELECT BsonGet_Int(BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)), '1.*'), '[+]') sum;
sum
170
SELECT department, BsonGet_Int(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"), 'salaries.[+]') Sumsal FROM t3 GROUP BY department;
department Sumsal
0021 28500
0318 72230
0319 89800
2452 45900
SELECT BsonGet_Real(@j1, '2');
BsonGet_Real(@j1, '2')
36.000000000000000
SELECT BsonGet_Real(@j1 json_, '3', 2);
BsonGet_Real(@j1 json_, '3', 2)
45.00
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '3');
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '3')
45.000000000000000
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '["+"]');
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '["+"]')
45.000000000000000
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[+]');
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[+]')
243.000000000000000
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[!]');
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[!]')
48.600000000000000
SELECT BsonGet_Real(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0');
BsonGet_Real(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0')
36.000000000000000
SELECT BsonGet_Real(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'price');
BsonGet_Real(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'price')
3.141600000000000
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}' json_, 'qty');
BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}' json_, 'qty')
56.000000000000000
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price');
BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price')
3.141600000000000
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price', 4);
BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price', 4)
3.1416
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose');
BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose')
NULL
SELECT department, BsonGet_Real(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
department Sumsal
0021 28500.000000000000000
0318 72230.000000000000000
0319 89800.950000000000000
2452 45900.000000000000000
#
# Documentation examples
#
SELECT
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '4') "Rank",
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[#]') "Number",
BsonGet_String(Bson_Make_Array(45,28,36,45,89), '[","]') "Concat",
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[+]') "Sum",
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[!]', 2) "Avg";
Rank Number Concat Sum Avg
89 5 45,28,36,45,89 243 48.60
SELECT
BsonGet_String('{"qty":7,"price":29.50,"garanty":null}', 'price') "String",
BsonGet_Int('{"qty":7,"price":29.50,"garanty":null}', 'price') "Int",
BsonGet_Real('{"qty":7,"price":29.50,"garanty":null}', 'price') "Real";
String Int Real
29.50 29 29.500000000000000
SELECT BsonGet_Real('{"qty":7,"price":29.50,"garanty":null}', 'price', 3) "Real";
Real
29.500
#
# Testing Locate
#
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'machin');
BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'machin')
$.truc
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),56);
BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),56)
$.qty
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),3.1416);
BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),3.1416)
$.price
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'chose');
BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'chose')
NULL
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, 'Jack') Path;
Path
$.AUTHORS[1].FN
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, 'jack' ci) Path;
Path
$.AUTHORS[1].FN
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, '{"FN":"Jack", "LN":"London"}' json_) Path;
Path
$.AUTHORS[1]
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, '{"FN":"jack", "LN":"London"}' json_) Path;
Path
NULL
SELECT BsonLocate('[45,28,36,45,89]',36);
BsonLocate('[45,28,36,45,89]',36)
$[2]
SELECT BsonLocate('[45,28,36,45,89]' json_,28.0);
BsonLocate('[45,28,36,45,89]' json_,28.0)
NULL
SELECT Bson_Locate_All('[45,28,36,45,89]',10);
Bson_Locate_All('[45,28,36,45,89]',10)
[]
SELECT Bson_Locate_All('[45,28,36,45,89]',45);
Bson_Locate_All('[45,28,36,45,89]',45)
["$[0]","$[3]"]
SELECT Bson_Locate_All('[[45,28],36,45,89]',45);
Bson_Locate_All('[[45,28],36,45,89]',45)
["$[0][0]","$[2]"]
SELECT Bson_Locate_All('[[45,28,45],36,45,89]',45);
Bson_Locate_All('[[45,28,45],36,45,89]',45)
["$[0][0]","$[0][2]","$[2]"]
SELECT Bson_Locate_All('[[45,28,45],36,45,89]',BsonGet_Int('[3,45]','[1]'));
Bson_Locate_All('[[45,28,45],36,45,89]',BsonGet_Int('[3,45]','[1]'))
["$[0][0]","$[0][2]","$[2]"]
SELECT BsonLocate('[[45,28,45],36,45,89]',45,n) from t1;
BsonLocate('[[45,28,45],36,45,89]',45,n)
$[0][0]
$[0][2]
$[2]
NULL
NULL
SELECT BsonGet_String(Bson_Locate_All('[[45,28,45],36,45,89]',45),concat('[',n-1,']')) FROM t1;
BsonGet_String(Bson_Locate_All('[[45,28,45],36,45,89]',45),concat('[',n-1,']'))
$[0][0]
$[0][2]
$[2]
NULL
NULL
SELECT BsonGet_String(Bson_Locate_All('[[45,28,45],36,45,89]',45),concat('[',n-1,']')) AS `Path` FROM t1 GROUP BY n HAVING `Path` IS NOT NULL;
Path
$[0][0]
$[0][2]
$[2]
SELECT Bson_Locate_All('[45,28,[36,45,89]]',45);
Bson_Locate_All('[45,28,[36,45,89]]',45)
["$[0]","$[2][1]"]
SELECT Bson_Locate_All('[[45,28],[36,45.0,89]]',BsonValue(45.0));
Bson_Locate_All('[[45,28],[36,45.0,89]]',BsonValue(45.0))
[]
SELECT Bson_Locate_All('[[45,28],[36,45.0,89]]',45.0);
Bson_Locate_All('[[45,28],[36,45.0,89]]',45.0)
["$[1][1]"]
SELECT BsonLocate('[[45,28],[36,45,89]]','[36,45,89]' json_);
BsonLocate('[[45,28],[36,45,89]]','[36,45,89]' json_)
$[1]
SELECT BsonLocate('[[45,28],[36,45,89]]','[45,28]' json_);
BsonLocate('[[45,28],[36,45,89]]','[45,28]' json_)
$[0]
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]','45') "All paths";
All paths
[]
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]','[36,45]' json_);
Bson_Locate_All('[[45,28],[[36,45],89]]','[36,45]' json_)
["$[1][0]"]
SELECT BsonGet_Int(Bson_Locate_All('[[45,28],[[36,45],89]]',45), '[#]') "Nb of occurs";
Nb of occurs
2
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]',45,2);
Bson_Locate_All('[[45,28],[[36,45],89]]',45,2)
["$[0][0]"]
SELECT BsonGet_String(Bson_Locate_All('[45,28,36,45,89]',45),'0');
BsonGet_String(Bson_Locate_All('[45,28,36,45,89]',45),'0')
$[0]
SELECT BsonLocate(Bson_File('test/biblio.json'), 'Knab');
BsonLocate(Bson_File('test/biblio.json'), 'Knab')
$[0].AUTHOR[1].LASTNAME
SELECT Bson_Locate_All('test/biblio.json' jfile_, 'Knab');
Bson_Locate_All('test/biblio.json' jfile_, 'Knab')
["$[0].AUTHOR[1].LASTNAME"]
#
# Testing json files
#
SELECT Bfile_Make('[{"_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]}]', 'test/fx.json', 0) AS NewFile;
NewFile
test/fx.json
SELECT Bfile_Make('test/fx.json', 1);
Bfile_Make('test/fx.json', 1)
test/fx.json
SELECT Bfile_Make('test/fx.json' jfile_);
Bfile_Make('test/fx.json' jfile_)
test/fx.json
SELECT Bfile_Make(Bbin_File('test/fx.json'), 0);
Bfile_Make(Bbin_File('test/fx.json'), 0)
test/fx.json
SELECT Bson_File('test/fx.json', 1);
Bson_File('test/fx.json', 1)
[{"_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]}]
Warnings:
Warning 1105 File pretty format doesn't match the specified pretty value
SELECT Bson_File('test/fx.json', 2);
Bson_File('test/fx.json', 2)
[{"_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]}]
Warnings:
Warning 1105 File pretty format doesn't match the specified pretty value
SELECT Bson_File('test/fx.json', 0);
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
SELECT Bson_File('test/fx.json', '[?]');
Bson_File('test/fx.json', '[?]')
NULL
Warnings:
Warning 1105
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]}
SELECT BsonGet_String(Bson_File('test/fx.json'), '1');
BsonGet_String(Bson_File('test/fx.json'), '1')
6 car roadster 56000 (6, 9)
SELECT BsonGet_Int(Bson_File('test/fx.json'), '1.mileage') AS Mileage;
Mileage
56000
SELECT BsonGet_Real(Bson_File('test/fx.json'), '0.price', 2) AS Price;
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'
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'
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'
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
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'
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
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
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'
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
#
# Testing new functions
#
SELECT Bson_Item_Merge('["a","b","c"]','["d","e","f"]') as "Result";
Result
["a","b","c","d","e","f"]
SELECT Bson_Item_Merge(Bson_Make_Array('a','b','c'), Bson_Make_Array('d','e','f')) as "Result";
Result
["a","b","c","d","e","f"]
SELECT
Bson_Set_Item('[1,2,3,{"quatre":4}]', 'foo', '$[1]', 5, '$[3].cinq') as "Set",
Bson_Insert_Item('[1,2,3,{"quatre":4}]', 'foo', '$[1]', 5, '$[3].cinq') as "Insert",
Bson_Update_Item(Bson_Make_Array(1,2,3,Bson_Object_Key('quatre',4)),'foo','$[1]',5,'$[3].cinq') "Update";
Set Insert Update
[1,"foo",3,{"quatre":4,"cinq":5}] [1,2,3,{"quatre":4,"cinq":5}] [1,"foo",3,{"quatre":4}]
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','1','[2].Deux');
bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','1','[2].Deux')
[1,3,{"quatre":4}]
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','["[1]","[3].Deux"]');
bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','["[1]","[3].Deux"]')
[1,3,{"quatre":4}]
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','$.[3].Deux');
bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','$.[3].Deux')
[1,2,3,{"quatre":4}]
SELECT Bson_Item_Merge(Bson_Get_Item("C:/Data/Json/bibdoc.json", '$[0].AUTHOR'), Bson_Make_Array(Bson_Object_Key('FIRSTNAME','Olivier','LASTNAME','Bertrand'))) "Result";
Result
[{"FIRSTNAME":"Jean-Christophe","LASTNAME":"Bernadac"},{"FIRSTNAME":"Franois","LASTNAME":"Knab"},{"FIRSTNAME":"Olivier","LASTNAME":"Bertrand"}]
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
--disable_query_log
#
# Check if server has support for loading plugins
#
if (`SELECT @@have_dynamic_loading != 'YES'`) {
--skip UDF requires dynamic loading
}
if (!$HA_CONNECT_SO) {
--skip Needs a dynamically built ha_connect.so
}
--eval CREATE FUNCTION bson_test RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsonvalue RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_make_array RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_array_add_values RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_array_add RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_array_delete RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_make_object RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_object_nonull RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_object_key RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_object_add RETURNS STRING SONAME '$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_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';
--eval CREATE AGGREGATE FUNCTION bson_object_grp RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsonlocate RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_locate_all RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_contains RETURNS INTEGER SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsoncontains_path RETURNS INTEGER SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_item_merge RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_get_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_delete_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsonget_string RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsonget_int RETURNS INTEGER SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bsonget_real RETURNS REAL SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_set_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_insert_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_update_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_file RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bson_serialize RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bfile_make RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bfile_convert RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bfile_bjson RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_make_array RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_array_add RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_array_add_values RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_array_delete RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE AGGREGATE FUNCTION bbin_array_grp RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE AGGREGATE FUNCTION bbin_object_grp RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_make_object RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_nonull RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_key RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_add RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_delete RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_list RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_object_values RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_get_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_item_merge RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_set_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_insert_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_update_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_delete_item RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_locate_all RETURNS STRING SONAME '$HA_CONNECT_SO';
--eval CREATE FUNCTION bbin_file RETURNS STRING SONAME '$HA_CONNECT_SO';
--enable_query_log
--source bson_udf.inc
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MTR_SUITE_DIR/std_data/biblio.json $MYSQLD_DATADIR/test/biblio.json
--copy_file $MTR_SUITE_DIR/std_data/employee.dat $MYSQLD_DATADIR/test/employee.dat
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=VIR BLOCK_SIZE=5;
--echo #
--echo # Test UDF's with constant arguments
--echo #
--error ER_CANT_INITIALIZE_UDF
SELECT BsonValue(56, 3.1416, 'foo', NULL);
SELECT BsonValue(3.1416);
SELECT BsonValue(-80);
SELECT BsonValue('foo');
SELECT BsonValue(9223372036854775807);
SELECT BsonValue(NULL);
SELECT BsonValue(TRUE);
SELECT BsonValue(FALSE);
SELECT BsonValue();
SELECT BsonValue('[11, 22, 33]' json_) FROM t1;
#
SELECT Bson_Make_Array();
SELECT Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL);
SELECT Bson_Make_Array(Bson_Make_Array(56, 3.1416, 'foo'), TRUE);
#
--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Array_Add(Bson_Make_Array(56, 3.1416, 'foo', NULL)) Array;
SELECT Bson_Array_Add(Bson_Make_Array(56, 3.1416, 'foo', NULL), 'One more') Array;
#--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Array_Add(BsonValue('one value'), 'One more');
#--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Array_Add('one value', 'One more');
SELECT Bson_Array_Add('one value' json_, 'One more');
#--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Array_Add(5 json_, 'One more');
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 0);
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 2) Array;
SELECT Bson_Array_Add('[5,3,8,7,9]' json_, 4, 9);
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), '[2]', 33, 1);
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, '[2]', 1);
SELECT Bson_Array_Add(Bson_Make_Array(1, 2, Bson_Make_Array(11, 22)), 33, 1, '[2]');
#
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin', NULL), 'One more', 'Two more') Array;
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin'), 'One more', 'Two more') Array FROM t1;
SELECT Bson_Array_Add_Values(Bson_Make_Array(56, 3.1416, 'machin'), n) Array FROM t1;
SELECT Bson_Array_Add_Values(Bson_Make_Array(n, 3.1416, 'machin'), n) Array FROM t1;
SELECT Bson_Array_Add_Values('[56]', 3.1416, 'machin') Array;
#
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), 0);
SELECT Bson_Array_Delete(Bson_Make_Object(56, 3.1416, 'My name is Foo', NULL), 2);
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2');
SELECT Bson_Array_Delete(Bson_Make_Array(56, 3.1416, 'My name is "Foo"', NULL), '2', 2); /* WARNING VOID */
#
SELECT Bson_Make_Object(56, 3.1416, 'foo', NULL);
SELECT Bson_Make_Object(56 qty, 3.1416 price, 'foo' truc, NULL garanty);
SELECT Bson_Make_Object();
SELECT Bson_Make_Object(Bson_Make_Array(56, 3.1416, 'foo'), NULL);
SELECT Bson_Make_Array(Bson_Make_Object(56 "qty", 3.1416 "price", 'foo') ,NULL);
SELECT Bson_Object_Key('qty', 56, 'price', 3.1416, 'truc', 'machin', 'garanty', NULL);
--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Object_Key('qty', 56, 'price', 3.1416, 'truc', 'machin', 'garanty');
#
SELECT Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'blue' color);
SELECT Bson_Object_Add(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 45.99 price);
SELECT Bson_Object_Add(Bson_File('notexist.json'), 'cheese' item, '[1]', 1);
#
SELECT Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'truc');
SELECT Bson_Object_Delete(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'chose');
#
SELECT Bson_Object_List(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty)) "Key List";
SELECT Bson_Object_List('{"qty":56, "price":3.1416, "truc":"machin", "garanty":null}') "Key List";
SELECT Bson_Object_Values('{"One":1,"Two":2,"Three":3}') "Value List";
--echo #
--echo # Test UDF's with column arguments
--echo #
CREATE TABLE t2
(
ISBN CHAR(15),
LANG CHAR(2),
SUBJECT CHAR(32),
AUTHOR CHAR(64),
TITLE CHAR(32),
TRANSLATION CHAR(32),
TRANSLATOR CHAR(80),
PUBLISHER CHAR(32),
DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=BSON FILE_NAME='biblio.json';
SELECT Bson_Make_Array(AUTHOR, TITLE, DATEPUB) FROM t2;
SELECT Bson_Make_Object(AUTHOR, TITLE, DATEPUB) FROM t2;
--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Array_Grp(TITLE, DATEPUB) FROM t2;
SELECT Bson_Array_Grp(TITLE) FROM t2;
CREATE TABLE t3 (
SERIALNO CHAR(5) NOT NULL,
NAME VARCHAR(12) NOT NULL FLAG=6,
SEX SMALLINT(1) NOT NULL,
TITLE VARCHAR(15) NOT NULL FLAG=20,
MANAGER CHAR(5) DEFAULT NULL,
DEPARTMENT CHAr(4) NOT NULL FLAG=41,
SECRETARY CHAR(5) DEFAULT NULL FLAG=46,
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';
SELECT DEPARTMENT, Bson_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT;
#SET connect_json_grp_size=30; Deprecated
SELECT BsonSet_Grp_Size(30);
SELECT Bson_Make_Object(title, Bson_Array_Grp(name) `json_names`) from t3 GROUP BY title;
SELECT Bson_Make_Array(DEPARTMENT, Bson_Array_Grp(NAME)) FROM t3 GROUP BY DEPARTMENT;
SELECT Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES) FROM t3 GROUP BY DEPARTMENT;
SELECT Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY)) json_EMPLOYES) FROM t3 GROUP BY DEPARTMENT;
SELECT Bson_Make_Object(DEPARTMENT, TITLE, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, SALARY)) json_EMPLOYES) FROM t3 GROUP BY DEPARTMENT, TITLE;
--error ER_CANT_INITIALIZE_UDF
SELECT Bson_Object_Grp(SALARY) FROM t3;
SELECT Bson_Object_Grp(NAME, SALARY) FROM t3;
SELECT Bson_Make_Object(DEPARTMENT, Bson_Object_Grp(NAME, SALARY) "Json_SALARIES") FROM t3 GROUP BY DEPARTMENT;
SELECT Bson_Array_Grp(NAME) FROM t3;
#
SELECT Bson_Object_Key(name, title) FROM t3 WHERE DEPARTMENT = 318;
SELECT Bson_Object_Grp(name, title) FROM t3 WHERE DEPARTMENT = 318;
--echo #
--echo # Test value getting UDF's
--echo #
SELECT BsonGet_String(Bson_Array_Grp(name),'[#]') FROM t3;
SELECT BsonGet_String(Bson_Array_Grp(name),'[","]') FROM t3;
SELECT BsonGet_String(Bson_Array_Grp(name),'[>]') FROM t3;
SET @j1 = '[45,28,36,45,89]';
SELECT BsonGet_String(@j1,'1');
SELECT BsonGet_String(@j1 json_,'3');
SELECT BsonGet_String(Bson_Make_Array(45,28,36,45,89),'3');
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";
SELECT BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.0');
SELECT BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.*');
SELECT BsonGet_String(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'truc');
SET @j2 = '{"qty":56,"price":3.141600,"truc":"machin","garanty":null}';
SELECT BsonGet_String(@j2 json_,'truc');
SELECT BsonGet_String(@j2,'truc');
SELECT BsonGet_String(@j2,'chose');
SELECT BsonGet_String(NULL json_, NULL); /* NULL WARNING */
SELECT department, BsonGet_String(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
#
SELECT BsonGet_Int(@j1, '4');
SELECT BsonGet_Int(@j1, '[#]');
SELECT BsonGet_Int(@j1, '[+]');
SELECT BsonGet_Int(@j1 json_, '3');
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '3');
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '["+"]');
SELECT BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[+]');
SELECT BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0');
SELECT BsonGet_Int(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '0.1');
SELECT BsonGet_Int(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'qty');
SELECT BsonGet_Int(@j2 json_, 'price');
SELECT BsonGet_Int(@j2, 'qty');
SELECT BsonGet_Int('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose');
SELECT BsonGet_Int(BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)), '1.*'), '[+]') sum;
SELECT department, BsonGet_Int(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"), 'salaries.[+]') Sumsal FROM t3 GROUP BY department;
#
SELECT BsonGet_Real(@j1, '2');
SELECT BsonGet_Real(@j1 json_, '3', 2);
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '3');
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '["+"]');
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[+]');
SELECT BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[!]');
SELECT BsonGet_Real(Bson_Make_Array(Bson_Make_Array(45,28), Bson_Make_Array(36,45,89)), '1.0');
SELECT BsonGet_Real(Bson_Make_Object(56 qty, 3.1416 price, 'machin' truc, NULL garanty), 'price');
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}' json_, 'qty');
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price');
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'price', 4);
SELECT BsonGet_Real('{"qty":56,"price":3.141600,"truc":"machin","garanty":null}', 'chose');
SELECT department, BsonGet_Real(Bson_Make_Object(department, Bson_Array_Grp(salary) "Json_salaries"),'salaries.[+]') Sumsal FROM t3 GROUP BY department;
--echo #
--echo # Documentation examples
--echo #
SELECT
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '4') "Rank",
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[#]') "Number",
BsonGet_String(Bson_Make_Array(45,28,36,45,89), '[","]') "Concat",
BsonGet_Int(Bson_Make_Array(45,28,36,45,89), '[+]') "Sum",
BsonGet_Real(Bson_Make_Array(45,28,36,45,89), '[!]', 2) "Avg";
SELECT
BsonGet_String('{"qty":7,"price":29.50,"garanty":null}', 'price') "String",
BsonGet_Int('{"qty":7,"price":29.50,"garanty":null}', 'price') "Int",
BsonGet_Real('{"qty":7,"price":29.50,"garanty":null}', 'price') "Real";
SELECT BsonGet_Real('{"qty":7,"price":29.50,"garanty":null}', 'price', 3) "Real";
--echo #
--echo # Testing Locate
--echo #
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'machin');
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),56);
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),3.1416);
SELECT BsonLocate(Bson_Make_Object(56 qty,3.1416 price,'machin' truc, NULL garanty),'chose');
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, 'Jack') Path;
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, 'jack' ci) Path;
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, '{"FN":"Jack", "LN":"London"}' json_) Path;
SELECT BsonLocate('{"AUTHORS":[{"FN":"Jules", "LN":"Verne"}, {"FN":"Jack", "LN":"London"}]}' json_, '{"FN":"jack", "LN":"London"}' json_) Path;
SELECT BsonLocate('[45,28,36,45,89]',36);
SELECT BsonLocate('[45,28,36,45,89]' json_,28.0);
SELECT Bson_Locate_All('[45,28,36,45,89]',10);
SELECT Bson_Locate_All('[45,28,36,45,89]',45);
SELECT Bson_Locate_All('[[45,28],36,45,89]',45);
SELECT Bson_Locate_All('[[45,28,45],36,45,89]',45);
SELECT Bson_Locate_All('[[45,28,45],36,45,89]',BsonGet_Int('[3,45]','[1]'));
SELECT BsonLocate('[[45,28,45],36,45,89]',45,n) from t1;
SELECT BsonGet_String(Bson_Locate_All('[[45,28,45],36,45,89]',45),concat('[',n-1,']')) FROM t1;
SELECT BsonGet_String(Bson_Locate_All('[[45,28,45],36,45,89]',45),concat('[',n-1,']')) AS `Path` FROM t1 GROUP BY n HAVING `Path` IS NOT NULL;
SELECT Bson_Locate_All('[45,28,[36,45,89]]',45);
SELECT Bson_Locate_All('[[45,28],[36,45.0,89]]',BsonValue(45.0));
SELECT Bson_Locate_All('[[45,28],[36,45.0,89]]',45.0);
SELECT BsonLocate('[[45,28],[36,45,89]]','[36,45,89]' json_);
SELECT BsonLocate('[[45,28],[36,45,89]]','[45,28]' json_);
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]','45') "All paths";
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]','[36,45]' json_);
SELECT BsonGet_Int(Bson_Locate_All('[[45,28],[[36,45],89]]',45), '[#]') "Nb of occurs";
SELECT Bson_Locate_All('[[45,28],[[36,45],89]]',45,2);
SELECT BsonGet_String(Bson_Locate_All('[45,28,36,45,89]',45),'0');
SELECT BsonLocate(Bson_File('test/biblio.json'), 'Knab');
SELECT Bson_Locate_All('test/biblio.json' jfile_, 'Knab');
--echo #
--echo # Testing json files
--echo #
SELECT Bfile_Make('[{"_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]}]', 'test/fx.json', 0) AS NewFile;
SELECT Bfile_Make('test/fx.json', 1);
SELECT Bfile_Make('test/fx.json' jfile_);
SELECT Bfile_Make(Bbin_File('test/fx.json'), 0);
SELECT Bson_File('test/fx.json', 1);
SELECT Bson_File('test/fx.json', 2);
SELECT Bson_File('test/fx.json', 0);
SELECT Bson_File('test/fx.json', '0');
SELECT Bson_File('test/fx.json', '[?]');
SELECT BsonGet_String(Bson_File('test/fx.json'), '1.*');
SELECT BsonGet_String(Bson_File('test/fx.json'), '1');
SELECT BsonGet_Int(Bson_File('test/fx.json'), '1.mileage') AS Mileage;
SELECT BsonGet_Real(Bson_File('test/fx.json'), '0.price', 2) AS Price;
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings');
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 1, 'ratings');
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings', 1);
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2.ratings'), 6, 0);
SELECT Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1);
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin);
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 70 H, 'size');
SELECT Bson_Object_Add(Bson_File('test/fx.json', '3'), 70 H, 'size');
SELECT Bson_Object_List(Bson_File('test/fx.json', '3.size'));
--echo #
--echo # Testing new functions
--echo #
SELECT Bson_Item_Merge('["a","b","c"]','["d","e","f"]') as "Result";
SELECT Bson_Item_Merge(Bson_Make_Array('a','b','c'), Bson_Make_Array('d','e','f')) as "Result";
SELECT
Bson_Set_Item('[1,2,3,{"quatre":4}]', 'foo', '$[1]', 5, '$[3].cinq') as "Set",
Bson_Insert_Item('[1,2,3,{"quatre":4}]', 'foo', '$[1]', 5, '$[3].cinq') as "Insert",
Bson_Update_Item(Bson_Make_Array(1,2,3,Bson_Object_Key('quatre',4)),'foo','$[1]',5,'$[3].cinq') "Update";
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','1','[2].Deux');
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','["[1]","[3].Deux"]');
SELECT bson_delete_item('[1,2,3,{"quatre":4,"Deux":2}]','$.[3].Deux');
SELECT Bson_Item_Merge(Bson_Get_Item("C:/Data/Json/bibdoc.json", '$[0].AUTHOR'), Bson_Make_Array(Bson_Object_Key('FIRSTNAME','Olivier','LASTNAME','Bertrand'))) "Result";
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
#
# Clean up
#
--source bson_udf2.inc
--remove_file $MYSQLD_DATADIR/test/biblio.json
--remove_file $MYSQLD_DATADIR/test/employee.dat
--remove_file $MYSQLD_DATADIR/test/fx.json
--disable_query_log
DROP FUNCTION bson_test;
DROP FUNCTION bsonvalue;
DROP FUNCTION bson_make_array;
DROP FUNCTION bson_array_add_values;
DROP FUNCTION bson_array_add;
DROP FUNCTION bson_array_delete;
DROP FUNCTION bson_make_object;
DROP FUNCTION bson_object_nonull;
DROP FUNCTION bson_object_key;
DROP FUNCTION bson_object_add;
DROP FUNCTION bson_object_delete;
DROP FUNCTION bson_object_list;
DROP FUNCTION bson_object_values;
DROP FUNCTION bsonset_grp_size;
DROP FUNCTION bsonget_grp_size;
DROP FUNCTION bson_array_grp;
DROP FUNCTION bson_object_grp;
DROP FUNCTION bsonlocate;
DROP FUNCTION bson_locate_all;
DROP FUNCTION bson_contains;
DROP FUNCTION bsoncontains_path;
DROP FUNCTION bson_item_merge;
DROP FUNCTION bson_get_item;
DROP FUNCTION bson_delete_item;
DROP FUNCTION bsonget_string;
DROP FUNCTION bsonget_int;
DROP FUNCTION bsonget_real;
DROP FUNCTION bson_set_item;
DROP FUNCTION bson_insert_item;
DROP FUNCTION bson_update_item;
DROP FUNCTION bson_serialize;
DROP FUNCTION bson_file;
DROP FUNCTION bfile_make;
DROP FUNCTION bfile_convert;
DROP FUNCTION bfile_bjson;
DROP FUNCTION bbin_make_array;
DROP FUNCTION bbin_array_add;
DROP FUNCTION bbin_array_add_values;
DROP FUNCTION bbin_array_delete;
DROP FUNCTION bbin_array_grp;
DROP FUNCTION bbin_object_grp;
DROP FUNCTION bbin_make_object;
DROP FUNCTION bbin_object_nonull;
DROP FUNCTION bbin_object_key;
DROP FUNCTION bbin_object_add;
DROP FUNCTION bbin_object_delete;
DROP FUNCTION bbin_object_list;
DROP FUNCTION bbin_object_values;
DROP FUNCTION bbin_get_item;
DROP FUNCTION bbin_set_item;
DROP FUNCTION bbin_insert_item;
DROP FUNCTION bbin_update_item;
DROP FUNCTION bbin_item_merge;
DROP FUNCTION bbin_delete_item;
DROP FUNCTION bbin_locate_all;
DROP FUNCTION bbin_file;
--enable_query_log
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