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
6f93df1c
Commit
6f93df1c
authored
Feb 05, 2021
by
Oleksandr Byelkin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '10.2' into 10.3
parents
6212cf86
e7d9c1d4
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
500 additions
and
306 deletions
+500
-306
storage/connect/bson.cpp
storage/connect/bson.cpp
+57
-58
storage/connect/bson.h
storage/connect/bson.h
+9
-10
storage/connect/bsonudf.cpp
storage/connect/bsonudf.cpp
+272
-107
storage/connect/bsonudf.h
storage/connect/bsonudf.h
+10
-2
storage/connect/ha_connect.cc
storage/connect/ha_connect.cc
+13
-3
storage/connect/jsonudf.cpp
storage/connect/jsonudf.cpp
+3
-1
storage/connect/mysql-test/connect/r/bson_udf.result
storage/connect/mysql-test/connect/r/bson_udf.result
+44
-67
storage/connect/mysql-test/connect/t/bson_udf.inc
storage/connect/mysql-test/connect/t/bson_udf.inc
+2
-0
storage/connect/mysql-test/connect/t/bson_udf.test
storage/connect/mysql-test/connect/t/bson_udf.test
+1
-0
storage/connect/mysql-test/connect/t/bson_udf2.inc
storage/connect/mysql-test/connect/t/bson_udf2.inc
+2
-0
storage/connect/plugutil.cpp
storage/connect/plugutil.cpp
+1
-1
storage/connect/tabbson.cpp
storage/connect/tabbson.cpp
+74
-54
storage/connect/tabbson.h
storage/connect/tabbson.h
+5
-2
storage/connect/tabjson.cpp
storage/connect/tabjson.cpp
+7
-1
No files found.
storage/connect/bson.cpp
View file @
6f93df1c
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
#undef SE_CATCH // Does not work for Linux
#undef SE_CATCH // Does not work for Linux
#endif
#endif
int
GetJsonDefPrec
(
void
);
#if defined(SE_CATCH)
#if defined(SE_CATCH)
/**************************************************************************/
/**************************************************************************/
/* This is the support of catching C interrupts to prevent crashes. */
/* This is the support of catching C interrupts to prevent crashes. */
...
@@ -80,7 +82,7 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL)
...
@@ -80,7 +82,7 @@ BDOC::BDOC(PGLOBAL G) : BJSON(G, NULL)
/***********************************************************************/
/***********************************************************************/
PBVAL
BDOC
::
ParseJson
(
PGLOBAL
g
,
char
*
js
,
size_t
lng
)
PBVAL
BDOC
::
ParseJson
(
PGLOBAL
g
,
char
*
js
,
size_t
lng
)
{
{
int
i
;
size_t
i
;
bool
b
=
false
,
ptyp
=
(
bool
*
)
pty
;
bool
b
=
false
,
ptyp
=
(
bool
*
)
pty
;
PBVAL
bvp
=
NULL
;
PBVAL
bvp
=
NULL
;
...
@@ -183,7 +185,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
...
@@ -183,7 +185,7 @@ PBVAL BDOC::ParseJson(PGLOBAL g, char* js, size_t lng)
/***********************************************************************/
/***********************************************************************/
/* Parse several items as being in an array. */
/* Parse several items as being in an array. */
/***********************************************************************/
/***********************************************************************/
OFFSET
BDOC
::
ParseAsArray
(
in
t
&
i
)
{
OFFSET
BDOC
::
ParseAsArray
(
size_
t
&
i
)
{
if
(
pty
[
0
]
&&
(
!
pretty
||
pretty
>
2
))
{
if
(
pty
[
0
]
&&
(
!
pretty
||
pretty
>
2
))
{
OFFSET
jsp
;
OFFSET
jsp
;
...
@@ -200,7 +202,7 @@ OFFSET BDOC::ParseAsArray(int& i) {
...
@@ -200,7 +202,7 @@ OFFSET BDOC::ParseAsArray(int& i) {
/***********************************************************************/
/***********************************************************************/
/* Parse a JSON Array. */
/* Parse a JSON Array. */
/***********************************************************************/
/***********************************************************************/
OFFSET
BDOC
::
ParseArray
(
in
t
&
i
)
OFFSET
BDOC
::
ParseArray
(
size_
t
&
i
)
{
{
int
level
=
0
;
int
level
=
0
;
bool
b
=
(
!
i
);
bool
b
=
(
!
i
);
...
@@ -212,7 +214,7 @@ OFFSET BDOC::ParseArray(int& i)
...
@@ -212,7 +214,7 @@ OFFSET BDOC::ParseArray(int& i)
switch
(
s
[
i
])
{
switch
(
s
[
i
])
{
case
','
:
case
','
:
if
(
level
<
2
)
{
if
(
level
<
2
)
{
sprintf
(
G
->
Message
,
"Unexpected ',' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected ',' near %.*s"
,
(
int
)
ARGS
);
throw
1
;
throw
1
;
}
else
}
else
level
=
1
;
level
=
1
;
...
@@ -220,7 +222,7 @@ OFFSET BDOC::ParseArray(int& i)
...
@@ -220,7 +222,7 @@ OFFSET BDOC::ParseArray(int& i)
break
;
break
;
case
']'
:
case
']'
:
if
(
level
==
1
)
{
if
(
level
==
1
)
{
sprintf
(
G
->
Message
,
"Unexpected ',]' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected ',]' near %.*s"
,
(
int
)
ARGS
);
throw
1
;
throw
1
;
}
// endif level
}
// endif level
...
@@ -234,7 +236,7 @@ OFFSET BDOC::ParseArray(int& i)
...
@@ -234,7 +236,7 @@ OFFSET BDOC::ParseArray(int& i)
break
;
break
;
default:
default:
if
(
level
==
2
)
{
if
(
level
==
2
)
{
sprintf
(
G
->
Message
,
"Unexpected value near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected value near %.*s"
,
(
int
)
ARGS
);
throw
1
;
throw
1
;
}
else
if
(
lastvlp
)
{
}
else
if
(
lastvlp
)
{
vlp
=
ParseValue
(
i
,
NewVal
());
vlp
=
ParseValue
(
i
,
NewVal
());
...
@@ -258,7 +260,7 @@ OFFSET BDOC::ParseArray(int& i)
...
@@ -258,7 +260,7 @@ OFFSET BDOC::ParseArray(int& i)
/***********************************************************************/
/***********************************************************************/
/* Parse a JSON Object. */
/* Parse a JSON Object. */
/***********************************************************************/
/***********************************************************************/
OFFSET
BDOC
::
ParseObject
(
in
t
&
i
)
OFFSET
BDOC
::
ParseObject
(
size_
t
&
i
)
{
{
OFFSET
key
;
OFFSET
key
;
int
level
=
0
;
int
level
=
0
;
...
@@ -281,7 +283,7 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -281,7 +283,7 @@ OFFSET BDOC::ParseObject(int& i)
level
=
2
;
level
=
2
;
}
else
{
}
else
{
sprintf
(
G
->
Message
,
"misplaced string near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"misplaced string near %.*s"
,
(
int
)
ARGS
);
throw
2
;
throw
2
;
}
// endif level
}
// endif level
...
@@ -291,14 +293,14 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -291,14 +293,14 @@ OFFSET BDOC::ParseObject(int& i)
ParseValue
(
++
i
,
GetVlp
(
lastbpp
));
ParseValue
(
++
i
,
GetVlp
(
lastbpp
));
level
=
3
;
level
=
3
;
}
else
{
}
else
{
sprintf
(
G
->
Message
,
"Unexpected ':' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected ':' near %.*s"
,
(
int
)
ARGS
);
throw
2
;
throw
2
;
}
// endif level
}
// endif level
break
;
break
;
case
','
:
case
','
:
if
(
level
<
3
)
{
if
(
level
<
3
)
{
sprintf
(
G
->
Message
,
"Unexpected ',' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected ',' near %.*s"
,
(
int
)
ARGS
);
throw
2
;
throw
2
;
}
else
}
else
level
=
1
;
level
=
1
;
...
@@ -306,7 +308,7 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -306,7 +308,7 @@ OFFSET BDOC::ParseObject(int& i)
break
;
break
;
case
'}'
:
case
'}'
:
if
(
!
(
level
==
0
||
level
==
3
))
{
if
(
!
(
level
==
0
||
level
==
3
))
{
sprintf
(
G
->
Message
,
"Unexpected '}' near %.*s"
,
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected '}' near %.*s"
,
(
int
)
ARGS
);
throw
2
;
throw
2
;
}
// endif level
}
// endif level
...
@@ -319,7 +321,7 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -319,7 +321,7 @@ OFFSET BDOC::ParseObject(int& i)
break
;
break
;
default:
default:
sprintf
(
G
->
Message
,
"Unexpected character '%c' near %.*s"
,
sprintf
(
G
->
Message
,
"Unexpected character '%c' near %.*s"
,
s
[
i
],
ARGS
);
s
[
i
],
(
int
)
ARGS
);
throw
2
;
throw
2
;
};
// endswitch s[i]
};
// endswitch s[i]
...
@@ -330,7 +332,7 @@ OFFSET BDOC::ParseObject(int& i)
...
@@ -330,7 +332,7 @@ OFFSET BDOC::ParseObject(int& i)
/***********************************************************************/
/***********************************************************************/
/* Parse a JSON Value. */
/* Parse a JSON Value. */
/***********************************************************************/
/***********************************************************************/
PBVAL
BDOC
::
ParseValue
(
in
t
&
i
,
PBVAL
bvp
)
PBVAL
BDOC
::
ParseValue
(
size_
t
&
i
,
PBVAL
bvp
)
{
{
for
(;
i
<
len
;
i
++
)
for
(;
i
<
len
;
i
++
)
switch
(
s
[
i
])
{
switch
(
s
[
i
])
{
...
@@ -396,14 +398,14 @@ PBVAL BDOC::ParseValue(int& i, PBVAL bvp)
...
@@ -396,14 +398,14 @@ PBVAL BDOC::ParseValue(int& i, PBVAL bvp)
return
bvp
;
return
bvp
;
err:
err:
sprintf
(
G
->
Message
,
"Unexpected character '%c' near %.*s"
,
s
[
i
],
ARGS
);
sprintf
(
G
->
Message
,
"Unexpected character '%c' near %.*s"
,
s
[
i
],
(
int
)
ARGS
);
throw
3
;
throw
3
;
}
// end of ParseValue
}
// end of ParseValue
/***********************************************************************/
/***********************************************************************/
/* Unescape and parse a JSON string. */
/* Unescape and parse a JSON string. */
/***********************************************************************/
/***********************************************************************/
OFFSET
BDOC
::
ParseString
(
in
t
&
i
)
OFFSET
BDOC
::
ParseString
(
size_
t
&
i
)
{
{
uchar
*
p
;
uchar
*
p
;
int
n
=
0
;
int
n
=
0
;
...
@@ -490,7 +492,7 @@ throw("Unexpected EOF in String");
...
@@ -490,7 +492,7 @@ throw("Unexpected EOF in String");
/***********************************************************************/
/***********************************************************************/
/* Parse a JSON numeric value. */
/* Parse a JSON numeric value. */
/***********************************************************************/
/***********************************************************************/
void
BDOC
::
ParseNumeric
(
in
t
&
i
,
PBVAL
vlp
)
void
BDOC
::
ParseNumeric
(
size_
t
&
i
,
PBVAL
vlp
)
{
{
char
buf
[
50
];
char
buf
[
50
];
int
n
=
0
;
int
n
=
0
;
...
@@ -767,7 +769,7 @@ bool BDOC::SerializeValue(PBVAL jvp, bool b)
...
@@ -767,7 +769,7 @@ bool BDOC::SerializeValue(PBVAL jvp, bool b)
case
TYPE_DBL
:
case
TYPE_DBL
:
sprintf
(
buf
,
"%.*lf"
,
jvp
->
Nd
,
*
(
double
*
)
MakePtr
(
Base
,
jvp
->
To_Val
));
sprintf
(
buf
,
"%.*lf"
,
jvp
->
Nd
,
*
(
double
*
)
MakePtr
(
Base
,
jvp
->
To_Val
));
return
jp
->
WriteStr
(
buf
);
return
jp
->
WriteStr
(
buf
);
case
(
char
)
TYPE_NULL
:
case
TYPE_NULL
:
return
jp
->
WriteStr
(
"null"
);
return
jp
->
WriteStr
(
"null"
);
case
TYPE_JVAL
:
case
TYPE_JVAL
:
return
SerializeValue
(
MVP
(
jvp
->
To_Val
));
return
SerializeValue
(
MVP
(
jvp
->
To_Val
));
...
@@ -884,7 +886,6 @@ PBPR BJSON::NewPair(OFFSET key, int type)
...
@@ -884,7 +886,6 @@ PBPR BJSON::NewPair(OFFSET key, int type)
PBPR
bpp
=
(
PBPR
)
BsonSubAlloc
(
sizeof
(
BPAIR
));
PBPR
bpp
=
(
PBPR
)
BsonSubAlloc
(
sizeof
(
BPAIR
));
bpp
->
Key
=
key
;
bpp
->
Key
=
key
;
bpp
->
Vlp
.
Ktp
=
TYPE_STRG
;
bpp
->
Vlp
.
Type
=
type
;
bpp
->
Vlp
.
Type
=
type
;
bpp
->
Vlp
.
To_Val
=
0
;
bpp
->
Vlp
.
To_Val
=
0
;
bpp
->
Vlp
.
Nd
=
0
;
bpp
->
Vlp
.
Nd
=
0
;
...
@@ -1508,12 +1509,8 @@ double BJSON::GetDouble(PBVAL vp)
...
@@ -1508,12 +1509,8 @@ double BJSON::GetDouble(PBVAL vp)
d
=
(
double
)
vlp
->
N
;
d
=
(
double
)
vlp
->
N
;
break
;
break
;
case
TYPE_FLOAT
:
case
TYPE_FLOAT
:
{
char
buf
[
32
];
d
=
(
double
)
vlp
->
F
;
int
n
=
(
vlp
->
Nd
)
?
vlp
->
Nd
:
5
;
break
;
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
));
...
@@ -1557,7 +1554,7 @@ PSZ BJSON::GetString(PBVAL vp, char* buff)
...
@@ -1557,7 +1554,7 @@ PSZ BJSON::GetString(PBVAL vp, char* buff)
case
TYPE_BOOL
:
case
TYPE_BOOL
:
p
=
(
PSZ
)((
vlp
->
B
)
?
"true"
:
"false"
);
p
=
(
PSZ
)((
vlp
->
B
)
?
"true"
:
"false"
);
break
;
break
;
case
(
char
)
TYPE_NULL
:
case
TYPE_NULL
:
p
=
(
PSZ
)
"null"
;
p
=
(
PSZ
)
"null"
;
break
;
break
;
default:
default:
...
@@ -1721,14 +1718,22 @@ void BJSON::SetBigint(PBVAL vlp, longlong ll)
...
@@ -1721,14 +1718,22 @@ void BJSON::SetBigint(PBVAL vlp, longlong ll)
/***********************************************************************/
/***********************************************************************/
/* Set the Value's value as the given DOUBLE. */
/* Set the Value's value as the given DOUBLE. */
/***********************************************************************/
/***********************************************************************/
void
BJSON
::
SetFloat
(
PBVAL
vlp
,
double
d
,
int
nd
)
void
BJSON
::
SetFloat
(
PBVAL
vlp
,
double
d
,
int
prec
)
{
{
int
nd
=
MY_MIN
((
prec
<
0
)
?
GetJsonDefPrec
()
:
prec
,
16
);
if
(
nd
<
6
&&
d
>=
FLT_MIN
&&
d
<=
FLT_MAX
)
{
vlp
->
F
=
(
float
)
d
;
vlp
->
Type
=
TYPE_FLOAT
;
}
else
{
double
*
dp
=
(
double
*
)
BsonSubAlloc
(
sizeof
(
double
));
double
*
dp
=
(
double
*
)
BsonSubAlloc
(
sizeof
(
double
));
*
dp
=
d
;
*
dp
=
d
;
vlp
->
To_Val
=
MOF
(
dp
);
vlp
->
To_Val
=
MOF
(
dp
);
vlp
->
Nd
=
MY_MIN
(
nd
,
16
);
vlp
->
Type
=
TYPE_DBL
;
vlp
->
Type
=
TYPE_DBL
;
}
// endif nd
vlp
->
Nd
=
nd
;
}
// end of SetFloat
}
// end of SetFloat
/***********************************************************************/
/***********************************************************************/
...
@@ -1745,13 +1750,7 @@ void BJSON::SetFloat(PBVAL vlp, PSZ s)
...
@@ -1745,13 +1750,7 @@ void BJSON::SetFloat(PBVAL vlp, PSZ s)
for
(
--
p
;
*
p
==
'0'
;
nd
--
,
p
--
);
for
(
--
p
;
*
p
==
'0'
;
nd
--
,
p
--
);
}
// endif p
}
// endif p
if
(
nd
<
6
&&
d
>=
FLT_MIN
&&
d
<=
FLT_MAX
)
{
vlp
->
F
=
(
float
)
d
;
vlp
->
Nd
=
nd
;
vlp
->
Type
=
TYPE_FLOAT
;
}
else
SetFloat
(
vlp
,
d
,
nd
);
SetFloat
(
vlp
,
d
,
nd
);
}
// end of SetFloat
}
// end of SetFloat
/***********************************************************************/
/***********************************************************************/
...
@@ -1772,7 +1771,7 @@ bool BJSON::IsValueNull(PBVAL vlp)
...
@@ -1772,7 +1771,7 @@ bool BJSON::IsValueNull(PBVAL vlp)
bool
b
;
bool
b
;
switch
(
vlp
->
Type
)
{
switch
(
vlp
->
Type
)
{
case
(
char
)
TYPE_NULL
:
case
TYPE_NULL
:
b
=
true
;
b
=
true
;
break
;
break
;
case
TYPE_JOB
:
case
TYPE_JOB
:
...
...
storage/connect/bson.h
View file @
6f93df1c
...
@@ -37,8 +37,7 @@ typedef struct _jvalue {
...
@@ -37,8 +37,7 @@ typedef struct _jvalue {
bool
B
;
// A boolean value True or false (0)
bool
B
;
// A boolean value True or false (0)
};
};
short
Nd
;
// Number of decimals
short
Nd
;
// Number of decimals
char
Type
;
// The value type
short
Type
;
// The value type
char
Ktp
;
// The key type
OFFSET
Next
;
// Offset to the next value in array
OFFSET
Next
;
// Offset to the next value in array
}
BVAL
,
*
PBVAL
;
// end of struct BVALUE
}
BVAL
,
*
PBVAL
;
// end of struct BVALUE
...
@@ -149,7 +148,7 @@ class BJSON : public BLOCK {
...
@@ -149,7 +148,7 @@ class BJSON : public BLOCK {
void
SetString
(
PBVAL
vlp
,
PSZ
s
,
int
ci
=
0
);
void
SetString
(
PBVAL
vlp
,
PSZ
s
,
int
ci
=
0
);
void
SetInteger
(
PBVAL
vlp
,
int
n
);
void
SetInteger
(
PBVAL
vlp
,
int
n
);
void
SetBigint
(
PBVAL
vlp
,
longlong
ll
);
void
SetBigint
(
PBVAL
vlp
,
longlong
ll
);
void
SetFloat
(
PBVAL
vlp
,
double
f
,
int
nd
=
16
);
void
SetFloat
(
PBVAL
vlp
,
double
f
,
int
nd
=
-
1
);
void
SetFloat
(
PBVAL
vlp
,
PSZ
s
);
void
SetFloat
(
PBVAL
vlp
,
PSZ
s
);
void
SetBool
(
PBVAL
vlp
,
bool
b
);
void
SetBool
(
PBVAL
vlp
,
bool
b
);
void
Clear
(
PBVAL
vlp
)
{
vlp
->
N
=
0
;
vlp
->
Nd
=
0
;
vlp
->
Next
=
0
;
}
void
Clear
(
PBVAL
vlp
)
{
vlp
->
N
=
0
;
vlp
->
Nd
=
0
;
vlp
->
Next
=
0
;
}
...
@@ -185,12 +184,12 @@ class BDOC : public BJSON {
...
@@ -185,12 +184,12 @@ class BDOC : public BJSON {
PSZ
Serialize
(
PGLOBAL
g
,
PBVAL
bvp
,
char
*
fn
,
int
pretty
);
PSZ
Serialize
(
PGLOBAL
g
,
PBVAL
bvp
,
char
*
fn
,
int
pretty
);
protected:
protected:
OFFSET
ParseArray
(
in
t
&
i
);
OFFSET
ParseArray
(
size_
t
&
i
);
OFFSET
ParseObject
(
in
t
&
i
);
OFFSET
ParseObject
(
size_
t
&
i
);
PBVAL
ParseValue
(
in
t
&
i
,
PBVAL
bvp
);
PBVAL
ParseValue
(
size_
t
&
i
,
PBVAL
bvp
);
OFFSET
ParseString
(
in
t
&
i
);
OFFSET
ParseString
(
size_
t
&
i
);
void
ParseNumeric
(
in
t
&
i
,
PBVAL
bvp
);
void
ParseNumeric
(
size_
t
&
i
,
PBVAL
bvp
);
OFFSET
ParseAsArray
(
in
t
&
i
);
OFFSET
ParseAsArray
(
size_
t
&
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
b
=
false
);
bool
SerializeValue
(
PBVAL
vp
,
bool
b
=
false
);
...
@@ -198,7 +197,7 @@ class BDOC : public BJSON {
...
@@ -198,7 +197,7 @@ class BDOC : public BJSON {
// Members used when parsing and serializing
// Members used when parsing and serializing
JOUT
*
jp
;
// Used with serialize
JOUT
*
jp
;
// Used with serialize
char
*
s
;
// The Json string to parse
char
*
s
;
// The Json string to parse
int
len
;
// The Json string length
size_t
len
;
// The Json string length
int
pretty
;
// The pretty style of the file to parse
int
pretty
;
// The pretty style of the file to parse
bool
pty
[
3
];
// Used to guess what pretty is
bool
pty
[
3
];
// Used to guess what pretty is
bool
comma
;
// True if Pretty = 1
bool
comma
;
// True if Pretty = 1
...
...
storage/connect/bsonudf.cpp
View file @
6f93df1c
...
@@ -27,13 +27,23 @@
...
@@ -27,13 +27,23 @@
#endif
#endif
#define M 6
#define M 6
int
JsonDefPrec
=
-
1
;
int
GetDefaultPrec
(
void
);
int
IsArgJson
(
UDF_ARGS
*
args
,
uint
i
);
int
IsArgJson
(
UDF_ARGS
*
args
,
uint
i
);
void
SetChanged
(
PBSON
bsp
);
void
SetChanged
(
PBSON
bsp
);
int
GetJsonDefPrec
(
void
);
static
PBSON
BbinAlloc
(
PGLOBAL
g
,
ulong
len
,
PBVAL
jsp
);
static
PBSON
BbinAlloc
(
PGLOBAL
g
,
ulong
len
,
PBVAL
jsp
);
/* --------------------------------- JSON UDF ---------------------------------- */
/* --------------------------------- JSON UDF ---------------------------------- */
/*********************************************************************************/
/* Replaces GetJsonGrpSize not usable when CONNECT is not installed. */
/*********************************************************************************/
int
GetJsonDefPrec
(
void
)
{
return
(
JsonDefPrec
<
0
)
?
GetDefaultPrec
()
:
JsonDefPrec
;
}
/* end of GetJsonDefPrec */
/*********************************************************************************/
/*********************************************************************************/
/* Program for saving the status of the memory pools. */
/* Program for saving the status of the memory pools. */
/*********************************************************************************/
/*********************************************************************************/
...
@@ -109,7 +119,7 @@ BJNX::BJNX(PGLOBAL g) : BDOC(g)
...
@@ -109,7 +119,7 @@ BJNX::BJNX(PGLOBAL g) : BDOC(g)
Value
=
NULL
;
Value
=
NULL
;
MulVal
=
NULL
;
MulVal
=
NULL
;
Jpath
=
NULL
;
Jpath
=
NULL
;
Buf_Type
=
TYPE_
NULL
;
Buf_Type
=
TYPE_
STRING
;
Long
=
len
;
Long
=
len
;
Prec
=
0
;
Prec
=
0
;
Nod
=
0
;
Nod
=
0
;
...
@@ -164,10 +174,9 @@ BJNX::BJNX(PGLOBAL g, PBVAL row, int type, int len, int prec, my_bool wr) : BDOC
...
@@ -164,10 +174,9 @@ BJNX::BJNX(PGLOBAL g, PBVAL row, int type, int len, int prec, my_bool wr) : BDOC
my_bool
BJNX
::
SetJpath
(
PGLOBAL
g
,
char
*
path
,
my_bool
jb
)
my_bool
BJNX
::
SetJpath
(
PGLOBAL
g
,
char
*
path
,
my_bool
jb
)
{
{
// Check Value was allocated
// Check Value was allocated
if
(
!
Value
)
if
(
Value
)
return
true
;
Value
->
SetNullable
(
true
);
Value
->
SetNullable
(
true
);
Jpath
=
path
;
Jpath
=
path
;
// Parse the json path
// Parse the json path
...
@@ -264,6 +273,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm)
...
@@ -264,6 +273,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm)
return
true
;
return
true
;
}
// endif's
}
// endif's
#if 0
// For calculated arrays, a local Value must be used
// For calculated arrays, a local Value must be used
switch (jnp->Op) {
switch (jnp->Op) {
case OP_NUM:
case OP_NUM:
...
@@ -295,6 +305,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm)
...
@@ -295,6 +305,7 @@ my_bool BJNX::SetArrayOptions(PGLOBAL g, char* p, int i, PSZ nm)
if (jnp->Valp)
if (jnp->Valp)
MulVal = AllocateValue(g, jnp->Valp);
MulVal = AllocateValue(g, jnp->Valp);
#endif // 0
return
false
;
return
false
;
}
// end of SetArrayOptions
}
// end of SetArrayOptions
...
@@ -378,7 +389,7 @@ my_bool BJNX::ParseJpath(PGLOBAL g)
...
@@ -378,7 +389,7 @@ my_bool BJNX::ParseJpath(PGLOBAL g)
}
// endfor i, p
}
// endfor i, p
Nod
=
i
;
Nod
=
i
;
MulVal
=
AllocateValue
(
g
,
Value
);
//
MulVal = AllocateValue(g, Value);
if
(
trace
(
1
))
if
(
trace
(
1
))
for
(
i
=
0
;
i
<
Nod
;
i
++
)
for
(
i
=
0
;
i
<
Nod
;
i
++
)
...
@@ -435,20 +446,42 @@ PSZ BJNX::MakeKey(UDF_ARGS *args, int i)
...
@@ -435,20 +446,42 @@ PSZ BJNX::MakeKey(UDF_ARGS *args, int i)
}
// end of MakeKey
}
// end of MakeKey
/*********************************************************************************/
/*********************************************************************************/
/* MakeJson:
Serialize the json item and set value to it.
*/
/* MakeJson:
Make the Json tree to serialize.
*/
/*********************************************************************************/
/*********************************************************************************/
P
VAL
BJNX
::
MakeJson
(
PGLOBAL
g
,
PBVAL
bvp
)
P
BVAL
BJNX
::
MakeJson
(
PGLOBAL
g
,
PBVAL
bvp
,
int
n
)
{
{
if
(
Value
->
IsTypeNum
())
{
PBVAL
vlp
,
jvp
=
bvp
;
strcpy
(
g
->
Message
,
"Cannot make Json for a numeric value"
);
Value
->
Reset
();
}
else
if
(
bvp
->
Type
!=
TYPE_JAR
&&
bvp
->
Type
!=
TYPE_JOB
)
{
strcpy
(
g
->
Message
,
"Target is not an array or object"
);
Value
->
Reset
();
}
else
Value
->
SetValue_psz
(
Serialize
(
g
,
bvp
,
NULL
,
0
));
return
Value
;
if
(
n
<
Nod
-
1
)
{
if
(
bvp
->
Type
==
TYPE_JAR
)
{
int
ars
=
GetArraySize
(
bvp
);
PJNODE
jnp
=
&
Nodes
[
n
];
jvp
=
NewVal
(
TYPE_JAR
);
jnp
->
Op
=
OP_EQ
;
for
(
int
i
=
0
;
i
<
ars
;
i
++
)
{
jnp
->
Rank
=
i
;
vlp
=
GetRowValue
(
g
,
bvp
,
n
);
AddArrayValue
(
jvp
,
DupVal
(
vlp
));
}
// endfor i
jnp
->
Op
=
OP_XX
;
jnp
->
Rank
=
0
;
}
else
if
(
bvp
->
Type
==
TYPE_JOB
)
{
jvp
=
NewVal
(
TYPE_JOB
);
for
(
PBPR
prp
=
GetObject
(
bvp
);
prp
;
prp
=
GetNext
(
prp
))
{
vlp
=
GetRowValue
(
g
,
GetVlp
(
prp
),
n
+
1
);
SetKeyValue
(
jvp
,
vlp
,
MZP
(
prp
->
Key
));
}
// endfor prp
}
// endif Type
}
// endif n
Jb
=
true
;
return
jvp
;
}
// end of MakeJson
}
// end of MakeJson
/*********************************************************************************/
/*********************************************************************************/
...
@@ -461,15 +494,18 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
...
@@ -461,15 +494,18 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
if
(
Jb
)
{
if
(
Jb
)
{
vp
->
SetValue_psz
(
Serialize
(
g
,
vlp
,
NULL
,
0
));
vp
->
SetValue_psz
(
Serialize
(
g
,
vlp
,
NULL
,
0
));
Jb
=
false
;
}
else
switch
(
vlp
->
Type
)
{
}
else
switch
(
vlp
->
Type
)
{
case
TYPE_DTM
:
case
TYPE_DTM
:
case
TYPE_STRG
:
case
TYPE_STRG
:
vp
->
SetValue_psz
(
GetString
(
vlp
));
vp
->
SetValue_psz
(
GetString
(
vlp
));
break
;
break
;
case
TYPE_INTG
:
case
TYPE_INTG
:
case
TYPE_BINT
:
vp
->
SetValue
(
GetInteger
(
vlp
));
vp
->
SetValue
(
GetInteger
(
vlp
));
break
;
break
;
case
TYPE_BINT
:
vp
->
SetValue
(
GetBigint
(
vlp
));
break
;
case
TYPE_DBL
:
case
TYPE_DBL
:
case
TYPE_FLOAT
:
case
TYPE_FLOAT
:
if
(
vp
->
IsTypeNum
())
if
(
vp
->
IsTypeNum
())
...
@@ -491,7 +527,7 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
...
@@ -491,7 +527,7 @@ void BJNX::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL vlp)
case
TYPE_JOB
:
case
TYPE_JOB
:
vp
->
SetValue_psz
(
GetObjectText
(
g
,
vlp
,
NULL
));
vp
->
SetValue_psz
(
GetObjectText
(
g
,
vlp
,
NULL
));
break
;
break
;
case
(
char
)
TYPE_NULL
:
case
TYPE_NULL
:
vp
->
SetNull
(
true
);
vp
->
SetNull
(
true
);
default:
default:
vp
->
Reset
();
vp
->
Reset
();
...
@@ -534,7 +570,7 @@ PVAL BJNX::GetColumnValue(PGLOBAL g, PBVAL row, int i)
...
@@ -534,7 +570,7 @@ PVAL BJNX::GetColumnValue(PGLOBAL g, PBVAL row, int i)
/*********************************************************************************/
/*********************************************************************************/
/* GetRowValue: */
/* GetRowValue: */
/*********************************************************************************/
/*********************************************************************************/
PBVAL
BJNX
::
GetRowValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
,
my_bool
b
)
PBVAL
BJNX
::
GetRowValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
)
{
{
my_bool
expd
=
false
;
my_bool
expd
=
false
;
PBVAL
bap
;
PBVAL
bap
;
...
@@ -546,9 +582,7 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b)
...
@@ -546,9 +582,7 @@ PBVAL BJNX::GetRowValue(PGLOBAL g, PBVAL row, int i, my_bool b)
vlp
=
NewVal
(
Value
);
vlp
=
NewVal
(
Value
);
return
vlp
;
return
vlp
;
}
else
if
(
Nodes
[
i
].
Op
==
OP_XX
)
{
}
else
if
(
Nodes
[
i
].
Op
==
OP_XX
)
{
Jb
=
b
;
return
MakeJson
(
g
,
row
,
i
);
// return DupVal(g, row);
return
row
;
// or last line ???
}
else
if
(
Nodes
[
i
].
Op
==
OP_EXP
)
{
}
else
if
(
Nodes
[
i
].
Op
==
OP_EXP
)
{
PUSH_WARNING
(
"Expand not supported by this function"
);
PUSH_WARNING
(
"Expand not supported by this function"
);
return
NULL
;
return
NULL
;
...
@@ -613,20 +647,104 @@ PVAL BJNX::ExpandArray(PGLOBAL g, PBVAL arp, int n)
...
@@ -613,20 +647,104 @@ PVAL BJNX::ExpandArray(PGLOBAL g, PBVAL arp, int n)
}
// end of ExpandArray
}
// end of ExpandArray
/*********************************************************************************/
/*********************************************************************************/
/* CalculateArray: NIY */
/* Get the value used for calculating the array. */
/*********************************************************************************/
PVAL
BJNX
::
GetCalcValue
(
PGLOBAL
g
,
PBVAL
bap
,
int
n
)
{
// For calculated arrays, a local Value must be used
int
lng
=
0
;
short
type
,
prec
=
0
;
bool
b
=
n
<
Nod
-
1
;
PVAL
valp
;
PBVAL
vlp
,
vp
;
OPVAL
op
=
Nodes
[
n
].
Op
;
switch
(
op
)
{
case
OP_NUM
:
type
=
TYPE_INT
;
break
;
case
OP_ADD
:
case
OP_MULT
:
if
(
!
IsTypeNum
(
Buf_Type
))
{
type
=
TYPE_INT
;
prec
=
0
;
for
(
vlp
=
GetArray
(
bap
);
vlp
;
vlp
=
GetNext
(
vlp
))
{
vp
=
(
b
&&
IsJson
(
vlp
))
?
GetRowValue
(
g
,
vlp
,
n
+
1
)
:
vlp
;
switch
(
vp
->
Type
)
{
case
TYPE_BINT
:
if
(
type
==
TYPE_INT
)
type
=
TYPE_BIGINT
;
break
;
case
TYPE_DBL
:
case
TYPE_FLOAT
:
type
=
TYPE_DOUBLE
;
prec
=
MY_MAX
(
prec
,
vp
->
Nd
);
break
;
default:
break
;
}
// endswitch Type
}
// endfor vlp
}
else
{
type
=
Buf_Type
;
prec
=
GetPrecision
();
}
// endif Buf_Type
break
;
case
OP_SEP
:
if
(
IsTypeChar
(
Buf_Type
))
{
type
=
TYPE_DOUBLE
;
prec
=
2
;
}
else
{
type
=
Buf_Type
;
prec
=
GetPrecision
();
}
// endif Buf_Type
break
;
case
OP_MIN
:
case
OP_MAX
:
type
=
Buf_Type
;
lng
=
Long
;
prec
=
GetPrecision
();
break
;
case
OP_CNC
:
type
=
TYPE_STRING
;
if
(
IsTypeChar
(
Buf_Type
))
{
lng
=
(
Long
)
?
Long
:
512
;
prec
=
GetPrecision
();
}
else
lng
=
512
;
break
;
default:
break
;
}
// endswitch Op
return
valp
=
AllocateValue
(
g
,
type
,
lng
,
prec
);
}
// end of GetCalcValue
/*********************************************************************************/
/* CalculateArray */
/*********************************************************************************/
/*********************************************************************************/
PVAL
BJNX
::
CalculateArray
(
PGLOBAL
g
,
PBVAL
bap
,
int
n
)
PVAL
BJNX
::
CalculateArray
(
PGLOBAL
g
,
PBVAL
bap
,
int
n
)
{
{
int
i
,
ars
=
GetArraySize
(
bap
),
nv
=
0
;
int
i
,
ars
=
GetArraySize
(
bap
),
nv
=
0
;
bool
err
;
bool
err
;
OPVAL
op
=
Nodes
[
n
].
Op
;
OPVAL
op
=
Nodes
[
n
].
Op
;
PVAL
val
[
2
],
vp
=
Nodes
[
n
].
Valp
;
PVAL
val
[
2
],
vp
=
GetCalcValue
(
g
,
bap
,
n
);
PVAL
mulval
=
AllocateValue
(
g
,
vp
);
PBVAL
bvrp
,
bvp
;
PBVAL
bvrp
,
bvp
;
BVAL
bval
;
BVAL
bval
;
vp
->
Reset
();
vp
->
Reset
();
xtrc
(
1
,
"CalculateArray size=%d op=%d
\n
"
,
ars
,
op
);
xtrc
(
1
,
"CalculateArray size=%d op=%d
\n
"
,
ars
,
op
);
try
{
for
(
i
=
0
;
i
<
ars
;
i
++
)
{
for
(
i
=
0
;
i
<
ars
;
i
++
)
{
bvrp
=
GetArrayValue
(
bap
,
i
);
bvrp
=
GetArrayValue
(
bap
,
i
);
xtrc
(
1
,
"i=%d nv=%d
\n
"
,
i
,
nv
);
xtrc
(
1
,
"i=%d nv=%d
\n
"
,
i
,
nv
);
...
@@ -649,9 +767,9 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
...
@@ -649,9 +767,9 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
SetJsonValue
(
g
,
vp
,
bvp
);
SetJsonValue
(
g
,
vp
,
bvp
);
continue
;
continue
;
}
else
}
else
SetJsonValue
(
g
,
MulV
al
,
bvp
);
SetJsonValue
(
g
,
mulv
al
,
bvp
);
if
(
!
MulV
al
->
IsNull
())
{
if
(
!
mulv
al
->
IsNull
())
{
switch
(
op
)
{
switch
(
op
)
{
case
OP_CNC
:
case
OP_CNC
:
if
(
Nodes
[
n
].
CncVal
)
{
if
(
Nodes
[
n
].
CncVal
)
{
...
@@ -659,18 +777,18 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
...
@@ -659,18 +777,18 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
err
=
vp
->
Compute
(
g
,
val
,
1
,
op
);
err
=
vp
->
Compute
(
g
,
val
,
1
,
op
);
}
// endif CncVal
}
// endif CncVal
val
[
0
]
=
MulV
al
;
val
[
0
]
=
mulv
al
;
err
=
vp
->
Compute
(
g
,
val
,
1
,
op
);
err
=
vp
->
Compute
(
g
,
val
,
1
,
op
);
break
;
break
;
// case OP_NUM:
// case OP_NUM:
case
OP_SEP
:
case
OP_SEP
:
val
[
0
]
=
Nodes
[
n
].
Val
p
;
val
[
0
]
=
v
p
;
val
[
1
]
=
MulV
al
;
val
[
1
]
=
mulv
al
;
err
=
vp
->
Compute
(
g
,
val
,
2
,
OP_ADD
);
err
=
vp
->
Compute
(
g
,
val
,
2
,
OP_ADD
);
break
;
break
;
default:
default:
val
[
0
]
=
Nodes
[
n
].
Val
p
;
val
[
0
]
=
v
p
;
val
[
1
]
=
MulV
al
;
val
[
1
]
=
mulv
al
;
err
=
vp
->
Compute
(
g
,
val
,
2
,
op
);
err
=
vp
->
Compute
(
g
,
val
,
2
,
op
);
}
// endswitch Op
}
// endswitch Op
...
@@ -692,15 +810,22 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
...
@@ -692,15 +810,22 @@ PVAL BJNX::CalculateArray(PGLOBAL g, PBVAL bap, int n)
if
(
op
==
OP_SEP
)
{
if
(
op
==
OP_SEP
)
{
// Calculate average
// Calculate average
MulV
al
->
SetValue
(
nv
);
mulv
al
->
SetValue
(
nv
);
val
[
0
]
=
vp
;
val
[
0
]
=
vp
;
val
[
1
]
=
MulV
al
;
val
[
1
]
=
mulv
al
;
if
(
vp
->
Compute
(
g
,
val
,
2
,
OP_DIV
))
if
(
vp
->
Compute
(
g
,
val
,
2
,
OP_DIV
))
vp
->
Reset
();
vp
->
Reset
();
}
// endif Op
}
// endif Op
}
catch
(
int
n
)
{
xtrc
(
1
,
"Exception %d: %s
\n
"
,
n
,
g
->
Message
);
PUSH_WARNING
(
g
->
Message
);
}
catch
(
const
char
*
msg
)
{
strcpy
(
g
->
Message
,
msg
);
}
// end catch
return
vp
;
return
vp
;
}
// end of CalculateArray
}
// end of CalculateArray
...
@@ -1320,7 +1445,7 @@ my_bool BJNX::CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2)
...
@@ -1320,7 +1445,7 @@ my_bool BJNX::CompareValues(PGLOBAL g, PBVAL v1, PBVAL v2)
b
=
(
v1
->
B
==
v2
->
B
);
b
=
(
v1
->
B
==
v2
->
B
);
break
;
break
;
case
(
char
)
TYPE_NULL
:
case
TYPE_NULL
:
b
=
(
v2
->
Type
==
TYPE_NULL
);
b
=
(
v2
->
Type
==
TYPE_NULL
);
break
;
break
;
default:
default:
...
@@ -1545,7 +1670,7 @@ PBVAL BJNX::ParseJsonFile(PGLOBAL g, char *fn, int& pty, size_t& len)
...
@@ -1545,7 +1670,7 @@ PBVAL BJNX::ParseJsonFile(PGLOBAL g, char *fn, int& pty, size_t& len)
len
=
(
size_t
)
mm
.
lenL
;
len
=
(
size_t
)
mm
.
lenL
;
if
(
mm
.
lenH
)
if
(
mm
.
lenH
)
len
+=
((
size_t
)
mm
.
lenH
*
0x000000001LL
)
;
len
+=
mm
.
lenH
;
memory
=
(
char
*
)
mm
.
memory
;
memory
=
(
char
*
)
mm
.
memory
;
...
@@ -2700,6 +2825,45 @@ void bson_object_values_deinit(UDF_INIT* initid)
...
@@ -2700,6 +2825,45 @@ void bson_object_values_deinit(UDF_INIT* initid)
JsonFreeMem
((
PGLOBAL
)
initid
->
ptr
);
JsonFreeMem
((
PGLOBAL
)
initid
->
ptr
);
}
// end of bson_object_values_deinit
}
// end of bson_object_values_deinit
/*********************************************************************************/
/* Set the value of JsonGrpSize. */
/*********************************************************************************/
my_bool
bsonset_def_prec_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
)
{
if
(
args
->
arg_count
!=
1
||
args
->
arg_type
[
0
]
!=
INT_RESULT
)
{
strcpy
(
message
,
"This function must have 1 integer argument"
);
return
true
;
}
else
return
false
;
}
// end of bsonset_def_prec_init
long
long
bsonset_def_prec
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
,
char
*
)
{
long
long
n
=
*
(
long
long
*
)
args
->
args
[
0
];
JsonDefPrec
=
(
int
)
n
;
return
(
long
long
)
GetJsonDefPrec
();
}
// end of bsonset_def_prec
/*********************************************************************************/
/* Get the value of JsonGrpSize. */
/*********************************************************************************/
my_bool
bsonget_def_prec_init
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
message
)
{
if
(
args
->
arg_count
!=
0
)
{
strcpy
(
message
,
"This function must have no arguments"
);
return
true
;
}
else
return
false
;
}
// end of bsonget_def_prec_init
long
long
bsonget_def_prec
(
UDF_INIT
*
initid
,
UDF_ARGS
*
args
,
char
*
,
char
*
)
{
return
(
long
long
)
GetJsonDefPrec
();
}
// end of bsonget_def_prec
/*********************************************************************************/
/*********************************************************************************/
/* Set the value of JsonGrpSize. */
/* Set the value of JsonGrpSize. */
/*********************************************************************************/
/*********************************************************************************/
...
@@ -2858,7 +3022,7 @@ void bson_object_grp_add(UDF_INIT *initid, UDF_ARGS *args, char*, char*)
...
@@ -2858,7 +3022,7 @@ void bson_object_grp_add(UDF_INIT *initid, UDF_ARGS *args, char*, char*)
PBVAL
bop
=
(
PBVAL
)
g
->
Activityp
;
PBVAL
bop
=
(
PBVAL
)
g
->
Activityp
;
if
(
g
->
N
--
>
0
)
if
(
g
->
N
--
>
0
)
bxp
->
SetKeyValue
(
bop
,
bxp
->
MakeValue
(
args
,
0
),
MakePSZ
(
g
,
args
,
1
));
bxp
->
SetKeyValue
(
bop
,
bxp
->
MakeValue
(
args
,
1
),
MakePSZ
(
g
,
args
,
0
));
}
// end of bson_object_grp_add
}
// end of bson_object_grp_add
...
@@ -3532,8 +3696,8 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
...
@@ -3532,8 +3696,8 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
{
{
char
*
path
,
*
str
=
NULL
;
char
*
path
,
*
str
=
NULL
;
PBVAL
jvp
;
PBVAL
jvp
;
PBJNX
bxp
=
NULL
;
PGLOBAL
g
=
(
PGLOBAL
)
initid
->
ptr
;
PGLOBAL
g
=
(
PGLOBAL
)
initid
->
ptr
;
BJNX
bnx
(
g
,
NULL
,
TYPE_STRING
,
initid
->
max_length
);
if
(
g
->
N
)
{
if
(
g
->
N
)
{
str
=
(
char
*
)
g
->
Activityp
;
str
=
(
char
*
)
g
->
Activityp
;
...
@@ -3546,8 +3710,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
...
@@ -3546,8 +3710,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
PUSH_WARNING
(
"CheckMemory error"
);
PUSH_WARNING
(
"CheckMemory error"
);
goto
fin
;
goto
fin
;
}
else
{
}
else
{
BJNX
bnx
(
g
);
bnx
.
Reset
();
jvp
=
bnx
.
MakeValue
(
args
,
0
,
true
);
jvp
=
bnx
.
MakeValue
(
args
,
0
,
true
);
if
(
g
->
Mrr
)
{
// First argument is a constant
if
(
g
->
Mrr
)
{
// First argument is a constant
...
@@ -3561,16 +3724,16 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
...
@@ -3561,16 +3724,16 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
jvp
=
(
PBVAL
)
g
->
Xchk
;
jvp
=
(
PBVAL
)
g
->
Xchk
;
path
=
MakePSZ
(
g
,
args
,
1
);
path
=
MakePSZ
(
g
,
args
,
1
);
bxp
=
new
(
g
)
BJNX
(
g
,
jvp
,
TYPE_STRING
,
initid
->
max_length
);
if
(
bxp
->
SetJpath
(
g
,
path
,
true
))
{
if
(
bnx
.
SetJpath
(
g
,
path
,
true
))
{
PUSH_WARNING
(
g
->
Message
);
goto
fin
;
goto
fin
;
}
else
}
else
bxp
->
ReadValue
(
g
);
jvp
=
bnx
.
GetRowValue
(
g
,
jvp
,
0
);
if
(
!
bxp
->
GetValue
()
->
IsNull
())
if
(
!
bnx
.
IsJson
(
jvp
))
{
str
=
bxp
->
GetValue
()
->
GetCharValue
();
strcpy
(
g
->
Message
,
"Not a Json item"
);
}
else
str
=
bnx
.
Serialize
(
g
,
jvp
,
NULL
,
0
);
if
(
initid
->
const_item
)
if
(
initid
->
const_item
)
// Keep result of constant function
// Keep result of constant function
...
@@ -3578,6 +3741,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
...
@@ -3578,6 +3741,7 @@ char *bson_get_item(UDF_INIT *initid, UDF_ARGS *args, char *result,
fin:
fin:
if
(
!
str
)
{
if
(
!
str
)
{
PUSH_WARNING
(
g
->
Message
);
*
is_null
=
1
;
*
is_null
=
1
;
*
res_length
=
0
;
*
res_length
=
0
;
}
else
}
else
...
@@ -3872,8 +4036,8 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
...
@@ -3872,8 +4036,8 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
char
*
p
,
*
path
;
char
*
p
,
*
path
;
double
d
;
double
d
;
PBVAL
jsp
,
jvp
;
PBVAL
jsp
,
jvp
;
PBJNX
bxp
=
NULL
;
PGLOBAL
g
=
(
PGLOBAL
)
initid
->
ptr
;
PGLOBAL
g
=
(
PGLOBAL
)
initid
->
ptr
;
BJNX
bnx
(
g
);
if
(
g
->
N
)
{
if
(
g
->
N
)
{
if
(
!
g
->
Activityp
)
{
if
(
!
g
->
Activityp
)
{
...
@@ -3892,8 +4056,7 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
...
@@ -3892,8 +4056,7 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
*
is_null
=
1
;
*
is_null
=
1
;
return
0.0
;
return
0.0
;
}
else
{
}
else
{
BJNX
bnx
(
g
);
bnx
.
Reset
();
jvp
=
bnx
.
MakeValue
(
args
,
0
);
jvp
=
bnx
.
MakeValue
(
args
,
0
);
if
((
p
=
bnx
.
GetString
(
jvp
)))
{
if
((
p
=
bnx
.
GetString
(
jvp
)))
{
...
@@ -3916,21 +4079,22 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
...
@@ -3916,21 +4079,22 @@ double bsonget_real(UDF_INIT *initid, UDF_ARGS *args,
jsp
=
(
PBVAL
)
g
->
Xchk
;
jsp
=
(
PBVAL
)
g
->
Xchk
;
path
=
MakePSZ
(
g
,
args
,
1
);
path
=
MakePSZ
(
g
,
args
,
1
);
bxp
=
new
(
g
)
BJNX
(
g
,
jsp
,
TYPE_DOUBLE
);
//bxp = new(g) BJNX(g, jsp, TYPE_DOUBLE, 32, jsp->Nd
);
if
(
b
xp
->
SetJpath
(
g
,
path
))
{
if
(
b
nx
.
SetJpath
(
g
,
path
))
{
PUSH_WARNING
(
g
->
Message
);
PUSH_WARNING
(
g
->
Message
);
*
is_null
=
1
;
*
is_null
=
1
;
return
0.0
;
return
0.0
;
}
else
}
else
bxp
->
ReadValue
(
g
);
jvp
=
bnx
.
GetRowValue
(
g
,
jsp
,
0
);
if
(
bxp
->
GetValue
()
->
IsNull
(
))
{
if
(
!
jvp
||
bnx
.
IsValueNull
(
jvp
))
{
*
is_null
=
1
;
*
is_null
=
1
;
return
0.0
;
return
0.0
;
}
// endif IsNull
}
else
if
(
args
->
arg_count
==
2
)
{
d
=
atof
(
bnx
.
GetString
(
jvp
));
d
=
bxp
->
GetValue
()
->
GetFloatValue
();
}
else
d
=
bnx
.
GetDouble
(
jvp
);
if
(
initid
->
const_item
)
{
if
(
initid
->
const_item
)
{
// Keep result of constant function
// Keep result of constant function
...
@@ -4716,7 +4880,8 @@ char *bson_serialize(UDF_INIT *initid, UDF_ARGS *args, char *result,
...
@@ -4716,7 +4880,8 @@ char *bson_serialize(UDF_INIT *initid, UDF_ARGS *args, char *result,
BJNX
bnx
(
bsp
->
G
);
BJNX
bnx
(
bsp
->
G
);
PBVAL
bvp
=
(
args
->
arg_count
==
1
)
?
(
PBVAL
)
bsp
->
Jsp
:
(
PBVAL
)
bsp
->
Top
;
PBVAL
bvp
=
(
args
->
arg_count
==
1
)
?
(
PBVAL
)
bsp
->
Jsp
:
(
PBVAL
)
bsp
->
Top
;
if
(
!
(
str
=
bnx
.
Serialize
(
g
,
bvp
,
bsp
->
Filename
,
bsp
->
Pretty
)))
// if (!(str = bnx.Serialize(g, bvp, bsp->Filename, bsp->Pretty)))
if
(
!
(
str
=
bnx
.
Serialize
(
g
,
bvp
,
NULL
,
0
)))
str
=
strcpy
(
result
,
g
->
Message
);
str
=
strcpy
(
result
,
g
->
Message
);
// Keep result of constant function
// Keep result of constant function
...
...
storage/connect/bsonudf.h
View file @
6f93df1c
...
@@ -81,6 +81,7 @@ typedef struct _jpn {
...
@@ -81,6 +81,7 @@ typedef struct _jpn {
extern
uint
JsonGrpSize
;
extern
uint
JsonGrpSize
;
uint
GetJsonGroupSize
(
void
);
uint
GetJsonGroupSize
(
void
);
typedef
class
BJNX
*
PBJNX
;
typedef
class
BJNX
*
PBJNX
;
/*********************************************************************************/
/*********************************************************************************/
...
@@ -102,7 +103,7 @@ class BJNX : public BDOC {
...
@@ -102,7 +103,7 @@ class BJNX : public BDOC {
my_bool
SetJpath
(
PGLOBAL
g
,
char
*
path
,
my_bool
jb
=
false
);
my_bool
SetJpath
(
PGLOBAL
g
,
char
*
path
,
my_bool
jb
=
false
);
my_bool
ParseJpath
(
PGLOBAL
g
);
my_bool
ParseJpath
(
PGLOBAL
g
);
void
ReadValue
(
PGLOBAL
g
);
void
ReadValue
(
PGLOBAL
g
);
PBVAL
GetRowValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
,
my_bool
b
=
true
);
PBVAL
GetRowValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PBVAL
GetJson
(
PGLOBAL
g
);
PBVAL
GetJson
(
PGLOBAL
g
);
my_bool
CheckPath
(
PGLOBAL
g
);
my_bool
CheckPath
(
PGLOBAL
g
);
my_bool
CheckPath
(
PGLOBAL
g
,
UDF_ARGS
*
args
,
PBVAL
jsp
,
PBVAL
&
jvp
,
int
n
);
my_bool
CheckPath
(
PGLOBAL
g
,
UDF_ARGS
*
args
,
PBVAL
jsp
,
PBVAL
&
jvp
,
int
n
);
...
@@ -123,7 +124,8 @@ class BJNX : public BDOC {
...
@@ -123,7 +124,8 @@ class BJNX : public BDOC {
PVAL
GetColumnValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PVAL
GetColumnValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PVAL
ExpandArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
ExpandArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
CalculateArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
CalculateArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
MakeJson
(
PGLOBAL
g
,
PBVAL
bvp
);
PVAL
GetCalcValue
(
PGLOBAL
g
,
PBVAL
bap
,
int
n
);
PBVAL
MakeJson
(
PGLOBAL
g
,
PBVAL
bvp
,
int
n
);
void
SetJsonValue
(
PGLOBAL
g
,
PVAL
vp
,
PBVAL
vlp
);
void
SetJsonValue
(
PGLOBAL
g
,
PVAL
vp
,
PBVAL
vlp
);
PBVAL
GetRow
(
PGLOBAL
g
);
PBVAL
GetRow
(
PGLOBAL
g
);
PBVAL
MoveVal
(
PBVAL
vlp
);
PBVAL
MoveVal
(
PBVAL
vlp
);
...
@@ -259,6 +261,12 @@ extern "C" {
...
@@ -259,6 +261,12 @@ extern "C" {
DllExport
double
bsonget_real
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
DllExport
double
bsonget_real
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
DllExport
void
bsonget_real_deinit
(
UDF_INIT
*
);
DllExport
void
bsonget_real_deinit
(
UDF_INIT
*
);
DllExport
my_bool
bsonset_def_prec_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
long
long
bsonset_def_prec
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
DllExport
my_bool
bsonget_def_prec_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
long
long
bsonget_def_prec
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
DllExport
my_bool
bsonset_grp_size_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
my_bool
bsonset_grp_size_init
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
);
DllExport
long
long
bsonset_grp_size
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
DllExport
long
long
bsonset_grp_size
(
UDF_INIT
*
,
UDF_ARGS
*
,
char
*
,
char
*
);
...
...
storage/connect/ha_connect.cc
View file @
6f93df1c
...
@@ -170,7 +170,7 @@
...
@@ -170,7 +170,7 @@
#define JSONMAX 10 // JSON Default max grp size
#define JSONMAX 10 // JSON Default max grp size
extern
"C"
{
extern
"C"
{
char
version
[]
=
"Version 1.07.0002
December 25, 2020
"
;
char
version
[]
=
"Version 1.07.0002
January 27, 2021
"
;
#if defined(__WIN__)
#if defined(__WIN__)
char
compver
[]
=
"Version 1.07.0002 "
__DATE__
" "
__TIME__
;
char
compver
[]
=
"Version 1.07.0002 "
__DATE__
" "
__TIME__
;
char
slash
=
'\\'
;
char
slash
=
'\\'
;
...
@@ -255,6 +255,7 @@ USETEMP UseTemp(void);
...
@@ -255,6 +255,7 @@ USETEMP UseTemp(void);
int
GetConvSize
(
void
);
int
GetConvSize
(
void
);
TYPCONV
GetTypeConv
(
void
);
TYPCONV
GetTypeConv
(
void
);
int
GetDefaultDepth
(
void
);
int
GetDefaultDepth
(
void
);
int
GetDefaultPrec
(
void
);
bool
JsonAllPath
(
void
);
bool
JsonAllPath
(
void
);
char
*
GetJsonNull
(
void
);
char
*
GetJsonNull
(
void
);
uint
GetJsonGrpSize
(
void
);
uint
GetJsonGrpSize
(
void
);
...
@@ -418,6 +419,12 @@ static MYSQL_THDVAR_INT(default_depth,
...
@@ -418,6 +419,12 @@ static MYSQL_THDVAR_INT(default_depth,
"Default depth used by Json, XML and Mongo discovery"
,
"Default depth used by Json, XML and Mongo discovery"
,
NULL
,
NULL
,
5
,
-
1
,
16
,
1
);
// Defaults to 5
NULL
,
NULL
,
5
,
-
1
,
16
,
1
);
// Defaults to 5
// Default precision for doubles
static
MYSQL_THDVAR_INT
(
default_prec
,
PLUGIN_VAR_RQCMDARG
,
"Default precision used for doubles"
,
NULL
,
NULL
,
6
,
0
,
16
,
1
);
// Defaults to 6
// Estimate max number of rows for JSON aggregate functions
// Estimate max number of rows for JSON aggregate functions
static
MYSQL_THDVAR_UINT
(
json_grp_size
,
static
MYSQL_THDVAR_UINT
(
json_grp_size
,
PLUGIN_VAR_RQCMDARG
,
// opt
PLUGIN_VAR_RQCMDARG
,
// opt
...
@@ -493,6 +500,7 @@ TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
...
@@ -493,6 +500,7 @@ TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
char
*
GetJsonNull
(
void
)
char
*
GetJsonNull
(
void
)
{
return
connect_hton
?
THDVAR
(
current_thd
,
json_null
)
:
NULL
;}
{
return
connect_hton
?
THDVAR
(
current_thd
,
json_null
)
:
NULL
;}
int
GetDefaultDepth
(
void
)
{
return
THDVAR
(
current_thd
,
default_depth
);}
int
GetDefaultDepth
(
void
)
{
return
THDVAR
(
current_thd
,
default_depth
);}
int
GetDefaultPrec
(
void
)
{
return
THDVAR
(
current_thd
,
default_prec
);}
uint
GetJsonGrpSize
(
void
)
uint
GetJsonGrpSize
(
void
)
{
return
connect_hton
?
THDVAR
(
current_thd
,
json_grp_size
)
:
10
;}
{
return
connect_hton
?
THDVAR
(
current_thd
,
json_grp_size
)
:
10
;}
size_t
GetWorkSize
(
void
)
{
return
(
size_t
)
THDVAR
(
current_thd
,
work_size
);}
size_t
GetWorkSize
(
void
)
{
return
(
size_t
)
THDVAR
(
current_thd
,
work_size
);}
...
@@ -4831,6 +4839,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
...
@@ -4831,6 +4839,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
lock.cc by lock_external() and unlock_external() in lock.cc;
lock.cc by lock_external() and unlock_external() in lock.cc;
the section "locking functions for mysql" in lock.cc;
the section "locking functions for mysql" in lock.cc;
copy_data_between_tables() in sql_table.cc.
copy_data_between_tables() in sql_table.cc.
*/
*/
int
ha_connect
::
external_lock
(
THD
*
thd
,
int
lock_type
)
int
ha_connect
::
external_lock
(
THD
*
thd
,
int
lock_type
)
{
{
...
@@ -7444,6 +7453,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
...
@@ -7444,6 +7453,7 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR
(
json_null
),
MYSQL_SYSVAR
(
json_null
),
MYSQL_SYSVAR
(
json_all_path
),
MYSQL_SYSVAR
(
json_all_path
),
MYSQL_SYSVAR
(
default_depth
),
MYSQL_SYSVAR
(
default_depth
),
MYSQL_SYSVAR
(
default_prec
),
MYSQL_SYSVAR
(
json_grp_size
),
MYSQL_SYSVAR
(
json_grp_size
),
#if defined(JAVA_SUPPORT)
#if defined(JAVA_SUPPORT)
MYSQL_SYSVAR
(
jvm_path
),
MYSQL_SYSVAR
(
jvm_path
),
...
...
storage/connect/jsonudf.cpp
View file @
6f93df1c
...
@@ -356,9 +356,11 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val)
...
@@ -356,9 +356,11 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val)
vp
->
SetValue_psz
(
val
->
GetString
(
g
));
vp
->
SetValue_psz
(
val
->
GetString
(
g
));
break
;
break
;
case
TYPE_INTG
:
case
TYPE_INTG
:
case
TYPE_BINT
:
vp
->
SetValue
(
val
->
GetInteger
());
vp
->
SetValue
(
val
->
GetInteger
());
break
;
break
;
case
TYPE_BINT
:
vp
->
SetValue
(
val
->
GetBigint
());
break
;
case
TYPE_DBL
:
case
TYPE_DBL
:
if
(
vp
->
IsTypeNum
())
if
(
vp
->
IsTypeNum
())
vp
->
SetValue
(
val
->
GetFloat
());
vp
->
SetValue
(
val
->
GetFloat
());
...
...
storage/connect/mysql-test/connect/r/bson_udf.result
View file @
6f93df1c
...
@@ -176,6 +176,9 @@ Value List
...
@@ -176,6 +176,9 @@ Value List
#
#
# Test UDF's with column arguments
# Test UDF's with column arguments
#
#
SELECT Bsonset_Def_Prec(2);
Bsonset_Def_Prec(2)
2
CREATE TABLE t2
CREATE TABLE t2
(
(
ISBN CHAR(15),
ISBN CHAR(15),
...
@@ -213,7 +216,7 @@ SALARY DOUBLE(8,2) NOT NULL FLAG=52
...
@@ -213,7 +216,7 @@ SALARY DOUBLE(8,2) NOT NULL FLAG=52
) ENGINE=CONNECT TABLE_TYPE=FIX BLOCK_SIZE=8 FILE_NAME='employee.dat' ENDING=1;
) 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 Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY) FROM t3 WHERE NAME = 'MERCHANT';
Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY)
Bson_Make_Object(SERIALNO, NAME, TITLE, SALARY)
{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.00
00000000000000
}
{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.00}
SELECT DEPARTMENT, Bson_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT;
SELECT DEPARTMENT, Bson_Array_Grp(NAME) FROM t3 GROUP BY DEPARTMENT;
DEPARTMENT Bson_Array_Grp(NAME)
DEPARTMENT Bson_Array_Grp(NAME)
0021 ["STRONG","SHORTSIGHT"]
0021 ["STRONG","SHORTSIGHT"]
...
@@ -249,41 +252,41 @@ Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES)
...
@@ -249,41 +252,41 @@ Bson_Make_Object(DEPARTMENT, Bson_Array_Grp(NAME) json_NAMES)
{"DEPARTMENT":"2452","NAMES":["BIGHEAD","ORELLY","BIGHORN","SMITH","CHERRY"]}
{"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;
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)
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.00
00000000000000},{"SERIALNO":"22222","NAME":"SHORTSIGHT","TITLE":"SECRETARY","SALARY":5500.00000000000000
00}]}
{"DEPARTMENT":"0021","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","TITLE":"DIRECTOR","SALARY":23000.00
},{"SERIALNO":"22222","NAME":"SHORTSIGHT","TITLE":"SECRETARY","SALARY":5500.
00}]}
{"DEPARTMENT":"0318","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","TITLE":"SALESMAN","SALARY":9600.00
00000000000000},{"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.00000000000000
00}]}
{"DEPARTMENT":"0318","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","TITLE":"SALESMAN","SALARY":9600.00
},{"SERIALNO":"24888","NAME":"PLUMHEAD","TITLE":"TYPIST","SALARY":2800.00},{"SERIALNO":"27845","NAME":"HONEY","TITLE":"SECRETARY","SALARY":4900.00},{"SERIALNO":"73452","NAME":"TONGHO","TITLE":"ENGINEER","SALARY":6800.00},{"SERIALNO":"74234","NAME":"WALTER","TITLE":"ENGINEER","SALARY":7400.00},{"SERIALNO":"77777","NAME":"SHRINKY","TITLE":"ADMINISTRATOR","SALARY":7500.00},{"SERIALNO":"70012","NAME":"WERTHER","TITLE":"DIRECTOR","SALARY":14500.00},{"SERIALNO":"78943","NAME":"MERCHANT","TITLE":"SALESMAN","SALARY":8700.00},{"SERIALNO":"73111","NAME":"WHEELFOR","TITLE":"SALESMAN","SALARY":10030.
00}]}
{"DEPARTMENT":"0319","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","TITLE":"SALESMAN","SALARY":14800.00
00000000000000},{"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.00000000000000
00}]}
{"DEPARTMENT":"0319","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","TITLE":"SALESMAN","SALARY":14800.00
},{"SERIALNO":"40567","NAME":"QUINN","TITLE":"DIRECTOR","SALARY":14000.00},{"SERIALNO":"00137","NAME":"BROWNY","TITLE":"ENGINEER","SALARY":10500.00},{"SERIALNO":"12345","NAME":"KITTY","TITLE":"TYPIST","SALARY":3000.45},{"SERIALNO":"33333","NAME":"MONAPENNY","TITLE":"SECRETARY","SALARY":3800.00},{"SERIALNO":"00023","NAME":"MARTIN","TITLE":"ENGINEER","SALARY":10000.00},{"SERIALNO":"07654","NAME":"FUNNIGUY","TITLE":"ADMINISTRATOR","SALARY":8500.00},{"SERIALNO":"45678","NAME":"BUGHAPPY","TITLE":"PROGRAMMER","SALARY":8500.00},{"SERIALNO":"56789","NAME":"FODDERMAN","TITLE":"SALESMAN","SALARY":7000.00},{"SERIALNO":"55555","NAME":"MESSIFUL","TITLE":"SECRETARY","SALARY":5000.50},{"SERIALNO":"98765","NAME":"GOOSEPEN","TITLE":"ADMINISTRATOR","SALARY":4700.
00}]}
{"DEPARTMENT":"2452","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","TITLE":"SCIENTIST","SALARY":8000.00
00000000000000},{"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.00000000000000
00}]}
{"DEPARTMENT":"2452","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","TITLE":"SCIENTIST","SALARY":8000.00
},{"SERIALNO":"31416","NAME":"ORELLY","TITLE":"ENGINEER","SALARY":13400.00},{"SERIALNO":"36666","NAME":"BIGHORN","TITLE":"SCIENTIST","SALARY":11000.00},{"SERIALNO":"02345","NAME":"SMITH","TITLE":"ENGINEER","SALARY":9000.00},{"SERIALNO":"11111","NAME":"CHERRY","TITLE":"SECRETARY","SALARY":4500.
00}]}
SELECT Bson_Make_Object(DEPARTMENT, TITLE, Bson_Array_Grp(Bson_Make_Object(SERIALNO, NAME, SALARY)) json_EMPLOYES) FROM t3 GROUP BY DEPARTMENT, TITLE;
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)
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.00
00000000000000
}]}
{"DEPARTMENT":"0021","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"87777","NAME":"STRONG","SALARY":23000.00}]}
{"DEPARTMENT":"0021","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"22222","NAME":"SHORTSIGHT","SALARY":5500.00
00000000000000
}]}
{"DEPARTMENT":"0021","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"22222","NAME":"SHORTSIGHT","SALARY":5500.00}]}
{"DEPARTMENT":"0318","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"77777","NAME":"SHRINKY","SALARY":7500.00
00000000000000
}]}
{"DEPARTMENT":"0318","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"77777","NAME":"SHRINKY","SALARY":7500.00}]}
{"DEPARTMENT":"0318","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"70012","NAME":"WERTHER","SALARY":14500.00
00000000000000
}]}
{"DEPARTMENT":"0318","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"70012","NAME":"WERTHER","SALARY":14500.00}]}
{"DEPARTMENT":"0318","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"73452","NAME":"TONGHO","SALARY":6800.00
00000000000000},{"SERIALNO":"74234","NAME":"WALTER","SALARY":7400.00000000000000
00}]}
{"DEPARTMENT":"0318","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"73452","NAME":"TONGHO","SALARY":6800.00
},{"SERIALNO":"74234","NAME":"WALTER","SALARY":7400.
00}]}
{"DEPARTMENT":"0318","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","SALARY":9600.00
00000000000000},{"SERIALNO":"78943","NAME":"MERCHANT","SALARY":8700.0000000000000000},{"SERIALNO":"73111","NAME":"WHEELFOR","SALARY":10030.00000000000000
00}]}
{"DEPARTMENT":"0318","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"74200","NAME":"BANCROFT","SALARY":9600.00
},{"SERIALNO":"78943","NAME":"MERCHANT","SALARY":8700.00},{"SERIALNO":"73111","NAME":"WHEELFOR","SALARY":10030.
00}]}
{"DEPARTMENT":"0318","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"27845","NAME":"HONEY","SALARY":4900.00
00000000000000
}]}
{"DEPARTMENT":"0318","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"27845","NAME":"HONEY","SALARY":4900.00}]}
{"DEPARTMENT":"0318","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"24888","NAME":"PLUMHEAD","SALARY":2800.00
00000000000000
}]}
{"DEPARTMENT":"0318","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"24888","NAME":"PLUMHEAD","SALARY":2800.00}]}
{"DEPARTMENT":"0319","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"98765","NAME":"GOOSEPEN","SALARY":4700.00
00000000000000},{"SERIALNO":"07654","NAME":"FUNNIGUY","SALARY":8500.00000000000000
00}]}
{"DEPARTMENT":"0319","TITLE":"ADMINISTRATOR","EMPLOYES":[{"SERIALNO":"98765","NAME":"GOOSEPEN","SALARY":4700.00
},{"SERIALNO":"07654","NAME":"FUNNIGUY","SALARY":8500.
00}]}
{"DEPARTMENT":"0319","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"40567","NAME":"QUINN","SALARY":14000.00
00000000000000
}]}
{"DEPARTMENT":"0319","TITLE":"DIRECTOR","EMPLOYES":[{"SERIALNO":"40567","NAME":"QUINN","SALARY":14000.00}]}
{"DEPARTMENT":"0319","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"00023","NAME":"MARTIN","SALARY":10000.00
00000000000000},{"SERIALNO":"00137","NAME":"BROWNY","SALARY":10500.00000000000000
00}]}
{"DEPARTMENT":"0319","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"00023","NAME":"MARTIN","SALARY":10000.00
},{"SERIALNO":"00137","NAME":"BROWNY","SALARY":10500.
00}]}
{"DEPARTMENT":"0319","TITLE":"PROGRAMMER","EMPLOYES":[{"SERIALNO":"45678","NAME":"BUGHAPPY","SALARY":8500.00
00000000000000
}]}
{"DEPARTMENT":"0319","TITLE":"PROGRAMMER","EMPLOYES":[{"SERIALNO":"45678","NAME":"BUGHAPPY","SALARY":8500.00}]}
{"DEPARTMENT":"0319","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","SALARY":14800.00
00000000000000},{"SERIALNO":"56789","NAME":"FODDERMAN","SALARY":7000.00000000000000
00}]}
{"DEPARTMENT":"0319","TITLE":"SALESMAN","EMPLOYES":[{"SERIALNO":"76543","NAME":"BULLOZER","SALARY":14800.00
},{"SERIALNO":"56789","NAME":"FODDERMAN","SALARY":7000.
00}]}
{"DEPARTMENT":"0319","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"33333","NAME":"MONAPENNY","SALARY":3800.00
00000000000000},{"SERIALNO":"55555","NAME":"MESSIFUL","SALARY":5000.500000000000000
0}]}
{"DEPARTMENT":"0319","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"33333","NAME":"MONAPENNY","SALARY":3800.00
},{"SERIALNO":"55555","NAME":"MESSIFUL","SALARY":5000.5
0}]}
{"DEPARTMENT":"0319","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"12345","NAME":"KITTY","SALARY":3000.4
499999999998181
}]}
{"DEPARTMENT":"0319","TITLE":"TYPIST","EMPLOYES":[{"SERIALNO":"12345","NAME":"KITTY","SALARY":3000.4
5
}]}
{"DEPARTMENT":"2452","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"31416","NAME":"ORELLY","SALARY":13400.00
00000000000000},{"SERIALNO":"02345","NAME":"SMITH","SALARY":9000.00000000000000
00}]}
{"DEPARTMENT":"2452","TITLE":"ENGINEER","EMPLOYES":[{"SERIALNO":"31416","NAME":"ORELLY","SALARY":13400.00
},{"SERIALNO":"02345","NAME":"SMITH","SALARY":9000.
00}]}
{"DEPARTMENT":"2452","TITLE":"SCIENTIST","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","SALARY":8000.00
00000000000000},{"SERIALNO":"36666","NAME":"BIGHORN","SALARY":11000.00000000000000
00}]}
{"DEPARTMENT":"2452","TITLE":"SCIENTIST","EMPLOYES":[{"SERIALNO":"34567","NAME":"BIGHEAD","SALARY":8000.00
},{"SERIALNO":"36666","NAME":"BIGHORN","SALARY":11000.
00}]}
{"DEPARTMENT":"2452","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"11111","NAME":"CHERRY","SALARY":4500.00
00000000000000
}]}
{"DEPARTMENT":"2452","TITLE":"SECRETARY","EMPLOYES":[{"SERIALNO":"11111","NAME":"CHERRY","SALARY":4500.00}]}
SELECT Bson_Object_Grp(SALARY) FROM t3;
SELECT Bson_Object_Grp(SALARY) FROM t3;
ERROR HY000: Can't initialize function 'bson_object_grp'; This function requires 2 arguments (key, value)
ERROR HY000: Can't initialize function 'bson_object_grp'; This function requires 2 arguments (key, value)
SELECT Bson_Object_Grp(NAME, SALARY) FROM t3;
SELECT Bson_Object_Grp(NAME, SALARY) FROM t3;
Bson_Object_Grp(NAME, SALARY)
Bson_Object_Grp(NAME, SALARY)
{"
":"MARTIN","ffffp@":"KITTY"
}
{"
BANCROFT":9600.00,"SMITH":9000.00,"MERCHANT":8700.00,"FUNNIGUY":8500.00,"BUGHAPPY":8500.00,"BIGHEAD":8000.00,"SHRINKY":7500.00,"WALTER":7400.00,"FODDERMAN":7000.00,"TONGHO":6800.00,"SHORTSIGHT":5500.00,"MESSIFUL":5000.50,"HONEY":4900.00,"GOOSEPEN":4700.00,"CHERRY":4500.00,"MONAPENNY":3800.00,"KITTY":3000.45,"PLUMHEAD":2800.00,"STRONG":23000.00,"BULLOZER":14800.00,"WERTHER":14500.00,"QUINN":14000.00,"ORELLY":13400.00,"BIGHORN":11000.00,"BROWNY":10500.00,"WHEELFOR":10030.00,"MARTIN":10000.00
}
SELECT Bson_Make_Object(DEPARTMENT, Bson_Object_Grp(NAME, SALARY) "Json_SALARIES") FROM t3 GROUP BY DEPARTMENT;
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")
Bson_Make_Object(DEPARTMENT, Bson_Object_Grp(NAME, SALARY) "Json_SALARIES")
{"DEPARTMENT":"0021","SALARIES":{"
":"SHORTSIGHT"
}}
{"DEPARTMENT":"0021","SALARIES":{"
STRONG":23000.00,"SHORTSIGHT":5500.00
}}
{"DEPARTMENT":"0318","SALARIES":{"
":"WHEELFOR"
}}
{"DEPARTMENT":"0318","SALARIES":{"
BANCROFT":9600.00,"PLUMHEAD":2800.00,"HONEY":4900.00,"TONGHO":6800.00,"WALTER":7400.00,"SHRINKY":7500.00,"WERTHER":14500.00,"MERCHANT":8700.00,"WHEELFOR":10030.00
}}
{"DEPARTMENT":"0319","SALARIES":{"
":"GOOSEPEN","ffffp@":"KITTY"
}}
{"DEPARTMENT":"0319","SALARIES":{"
BULLOZER":14800.00,"QUINN":14000.00,"BROWNY":10500.00,"KITTY":3000.45,"MONAPENNY":3800.00,"MARTIN":10000.00,"FUNNIGUY":8500.00,"BUGHAPPY":8500.00,"FODDERMAN":7000.00,"MESSIFUL":5000.50,"GOOSEPEN":4700.00
}}
{"DEPARTMENT":"2452","SALARIES":{"
":"CHERRY"
}}
{"DEPARTMENT":"2452","SALARIES":{"
BIGHEAD":8000.00,"ORELLY":13400.00,"BIGHORN":11000.00,"SMITH":9000.00,"CHERRY":4500.00
}}
SELECT Bson_Array_Grp(NAME) FROM t3;
SELECT Bson_Array_Grp(NAME) FROM t3;
Bson_Array_Grp(NAME)
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"]
["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"]
...
@@ -300,7 +303,7 @@ Bson_Object_Key(name, title)
...
@@ -300,7 +303,7 @@ Bson_Object_Key(name, title)
{"WHEELFOR":"SALESMAN"}
{"WHEELFOR":"SALESMAN"}
SELECT Bson_Object_Grp(name, title) FROM t3 WHERE DEPARTMENT = 318;
SELECT Bson_Object_Grp(name, title) FROM t3 WHERE DEPARTMENT = 318;
Bson_Object_Grp(name, title)
Bson_Object_Grp(name, title)
{"
SALESMAN":"WHEELFOR","ADMINISTRATOR":"SHRINKY","ENGINEER":"TONGHO","SECRETARY":"HONEY","TYPIST":"PLUMHEAD","DIRECTOR":"WERTHER
"}
{"
BANCROFT":"SALESMAN","MERCHANT":"SALESMAN","SHRINKY":"ADMINISTRATOR","WALTER":"ENGINEER","TONGHO":"ENGINEER","HONEY":"SECRETARY","PLUMHEAD":"TYPIST","WERTHER":"DIRECTOR","WHEELFOR":"SALESMAN
"}
#
#
# Test value getting UDF's
# Test value getting UDF's
#
#
...
@@ -325,7 +328,7 @@ BsonGet_String(Bson_Make_Array(45,28,36,45,89),'3')
...
@@ -325,7 +328,7 @@ BsonGet_String(Bson_Make_Array(45,28,36,45,89),'3')
45
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";
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
list egal sum
45+28+36+45+89 = 243
.00
45+28+36+45+89 = 243
SELECT BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.0');
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')
BsonGet_String(Bson_Make_Array(Bson_Make_Array(45,28),Bson_Make_Array(36,45,89)),'1.0')
36
36
...
@@ -603,14 +606,12 @@ Bson_File('test/fx.json', 0)
...
@@ -603,14 +606,12 @@ Bson_File('test/fx.json', 0)
[{"_id":5,"type":"food","item":"beer","taste":"light","price":5.65,"ratings":[5,8,9]},{"_id":6,"type":"car","item":"roadster","mileage":56000,"ratings":[6,9]},{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4]},{"_id":8,"type":"furniture","item":"table","size":{"W":60,"L":80,"H":40},"ratings":[5,8,7]}]
[{"_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');
SELECT Bson_File('test/fx.json', '0');
Bson_File('test/fx.json', '0')
Bson_File('test/fx.json', '0')
NULL
{"_id":5,"type":"food","item":"beer","taste":"light","price":5.65,"ratings":[5,8,9]}
Warnings:
Warning 1105
SELECT Bson_File('test/fx.json', '[?]');
SELECT Bson_File('test/fx.json', '[?]');
Bson_File('test/fx.json', '[?]')
Bson_File('test/fx.json', '[?]')
NULL
NULL
Warnings:
Warnings:
Warning 1105
Warning 1105
Invalid function specification ?
SELECT BsonGet_String(Bson_File('test/fx.json'), '1.*');
SELECT BsonGet_String(Bson_File('test/fx.json'), '1.*');
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]}
{"_id":6,"type":"car","item":"roadster","mileage":56000,"ratings":[6,9]}
...
@@ -625,57 +626,33 @@ Price
...
@@ -625,57 +626,33 @@ Price
5.65
5.65
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings');
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings');
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings')
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings')
NULL
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4,6]}
Warnings:
Warning 1105
Warning 1105 No sub-item at '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, 1, 'ratings');
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
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,6,4]}
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings', 1);
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)
Bson_Array_Add(Bson_File('test/fx.json', '2'), 6, 'ratings', 1)
NULL
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,6,4]}
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
SELECT Bson_Array_Add(Bson_File('test/fx.json', '2.ratings'), 6, 0);
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)
Bson_Array_Add(Bson_File('test/fx.json', '2.ratings'), 6, 0)
[6,null]
[6,2,4]
Warnings:
Warning 1105
SELECT Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1);
SELECT Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1);
Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1)
Bson_Array_Delete(Bson_File('test/fx.json', '2'), 'ratings', 1)
NULL
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2]}
Warnings:
Warning 1105
Warning 1105 No sub-item at 'ratings'
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin);
SELECT Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin);
Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin)
Bson_Object_Add(Bson_File('test/fx.json', '2'), 'france' origin)
NULL
{"_id":7,"type":"food","item":"meat","origin":"france","ratings":[2,4]}
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');
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')
Bson_Object_Add(Bson_File('test/fx.json', '2'), 70 H, 'size')
NULL
{"_id":7,"type":"food","item":"meat","origin":"argentina","ratings":[2,4]}
Warnings:
Warnings:
Warning 1105
Warning 1105 No sub-item at 'size'
Warning 1105 No sub-item at 'size'
SELECT Bson_Object_Add(Bson_File('test/fx.json', '3'), 70 H, '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')
Bson_Object_Add(Bson_File('test/fx.json', '3'), 70 H, 'size')
NULL
{"_id":8,"type":"furniture","item":"table","size":{"W":60,"L":80,"H":70},"ratings":[5,8,7]}
Warnings:
Warning 1105
Warning 1105 No sub-item at 'size'
SELECT Bson_Object_List(Bson_File('test/fx.json', '3.size'));
SELECT Bson_Object_List(Bson_File('test/fx.json', '3.size'));
Bson_Object_List(Bson_File('test/fx.json', '3.size'))
Bson_Object_List(Bson_File('test/fx.json', '3.size'))
NULL
["W","L","H"]
Warnings:
Warning 1105
Warning 1105 First argument is not an object
#
#
# Testing new functions
# Testing new functions
#
#
...
...
storage/connect/mysql-test/connect/t/bson_udf.inc
View file @
6f93df1c
...
@@ -22,6 +22,8 @@ if (!$HA_CONNECT_SO) {
...
@@ -22,6 +22,8 @@ if (!$HA_CONNECT_SO) {
--
eval
CREATE
FUNCTION
bson_object_delete
RETURNS
STRING
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bson_object_delete
RETURNS
STRING
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bson_object_list
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
bson_object_values
RETURNS
STRING
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bsonset_def_prec
RETURNS
INTEGER
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bsonget_def_prec
RETURNS
INTEGER
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bsonset_grp_size
RETURNS
INTEGER
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bsonset_grp_size
RETURNS
INTEGER
SONAME
'$HA_CONNECT_SO'
;
--
eval
CREATE
FUNCTION
bsonget_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_array_grp
RETURNS
STRING
SONAME
'$HA_CONNECT_SO'
;
...
...
storage/connect/mysql-test/connect/t/bson_udf.test
View file @
6f93df1c
...
@@ -77,6 +77,7 @@ SELECT Bson_Object_Values('{"One":1,"Two":2,"Three":3}') "Value List";
...
@@ -77,6 +77,7 @@ SELECT Bson_Object_Values('{"One":1,"Two":2,"Three":3}') "Value List";
--
echo
#
--
echo
#
--
echo
# Test UDF's with column arguments
--
echo
# Test UDF's with column arguments
--
echo
#
--
echo
#
SELECT
Bsonset_Def_Prec
(
2
);
CREATE
TABLE
t2
CREATE
TABLE
t2
(
(
ISBN
CHAR
(
15
),
ISBN
CHAR
(
15
),
...
...
storage/connect/mysql-test/connect/t/bson_udf2.inc
View file @
6f93df1c
...
@@ -13,6 +13,8 @@ DROP FUNCTION bson_object_add;
...
@@ -13,6 +13,8 @@ DROP FUNCTION bson_object_add;
DROP
FUNCTION
bson_object_delete
;
DROP
FUNCTION
bson_object_delete
;
DROP
FUNCTION
bson_object_list
;
DROP
FUNCTION
bson_object_list
;
DROP
FUNCTION
bson_object_values
;
DROP
FUNCTION
bson_object_values
;
DROP
FUNCTION
bsonset_def_prec
;
DROP
FUNCTION
bsonget_def_prec
;
DROP
FUNCTION
bsonset_grp_size
;
DROP
FUNCTION
bsonset_grp_size
;
DROP
FUNCTION
bsonget_grp_size
;
DROP
FUNCTION
bsonget_grp_size
;
DROP
FUNCTION
bson_array_grp
;
DROP
FUNCTION
bson_array_grp
;
...
...
storage/connect/plugutil.cpp
View file @
6f93df1c
...
@@ -628,7 +628,7 @@ size_t MakeOff(void* memp, void* ptr)
...
@@ -628,7 +628,7 @@ size_t MakeOff(void* memp, void* ptr)
DoThrow
(
999
);
DoThrow
(
999
);
}
// endif ptr
}
// endif ptr
#endif // _DEBUG || DEVELOPMENT
#endif // _DEBUG || DEVELOPMENT
return
(
size_t
)((
char
*
)
ptr
-
(
size_t
)
memp
);
return
(
size_t
)((
(
char
*
)
ptr
)
-
((
char
*
)
memp
)
);
}
else
}
else
return
0
;
return
0
;
...
...
storage/connect/tabbson.cpp
View file @
6f93df1c
...
@@ -719,7 +719,10 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
...
@@ -719,7 +719,10 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
if
(
jvp
)
{
if
(
jvp
)
{
vp
->
SetNull
(
false
);
vp
->
SetNull
(
false
);
switch
(
jvp
->
Type
)
{
if
(
Jb
)
{
vp
->
SetValue_psz
(
Serialize
(
g
,
jvp
,
NULL
,
0
));
Jb
=
false
;
}
else
switch
(
jvp
->
Type
)
{
case
TYPE_STRG
:
case
TYPE_STRG
:
case
TYPE_INTG
:
case
TYPE_INTG
:
case
TYPE_BINT
:
case
TYPE_BINT
:
...
@@ -780,53 +783,59 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
...
@@ -780,53 +783,59 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
/***********************************************************************/
/***********************************************************************/
/* MakeJson: Serialize the json item and set value to it. */
/* MakeJson: Serialize the json item and set value to it. */
/***********************************************************************/
/***********************************************************************/
P
VAL
BCUTIL
::
MakeBson
(
PGLOBAL
g
,
PBVAL
jsp
)
P
BVAL
BCUTIL
::
MakeBson
(
PGLOBAL
g
,
PBVAL
jsp
,
int
n
)
{
{
if
(
Cp
->
Value
->
IsTypeNum
())
{
PBVAL
vlp
,
jvp
=
jsp
;
strcpy
(
g
->
Message
,
"Cannot make Json for a numeric column"
);
if
(
!
Cp
->
Warned
)
{
if
(
n
<
Cp
->
Nod
-
1
)
{
PushWarning
(
g
,
Tp
);
if
(
jsp
->
Type
==
TYPE_JAR
)
{
Cp
->
Warned
=
true
;
int
ars
=
GetArraySize
(
jsp
)
;
}
// endif Warned
PJNODE
jnp
=
&
Cp
->
Nodes
[
n
];
Cp
->
Value
->
Reset
();
jvp
=
NewVal
(
TYPE_JAR
);
#if 0
jnp
->
Op
=
OP_EQ
;
} else if (Value->GetType() == TYPE_BIN) {
if ((unsigned)Value->GetClen() >= sizeof(BSON)) {
ulong len = Tjp->Lrecl ? Tjp->Lrecl : 500;
PBSON bsp = JbinAlloc(g, NULL, len, jsp);
strcat(bsp->Msg, " column");
for
(
int
i
=
0
;
i
<
ars
;
i
++
)
{
((BINVAL*)Value)->SetBinValue(bsp, sizeof(BSON));
jnp
->
Rank
=
i
;
} else {
vlp
=
GetRowValue
(
g
,
jsp
,
n
);
strcpy(g->Message, "Column size too small");
AddArrayValue
(
jvp
,
DupVal
(
vlp
));
Value->SetValue_char(NULL, 0);
}
// endfor i
} // endif Clen
#endif // 0
jnp
->
Op
=
OP_XX
;
}
else
jnp
->
Rank
=
0
;
Cp
->
Value
->
SetValue_psz
(
Serialize
(
g
,
jsp
,
NULL
,
0
));
}
else
if
(
jsp
->
Type
==
TYPE_JOB
)
{
jvp
=
NewVal
(
TYPE_JOB
);
for
(
PBPR
prp
=
GetObject
(
jsp
);
prp
;
prp
=
GetNext
(
prp
))
{
vlp
=
GetRowValue
(
g
,
GetVlp
(
prp
),
n
+
1
);
SetKeyValue
(
jvp
,
vlp
,
MZP
(
prp
->
Key
));
}
// endfor prp
}
// endif Type
}
// endif's
return
Cp
->
Value
;
Jb
=
true
;
}
// end of MakeJson
return
jvp
;
}
// end of MakeBson
/***********************************************************************/
/***********************************************************************/
/* Get
ColumnValue:
*/
/* Get
RowValue:
*/
/***********************************************************************/
/***********************************************************************/
P
VAL
BCUTIL
::
GetColumn
Value
(
PGLOBAL
g
,
PBVAL
row
,
int
i
)
P
BVAL
BCUTIL
::
GetRow
Value
(
PGLOBAL
g
,
PBVAL
row
,
int
i
)
{
{
int
nod
=
Cp
->
Nod
,
n
=
nod
-
1
;
int
nod
=
Cp
->
Nod
,
n
=
nod
-
1
;
JNODE
*
nodes
=
Cp
->
Nodes
;
JNODE
*
nodes
=
Cp
->
Nodes
;
PVAL
value
=
Cp
->
Value
;
PBVAL
arp
;
PBVAL
arp
;
PBVAL
bvp
=
NULL
;
PBVAL
bvp
=
NULL
;
for
(;
i
<
nod
&&
row
;
i
++
)
{
for
(;
i
<
nod
&&
row
;
i
++
)
{
if
(
nodes
[
i
].
Op
==
OP_NUM
)
{
if
(
nodes
[
i
].
Op
==
OP_NUM
)
{
value
->
SetValue
(
row
->
Type
==
TYPE_JAR
?
GetSize
(
row
)
:
1
);
bvp
=
NewVal
(
TYPE_INT
);
return
(
value
);
bvp
->
N
=
(
row
->
Type
==
TYPE_JAR
)
?
GetSize
(
row
)
:
1
;
return
(
bvp
);
}
else
if
(
nodes
[
i
].
Op
==
OP_XX
)
{
}
else
if
(
nodes
[
i
].
Op
==
OP_XX
)
{
return
MakeBson
(
g
,
row
);
return
MakeBson
(
g
,
row
,
i
);
}
else
switch
(
row
->
Type
)
{
}
else
switch
(
row
->
Type
)
{
case
TYPE_JOB
:
case
TYPE_JOB
:
if
(
!
nodes
[
i
].
Key
)
{
if
(
!
nodes
[
i
].
Key
)
{
...
@@ -847,9 +856,9 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
...
@@ -847,9 +856,9 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
if
(
nodes
[
i
].
Op
==
OP_EQ
)
if
(
nodes
[
i
].
Op
==
OP_EQ
)
bvp
=
GetArrayValue
(
arp
,
nodes
[
i
].
Rank
);
bvp
=
GetArrayValue
(
arp
,
nodes
[
i
].
Rank
);
else
if
(
nodes
[
i
].
Op
==
OP_EXP
)
else
if
(
nodes
[
i
].
Op
==
OP_EXP
)
return
ExpandArray
(
g
,
arp
,
i
);
return
NewVal
(
ExpandArray
(
g
,
arp
,
i
)
);
else
else
return
CalculateArray
(
g
,
arp
,
i
);
return
NewVal
(
CalculateArray
(
g
,
arp
,
i
)
);
}
else
{
}
else
{
// Unexpected array, unwrap it as [0]
// Unexpected array, unwrap it as [0]
...
@@ -871,6 +880,17 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
...
@@ -871,6 +880,17 @@ PVAL BCUTIL::GetColumnValue(PGLOBAL g, PBVAL row, int i)
}
// endfor i
}
// endfor i
return
bvp
;
}
// end of GetColumnValue
/***********************************************************************/
/* GetColumnValue: */
/***********************************************************************/
PVAL
BCUTIL
::
GetColumnValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
)
{
PVAL
value
=
Cp
->
Value
;
PBVAL
bvp
=
GetRowValue
(
g
,
row
,
i
);
SetJsonValue
(
g
,
value
,
bvp
);
SetJsonValue
(
g
,
value
,
bvp
);
return
value
;
return
value
;
}
// end of GetColumnValue
}
// end of GetColumnValue
...
...
storage/connect/tabbson.h
View file @
6f93df1c
...
@@ -127,11 +127,13 @@ class BTUTIL : public BDOC {
...
@@ -127,11 +127,13 @@ class BTUTIL : public BDOC {
class
BCUTIL
:
public
BTUTIL
{
class
BCUTIL
:
public
BTUTIL
{
public:
public:
// Constructor
// Constructor
BCUTIL
(
PGLOBAL
G
,
PBSCOL
cp
,
TDBBSN
*
tp
)
:
BTUTIL
(
G
,
tp
)
{
Cp
=
cp
;
}
BCUTIL
(
PGLOBAL
G
,
PBSCOL
cp
,
TDBBSN
*
tp
)
:
BTUTIL
(
G
,
tp
)
{
Cp
=
cp
;
Jb
=
false
;
}
// Utility functions
// Utility functions
void
SetJsonValue
(
PGLOBAL
g
,
PVAL
vp
,
PBVAL
jvp
);
void
SetJsonValue
(
PGLOBAL
g
,
PVAL
vp
,
PBVAL
jvp
);
PVAL
MakeBson
(
PGLOBAL
g
,
PBVAL
jsp
);
PBVAL
MakeBson
(
PGLOBAL
g
,
PBVAL
jsp
,
int
n
);
PBVAL
GetRowValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PVAL
GetColumnValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PVAL
GetColumnValue
(
PGLOBAL
g
,
PBVAL
row
,
int
i
);
PVAL
ExpandArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
ExpandArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
CalculateArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
PVAL
CalculateArray
(
PGLOBAL
g
,
PBVAL
arp
,
int
n
);
...
@@ -140,6 +142,7 @@ class BCUTIL : public BTUTIL {
...
@@ -140,6 +142,7 @@ class BCUTIL : public BTUTIL {
protected:
protected:
// Member
// Member
PBSCOL
Cp
;
PBSCOL
Cp
;
bool
Jb
;
};
// end of class BCUTIL
};
// end of class BCUTIL
/* -------------------------- TDBBSN class --------------------------- */
/* -------------------------- TDBBSN class --------------------------- */
...
...
storage/connect/tabjson.cpp
View file @
6f93df1c
...
@@ -1024,6 +1024,12 @@ bool TDBJSN::OpenDB(PGLOBAL g)
...
@@ -1024,6 +1024,12 @@ bool TDBJSN::OpenDB(PGLOBAL g)
/* Lrecl is Ok. */
/* Lrecl is Ok. */
/*********************************************************************/
/*********************************************************************/
size_t
linelen
=
Lrecl
;
size_t
linelen
=
Lrecl
;
MODE
mode
=
Mode
;
// Buffer must be allocated in g->Sarea
Mode
=
MODE_ANY
;
Txfp
->
AllocateBuffer
(
g
);
Mode
=
mode
;
//To_Line = (char*)PlugSubAlloc(g, NULL, linelen);
//To_Line = (char*)PlugSubAlloc(g, NULL, linelen);
//memset(To_Line, 0, linelen);
//memset(To_Line, 0, linelen);
...
...
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