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
7f7e6614
Commit
7f7e6614
authored
Feb 02, 2021
by
Oleksandr Byelkin
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'connect/10.2' into 10.2
parents
ff5186fd
571294f9
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
460 additions
and
269 deletions
+460
-269
storage/connect/bson.cpp
storage/connect/bson.cpp
+38
-39
storage/connect/bson.h
storage/connect/bson.h
+2
-3
storage/connect/bsonudf.cpp
storage/connect/bsonudf.cpp
+265
-103
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
+38
-61
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/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 @
7f7e6614
...
@@ -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. */
...
@@ -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
;
...
@@ -1498,31 +1499,27 @@ double BJSON::GetDouble(PBVAL vp)
...
@@ -1498,31 +1499,27 @@ double BJSON::GetDouble(PBVAL vp)
PBVAL
vlp
=
(
vp
->
Type
==
TYPE_JVAL
)
?
MVP
(
vp
->
To_Val
)
:
vp
;
PBVAL
vlp
=
(
vp
->
Type
==
TYPE_JVAL
)
?
MVP
(
vp
->
To_Val
)
:
vp
;
switch
(
vlp
->
Type
)
{
switch
(
vlp
->
Type
)
{
case
TYPE_DBL
:
case
TYPE_DBL
:
d
=
*
(
double
*
)
MP
(
vlp
->
To_Val
);
d
=
*
(
double
*
)
MP
(
vlp
->
To_Val
);
break
;
break
;
case
TYPE_BINT
:
case
TYPE_BINT
:
d
=
(
double
)
*
(
longlong
*
)
MP
(
vlp
->
To_Val
);
d
=
(
double
)
*
(
longlong
*
)
MP
(
vlp
->
To_Val
);
break
;
break
;
case
TYPE_INTG
:
case
TYPE_INTG
:
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
;
case
TYPE_DTM
:
sprintf
(
buf
,
"%.*f"
,
n
,
vlp
->
F
);
case
TYPE_STRG
:
d
=
atof
(
buf
);
d
=
atof
(
MZP
(
vlp
->
To_Val
));
}
break
;
break
;
case
TYPE_DTM
:
case
TYPE_BOOL
:
case
TYPE_STRG
:
d
=
(
vlp
->
B
)
?
1.0
:
0.0
;
d
=
atof
(
MZP
(
vlp
->
To_Val
));
break
;
break
;
default:
case
TYPE_BOOL
:
d
=
0.0
;
d
=
(
vlp
->
B
)
?
1.0
:
0.0
;
break
;
default:
d
=
0.0
;
}
// endswitch Type
}
// endswitch Type
return
d
;
return
d
;
...
@@ -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
)
{
{
double
*
dp
=
(
double
*
)
BsonSubAlloc
(
sizeof
(
double
));
int
nd
=
MY_MIN
((
prec
<
0
)
?
GetJsonDefPrec
()
:
prec
,
16
);
if
(
nd
<
6
&&
d
>=
FLT_MIN
&&
d
<=
FLT_MAX
)
{
vlp
->
F
=
(
float
)
d
;
vlp
->
Type
=
TYPE_FLOAT
;
}
else
{
double
*
dp
=
(
double
*
)
BsonSubAlloc
(
sizeof
(
double
));
*
dp
=
d
;
vlp
->
To_Val
=
MOF
(
dp
);
vlp
->
Type
=
TYPE_DBL
;
}
// endif nd
*
dp
=
d
;
vlp
->
Nd
=
nd
;
vlp
->
To_Val
=
MOF
(
dp
);
vlp
->
Nd
=
MY_MIN
(
nd
,
16
);
vlp
->
Type
=
TYPE_DBL
;
}
// 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
)
{
SetFloat
(
vlp
,
d
,
nd
);
vlp
->
F
=
(
float
)
d
;
vlp
->
Nd
=
nd
;
vlp
->
Type
=
TYPE_FLOAT
;
}
else
SetFloat
(
vlp
,
d
,
nd
);
}
// end of SetFloat
}
// end of SetFloat
/***********************************************************************/
/***********************************************************************/
...
...
storage/connect/bson.h
View file @
7f7e6614
...
@@ -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
;
}
...
...
storage/connect/bsonudf.cpp
View file @
7f7e6614
This diff is collapsed.
Click to expand it.
storage/connect/bsonudf.h
View file @
7f7e6614
...
@@ -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 @
7f7e6614
...
@@ -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
);
...
@@ -420,9 +421,15 @@ static MYSQL_THDVAR_INT(default_depth,
...
@@ -420,9 +421,15 @@ 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
"max number of rows for JSON aggregate functions."
,
"max number of rows for JSON aggregate functions."
,
NULL
,
NULL
,
JSONMAX
,
1
,
INT_MAX
,
1
);
NULL
,
NULL
,
JSONMAX
,
1
,
INT_MAX
,
1
);
...
@@ -495,6 +502,7 @@ TYPCONV GetTypeConv(void) {return (TYPCONV)THDVAR(current_thd, type_conv);}
...
@@ -495,6 +502,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
);}
...
@@ -4833,6 +4841,7 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
...
@@ -4833,6 +4841,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,7 +7453,8 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
...
@@ -7444,7 +7453,8 @@ 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
(
json_grp_size
),
MYSQL_SYSVAR
(
default_prec
),
MYSQL_SYSVAR
(
json_grp_size
),
#if defined(JAVA_SUPPORT)
#if defined(JAVA_SUPPORT)
MYSQL_SYSVAR
(
jvm_path
),
MYSQL_SYSVAR
(
jvm_path
),
MYSQL_SYSVAR
(
class_path
),
MYSQL_SYSVAR
(
class_path
),
...
...
storage/connect/jsonudf.cpp
View file @
7f7e6614
...
@@ -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 @
7f7e6614
This diff is collapsed.
Click to expand it.
storage/connect/mysql-test/connect/t/bson_udf.inc
View file @
7f7e6614
...
@@ -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 @
7f7e6614
...
@@ -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 @
7f7e6614
...
@@ -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/tabbson.cpp
View file @
7f7e6614
...
@@ -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
:
...
@@ -727,29 +730,29 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
...
@@ -727,29 +730,29 @@ void BCUTIL::SetJsonValue(PGLOBAL g, PVAL vp, PBVAL jvp)
case
TYPE_DTM
:
case
TYPE_DTM
:
case
TYPE_FLOAT
:
case
TYPE_FLOAT
:
switch
(
vp
->
GetType
())
{
switch
(
vp
->
GetType
())
{
case
TYPE_STRING
:
case
TYPE_STRING
:
case
TYPE_DATE
:
case
TYPE_DATE
:
case
TYPE_DECIM
:
case
TYPE_DECIM
:
vp
->
SetValue_psz
(
GetString
(
jvp
));
vp
->
SetValue_psz
(
GetString
(
jvp
));
break
;
break
;
case
TYPE_INT
:
case
TYPE_INT
:
case
TYPE_SHORT
:
case
TYPE_SHORT
:
case
TYPE_TINY
:
case
TYPE_TINY
:
vp
->
SetValue
(
GetInteger
(
jvp
));
vp
->
SetValue
(
GetInteger
(
jvp
));
break
;
break
;
case
TYPE_BIGINT
:
case
TYPE_BIGINT
:
vp
->
SetValue
(
GetBigint
(
jvp
));
vp
->
SetValue
(
GetBigint
(
jvp
));
break
;
break
;
case
TYPE_DOUBLE
:
case
TYPE_DOUBLE
:
vp
->
SetValue
(
GetDouble
(
jvp
));
vp
->
SetValue
(
GetDouble
(
jvp
));
if
(
jvp
->
Type
==
TYPE_DBL
||
jvp
->
Type
==
TYPE_FLOAT
)
if
(
jvp
->
Type
==
TYPE_DBL
||
jvp
->
Type
==
TYPE_FLOAT
)
vp
->
SetPrec
(
jvp
->
Nd
);
vp
->
SetPrec
(
jvp
->
Nd
);
break
;
break
;
default:
default:
sprintf
(
G
->
Message
,
"Unsupported column type %d"
,
vp
->
GetType
());
sprintf
(
G
->
Message
,
"Unsupported column type %d"
,
vp
->
GetType
());
throw
888
;
throw
888
;
}
// endswitch Type
}
// endswitch Type
break
;
break
;
...
@@ -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
);
return
Cp
->
Value
;
for
(
PBPR
prp
=
GetObject
(
jsp
);
prp
;
prp
=
GetNext
(
prp
))
{
}
// end of MakeJson
vlp
=
GetRowValue
(
g
,
GetVlp
(
prp
),
n
+
1
);
SetKeyValue
(
jvp
,
vlp
,
MZP
(
prp
->
Key
));
}
// endfor prp
}
// endif Type
}
// endif's
Jb
=
true
;
return
jvp
;
}
// end of MakeBson
/***********************************************************************/
/***********************************************************************/
/* 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 @
7f7e6614
...
@@ -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 @
7f7e6614
...
@@ -1024,8 +1024,14 @@ bool TDBJSN::OpenDB(PGLOBAL g)
...
@@ -1024,8 +1024,14 @@ bool TDBJSN::OpenDB(PGLOBAL g)
/* Lrecl is Ok. */
/* Lrecl is Ok. */
/*********************************************************************/
/*********************************************************************/
size_t
linelen
=
Lrecl
;
size_t
linelen
=
Lrecl
;
MODE
mode
=
Mode
;
//To_Line = (char*)PlugSubAlloc(g, NULL, linelen);
// Buffer must be allocated in g->Sarea
Mode
=
MODE_ANY
;
Txfp
->
AllocateBuffer
(
g
);
Mode
=
mode
;
//To_Line = (char*)PlugSubAlloc(g, NULL, linelen);
//memset(To_Line, 0, linelen);
//memset(To_Line, 0, linelen);
To_Line
=
Txfp
->
GetBuf
();
To_Line
=
Txfp
->
GetBuf
();
xtrc
(
1
,
"OpenJSN: R%hd mode=%d To_Line=%p
\n
"
,
Tdb_No
,
Mode
,
To_Line
);
xtrc
(
1
,
"OpenJSN: R%hd mode=%d To_Line=%p
\n
"
,
Tdb_No
,
Mode
,
To_Line
);
...
...
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