Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
dc8f914c
Commit
dc8f914c
authored
Nov 25, 2020
by
Olivier Bertrand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove based enum not accepted by most gcc compilers
parent
dae4bd0b
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
2270 additions
and
568 deletions
+2270
-568
storage/connect/bson.cpp
storage/connect/bson.cpp
+586
-430
storage/connect/bson.h
storage/connect/bson.h
+95
-92
storage/connect/json.h
storage/connect/json.h
+1
-40
storage/connect/jsonudf.cpp
storage/connect/jsonudf.cpp
+1475
-1
storage/connect/jsonudf.h
storage/connect/jsonudf.h
+110
-4
storage/connect/tabjson.cpp
storage/connect/tabjson.cpp
+2
-0
storage/connect/value.cpp
storage/connect/value.cpp
+1
-1
No files found.
storage/connect/bson.cpp
View file @
dc8f914c
This diff is collapsed.
Click to expand it.
storage/connect/bson.h
View file @
dc8f914c
...
...
@@ -16,20 +16,25 @@
#define X
#endif
#define ARGS MY_MIN(24,(int)len-i),s+MY_MAX(i-3,0)
#define MOF(X) MakeOff(Base, X)
#define MP(X) MakePtr(Base, X)
#define MPP(X) (PBPR)MakePtr(Base, X)
#define MVP(X) (PBVAL)MakePtr(Base, X)
#define MZP(X) (PSZ)MakePtr(Base, X)
#define LLN(X) *(longlong*)MakePtr(Base, X)
#define DBL(X) *(double*)MakePtr(Base, X)
class
BDOC
;
class
BOUT
;
//class
JSON;
class
B
JSON
;
typedef
class
BDOC
*
PBDOC
;
//typedef class BJSON* PBSON;
// BSON size should be equal on Linux and Windows
#define BMX 255
typedef
uint
OFFSET
;
typedef
class
BJSON
*
PBJSON
;
typedef
uint
OFFSET
;
/***********************************************************************/
/* Structure
JVALUE.
*/
/* Structure
BVAL. Binary representation of a JVALUE.
*/
/***********************************************************************/
typedef
struct
_jvalue
{
union
{
...
...
@@ -39,12 +44,12 @@ typedef struct _jvalue {
bool
B
;
// A boolean value True or false (0)
};
short
Nd
;
// Number of decimals
JTYP
Type
;
// The value type
short
Type
;
// The value type
OFFSET
Next
;
// Offset to the next value in array
}
BVAL
,
*
PBVAL
;
// end of struct BVALUE
/***********************************************************************/
/* Structure
J
PAIR. The pairs of a json Object. */
/* Structure
B
PAIR. The pairs of a json Object. */
/***********************************************************************/
typedef
struct
_jpair
{
OFFSET
Key
;
// Offset to this pair key name
...
...
@@ -52,26 +57,6 @@ typedef struct _jpair {
OFFSET
Next
;
// Offset to the next pair in object
}
BPAIR
,
*
PBPR
;
// end of struct BPAIR
#if 0
/***********************************************************************/
/* Structure used to return binary json to Json UDF functions. */
/* (should be moved to jsonudf.h). */
/***********************************************************************/
typedef struct _JsonBin {
char Msg[BMX + 1];
char *Filename;
PGLOBAL G;
int Pretty;
ulong Reslen;
my_bool Changed;
PBSON Top;
PBSON Jsp;
PBJN Bsp;
} BJSON, *PBJN ; // end of struct BJSON
PBJN JbinAlloc(PGLOBAL g, UDF_ARGS* args, ulong len, PJSON jsp);
#endif // 0
char
*
NextChr
(
PSZ
s
,
char
sep
);
char
*
GetJsonNull
(
void
);
const
char
*
GetFmt
(
int
type
,
bool
un
);
...
...
@@ -79,15 +64,84 @@ const char* GetFmt(int type, bool un);
DllExport
bool
IsNum
(
PSZ
s
);
/***********************************************************************/
/* Class
JDOC. The class for parsing and serializing json documents.
*/
/* Class
BJSON. The class handling all BJSON operations.
*/
/***********************************************************************/
class
B
DOC
:
public
BLOCK
{
class
B
JSON
:
public
BLOCK
{
public:
BDOC
(
void
);
// Constructor
BJSON
(
void
*
base
,
PBVAL
vp
=
NULL
)
{
Base
=
base
;
Bvp
=
vp
;
}
void
*
BsonSubAlloc
(
PGLOBAL
g
,
size_t
size
);
PBPR
SubAllocPair
(
PGLOBAL
g
,
OFFSET
key
);
void
*
GetBase
(
void
)
{
return
Base
;
}
// SubAlloc functions
void
*
BsonSubAlloc
(
PGLOBAL
g
,
size_t
size
);
PBPR
SubAllocPair
(
PGLOBAL
g
,
OFFSET
key
,
OFFSET
val
=
0
);
PBVAL
SubAllocVal
(
PGLOBAL
g
);
PBVAL
SubAllocVal
(
PGLOBAL
g
,
OFFSET
toval
,
JTYP
type
=
TYPE_UNKNOWN
,
short
nd
=
0
);
PBVAL
SubAllocVal
(
PGLOBAL
g
,
PVAL
valp
);
PBVAL
DupVal
(
PGLOBAL
g
,
PBVAL
bvp
);
// Array functions
int
GetArraySize
(
PBVAL
bap
,
bool
b
=
false
);
PBVAL
GetArrayValue
(
PBVAL
bap
,
int
i
);
PSZ
GetArrayText
(
PGLOBAL
g
,
PBVAL
bap
,
PSTRG
text
);
PBVAL
MergeArray
(
PGLOBAL
g
,
PBVAL
bap1
,
PBVAL
bap2
);
PBVAL
DeleteValue
(
PBVAL
bap
,
int
n
);
PBVAL
AddArrayValue
(
PGLOBAL
g
,
PBVAL
bap
,
PBVAL
nvp
=
NULL
,
int
*
x
=
NULL
);
PBVAL
SetArrayValue
(
PGLOBAL
g
,
PBVAL
bap
,
PBVAL
nvp
,
int
n
);
bool
IsArrayNull
(
PBVAL
bap
);
// Object functions
int
GetObjectSize
(
PBPR
bop
,
bool
b
=
false
);
PSZ
GetObjectText
(
PGLOBAL
g
,
PBPR
bop
,
PSTRG
text
);
PBPR
MergeObject
(
PGLOBAL
g
,
PBPR
bop1
,
PBPR
bop2
);
PBPR
AddPair
(
PGLOBAL
g
,
PBPR
bop
,
PSZ
key
,
OFFSET
val
=
0
);
PBVAL
GetKeyValue
(
PBPR
bop
,
PSZ
key
);
PBVAL
GetKeyList
(
PGLOBAL
g
,
PBPR
bop
);
PBVAL
GetObjectValList
(
PGLOBAL
g
,
PBPR
bop
);
PBPR
SetKeyValue
(
PGLOBAL
g
,
PBPR
bop
,
OFFSET
bvp
,
PSZ
key
);
PBPR
DeleteKey
(
PBPR
bop
,
PCSZ
k
);
bool
IsObjectNull
(
PBPR
bop
);
// Value functions
int
GetSize
(
PBVAL
vlp
,
bool
b
=
false
);
PBPR
GetObject
(
PBVAL
vlp
);
PBVAL
GetArray
(
PBVAL
vlp
);
//PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
PSZ
GetValueText
(
PGLOBAL
g
,
PBVAL
vlp
,
PSTRG
text
);
//inline PJSON GetJson(void) { return (DataType == TYPE_JSON ? Jsp : this); }
PSZ
GetString
(
PGLOBAL
g
,
PBVAL
vp
,
char
*
buff
=
NULL
);
int
GetInteger
(
PBVAL
vp
);
long
long
GetBigint
(
PBVAL
vp
);
double
GetDouble
(
PBVAL
vp
);
PVAL
GetValue
(
PGLOBAL
g
,
PBVAL
vp
);
void
SetValueObj
(
PBVAL
vlp
,
PBPR
bop
);
void
SetValueArr
(
PBVAL
vlp
,
PBVAL
bap
);
void
SetValueVal
(
PBVAL
vlp
,
PBVAL
vp
);
void
SetValue
(
PGLOBAL
g
,
PBVAL
vlp
,
PVAL
valp
);
void
SetString
(
PBVAL
vlp
,
PSZ
s
,
int
ci
=
0
);
void
SetInteger
(
PBVAL
vlp
,
int
n
);
void
SetBigint
(
PGLOBAL
g
,
PBVAL
vlp
,
longlong
ll
);
void
SetFloat
(
PBVAL
vlp
,
double
f
);
void
SetBool
(
PBVAL
vlp
,
bool
b
);
bool
IsValueNull
(
PBVAL
vlp
);
// Members
PBVAL
Bvp
;
void
*
Base
;
protected:
// Default constructor not to be used
BJSON
(
void
)
{}
};
// end of class BJSON
/***********************************************************************/
/* Class JDOC. The class for parsing and serializing json documents. */
/***********************************************************************/
class
BDOC
:
public
BJSON
{
public:
BDOC
(
void
*
);
PBVAL
ParseJson
(
PGLOBAL
g
,
char
*
s
,
size_t
n
,
int
*
prty
=
NULL
,
bool
*
b
=
NULL
);
PSZ
Serialize
(
PGLOBAL
g
,
PBVAL
bvp
,
char
*
fn
,
int
pretty
);
...
...
@@ -98,72 +152,21 @@ class BDOC : public BLOCK {
OFFSET
ParseString
(
PGLOBAL
g
,
int
&
i
);
void
ParseNumeric
(
PGLOBAL
g
,
int
&
i
,
PBVAL
bvp
);
OFFSET
ParseAsArray
(
PGLOBAL
g
,
int
&
i
,
int
pretty
,
int
*
ptyp
);
bool
SerializeArray
(
OFFSET
arp
,
bool
b
);
bool
SerializeObject
(
OFFSET
obp
);
bool
SerializeValue
(
PBVAL
vp
);
bool
SerializeArray
(
OFFSET
arp
,
bool
b
);
bool
SerializeObject
(
OFFSET
obp
);
bool
SerializeValue
(
PBVAL
vp
);
// Members used when parsing and serializing
private:
JOUT
*
jp
;
// Used with serialize
void
*
base
;
// The base for making offsets or pointers
char
*
s
;
// The Json string to parse
int
len
;
// The Json string length
bool
pty
[
3
];
// Used to guess what pretty is
// Default constructor not to be used
BDOC
(
void
)
{}
};
// end of class BDOC
#if 0
/***********************************************************************/
/* Class BJSON. The class handling all BSON operations. */
/***********************************************************************/
class BJSON : public BLOCK {
public:
// Constructor
BJSON(PBVAL vp, void* base) { Vlp = vp; Base = base; }
// Array functions
int GetSize(bool b);
PBVAL GetArrayValue(int i);
PSZ GetText(PGLOBAL g, PSTRG text);
bool Merge(PGLOBAL g, PBVAL jsp);
bool DeleteValue(int n);
PBVAL AddArrayValue(PGLOBAL g, PBVAL jvp = NULL, int* x = NULL);
bool SetArrayValue(PGLOBAL g, PBVAL jvp, int i);
// Object functions
int GetObjectSize(PBPR prp, bool b);
PSZ GetObjectText(PGLOBAL g, PBPR prp, PSTRG text);
bool MergeObject(PGLOBAL g, PBPR prp);
PJPR AddPair(PGLOBAL g, PCSZ key);
PJVAL GetKeyValue(const char* key);
PJAR GetKeyList(PGLOBAL g);
PJAR GetValList(PGLOBAL g);
void SetKeyValue(PGLOBAL g, PBVAL jvp, PCSZ key);
void DeleteKey(PCSZ k);
// Value functions
PBPR GetObject(void);
PBVAL GetArray(void);
PJSON GetJsp(void) { return (DataType == TYPE_JSON ? Jsp : NULL); }
PSZ GetValueText(PGLOBAL g, PSTRG text);
inline PJSON GetJson(void) { return (DataType == TYPE_JSON ? Jsp : this); }
PSZ GetString(PGLOBAL g, char* buff = NULL);
int GetInteger(void);
long long GetBigint(void);
double GetFloat(void);
PVAL GetValue(PGLOBAL g);
void SetValue(PJSON jsp);
void SetValue(PGLOBAL g, PVAL valp);
void SetString(PGLOBAL g, PSZ s, int ci = 0);
void SetInteger(PGLOBAL g, int n);
void SetBigint(PGLOBAL g, longlong ll);
void SetFloat(PGLOBAL g, double f);
void SetBool(PGLOBAL g, bool b);
// Members
PBVAL Vlp;
void* Base;
}; // end of class BJSON
/***********************************************************************/
/* Class JOBJECT: contains a list of value pairs. */
/***********************************************************************/
...
...
storage/connect/json.h
View file @
dc8f914c
...
...
@@ -15,10 +15,7 @@
#define X
#endif
// Required by some compilers
enum
JTYP
:
short
;
enum
JTYP
:
short
{
enum
JTYP
{
TYPE_NULL
=
TYPE_VOID
,
TYPE_STRG
=
TYPE_STRING
,
TYPE_DBL
=
TYPE_DOUBLE
,
...
...
@@ -48,9 +45,6 @@ typedef class JVALUE *PJVAL;
typedef
class
JOBJECT
*
PJOB
;
typedef
class
JARRAY
*
PJAR
;
// BSON size should be equal on Linux and Windows
#define BMX 255
typedef
struct
BSON
*
PBSON
;
typedef
struct
JPAIR
*
PJPR
;
//typedef struct VAL *PVL;
...
...
@@ -63,39 +57,6 @@ struct JPAIR {
PJPR
Next
;
// To the next pair
};
// end of struct JPAIR
#if 0
/***********************************************************************/
/* Structure VAL (string, int, float, bool or null) */
/***********************************************************************/
struct VAL {
union {
char *Strp; // Ptr to a string
int N; // An integer value
long long LLn; // A big integer value
double F; // A float value
bool B; // True or false
};
int Nd; // Decimal number
JTYP Type; // The value type
}; // end of struct VAL
#endif // 0
/***********************************************************************/
/* Structure used to return binary json to Json UDF functions. */
/***********************************************************************/
struct
BSON
{
char
Msg
[
BMX
+
1
];
char
*
Filename
;
PGLOBAL
G
;
int
Pretty
;
ulong
Reslen
;
my_bool
Changed
;
PJSON
Top
;
PJSON
Jsp
;
PBSON
Bsp
;
};
// end of struct BSON
PBSON
JbinAlloc
(
PGLOBAL
g
,
UDF_ARGS
*
args
,
ulong
len
,
PJSON
jsp
);
//PVL AllocVal(PGLOBAL g, JTYP type);
char
*
NextChr
(
PSZ
s
,
char
sep
);
char
*
GetJsonNull
(
void
);
...
...
storage/connect/jsonudf.cpp
View file @
dc8f914c
This diff is collapsed.
Click to expand it.
storage/connect/jsonudf.h
View file @
dc8f914c
/******************** tabjson H Declares Source Code File (.H) *******************/
/* Name: jsonudf.h Version 1.
3
*/
/* Name: jsonudf.h Version 1.
4
*/
/* */
/* (C) Copyright to the author Olivier BERTRAND 2015-20
17
*/
/* (C) Copyright to the author Olivier BERTRAND 2015-20
20
*/
/* */
/* This file contains the JSON UDF function and class declares. */
/*********************************************************************************/
...
...
@@ -15,6 +15,27 @@
#define UDF_EXEC_ARGS \
UDF_INIT*, UDF_ARGS*, char*, unsigned long*, char*, char*
// BSON size should be equal on Linux and Windows
#define BMX 255
typedef
struct
BSON
*
PBSON
;
/***********************************************************************/
/* Structure used to return binary json to Json UDF functions. */
/***********************************************************************/
struct
BSON
{
char
Msg
[
BMX
+
1
];
char
*
Filename
;
PGLOBAL
G
;
int
Pretty
;
ulong
Reslen
;
my_bool
Changed
;
PJSON
Top
;
PJSON
Jsp
;
PBSON
Bsp
;
};
// end of struct BSON
PBSON
JbinAlloc
(
PGLOBAL
g
,
UDF_ARGS
*
args
,
ulong
len
,
PJSON
jsp
);
/*********************************************************************************/
/* The JSON tree node. Can be an Object or an Array. */
/*********************************************************************************/
...
...
@@ -29,8 +50,6 @@ typedef struct _jnode {
}
JNODE
,
*
PJNODE
;
typedef
class
JSNX
*
PJSNX
;
typedef
class
JOUTPATH
*
PJTP
;
typedef
class
JOUTALL
*
PJTA
;
extern
"C"
{
DllExport
my_bool
jsonvalue_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
...
...
@@ -368,3 +387,90 @@ class JUP : public BLOCK {
int
k
,
recl
;
};
// end of class JUP
/* --------------------------- New Testing BJSON Stuff --------------------------*/
typedef
class
BJNX
*
PBJNX
;
/*********************************************************************************/
/* Class BJNX: BJSON access methods. */
/*********************************************************************************/
class
BJNX
:
public
BDOC
{
public:
// Constructors
BJNX
(
PGLOBAL
g
,
PBVAL
row
,
int
type
,
int
len
=
64
,
int
prec
=
0
,
my_bool
wr
=
false
);
// Implementation
int
GetPrecision
(
void
)
{
return
Prec
;
}
PVAL
GetValue
(
void
)
{
return
Value
;
}
// Methods
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
GetJson
(
PGLOBAL
g
);
my_bool
CheckPath
(
PGLOBAL
g
);
my_bool
WriteValue
(
PGLOBAL
g
,
PBVAL
jvalp
);
char
*
Locate
(
PGLOBAL
g
,
PBVAL
jsp
,
PBVAL
jvp
,
int
k
=
1
);
char
*
LocateAll
(
PGLOBAL
g
,
PBVAL
jsp
,
PBVAL
jvp
,
int
mx
=
10
);
protected:
my_bool
SetArrayOptions
(
PGLOBAL
g
,
char
*
p
,
int
i
,
PSZ
nm
);
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
);
void
SetJsonValue
(
PGLOBAL
g
,
PVAL
vp
,
PBVAL
vlp
);
PBVAL
GetRow
(
PGLOBAL
g
);
my_bool
CompareValues
(
PGLOBAL
g
,
PBVAL
v1
,
PBVAL
v2
);
my_bool
LocateArray
(
PGLOBAL
g
,
PBVAL
jarp
);
my_bool
LocateObject
(
PGLOBAL
g
,
PBPR
jobp
);
my_bool
LocateValue
(
PGLOBAL
g
,
PBVAL
jvp
);
my_bool
LocateArrayAll
(
PGLOBAL
g
,
PBVAL
jarp
);
my_bool
LocateObjectAll
(
PGLOBAL
g
,
PBPR
jobp
);
my_bool
LocateValueAll
(
PGLOBAL
g
,
PBVAL
jvp
);
my_bool
CompareTree
(
PGLOBAL
g
,
PBVAL
jp1
,
PBVAL
jp2
);
my_bool
AddPath
(
void
);
// Default constructor not to be used
BJNX
(
void
)
{}
// Members
PBVAL
Row
;
PBVAL
Bvalp
;
PJPN
Jpnp
;
JOUTSTR
*
Jp
;
JNODE
*
Nodes
;
// The intermediate objects
PVAL
Value
;
PVAL
MulVal
;
// To value used by multiple column
char
*
Jpath
;
// The json path
int
Buf_Type
;
int
Long
;
int
Prec
;
int
Nod
;
// The number of intermediate objects
int
Xnod
;
// Index of multiple values
int
K
;
// Kth item to locate
int
I
;
// Index of JPN
int
Imax
;
// Max number of JPN's
int
B
;
// Index base
my_bool
Xpd
;
// True for expandable column
my_bool
Parsed
;
// True when parsed
my_bool
Found
;
// Item found by locate
my_bool
Wr
;
// Write mode
my_bool
Jb
;
// Must return json item
};
// end of class BJNX
extern
"C"
{
DllExport
my_bool
json_test_bson_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
char
*
json_test_bson
(
UDF_EXEC_ARGS
);
DllExport
void
json_test_bson_deinit
(
UDF_INIT
*
);
DllExport
my_bool
jsonlocate_bson_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
char
*
jsonlocate_bson
(
UDF_EXEC_ARGS
);
DllExport
void
jsonlocate_bson_deinit
(
UDF_INIT
*
);
DllExport
my_bool
json_locate_all_bson_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
char
*
json_locate_all_bson
(
UDF_EXEC_ARGS
);
DllExport
void
json_locate_all_bson_deinit
(
UDF_INIT
*
);
}
// extern "C"
storage/connect/tabjson.cpp
View file @
dc8f914c
...
...
@@ -1596,6 +1596,7 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
if
(
Value
->
IsTypeNum
())
{
strcpy
(
g
->
Message
,
"Cannot make Json for a numeric column"
);
Value
->
Reset
();
#if 0
} else if (Value->GetType() == TYPE_BIN) {
if ((unsigned)Value->GetClen() >= sizeof(BSON)) {
ulong len = Tjp->Lrecl ? Tjp->Lrecl : 500;
...
...
@@ -1607,6 +1608,7 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
strcpy(g->Message, "Column size too small");
Value->SetValue_char(NULL, 0);
} // endif Clen
#endif 0
}
else
Value
->
SetValue_psz
(
Serialize
(
g
,
jsp
,
NULL
,
0
));
...
...
storage/connect/value.cpp
View file @
dc8f914c
...
...
@@ -197,7 +197,7 @@ const char *GetFormatType(int type)
case
TYPE_DOUBLE
:
c
=
"F"
;
break
;
case
TYPE_DATE
:
c
=
"D"
;
break
;
case
TYPE_TINY
:
c
=
"T"
;
break
;
case
TYPE_DECIM
:
c
=
"
M
"
;
break
;
case
TYPE_DECIM
:
c
=
"
F
"
;
break
;
case
TYPE_BIN
:
c
=
"B"
;
break
;
case
TYPE_PCHAR
:
c
=
"P"
;
break
;
}
// endswitch type
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment