Skip to content

Commit

Permalink
Merge remote-tracking branch 'connect/10.2' into 10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cvicentiu committed Sep 19, 2017
2 parents 22c322c + bf34e9d commit 5b9c32e
Show file tree
Hide file tree
Showing 32 changed files with 440 additions and 214 deletions.
82 changes: 50 additions & 32 deletions storage/connect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ int main() {
ENDIF(CONNECT_WITH_ODBC)

#
# JDBC and MongoDB Java Driver
# JDBC with MongoDB Java Driver included but disabled
#
OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
Expand All @@ -265,13 +265,13 @@ IF(CONNECT_WITH_JDBC)
MysqlInterface.java OracleInterface.java PostgresqlInterface.java
JavaWrappers.jar)
add_definitions(-DJDBC_SUPPORT)
IF(CONNECT_WITH_MONGO)
IF(CONNECT_WITH_MONGO)
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
jmgfam.cpp jmgoconn.cpp mongo.cpp tabjmg.cpp
jmgfam.h jmgoconn.h mongo.h tabjmg.h
Mongo2Interface.java Mongo3Interface.java)
add_definitions(-DMONGO_SUPPORT)
ENDIF()
add_definitions(-DMONGO_SUPPORT -DMONGO_ENABLED=0)
ENDIF()
ELSE()
SET(JDBC_LIBRARY "")
ENDIF()
Expand All @@ -290,33 +290,36 @@ IF(CONNECT_WITH_ZIP)
ENDIF(CONNECT_WITH_ZIP)

#
# MONGO C Driver (CMAKE NOT YET WORKING)
# MONGO C Driver
#

#IF(CONNECT_WITH_MONGO)
# IF(WIN32)
# # Adding some typical places to search in
# SET(PC_MONGO_INCLUDE_DIRS
# C:/mongo-c-driver/include
# D:/mongo-c-driver/include)
# SET(PC_MONGO_LIBRARY_DIRS
# C:/mongo-c-driver/lib
# D:/mongo-c-driver/lib)
# ENDIF(WIN32)
# FIND_PACKAGE(libmongoc 1.7)
# IF (MONGO_FOUND)
# INCLUDE_DIRECTORIES(${MONGO_INCLUDE_DIR})
# SET(MONGO_LIBRARY ${MONGO_LIBRARIES})
# SET(CONNECT_SOURCES ${CONNECT_SOURCES}
# cmgoconn.cpp cmgfam.cpp tabcmg.cpp
# cmgoconn.h cmgfam.h tabcmg.h)
# add_definitions(-DCMGO_SUPPORT)
# IF (NOT JAVA_FOUND AND JNI_FOUND)
# SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
# add_definitions(-DMONGO_SUPPORT)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
# ENDIF(MONGO_FOUND)
#ENDIF(CONNECT_WITH_MONGO)
IF(CONNECT_WITH_MONGO)
IF(WIN32)
# Adding some typical places to search in
SET(PC_MONGO_INCLUDE_DIRS
C:/mongo-c-driver/include
D:/mongo-c-driver/include)
SET(PC_MONGO_LIBRARY_DIRS
C:/mongo-c-driver/lib
D:/mongo-c-driver/lib)
ENDIF(WIN32)
FIND_PACKAGE(libmongoc-1.0 1.7)
IF (libmongoc-1.0_FOUND)
INCLUDE_DIRECTORIES(${MONGOC_INCLUDE_DIRS})
SET(MONGOC_LIBRARY ${MONGOC_LIBRARIES})
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
cmgoconn.cpp cmgfam.cpp tabcmg.cpp
cmgoconn.h cmgfam.h tabcmg.h)
add_definitions(-DCMGO_SUPPORT)
IF (NOT JAVA_FOUND AND JNI_FOUND)
SET(CONNECT_SOURCES ${CONNECT_SOURCES} mongo.cpp mongo.h)
add_definitions(-DMONGO_SUPPORT -DMONGO_ENABLED=1)
ELSE ()
remove_definitions(-DMONGO_ENABLED=0)
add_definitions(-DMONGO_ENABLED=1)
ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
ENDIF(libmongoc-1.0_FOUND)
ENDIF(CONNECT_WITH_MONGO)


#
Expand All @@ -337,9 +340,25 @@ MYSQL_ADD_PLUGIN(connect ${CONNECT_SOURCES}
STORAGE_ENGINE
COMPONENT connect-engine
RECOMPILE_FOR_EMBEDDED
# LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY} $(MONGO_LIBRARY)
LINK_LIBRARIES ${ZLIB_LIBRARY} ${XML_LIBRARY} ${ICONV_LIBRARY}
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${IPHLPAPI_LIBRARY})
${ODBC_LIBRARY} ${JDBC_LIBRARY} ${MONGOC_LIBRARY} ${IPHLPAPI_LIBRARY})

IF(NOT TARGET connect)
RETURN()
ENDIF()

# Install some extra files that belong to connect engine
IF(WIN32)
# install ha_connect.lib
GET_TARGET_PROPERTY(CONNECT_LOCATION connect LOCATION)
STRING(REPLACE "dll" "lib" CONNECT_LIB ${CONNECT_LOCATION})
IF(CMAKE_CONFIGURATION_TYPES)
STRING(REPLACE "${CMAKE_CFG_INTDIR}" "\${CMAKE_INSTALL_CONFIG_NAME}"
CONNECT_LIB ${CONNECT_LIB})
ENDIF()
INSTALL(FILES ${CONNECT_LIB}
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF(WIN32)

IF(NOT TARGET connect)
RETURN()
Expand Down Expand Up @@ -368,4 +387,3 @@ IF(CONNECT_WITH_JDBC AND JAVA_FOUND AND JNI_FOUND)
${CMAKE_CURRENT_BINARY_DIR}/JdbcInterface.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
ENDIF()

56 changes: 41 additions & 15 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@
#define JSONMAX 10 // JSON Default max grp size

extern "C" {
char version[]= "Version 1.06.0001 April 17, 2017";
char version[]= "Version 1.06.0004 September 03, 2017";
#if defined(__WIN__)
char compver[]= "Version 1.06.0001 " __DATE__ " " __TIME__;
char compver[]= "Version 1.06.0004 " __DATE__ " " __TIME__;
char slash= '\\';
#else // !__WIN__
char slash= '/';
Expand Down Expand Up @@ -359,6 +359,13 @@ static MYSQL_THDVAR_STR(java_wrapper,
NULL, NULL, "wrappers/JdbcInterface");
#endif // JDBC_SUPPORT

#if defined(MONGO_SUPPORT)
// Enabling MONGO table type
static MYSQL_THDVAR_BOOL(enable_mongo, PLUGIN_VAR_RQCMDARG,
"Enabling the MongoDB access",
NULL, NULL, MONGO_ENABLED);
#endif // MONGO_SUPPORT

#if defined(XMSG) || defined(NEWMSG)
const char *language_names[]=
{
Expand Down Expand Up @@ -419,6 +426,10 @@ char *GetJavaWrapper(void)
{return connect_hton ? THDVAR(current_thd, java_wrapper) : (char*)"wrappers/JdbcInterface";}
#endif // JDBC_SUPPORT

#if defined(MONGO_SUPPORT)
bool MongoEnabled(void) { return THDVAR(current_thd, enable_mongo); }
#endif // MONGO_SUPPORT

extern "C" const char *msglang(void)
{
#if defined(FRENCH)
Expand Down Expand Up @@ -1285,9 +1296,14 @@ PCSZ ha_connect::GetStringOption(PCSZ opname, PCSZ sdef)
else
opval= GetListOption(xp->g, opname, options->oplist);

} else if (!stricmp(opname, "Query_String"))
opval= thd_query_string(table->in_use)->str;
else if (!stricmp(opname, "Partname"))
} else if (!stricmp(opname, "Query_String")) {
// This escapes everything and returns a wrong query
// opval = thd_query_string(table->in_use)->str;
opval = (PCSZ)PlugSubAlloc(xp->g, NULL,
thd_query_string(table->in_use)->length + 1);
strcpy((char*)opval, thd_query_string(table->in_use)->str);
// sprintf((char*)opval, "%s", thd_query_string(table->in_use)->str);
} else if (!stricmp(opname, "Partname"))
opval= partname;
else if (!stricmp(opname, "Table_charset")) {
const CHARSET_INFO *chif= (tshp) ? tshp->table_charset
Expand Down Expand Up @@ -1433,7 +1449,7 @@ PFOS ha_connect::GetFieldOptionStruct(Field *fdp)
void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
{
const char *cp;
char *chset, v;
char *chset, v = 0;
ha_field_option_struct *fop;
Field* fp;
Field* *fldp;
Expand Down Expand Up @@ -1486,7 +1502,6 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)
} // endif fop

chset = (char *)fp->charset()->name;
v = (!strcmp(chset, "binary")) ? 'B' : 0;

switch (fp->type()) {
case MYSQL_TYPE_BLOB:
Expand All @@ -1501,8 +1516,9 @@ void *ha_connect::GetColumnOption(PGLOBAL g, void *field, PCOLINFO pcf)

switch (pcf->Type) {
case TYPE_STRING:
// Do something for case
cp= fp->charset()->name;
case TYPE_BIN:
// Do something for case
cp= chset;

// Find if collation name ends by _ci
if (!strcmp(cp + strlen(cp) - 3, "_ci")) {
Expand Down Expand Up @@ -2114,6 +2130,11 @@ int ha_connect::MakeRecord(char *buf)
charset= tdbp->data_charset();
rc= fp->store(p, strlen(p), charset, CHECK_FIELD_WARN);
break;
case TYPE_BIN:
p = value->GetCharValue();
charset = &my_charset_bin;
rc = fp->store(p, strlen(p), charset, CHECK_FIELD_WARN);
break;
case TYPE_DOUBLE:
rc= fp->store(value->GetFloatValue());
break;
Expand Down Expand Up @@ -5163,7 +5184,8 @@ static bool add_field(String *sql, const char *field_name, int typ, int len,
error|= sql->append("` ");
error|= sql->append(type);

if (len && typ != TYPE_DATE && (typ != TYPE_DOUBLE || dec >= 0)) {
if (typ == TYPE_STRING ||
(len && typ != TYPE_DATE && (typ != TYPE_DOUBLE || dec >= 0))) {
error|= sql->append('(');
error|= sql->append_ulonglong(len);

Expand Down Expand Up @@ -6389,6 +6411,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
#if 0
if (!fp->field_length) {
sprintf(g->Message, "Unsupported 0 length for column %s",
fp->field_name);
Expand All @@ -6398,7 +6421,7 @@ int ha_connect::create(const char *name, TABLE *table_arg,
MYF(0), fp->field_name);
DBUG_RETURN(rc);
} // endif fp

#endif // 0
break; // To be checked
case MYSQL_TYPE_BIT:
case MYSQL_TYPE_NULL:
Expand Down Expand Up @@ -7166,7 +7189,10 @@ static struct st_mysql_sys_var* connect_system_variables[]= {
MYSQL_SYSVAR(class_path),
MYSQL_SYSVAR(java_wrapper),
#endif // JDBC_SUPPORT
NULL
#if defined(MONGO_SUPPORT)
MYSQL_SYSVAR(enable_mongo),
#endif // MONGO_SUPPORT
NULL
};

maria_declare_plugin(connect)
Expand All @@ -7175,14 +7201,14 @@ maria_declare_plugin(connect)
&connect_storage_engine,
"CONNECT",
"Olivier Bertrand",
"Management of External Data (SQL/MED), including many file formats",
"Management of External Data (SQL/NOSQL/MED), including many file formats",
PLUGIN_LICENSE_GPL,
connect_init_func, /* Plugin Init */
connect_done_func, /* Plugin Deinit */
0x0106, /* version number (1.05) */
NULL, /* status variables */
connect_system_variables, /* system variables */
"1.06.0001", /* string version */
MariaDB_PLUGIN_MATURITY_BETA /* maturity */
"1.06.0004", /* string version */
MariaDB_PLUGIN_MATURITY_STABLE /* maturity */
}
maria_declare_plugin_end;
7 changes: 7 additions & 0 deletions storage/connect/ha_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ const char *GetValStr(OPVAL vop, bool neg);
PFIL CondFilter(PGLOBAL g, Item *cond);
//PFIL CheckFilter(PGLOBAL g);

/** admin commands - called from mysql_admin_table */
virtual int check(THD* thd, HA_CHECK_OPT* check_opt)
{
// TODO: implement it
return HA_ADMIN_OK; // Just to avoid error message with checktables
} // end of check

/**
Number of rows in table. It will only be called if
(table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/jsonudf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n)
SetJsonValue(g, MulVal, jvp, n);

if (!MulVal->IsNull()) {
switch (op) {
switch (op) {
case OP_CNC:
if (Nodes[n].CncVal) {
val[0] = Nodes[n].CncVal;
Expand Down
11 changes: 10 additions & 1 deletion storage/connect/mycat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
extern "C" HINSTANCE s_hModule; // Saved module handle
#endif // !__WIN__

#if defined(MONGO_SUPPORT)
bool MongoEnabled(void);
#endif // MONGO_SUPPORT
PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);

/***********************************************************************/
Expand Down Expand Up @@ -558,7 +561,13 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(MONGO_SUPPORT)
case TAB_MONGO: tdp = new(g) MGODEF; break;
case TAB_MONGO:
if (MongoEnabled())
tdp = new(g) MGODEF;
else
strcpy(g->Message, "MONGO type not enabled");

break;
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
Expand Down
5 changes: 3 additions & 2 deletions storage/connect/myconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db,
int pt, const char *csname)
{
const char *pipe = NULL;
uint cto = 6000, nrt = 12000;
uint cto = 10, nrt = 20;
my_bool my_true= 1;

m_DB = mysql_init(NULL);
Expand Down Expand Up @@ -525,7 +525,8 @@ int MYSQLC::Open(PGLOBAL g, const char *host, const char *db,
mysql_options(m_DB, MYSQL_OPT_USE_THREAD_SPECIFIC_MEMORY,
(char*)&my_true);

if (!mysql_real_connect(m_DB, host, user, pwd, db, pt, pipe, CLIENT_MULTI_RESULTS)) {
if (!mysql_real_connect(m_DB, host, user, pwd, db, pt, pipe,
CLIENT_MULTI_RESULTS | CLIENT_REMEMBER_OPTIONS)) {
#if defined(_DEBUG)
sprintf(g->Message, "mysql_real_connect failed: (%d) %s",
mysql_errno(m_DB), mysql_error(m_DB));
Expand Down
17 changes: 8 additions & 9 deletions storage/connect/mysql-test/connect/r/json_java_2.result
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar';
set connect_enable_mongo=1;
#
# Test the MONGO table type
#
Expand All @@ -25,7 +26,6 @@ address_street 1 CHAR 38 38 0 0 address.street
address_zipcode 1 CHAR 5 5 0 0 address.zipcode
borough 1 CHAR 13 13 0 0
cuisine 1 CHAR 64 64 0 0
grades 1 CHAR 0 0 0 1
grades_date 1 CHAR 256 256 0 1 grades.0.date
grades_grade 1 CHAR 14 14 0 1 grades.0.grade
grades_score 5 BIGINT 2 2 0 1 grades.0.score
Expand Down Expand Up @@ -72,20 +72,19 @@ t1 CREATE TABLE `t1` (
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`cuisine` char(64) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` varchar(256) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
`name` char(98) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=Java,Version=2' `DATA_CHARSET`='utf8' `LRECL`=4096
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 2 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 2 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 2 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 2 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 2 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
_id address_building address_coord address_street address_zipcode borough cuisine grades_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
Expand Down Expand Up @@ -259,7 +258,6 @@ t1 CREATE TABLE `t1` (
`address_street` char(38) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades` char(1) DEFAULT NULL,
`grades_date` char(24) DEFAULT NULL `FIELD_FORMAT`='grades.0.date',
`grades_grade` char(14) DEFAULT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_score` bigint(2) DEFAULT NULL `FIELD_FORMAT`='grades.0.score',
Expand Down Expand Up @@ -384,3 +382,4 @@ planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
set connect_enable_mongo=0;
Loading

0 comments on commit 5b9c32e

Please sign in to comment.