Commit d8f99f16 authored by Olivier Bertrand's avatar Olivier Bertrand

- Add FBLOCK when opening ODBC, JSON and MONGO tables.

This to have automatic closing in case of thrown error.
  modified:   storage/connect/cmgoconn.cpp
  modified:   storage/connect/cmgoconn.h
  modified:   storage/connect/filamzip.cpp
  modified:   storage/connect/javaconn.cpp
  modified:   storage/connect/javaconn.h
  modified:   storage/connect/odbconn.cpp
  modified:   storage/connect/odbconn.h
  modified:   storage/connect/plgdbsem.h
  modified:   storage/connect/plgdbutl.cpp

- Fix INCOL bug when inserting several lines to MONGO tables
  modified:   storage/connect/cmgoconn.cpp
  modified:   storage/connect/tabcmg.cpp
  modified:   storage/connect/tabjmg.cpp

- MONGO_SUPPORT is set for both MongoDB drivers
  CMGO_SUPPORT  is set only when the C driver is available
  modified:   storage/connect/CMakeLists.txt
  modified:   storage/connect/filter.h
  modified:   storage/connect/filter.h
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/mongo.cpp
  modified:   storage/connect/mycat.cc
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h

- Separate enums JCATINFO and
  modified:   storage/connect/javaconn.h
  modified:   storage/connect/jdbconn.cpp

- Fix crash when executing JDBC catfunc=driver
  modified:   storage/connect/jdbconn.cpp

- Report an error when the Mongo driver if explicitly
specified and not supported.
  modified:   storage/connect/mongo.cpp

- Fix bug causing catalog JSON tables to fail
  modified:   storage/connect/tabjson.cpp

- Protect by mutex the Ready variable of the TBLTBM table type
  modified:   storage/connect/tabtbl.cpp

- Put testing of Thread TBL tables in a separate test
With added case and modified old case that could avoid the test to fail.
  modified:   storage/connect/mysql-test/connect/r/tbl.result
  modified:   storage/connect/mysql-test/connect/t/tbl.test
  new file:   storage/connect/mysql-test/connect/r/tbl_thread.result
  new file:   storage/connect/mysql-test/connect/t/tbl_thread.test

- jmongo3.test no more exists
  deleted:    storage/connect/mysql-test/connect/t/jmongo3.test

- Add new tests for the MONGO feature (disabled)
  modified:   storage/connect/mysql-test/connect/disabled.def
  new file:   storage/connect/mysql-test/connect/r/json_java_2.result
  new file:   storage/connect/mysql-test/connect/r/json_java_3.result
  new file:   storage/connect/mysql-test/connect/r/json_mongo_c.result
  new file:   storage/connect/mysql-test/connect/r/mongo_c.result
  new file:   storage/connect/mysql-test/connect/r/mongo_java_2.result
  new file:   storage/connect/mysql-test/connect/r/mongo_java_3.result
  new file:   storage/connect/mysql-test/connect/std_data/Mongo2.jar
  new file:   storage/connect/mysql-test/connect/std_data/cities.json
  new file:   storage/connect/mysql-test/connect/t/json_java_2.test
  new file:   storage/connect/mysql-test/connect/t/json_java_3.test
  new file:   storage/connect/mysql-test/connect/t/json_mongo_c.test
  new file:   storage/connect/mysql-test/connect/t/mongo.inc
  new file:   storage/connect/mysql-test/connect/t/mongo_c.test
  new file:   storage/connect/mysql-test/connect/t/mongo_java_2.test
  new file:   storage/connect/mysql-test/connect/t/mongo_java_3.test
  new file:   storage/connect/mysql-test/connect/t/mongo_test.inc
parent df3fd420
......@@ -247,11 +247,8 @@ ENDIF(CONNECT_WITH_ODBC)
#
# JDBC and MongoDB Java Driver
#
IF(APPLE)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine without JDBC support" OFF)
ELSE()
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
ENDIF()
OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
OPTION(CONNECT_WITH_JDBC "Compile CONNECT storage engine with JDBC support" ON)
IF(CONNECT_WITH_JDBC)
FIND_PACKAGE(Java 1.6)
......@@ -263,12 +260,9 @@ IF(CONNECT_WITH_JDBC)
# SET(JDBC_LIBRARY ${JAVA_JVM_LIBRARY}) will be dynamically linked
SET(CONNECT_SOURCES ${CONNECT_SOURCES}
javaconn.cpp jdbconn.cpp tabjdbc.cpp
jmgoconn.cpp jmgfam.cpp mongo.cpp tabjmg.cpp
jdbccat.h javaconn.h jdbconn.h tabjdbc.h
jmgoconn.h jmgfam.h mongo.h tabjmg.h
JdbcInterface.java ApacheInterface.java MariadbInterface.java
MysqlInterface.java OracleInterface.java PostgresqlInterface.java
Mongo2Interface.java Mongo3Interface.java
JavaWrappers.jar)
# TODO: Find how to compile and install the java wrapper classes
# Find required libraries and include directories
......@@ -278,6 +272,13 @@ IF(CONNECT_WITH_JDBC)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/JavaWrappers.jar
DESTINATION ${INSTALL_PLUGINDIR} COMPONENT connect-engine)
add_definitions(-DJDBC_SUPPORT)
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()
ELSE()
SET(JDBC_LIBRARY "")
ENDIF()
......@@ -299,8 +300,6 @@ ENDIF(CONNECT_WITH_ZIP)
# MONGO C Driver (CMAKE NOT YET WORKING)
#
#OPTION(CONNECT_WITH_MONGO "Compile CONNECT storage engine with MONGO support" ON)
#IF(CONNECT_WITH_MONGO)
# IF(WIN32)
# # Adding some typical places to search in
......@@ -311,17 +310,18 @@ ENDIF(CONNECT_WITH_ZIP)
# C:/mongo-c-driver/lib
# D:/mongo-c-driver/lib)
# ENDIF(WIN32)
# FIND_PACKAGE(libmongoc)
# 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)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
# add_definitions(-DMONGO_SUPPORT)
# ENDIF (NOT JAVA_FOUND AND JNI_FOUND)
# ENDIF(MONGO_FOUND)
#ENDIF(CONNECT_WITH_MONGO)
......
......@@ -92,6 +92,32 @@ void INCOL::AddCol(PGLOBAL g, PCOL colp, char *jp)
} // end of AddCol
/***********************************************************************/
/* Clear. */
/***********************************************************************/
void INCOL::Init(void)
{
bson_init(Child);
for (PKC kp = Klist; kp; kp = kp->Next)
if (kp->Incolp)
kp->Incolp->Init();
} // end of init
/***********************************************************************/
/* Destroy. */
/***********************************************************************/
void INCOL::Destroy(void)
{
bson_destroy(Child);
for (PKC kp = Klist; kp; kp = kp->Next)
if (kp->Incolp)
kp->Incolp->Destroy();
} // end of Destroy
/* -------------------------- Class CMgoConn ------------------------- */
/***********************************************************************/
......@@ -109,6 +135,7 @@ CMgoConn::CMgoConn(PGLOBAL g, PCPARM pcg)
Query = NULL;
Opts = NULL;
Fpc = NULL;
fp = NULL;
m_Connected = false;
} // end of CMgoConn standard constructor
......@@ -149,6 +176,24 @@ bool CMgoConn::Connect(PGLOBAL g)
return true;
} // endif Collection
/*********************************************************************/
/* Link a Fblock. This make possible to automatically close it */
/* in case of error (throw). */
/*********************************************************************/
PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr;
fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK));
fp->Type = TYPE_FB_MONGO;
fp->Fname = NULL;
fp->Next = dbuserp->Openlist;
dbuserp->Openlist = fp;
fp->Count = 1;
fp->Length = 0;
fp->Memory = NULL;
fp->Mode = MODE_ANY;
fp->File = this;
fp->Handle = 0;
m_Connected = true;
return false;
} // end of Connect
......@@ -493,19 +538,19 @@ bool CMgoConn::DocWrite(PGLOBAL g, PINCOL icp)
bool isdoc = !kp->Incolp->Array;
if (isdoc)
BSON_APPEND_DOCUMENT_BEGIN(&icp->Child, kp->Key, &kp->Incolp->Child);
BSON_APPEND_DOCUMENT_BEGIN(icp->Child, kp->Key, kp->Incolp->Child);
else
BSON_APPEND_ARRAY_BEGIN(&icp->Child, kp->Key, &kp->Incolp->Child);
BSON_APPEND_ARRAY_BEGIN(icp->Child, kp->Key, kp->Incolp->Child);
if (DocWrite(g, kp->Incolp))
return true;
if (isdoc)
bson_append_document_end(&icp->Child, &kp->Incolp->Child);
bson_append_document_end(icp->Child, kp->Incolp->Child);
else
bson_append_array_end(&icp->Child, &kp->Incolp->Child);
bson_append_array_end(icp->Child, kp->Incolp->Child);
} else if (AddValue(g, kp->Colp, &icp->Child, kp->Key, false))
} else if (AddValue(g, kp->Colp, icp->Child, kp->Key, false))
return true;
return false;
......@@ -520,19 +565,19 @@ int CMgoConn::Write(PGLOBAL g)
PTDB tp = Pcg->Tdbp;
if (tp->GetMode() == MODE_INSERT) {
bson_init(&Fpc->Child);
Fpc->Init();
if (DocWrite(g, Fpc))
return RC_FX;
if (trace) {
char *str = bson_as_json(&Fpc->Child, NULL);
char *str = bson_as_json(Fpc->Child, NULL);
htrc("Inserting: %s\n", str);
bson_free(str);
} // endif trace
if (!mongoc_collection_insert(Collection, MONGOC_INSERT_NONE,
&Fpc->Child, NULL, &Error)) {
Fpc->Child, NULL, &Error)) {
sprintf(g->Message, "Mongo insert: %s", Error.message);
rc = RC_FX;
} // endif insert
......@@ -641,6 +686,8 @@ void CMgoConn::Close(void)
if (Client) mongoc_client_pool_push(Pool, Client);
if (Pool) mongoc_client_pool_destroy(Pool);
if (Uri) mongoc_uri_destroy(Uri);
if (Fpc) Fpc->Destroy();
if (fp) fp->Count = 0;
} // end of Close
/***********************************************************************/
......
......@@ -48,13 +48,15 @@ typedef struct KEYCOL {
class INCOL : public BLOCK {
public:
// Constructor
INCOL(bool ar) { Klist = NULL; Array = ar; }
INCOL(bool ar) { Child = bson_new(); Klist = NULL; Array = ar; }
// Methods
void AddCol(PGLOBAL g, PCOL colp, char *jp);
void Init(void);
void Destroy(void);
//Members
bson_t Child;
bson_t *Child;
PKC Klist;
bool Array;
}; // end of INCOL;
......@@ -108,5 +110,6 @@ class CMgoConn : public BLOCK {
bson_iter_t Iter; // Used to retrieve column value
bson_iter_t Desc; // Descendant iter
PINCOL Fpc; // To insert INCOL classes
PFBLOCK fp;
bool m_Connected;
}; // end of class CMgoConn
......@@ -290,6 +290,9 @@ void ZIPUTIL::close()
zipfile = NULL;
} // endif zipfile
if (fp)
fp->Count = 0;
} // end of close
/***********************************************************************/
......@@ -493,6 +496,9 @@ void UNZIPUTL::close()
zipfile = NULL;
} // endif zipfile
if (fp)
fp->Count = 0;
} // end of close
/***********************************************************************/
......
......@@ -1405,7 +1405,7 @@ PFIL FILTER::Copy(PTABS t)
} // end of Copy
#endif // 0
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
/***********************************************************************/
/* Make selector json representation for Mongo tables. */
/***********************************************************************/
......@@ -1483,7 +1483,7 @@ bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
s->Append('}');
return false;
} // end of MakeSelector
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
/*********************************************************************/
/* Make file output of FILTER contents. */
......
......@@ -61,9 +61,9 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */
//virtual PXOB CheckSubQuery(PGLOBAL, PSQL);
//virtual bool CheckLocal(PTDB);
//virtual int CheckSpcCol(PTDB tdbp, int n);
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s);
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
virtual void Printf(PGLOBAL g, FILE *f, uint n);
virtual void Prints(PGLOBAL g, char *ps, uint z);
// PFIL Linearize(bool nosep);
......
......@@ -208,16 +208,18 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
#if defined(JDBC_SUPPORT) || defined(MONGO_SUPPORT)
#if defined(MONGO_SUPPORT)
PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ url, PTOS topt, bool info);
#endif // JDBC_SUPPORT || MONGO_SUPPORT
#endif // MONGO_SUPPORT
int TranslateJDBCType(int stp, char *tn, int prec, int& len, char& v);
void PushWarning(PGLOBAL g, THD *thd, int level);
bool CheckSelf(PGLOBAL g, TABLE_SHARE *s, PCSZ host, PCSZ db,
PCSZ tab, PCSZ src, int port);
bool ZipLoadFile(PGLOBAL, PCSZ, PCSZ, PCSZ, bool, bool);
bool ExactInfo(void);
#if defined(CMGO_SUPPORT)
void mongo_init(bool);
#endif // CMGO_SUPPORT
USETEMP UseTemp(void);
int GetConvSize(void);
TYPCONV GetTypeConv(void);
......@@ -688,9 +690,9 @@ static int connect_init_func(void *p)
XmlInitParserLib();
#endif // LIBXML2_SUPPORT
#if defined(MONGO_SUPPORT)
#if defined(CMGO_SUPPORT)
mongo_init(true);
#endif // MONGO_SUPPORT
#endif // CMGO_SUPPORT
init_connect_psi_keys();
......@@ -730,9 +732,9 @@ static int connect_done_func(void *)
XmlCleanupParserLib();
#endif // LIBXML2_SUPPORT
#if defined(MONGO_SUPPORT)
#if defined(CMGO_SUPPORT)
mongo_init(false);
#endif // MONGO_SUPPORT
#endif // CMGO_SUPPORT
#ifdef JDBC_SUPPORT
JAVAConn::ResetJVM();
......@@ -5360,11 +5362,11 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
#if defined(JDBC_SUPPORT)
PJPARM sjp= NULL;
#endif // JDBC_SUPPORT
#if defined(JDBC_SUPPORT) || defined(MONGO_SUPPORT)
#if defined(MONGO_SUPPORT)
PCSZ driver= NULL;
char *url= NULL;
//char *prop= NULL;
#endif // JDBC_SUPPORT || MONGO_SUPPORT
#endif // MONGO_SUPPORT
uint tm, fnc= FNC_NO, supfnc= (FNC_NO | FNC_COL);
bool bif, ok= false, dbf= false;
TABTYPE ttp= TAB_UNDEF;
......@@ -5639,14 +5641,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
ok = true;
break;
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
case TAB_MONGO:
if (!topt->tabname)
topt->tabname = tab;
ok = true;
break;
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
case TAB_VIR:
ok = true;
break;
......@@ -5789,22 +5791,14 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_JSON:
qrp = JSONColumns(g, db, dsn, topt, fnc == FNC_COL);
break;
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
case TAB_MONGO:
if (!(url = strz(g, create_info->connect_string)) || !*url)
url = "mongodb://localhost:27017";
#if !defined(MONGO_SUPPORT)
driver = "JAVA";
#elif !defined(JDBC_SUPPORT)
driver = "C";
#else // MONGO_SUPPORT && JDBC_SUPPORT
if (!driver)
driver = "C";
#endif // MONGO_SUPPORT && JDBC_SUPPORT
qrp = MGOColumns(g, db, url, topt, fnc == FNC_COL);
break;
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
case TAB_XML:
qrp = XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL);
......
......@@ -124,6 +124,7 @@ JAVAConn::JAVAConn(PGLOBAL g, PCSZ wrapper)
m_Wrap = strcat(strcpy(wn, "wrappers/"), m_Wrap);
} // endif m_Wrap
fp = NULL;
m_Opened = false;
m_Connected = false;
m_Rows = 0;
......@@ -567,6 +568,24 @@ bool JAVAConn::Open(PGLOBAL g)
return true;
} // endif Check
/*********************************************************************/
/* Link a Fblock. This make possible to automatically close it */
/* in case of error (throw). */
/*********************************************************************/
PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr;
fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK));
fp->Type = TYPE_FB_JAVA;
fp->Fname = NULL;
fp->Next = dbuserp->Openlist;
dbuserp->Openlist = fp;
fp->Count = 1;
fp->Length = 0;
fp->Memory = NULL;
fp->Mode = MODE_ANY;
fp->File = this;
fp->Handle = 0;
m_Opened = true;
return false;
} // end of Open
......@@ -595,5 +614,8 @@ void JAVAConn::Close()
if ((rc = jvm->DetachCurrentThread()) != JNI_OK)
printf("DetachCurrentThread: rc=%d\n", (int)rc);
if (fp)
fp->Count = 0;
m_Opened = false;
} // end of Close
......@@ -25,18 +25,16 @@
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
//efine MAX_CONNECT_LEN 512 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE 0 // TYPE_NULL
//efine DEFAULT_FIELD_TYPE 0 // TYPE_NULL
#if !defined(__WIN__)
typedef unsigned char *PUCHAR;
#endif // !__WIN__
enum JCATINFO {
CAT_TAB = 1, // JDBC Tables
CAT_COL = 2, // JDBC Columns
CAT_KEY = 3, // JDBC PrimaryKeys
//CAT_STAT = 4, // SQLStatistics
//CAT_SPC = 5 // SQLSpecialColumns
JCAT_TAB = 1, // JDBC Tables
JCAT_COL = 2, // JDBC Columns
JCAT_KEY = 3, // JDBC PrimaryKeys
};
/***********************************************************************/
......@@ -121,6 +119,7 @@ class JAVAConn : public BLOCK {
jclass jdi; // Pointer to the java wrapper class
jobject job; // The java wrapper class object
jmethodID errid; // The GetErrmsg method ID
PFBLOCK fp;
bool m_Opened;
bool m_Connected;
PCSZ DiscFunc;
......
......@@ -289,7 +289,7 @@ PQRYRES JDBCColumns(PGLOBAL g, PCSZ db, PCSZ table, PCSZ colpat,
if (trace)
htrc("Getting col results ncol=%d\n", qrp->Nbcol);
if (!(cap = AllocCatInfo(g, CAT_COL, db, table, qrp)))
if (!(cap = AllocCatInfo(g, JCAT_COL, db, table, qrp)))
return NULL;
// Colpat cannot be null or empty for some drivers
......@@ -410,7 +410,7 @@ PQRYRES JDBCTables(PGLOBAL g, PCSZ db, PCSZ tabpat, PCSZ tabtyp,
return qrp;
// Tabpat cannot be null or empty for some drivers
if (!(cap = AllocCatInfo(g, CAT_TAB, db,
if (!(cap = AllocCatInfo(g, JCAT_TAB, db,
(tabpat && *tabpat) ? tabpat : PlugDup(g, "%"), qrp)))
return NULL;
......@@ -465,7 +465,7 @@ PQRYRES JDBCDrivers(PGLOBAL g, int maxres, bool info)
if (!info) {
jcp = new(g) JDBConn(g, NULL);
if (jcp->Open(NULL) != RC_OK)
if (jcp->Open(g) != RC_OK)
return NULL;
if (!maxres)
......@@ -1407,28 +1407,19 @@ bool JDBConn::SetParam(JDBCCOL *colp)
// Now do call the proper JDBC API
switch (cap->Id) {
case CAT_COL:
case JCAT_COL:
fnc = "GetColumns";
break;
case CAT_TAB:
case JCAT_TAB:
fnc = "GetTables";
break;
#if 0
case CAT_KEY:
case JCAT_KEY:
fnc = "SQLPrimaryKeys";
rc = SQLPrimaryKeys(hstmt, name.ptr(2), name.length(2),
name.ptr(1), name.length(1),
name.ptr(0), name.length(0));
break;
case CAT_STAT:
fnc = "SQLStatistics";
rc = SQLStatistics(hstmt, name.ptr(2), name.length(2),
name.ptr(1), name.length(1),
name.ptr(0), name.length(0),
cap->Unique, cap->Accuracy);
break;
case CAT_SPC:
ThrowDJX("SQLSpecialColumns not available yet");
#endif // 0
default:
sprintf(g->Message, "Invalid SQL function id");
......
......@@ -18,7 +18,7 @@
#include "plgdbsem.h"
#include "xtable.h"
#include "tabext.h"
#if defined(MONGO_SUPPORT)
#if defined(CMGO_SUPPORT)
#include "tabcmg.h"
#endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT)
......@@ -61,18 +61,29 @@ PQRYRES MGOColumns(PGLOBAL g, PCSZ db, PCSZ uri, PTOS topt, bool info)
/*********************************************************************/
/* Open MongoDB. */
/*********************************************************************/
# if !defined(JDBC_SUPPORT)
PCSZ drv = GetStringTableOption(g, topt, "Driver", NULL);
if (drv && toupper(*drv) == 'C') {
#if defined(CMGO_SUPPORT)
cmgd = new(g) CMGDISC(g, (int*)length);
#elif !defined(MONGO_SUPPORT)
#else
sprintf(g->Message, "Mongo %s Driver not available", "C");
goto err;
#endif
} else if (drv && toupper(*drv) == 'J') {
#if defined(JDBC_SUPPORT)
cmgd = new(g) JMGDISC(g, (int*)length);
#else
PCSZ drv = GetStringTableOption(g, topt, "Driver", "C");
if (toupper(*drv) == 'C')
sprintf(g->Message, "Mongo %s Driver not available", "Java");
goto err;
#endif
} else { // Driver not specified
#if defined(CMGO_SUPPORT)
cmgd = new(g) CMGDISC(g, (int*)length);
else
#else
cmgd = new(g) JMGDISC(g, (int*)length);
#endif
} // endif drv
if ((n = cmgd->GetColumns(g, db, uri, topt)) < 0)
goto err;
......@@ -302,13 +313,7 @@ bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
else if (!Tabschema)
Tabschema = GetStringCatInfo(g, "Dbname", "*");
# if !defined(JDBC_SUPPORT)
Driver = "C";
#elif !defined(MONGO_SUPPORT)
Driver = "JAVA";
#else
Driver = GetStringCatInfo(g, "Driver", "C");
#endif
Driver = GetStringCatInfo(g, "Driver", NULL);
Uri = GetStringCatInfo(g, "Connect", "mongodb://localhost:27017");
Colist = GetStringCatInfo(g, "Colist", NULL);
Filter = GetStringCatInfo(g, "Filter", NULL);
......@@ -329,27 +334,38 @@ bool MGODEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
/***********************************************************************/
PTDB MGODEF::GetTable(PGLOBAL g, MODE m)
{
if (Catfunc == FNC_COL) {
#if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C')
return new(g)TDBGOL(this);
#endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT)
return new(g)TDBJGL(this);
#else // !JDBC_SUPPORT
strcpy(g->Message, "No column find, no MONGO nor Java support");
return NULL;
#endif // !JDBC_SUPPORT
} // endif Catfunc
#if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C')
if (Driver && toupper(*Driver) == 'C') {
#if defined(CMGO_SUPPORT)
if (Catfunc == FNC_COL)
return new(g) TDBGOL(this);
else
return new(g) TDBCMG(this);
#endif // MONGO_SUPPORT
#else
sprintf(g->Message, "Mongo %s Driver not available", "C");
return NULL;
#endif
} else if (Driver && toupper(*Driver) == 'J') {
#if defined(JDBC_SUPPORT)
if (Catfunc == FNC_COL)
return new(g) TDBJGL(this);
else
return new(g) TDBJMG(this);
#else // !JDBC_SUPPORT
strcpy(g->Message, "No MONGO nor Java support");
#else
sprintf(g->Message, "Mongo %s Driver not available", "Java");
return NULL;
#endif // !JDBC_SUPPORT
#endif
} else { // Driver not specified
#if defined(CMGO_SUPPORT)
if (Catfunc == FNC_COL)
return new(g) TDBGOL(this);
else
return new(g) TDBCMG(this);
#else
if (Catfunc == FNC_COL)
return new(g) TDBJGL(this);
else
return new(g) TDBJMG(this);
#endif
} // endif Driver
} // end of GetTable
......@@ -96,9 +96,9 @@
#if defined(XML_SUPPORT)
#include "tabxml.h"
#endif // XML_SUPPORT
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
#include "mongo.h"
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
#include "tabzip.h"
#endif // ZIP_SUPPORT
......@@ -164,7 +164,7 @@ TABTYPE GetTypeID(const char *type)
#if defined(ZIP_SUPPORT)
: (!stricmp(type, "ZIP")) ? TAB_ZIP
#endif
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
: (!stricmp(type, "MONGO")) ? TAB_MONGO
#endif
: (!stricmp(type, "OEM")) ? TAB_OEM : TAB_NIY;
......@@ -557,9 +557,9 @@ PRELDEF MYCAT::MakeTableDesc(PGLOBAL g, PTABLE tablep, LPCSTR am)
#endif // PIVOT_SUPPORT
case TAB_VIR: tdp= new(g) VIRDEF; break;
case TAB_JSON: tdp= new(g) JSONDEF; break;
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
case TAB_MONGO: tdp = new(g) MGODEF; break;
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
#if defined(ZIP_SUPPORT)
case TAB_ZIP: tdp= new(g) ZIPDEF; break;
#endif // ZIP_SUPPORT
......
......@@ -13,6 +13,9 @@ jdbc : Variable settings depend on machine configuration
jdbc_new : Variable settings depend on machine configuration
jdbc_oracle : Variable settings depend on machine configuration
jdbc_postgresql : Variable settings depend on machine configuration
json_mgo : Need MongoDB running and its C Driver installed
mongo : Need MongoDB running and its C Driver installed
jmongo3 : Need MongoDB running and its Java Driver installed
json_mongo_c : Need MongoDB running and its C Driver installed
json_java_2 : Need MongoDB running and its Java Driver installed
json_java_3 : Need MongoDB running and its Java Driver installed
mongo_c : Need MongoDB running and its C Driver installed
mongo_java_2 : Need MongoDB running and its Java Driver installed
mongo_java_3 : Need MongoDB running and its Java Driver installed
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar';
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CONNECTION='mongodb://localhost:27017' LRECL=4096
OPTION_LIST='Driver=Java,Version=2' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51c"},"address":{"building":"1007","coord":[-73.856077,40.848447],"street":"Morris Park Ave","zipcode":"10462"},"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":"2014-03-03T00:00:00.000Z"},"grade":"A","score":2},{"date":{"$date":"2013-09-11T00:00:00.000Z"},"grade":"A","score":6},{"date":{"$date":"2013-01-24T00:00:00.000Z"},"grade":"A","score":10},{"date":{"$date":"2011-11-23T00:00:00.000Z"},"grade":"A","score":9},{"date":{"$date":"2011-03-10T00:00:00.000Z"},"grade":"B","score":14}],"name":"Morris Park Bake Shop","restaurant_id":"30075445"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51d"},"address":{"building":"469","coord":[-73.961704,40.662942],"street":"Flatbush Avenue","zipcode":"11225"},"borough":"Brooklyn","cuisine":"Hamburgers","grades":[{"date":{"$date":"2014-12-30T00:00:00.000Z"},"grade":"A","score":8},{"date":{"$date":"2014-07-01T00:00:00.000Z"},"grade":"B","score":23},{"date":{"$date":"2013-04-30T00:00:00.000Z"},"grade":"A","score":12},{"date":{"$date":"2012-05-08T00:00:00.000Z"},"grade":"A","score":12}],"name":"Wendy'S","restaurant_id":"30112340"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51e"},"address":{"building":"351","coord":[-73.98513559999999,40.7676919],"street":"West 57 Street","zipcode":"10019"},"borough":"Manhattan","cuisine":"Irish","grades":[{"date":{"$date":"2014-09-06T00:00:00.000Z"},"grade":"A","score":2},{"date":{"$date":"2013-07-22T00:00:00.000Z"},"grade":"A","score":11},{"date":{"$date":"2012-07-31T00:00:00.000Z"},"grade":"A","score":12},{"date":{"$date":"2011-12-29T00:00:00.000Z"},"grade":"A","score":12}],"name":"Dj Reynolds Pub And Restaurant","restaurant_id":"30191841"}
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=Java,Version=2' DATA_CHARSET=utf8 CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Jpath
_id 1 CHAR 24 24 0 0 _id
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 256 256 0 1 address.coord
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
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
OPTION_LIST='Level=1,Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096 DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` varchar(256) DEFAULT NULL `FIELD_FORMAT`='address.coord',
`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,
`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
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"grades":0}' OPTION_LIST='Driver=Java,Version=2,level=0' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 40.848447 Morris Park Ave 10462 Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 40.662942 Flatbush Avenue 11225 Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 40.7676919 West 57 Street 10019 Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 40.579505 Stillwell Avenue 11224 Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 40.7311739 63 Road 11374 Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 8825 -73.8803827 40.7643124 Astoria Boulevard 11369 Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 2206 -74.1377286 40.6119572 Victory Boulevard 10314 Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 7114 -73.9068506 40.6199034 Avenue U 11234 Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 6409 -74.00528899999999 40.628886 11 Avenue 11219 Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 1839 -73.9482609 40.6408271 Nostrand Avenue 11226 Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 1970-01-01
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 1970-01-01
Wendy'S Flatbush Avenue 8 1970-01-01
Dj Reynolds Pub And Restaurant West 57 Street 2 1970-01-01
Riviera Caterer Stillwell Avenue 5 1970-01-01
Tov Kosher Kitchen 63 Road 20 1970-01-01
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 1970-01-01 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 1970-01-01 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 1970-01-01 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 1970-01-01 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 1970-01-01 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 1970-01-01 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 1970-01-01 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 1970-01-01 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 1970-01-01 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 1970-01-01 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 1970-01-01 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 1970-01-01 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 1970-01-01 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 1970-01-01 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 1970-01-01 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 1970-01-01 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 1970-01-01 01:33:34 B 15
Tout Va Bien Manhattan 1970-01-01 01:33:34 A 13
Tout Va Bien Manhattan 1970-01-01 01:33:33 C 36
Tout Va Bien Manhattan 1970-01-01 01:33:33 B 22
Tout Va Bien Manhattan 1970-01-01 01:33:32 C 36
Tout Va Bien Manhattan 1970-01-01 01:33:32 C 7
La Grenouille Manhattan 1970-01-01 01:33:34 A 10
La Grenouille Manhattan 1970-01-01 01:33:33 A 9
La Grenouille Manhattan 1970-01-01 01:33:32 A 13
Le Perigord Manhattan 1970-01-01 01:33:34 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 1970-01-01 01:33:34
Bistro Sk A 12 1970-01-01 01:33:34
Bistro Sk B 18 1970-01-01 01:33:33
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"cuisine":0}' CONNECTION='mongodb://localhost:27017' LRECL=4096
OPTION_LIST='Driver=Java,level=2,version=2';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` double(18,16) DEFAULT NULL `FIELD_FORMAT`='address.coord.0',
`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',
`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' `COLIST`='{"cuisine":0}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=Java,level=2,version=2' `LRECL`=4096
SELECT name, borough, address_street, grades_score AS score FROM t1 WHERE grades_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
OPTION_LIST='Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096 DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2' CONNECTION='mongodb://localhost:27017' LRECL=4096;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 NULL 44 27
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=YES' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1;
item total average
journal 285 57.00
notebook 1368 456.00
paper 23 5.75
planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar';
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CONNECTION='mongodb://localhost:27017' LRECL=4096
OPTION_LIST='Driver=Java,Version=3' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51c"},"address":{"building":"1007","coord":[-73.856077,40.848447],"street":"Morris Park Ave","zipcode":"10462"},"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":1393804800000},"grade":"A","score":2},{"date":{"$date":1378857600000},"grade":"A","score":6},{"date":{"$date":1358985600000},"grade":"A","score":10},{"date":{"$date":1322006400000},"grade":"A","score":9},{"date":{"$date":1299715200000},"grade":"B","score":14}],"name":"Morris Park Bake Shop","restaurant_id":"30075445"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51d"},"address":{"building":"469","coord":[-73.961704,40.662942],"street":"Flatbush Avenue","zipcode":"11225"},"borough":"Brooklyn","cuisine":"Hamburgers","grades":[{"date":{"$date":1419897600000},"grade":"A","score":8},{"date":{"$date":1404172800000},"grade":"B","score":23},{"date":{"$date":1367280000000},"grade":"A","score":12},{"date":{"$date":1336435200000},"grade":"A","score":12}],"name":"Wendy'S","restaurant_id":"30112340"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51e"},"address":{"building":"351","coord":[-73.98513559999999,40.7676919],"street":"West 57 Street","zipcode":"10019"},"borough":"Manhattan","cuisine":"Irish","grades":[{"date":{"$date":1409961600000},"grade":"A","score":2},{"date":{"$date":1374451200000},"grade":"A","score":11},{"date":{"$date":1343692800000},"grade":"A","score":12},{"date":{"$date":1325116800000},"grade":"A","score":12}],"name":"Dj Reynolds Pub And Restaurant","restaurant_id":"30191841"}
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=Java,Version=3' DATA_CHARSET=utf8 CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Jpath
_id 1 CHAR 24 24 0 0 _id
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 256 256 0 1 address.coord
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
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
OPTION_LIST='Level=1,Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096 DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` varchar(256) DEFAULT NULL `FIELD_FORMAT`='address.coord',
`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,
`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=3' `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 1 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 1 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 1 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 1 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 1 1416787200 Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"grades":0}' OPTION_LIST='Driver=Java,Version=3,level=0' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 40.848447 Morris Park Ave 10462 Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 40.662942 Flatbush Avenue 11225 Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 40.7676919 West 57 Street 10019 Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 40.579505 Stillwell Avenue 11224 Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 40.7311739 63 Road 11374 Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 8825 -73.8803827 40.7643124 Astoria Boulevard 11369 Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 2206 -74.1377286 40.6119572 Victory Boulevard 10314 Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 7114 -73.9068506 40.6199034 Avenue U 11234 Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 6409 -74.00528899999999 40.628886 11 Avenue 11219 Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 1839 -73.9482609 40.6408271 Nostrand Avenue 11226 Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 2014-03-03
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 2014-03-03
Wendy'S Flatbush Avenue 8 2014-12-30
Dj Reynolds Pub And Restaurant West 57 Street 2 2014-09-06
Riviera Caterer Stillwell Avenue 5 2014-06-10
Tov Kosher Kitchen 63 Road 20 2014-11-24
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 2014-10-23 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 2014-08-14 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 2014-09-29 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 2014-02-11 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 2014-10-08 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 2014-06-09 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 2014-10-22 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 2014-07-26 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 2014-12-03 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 2015-01-16 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 2014-08-27 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 2014-06-03 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 2014-08-07 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 2014-12-27 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 2014-10-28 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 2014-08-18 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 2014-11-10 01:00:00 B 15
Tout Va Bien Manhattan 2014-04-03 02:00:00 A 13
Tout Va Bien Manhattan 2013-07-17 02:00:00 C 36
Tout Va Bien Manhattan 2013-02-06 01:00:00 B 22
Tout Va Bien Manhattan 2012-07-16 02:00:00 C 36
Tout Va Bien Manhattan 2012-03-08 01:00:00 C 7
La Grenouille Manhattan 2014-04-09 02:00:00 A 10
La Grenouille Manhattan 2013-03-05 01:00:00 A 9
La Grenouille Manhattan 2012-02-02 01:00:00 A 13
Le Perigord Manhattan 2014-07-14 02:00:00 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 2014-11-21 01:00:00
Bistro Sk A 12 2014-02-19 01:00:00
Bistro Sk B 18 2013-06-12 02:00:00
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"cuisine":0}' CONNECTION='mongodb://localhost:27017' LRECL=4096
OPTION_LIST='Driver=Java,level=2,version=3';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` double(18,16) DEFAULT NULL `FIELD_FORMAT`='address.coord.0',
`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` bigint(13) 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' `COLIST`='{"cuisine":0}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=Java,level=2,version=3' `LRECL`=4096
SELECT name, borough, address_street, grades_score AS score FROM t1 WHERE grades_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
OPTION_LIST='Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096 DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3' CONNECTION='mongodb://localhost:27017' LRECL=4096;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 NULL 44 27
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=YES' CONNECTION='mongodb://localhost:27017' LRECL=4096;
SELECT * FROM t1;
item total average
journal 285 57.00
notebook 1368 456.00
paper 23 5.75
planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CONNECTION='mongodb://localhost:27017' LRECL=1024
OPTION_LIST='Driver=C,Version=0' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51c"},"address":{"building":"1007","coord":[-73.856076999999999089,40.848447000000000173],"street":"Morris Park Ave","zipcode":"10462"},"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":1393804800000},"grade":"A","score":2},{"date":{"$date":1378857600000},"grade":"A","score":6},{"date":{"$date":1358985600000},"grade":"A","score":10},{"date":{"$date":1322006400000},"grade":"A","score":9},{"date":{"$date":1299715200000},"grade":"B","score":14}],"name":"Morris Park Bake Shop","restaurant_id":"30075445"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51d"},"address":{"building":"469","coord":[-73.96170399999999745,40.66294200000000103],"street":"Flatbush Avenue","zipcode":"11225"},"borough":"Brooklyn","cuisine":"Hamburgers","grades":[{"date":{"$date":1419897600000},"grade":"A","score":8},{"date":{"$date":1404172800000},"grade":"B","score":23},{"date":{"$date":1367280000000},"grade":"A","score":12},{"date":{"$date":1336435200000},"grade":"A","score":12}],"name":"Wendy'S","restaurant_id":"30112340"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51e"},"address":{"building":"351","coord":[-73.985135599999992451,40.767691900000002647],"street":"West 57 Street","zipcode":"10019"},"borough":"Manhattan","cuisine":"Irish","grades":[{"date":{"$date":1409961600000},"grade":"A","score":2},{"date":{"$date":1374451200000},"grade":"A","score":11},{"date":{"$date":1343692800000},"grade":"A","score":12},{"date":{"$date":1325116800000},"grade":"A","score":12}],"name":"Dj Reynolds Pub And Restaurant","restaurant_id":"30191841"}
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=C,Version=0' DATA_CHARSET=utf8 CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Jpath
_id 1 CHAR 24 24 0 0 _id
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 256 256 0 1 address.coord
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
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
OPTION_LIST='Level=1,Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` varchar(256) DEFAULT NULL `FIELD_FORMAT`='address.coord',
`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,
`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=C,Version=0' `DATA_CHARSET`='utf8' `LRECL`=1024
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.856076999999999089 Morris Park Ave 10462 Bronx Bakery 1 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745 Flatbush Avenue 11225 Brooklyn Hamburgers 1 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451 West 57 Street 10019 Manhattan Irish 1 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523 Stillwell Avenue 11224 Brooklyn American 1 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639 63 Road 11374 Queens Jewish/Kosher 1 1416787200 Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"projection":{"grades":0}}' OPTION_LIST='Driver=C,Version=0,level=0' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856076999999999089 40.848447000000000173 Morris Park Ave 10462 Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745 40.66294200000000103 Flatbush Avenue 11225 Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451 40.767691900000002647 West 57 Street 10019 Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523 40.579504999999997494 Stillwell Avenue 11224 Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639 40.731173900000001709 63 Road 11374 Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 8825 -73.880382699999998408 40.764312400000001446 Astoria Boulevard 11369 Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 2206 -74.137728600000002643 40.611957199999999091 Victory Boulevard 10314 Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 7114 -73.906850599999998508 40.619903399999998328 Avenue U 11234 Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 6409 -74.005288999999990551 40.628886000000001388 11 Avenue 11219 Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 1839 -73.948260899999993967 40.640827100000002758 Nostrand Avenue 11226 Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 2014-03-03
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 2014-03-03
Wendy'S Flatbush Avenue 8 2014-12-30
Dj Reynolds Pub And Restaurant West 57 Street 2 2014-09-06
Riviera Caterer Stillwell Avenue 5 2014-06-10
Tov Kosher Kitchen 63 Road 20 2014-11-24
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 2014-10-23 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 2014-08-14 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 2014-09-29 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 2014-02-11 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 2014-10-08 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 2014-06-09 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 2014-10-22 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 2014-07-26 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 2014-12-03 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 2015-01-16 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 2014-08-27 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 2014-06-03 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 2014-08-07 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 2014-12-27 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 2014-10-28 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 2014-08-18 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 2014-11-10 01:00:00 B 15
Tout Va Bien Manhattan 2014-04-03 02:00:00 A 13
Tout Va Bien Manhattan 2013-07-17 02:00:00 C 36
Tout Va Bien Manhattan 2013-02-06 01:00:00 B 22
Tout Va Bien Manhattan 2012-07-16 02:00:00 C 36
Tout Va Bien Manhattan 2012-03-08 01:00:00 C 7
La Grenouille Manhattan 2014-04-09 02:00:00 A 10
La Grenouille Manhattan 2013-03-05 01:00:00 A 9
La Grenouille Manhattan 2012-02-02 01:00:00 A 13
Le Perigord Manhattan 2014-07-14 02:00:00 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 2014-11-21 01:00:00
Bistro Sk A 12 2014-02-19 01:00:00
Bistro Sk B 18 2013-06-12 02:00:00
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"projection":{"cuisine":0}}' CONNECTION='mongodb://localhost:27017' LRECL=1024
OPTION_LIST='Driver=C,level=2,version=0';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL `FIELD_FORMAT`='_id',
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` double(23,20) DEFAULT NULL `FIELD_FORMAT`='address.coord.0',
`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` bigint(13) 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' `COLIST`='{"projection":{"cuisine":0}}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=C,level=2,version=0' `LRECL`=1024
SELECT name, borough, address_street, grades_score AS score FROM t1 WHERE grades_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
OPTION_LIST='Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=1' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0' CONNECTION='mongodb://localhost:27017' LRECL=1024;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 44 27 NULL
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=JSON TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=YES' CONNECTION='mongodb://localhost:27017' LRECL=1024;
SELECT * FROM t1;
item total average
journal 285 57.00
notebook 1368 456.00
paper 23 5.75
planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Driver=C,Version=0' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51c"},"address":{"building":"1007","coord":[-73.856076999999999089,40.848447000000000173],"street":"Morris ParkAve", "zipcode":"10462"},"borough":"Bronx","cuisine":"Bakery","grades":[{"date":{"$date":1393804800000},"grade":"A","score":2},{"date":{"$date":1378857600000},"grade":"A","score":6},{"date":{"$date":1358985600000},"grade":"A","score":10},{"date":{"$date":1322006400000},"grade":"A","score":9},{"date":{"$date":1299715200000},"grade":"B","score":14}],"name":"Morris ParkBakeShop", "restaurant_id":"30075445"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51d"},"address":{"building":"469","coord":[-73.96170399999999745,40.66294200000000103],"street":"Flatbush Avenue", "zipcode":"11225"},"borough":"Brooklyn","cuisine":"Hamburgers","grades":[{"date":{"$date":1419897600000},"grade":"A","score":8},{"date":{"$date":1404172800000},"grade":"B","score":23},{"date":{"$date":1367280000000},"grade":"A","score":12},{"date":{"$date":1336435200000},"grade":"A","score":12}],"name":"Wendy'S","restaurant_id":"30112340"}
{"_id":{"$oid":"58ada47de5a51ddfcd5ed51e"},"address":{"building":"351","coord":[-73.985135599999992451,40.767691900000002647],"street":"West 57Street", "zipcode":"10019"},"borough":"Manhattan","cuisine":"Irish","grades":[{"date":{"$date":1409961600000},"grade":"A","score":2},{"date":{"$date":1374451200000},"grade":"A","score":11},{"date":{"$date":1343692800000},"grade":"A","score":12},{"date":{"$date":1325116800000},"grade":"A","score":12}],"name":"Dj ReynoldsPubAndRestaurant", "restaurant_id":"30191841"}
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=C,Version=0' DATA_CHARSET=utf8 ;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Bpath
_id 1 CHAR 24 24 0 0
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 512 512 0 0 address.coord
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_0 1 CHAR 512 512 0 1 grades.0
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Level=1,Driver=C,Version=0' DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` varchar(512) NOT NULL `FIELD_FORMAT`='address.coord',
`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,
`cuisine` char(64) NOT NULL,
`grades_0` varchar(512) DEFAULT NULL `FIELD_FORMAT`='grades.0',
`name` char(98) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=C,Version=0' `DATA_CHARSET`='utf8'
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades_0 name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 Morris Park Ave 10462 Bronx Bakery {"date":{"$date":1393804800000},"grade":"A","score":2} Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 Flatbush Avenue 11225 Brooklyn Hamburgers {"date":{"$date":1419897600000},"grade":"A","score":8} Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 West 57 Street 10019 Manhattan Irish {"date":{"$date":1409961600000},"grade":"A","score":2} Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 Stillwell Avenue 11224 Brooklyn American {"date":{"$date":1402358400000},"grade":"A","score":5} Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 63 Road 11374 Queens Jewish/Kosher {"date":{"$date":1416787200000},"grade":"Z","score":20} Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"projection":{"grades":0}}' OPTION_LIST='Driver=C,Version=0,level=0' ;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c {"building":"1007","coord":[-73.856076999999999089,40.848447000000000173],"street":"Morris ParkAve", "zipcode":"10462"} Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d {"building":"469","coord":[-73.96170399999999745,40.66294200000000103],"street":"Flatbush Avenue", "zipcode":"11225"} Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e {"building":"351","coord":[-73.985135599999992451,40.767691900000002647],"street":"West 57Street", "zipcode":"10019"} Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f {"building":"2780","coord":[-73.982419999999990523,40.579504999999997494],"street":"Stillwell Avenue", "zipcode":"11224"} Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 {"building":"97-22","coord":[-73.860115199999995639,40.731173900000001709],"street":"63 Road", "zipcode":"11374"} Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 {"building":"8825","coord":[-73.880382699999998408,40.764312400000001446],"street":"Astoria Boulevard", "zipcode":"11369"} Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 {"building":"2206","coord":[-74.137728600000002643,40.611957199999999091],"street":"Victory Boulevard", "zipcode":"10314"} Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 {"building":"7114","coord":[-73.906850599999998508,40.619903399999998328],"street":"Avenue U", "zipcode":"11234"} Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 {"building":"6409","coord":[-74.005288999999990551,40.628886000000001388],"street":"11 Avenue", "zipcode":"11219"} Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 {"building":"1839","coord":[-73.948260899999993967,40.640827100000002758],"street":"Nostrand Avenue", "zipcode":"11226"} Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0' ;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 2014-03-03
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 2014-03-03
Wendy'S Flatbush Avenue 8 2014-12-30
Dj Reynolds Pub And Restaurant West 57 Street 2 2014-09-06
Riviera Caterer Stillwell Avenue 5 2014-06-10
Tov Kosher Kitchen 63 Road 20 2014-11-24
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 2014-10-23 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 2014-08-14 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 2014-09-29 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 2014-02-11 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 2014-10-08 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 2014-06-09 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 2014-10-22 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 2014-07-26 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 2014-12-03 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 2015-01-16 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 2014-08-27 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 2014-06-03 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 2014-08-07 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 2014-12-27 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 2014-10-28 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 2014-08-18 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=C,Version=0' ;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=1' ;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 2014-11-10 01:00:00 B 15
Tout Va Bien Manhattan 2014-04-03 02:00:00 A 13
Tout Va Bien Manhattan 2013-07-17 02:00:00 C 36
Tout Va Bien Manhattan 2013-02-06 01:00:00 B 22
Tout Va Bien Manhattan 2012-07-16 02:00:00 C 36
Tout Va Bien Manhattan 2012-03-08 01:00:00 C 7
La Grenouille Manhattan 2014-04-09 02:00:00 A 10
La Grenouille Manhattan 2013-03-05 01:00:00 A 9
La Grenouille Manhattan 2012-02-02 01:00:00 A 13
Le Perigord Manhattan 2014-07-14 02:00:00 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 2014-11-21 01:00:00
Bistro Sk A 12 2014-02-19 01:00:00
Bistro Sk B 18 2013-06-12 02:00:00
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"projection":{"cuisine":0}}'
OPTION_LIST='Driver=C,level=2,version=0';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(6) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord_0` double(12,6) NOT NULL `FIELD_FORMAT`='address.coord.0',
`address_street` char(25) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades_0_date` datetime NOT NULL `FIELD_FORMAT`='grades.0.date',
`grades_0_grade` char(14) NOT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_0_score` int(11) NOT NULL `FIELD_FORMAT`='grades.0.score',
`name` char(32) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `COLIST`='{"projection":{"cuisine":0}}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=C,level=2,version=0'
SELECT name, borough, address_street, grades_0_score AS score FROM t1 WHERE grades_0_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
OPTION_LIST='Driver=C,Version=0' ;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=C,Version=0' DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=1' ;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=C,Version=0' ;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 NULL 44 27
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=C,Version=0,Pipeline=YES' ;
SELECT * FROM t1;
item total average
journal 285 57.000000
notebook 1368 456.000000
paper 23 5.750000
planner 167 41.750000
postcard 23 5.750000
DROP TABLE t1;
true
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo2.jar';
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Driver=Java,Version=2' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51c"} , "address" : { "building" : "1007" , "coord" : [ -73.856077 , 40.848447] , "street" : "Morris Park Ave" , "zipcode" : "10462"} , "borough" : "Bronx" , "cuisine" : "Bakery" , "grades" : [ { "date" : { "$date" : "2014-03-03T00:00:00.000Z"} , "grade" : "A" , "score" : 2} , { "date" : { "$date" : "2013-09-11T00:00:00.000Z"} , "grade" : "A" , "score" : 6} , { "date" : { "$date" : "2013-01-24T00:00:00.000Z"} , "grade" : "A" , "score" : 10} , { "date" : { "$date" : "2011-11-23T00:00:00.000Z"} , "grade" : "A" , "score" : 9} , { "date" : { "$date" : "2011-03-10T00:00:00.000Z"} , "grade" : "B" , "score" : 14}] , "name" : "Morris Park Bake Shop" , "restaurant_id" : "30075445"}
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51d"} , "address" : { "building" : "469" , "coord" : [ -73.961704 , 40.662942] , "street" : "Flatbush Avenue" , "zipcode" : "11225"} , "borough" : "Brooklyn" , "cuisine" : "Hamburgers" , "grades" : [ { "date" : { "$date" : "2014-12-30T00:00:00.000Z"} , "grade" : "A" , "score" : 8} , { "date" : { "$date" : "2014-07-01T00:00:00.000Z"} , "grade" : "B" , "score" : 23} , { "date" : { "$date" : "2013-04-30T00:00:00.000Z"} , "grade" : "A" , "score" : 12} , { "date" : { "$date" : "2012-05-08T00:00:00.000Z"} , "grade" : "A" , "score" : 12}] , "name" : "Wendy'S" , "restaurant_id" : "30112340"}
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51e"} , "address" : { "building" : "351" , "coord" : [ -73.98513559999999 , 40.7676919] , "street" : "West 57 Street" , "zipcode" : "10019"} , "borough" : "Manhattan" , "cuisine" : "Irish" , "grades" : [ { "date" : { "$date" : "2014-09-06T00:00:00.000Z"} , "grade" : "A" , "score" : 2} , { "date" : { "$date" : "2013-07-22T00:00:00.000Z"} , "grade" : "A" , "score" : 11} , { "date" : { "$date" : "2012-07-31T00:00:00.000Z"} , "grade" : "A" , "score" : 12} , { "date" : { "$date" : "2011-12-29T00:00:00.000Z"} , "grade" : "A" , "score" : 12}] , "name" : "Dj Reynolds Pub And Restaurant" , "restaurant_id" : "30191841"}
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=Java,Version=2' DATA_CHARSET=utf8 ;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Bpath
_id 1 CHAR 24 24 0 0
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 41 41 0 0 address.coord
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_0 1 CHAR 99 99 0 1 grades.0
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Level=1,Driver=Java,Version=2' DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` char(41) NOT NULL `FIELD_FORMAT`='address.coord',
`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,
`cuisine` char(64) NOT NULL,
`grades_0` char(99) DEFAULT NULL `FIELD_FORMAT`='grades.0',
`name` char(98) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=Java,Version=2' `DATA_CHARSET`='utf8'
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades_0 name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 [ -73.856077 , 40.848447] Morris Park Ave 10462 Bronx Bakery { "date" : { "$date" : "2014-03-03T00:00:00.000Z"} , "grade" : "A" , "score" : 2} Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 [ -73.961704 , 40.662942] Flatbush Avenue 11225 Brooklyn Hamburgers { "date" : { "$date" : "2014-12-30T00:00:00.000Z"} , "grade" : "A" , "score" : 8} Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 [ -73.98513559999999 , 40.7676919] West 57 Street 10019 Manhattan Irish { "date" : { "$date" : "2014-09-06T00:00:00.000Z"} , "grade" : "A" , "score" : 2} Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 [ -73.98241999999999 , 40.579505] Stillwell Avenue 11224 Brooklyn American { "date" : { "$date" : "2014-06-10T00:00:00.000Z"} , "grade" : "A" , "score" : 5} Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 [ -73.8601152 , 40.7311739] 63 Road 11374 Queens Jewish/Kosher { "date" : { "$date" : "2014-11-24T00:00:00.000Z"} , "grade" : "Z" , "score" : 20} Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"grades":0}' OPTION_LIST='Driver=Java,Version=2,level=0' ;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c { "building" : "1007" , "coord" : [ -73.856077 , 40.848447] , "street" : "Morris Park Ave" , "zipcode" : "10462"} Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d { "building" : "469" , "coord" : [ -73.961704 , 40.662942] , "street" : "Flatbush Avenue" , "zipcode" : "11225"} Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e { "building" : "351" , "coord" : [ -73.98513559999999 , 40.7676919] , "street" : "West 57 Street" , "zipcode" : "10019"} Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f { "building" : "2780" , "coord" : [ -73.98241999999999 , 40.579505] , "street" : "Stillwell Avenue" , "zipcode" : "11224"} Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 { "building" : "97-22" , "coord" : [ -73.8601152 , 40.7311739] , "street" : "63 Road" , "zipcode" : "11374"} Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 { "building" : "8825" , "coord" : [ -73.8803827 , 40.7643124] , "street" : "Astoria Boulevard" , "zipcode" : "11369"} Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 { "building" : "2206" , "coord" : [ -74.1377286 , 40.6119572] , "street" : "Victory Boulevard" , "zipcode" : "10314"} Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 { "building" : "7114" , "coord" : [ -73.9068506 , 40.6199034] , "street" : "Avenue U" , "zipcode" : "11234"} Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 { "building" : "6409" , "coord" : [ -74.00528899999999 , 40.628886] , "street" : "11 Avenue" , "zipcode" : "11219"} Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 { "building" : "1839" , "coord" : [ -73.9482609 , 40.6408271] , "street" : "Nostrand Avenue" , "zipcode" : "11226"} Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2' ;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 2014-03-03
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 2014-03-03
Wendy'S Flatbush Avenue 8 2014-12-30
Dj Reynolds Pub And Restaurant West 57 Street 2 2014-09-06
Riviera Caterer Stillwell Avenue 5 2014-06-10
Tov Kosher Kitchen 63 Road 20 2014-11-24
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 2014-10-23 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 2014-08-14 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 2014-09-29 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 2014-02-11 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 2014-10-08 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 2014-06-09 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 2014-10-22 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 2014-07-26 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 2014-12-03 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 2015-01-16 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 2014-08-27 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 2014-06-03 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 2014-08-07 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 2014-12-27 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 2014-10-28 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 2014-08-18 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=Java,Version=2' ;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=1' ;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 2014-11-10 01:00:00 B 15
Tout Va Bien Manhattan 2014-04-03 02:00:00 A 13
Tout Va Bien Manhattan 2013-07-17 02:00:00 C 36
Tout Va Bien Manhattan 2013-02-06 01:00:00 B 22
Tout Va Bien Manhattan 2012-07-16 02:00:00 C 36
Tout Va Bien Manhattan 2012-03-08 01:00:00 C 7
La Grenouille Manhattan 2014-04-09 02:00:00 A 10
La Grenouille Manhattan 2013-03-05 01:00:00 A 9
La Grenouille Manhattan 2012-02-02 01:00:00 A 13
Le Perigord Manhattan 2014-07-14 02:00:00 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 2014-11-21 01:00:00
Bistro Sk A 12 2014-02-19 01:00:00
Bistro Sk B 18 2013-06-12 02:00:00
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"cuisine":0}'
OPTION_LIST='Driver=Java,level=2,version=2';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(6) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord_0` double(18,14) NOT NULL `FIELD_FORMAT`='address.coord.0',
`address_street` char(25) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades_0_date` datetime NOT NULL `FIELD_FORMAT`='grades.0.date',
`grades_0_grade` char(14) NOT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_0_score` int(2) NOT NULL `FIELD_FORMAT`='grades.0.score',
`name` char(32) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `COLIST`='{"cuisine":0}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=Java,level=2,version=2'
SELECT name, borough, address_street, grades_0_score AS score FROM t1 WHERE grades_0_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
OPTION_LIST='Driver=Java,Version=2' ;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=Java,Version=2' DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=1' ;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=2' ;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 NULL 44 27
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=Java,Version=2,Pipeline=YES' ;
SELECT * FROM t1;
item total average
journal 285 57.00
notebook 1368 456.00
paper 23 5.75
planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
SET GLOBAL connect_class_path='C:/MariaDB-10.2/MariaDB/storage/connect/mysql-test/connect/std_data/Mongo3.jar';
#
# Test the MONGO table type
#
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Driver=Java,Version=3' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
Document
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51c" }, "address" : { "building" : "1007", "coord" : [-73.856077, 40.848447], "street" : "Morris Park Ave", "zipcode" : "10462" }, "borough" : "Bronx", "cuisine" : "Bakery", "grades" : [{ "date" : { "$date" : 1393804800000 }, "grade" : "A", "score" : 2 }, { "date" : { "$date" : 1378857600000 }, "grade" : "A", "score" : 6 }, { "date" : { "$date" : 1358985600000 }, "grade" : "A", "score" : 10 }, { "date" : { "$date" : 1322006400000 }, "grade" : "A", "score" : 9 }, { "date" : { "$date" : 1299715200000 }, "grade" : "B", "score" : 14 }], "name" : "Morris Park Bake Shop", "restaurant_id" : "30075445" }
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51d" }, "address" : { "building" : "469", "coord" : [-73.961704, 40.662942], "street" : "Flatbush Avenue", "zipcode" : "11225" }, "borough" : "Brooklyn", "cuisine" : "Hamburgers", "grades" : [{ "date" : { "$date" : 1419897600000 }, "grade" : "A", "score" : 8 }, { "date" : { "$date" : 1404172800000 }, "grade" : "B", "score" : 23 }, { "date" : { "$date" : 1367280000000 }, "grade" : "A", "score" : 12 }, { "date" : { "$date" : 1336435200000 }, "grade" : "A", "score" : 12 }], "name" : "Wendy'S", "restaurant_id" : "30112340" }
{ "_id" : { "$oid" : "58ada47de5a51ddfcd5ed51e" }, "address" : { "building" : "351", "coord" : [-73.98513559999999, 40.7676919], "street" : "West 57 Street", "zipcode" : "10019" }, "borough" : "Manhattan", "cuisine" : "Irish", "grades" : [{ "date" : { "$date" : 1409961600000 }, "grade" : "A", "score" : 2 }, { "date" : { "$date" : 1374451200000 }, "grade" : "A", "score" : 11 }, { "date" : { "$date" : 1343692800000 }, "grade" : "A", "score" : 12 }, { "date" : { "$date" : 1325116800000 }, "grade" : "A", "score" : 12 }], "name" : "Dj Reynolds Pub And Restaurant", "restaurant_id" : "30191841" }
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=Java,Version=3' DATA_CHARSET=utf8 ;
SELECT * from t1;
Column_Name Data_Type Type_Name Column_Size Buffer_Length Decimal_Digits Nullable Bpath
_id 1 CHAR 24 24 0 0
address_building 1 CHAR 10 10 0 0 address.building
address_coord 1 CHAR 39 39 0 0 address.coord
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_0 1 CHAR 84 84 0 1 grades.0
name 1 CHAR 98 98 0 0
restaurant_id 1 CHAR 8 8 0 0
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3';
SELECT * FROM t1 LIMIT 10;
_id name cuisine borough restaurant_id
58ada47de5a51ddfcd5ed51c Morris Park Bake Shop Bakery Bronx 30075445
58ada47de5a51ddfcd5ed51d Wendy'S Hamburgers Brooklyn 30112340
58ada47de5a51ddfcd5ed51e Dj Reynolds Pub And Restaurant Irish Manhattan 30191841
58ada47de5a51ddfcd5ed51f Riviera Caterer American Brooklyn 40356018
58ada47de5a51ddfcd5ed520 Tov Kosher Kitchen Jewish/Kosher Queens 40356068
58ada47de5a51ddfcd5ed521 Brunos On The Boulevard American Queens 40356151
58ada47de5a51ddfcd5ed522 Kosher Island Jewish/Kosher Staten Island 40356442
58ada47de5a51ddfcd5ed523 Wilken'S Fine Food Delicatessen Brooklyn 40356483
58ada47de5a51ddfcd5ed524 Regina Caterers American Brooklyn 40356649
58ada47de5a51ddfcd5ed525 Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn 40356731
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
OPTION_LIST='Level=1,Driver=Java,Version=3' DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(10) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord` char(39) NOT NULL `FIELD_FORMAT`='address.coord',
`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,
`cuisine` char(64) NOT NULL,
`grades_0` char(84) DEFAULT NULL `FIELD_FORMAT`='grades.0',
`name` char(98) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `OPTION_LIST`='Level=1,Driver=Java,Version=3' `DATA_CHARSET`='utf8'
SELECT * FROM t1 LIMIT 5;
_id address_building address_coord address_street address_zipcode borough cuisine grades_0 name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 [-73.856077, 40.848447] Morris Park Ave 10462 Bronx Bakery { "date" : { "$date" : 1393804800000 }, "grade" : "A", "score" : 2 } Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 [-73.961704, 40.662942] Flatbush Avenue 11225 Brooklyn Hamburgers { "date" : { "$date" : 1419897600000 }, "grade" : "A", "score" : 8 } Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 [-73.98513559999999, 40.7676919] West 57 Street 10019 Manhattan Irish { "date" : { "$date" : 1409961600000 }, "grade" : "A", "score" : 2 } Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 [-73.98241999999999, 40.579505] Stillwell Avenue 11224 Brooklyn American { "date" : { "$date" : 1402358400000 }, "grade" : "A", "score" : 5 } Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 [-73.8601152, 40.7311739] 63 Road 11374 Queens Jewish/Kosher { "date" : { "$date" : 1416787200000 }, "grade" : "Z", "score" : 20 } Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"grades":0}' OPTION_LIST='Driver=Java,Version=3,level=0' ;
SELECT * FROM t1 LIMIT 10;
_id address borough cuisine name restaurant_id
58ada47de5a51ddfcd5ed51c { "building" : "1007", "coord" : [-73.856077, 40.848447], "street" : "Morris Park Ave", "zipcode" : "10462" } Bronx Bakery Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d { "building" : "469", "coord" : [-73.961704, 40.662942], "street" : "Flatbush Avenue", "zipcode" : "11225" } Brooklyn Hamburgers Wendy'S 30112340
58ada47de5a51ddfcd5ed51e { "building" : "351", "coord" : [-73.98513559999999, 40.7676919], "street" : "West 57 Street", "zipcode" : "10019" } Manhattan Irish Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f { "building" : "2780", "coord" : [-73.98241999999999, 40.579505], "street" : "Stillwell Avenue", "zipcode" : "11224" } Brooklyn American Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 { "building" : "97-22", "coord" : [-73.8601152, 40.7311739], "street" : "63 Road", "zipcode" : "11374" } Queens Jewish/Kosher Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed521 { "building" : "8825", "coord" : [-73.8803827, 40.7643124], "street" : "Astoria Boulevard", "zipcode" : "11369" } Queens American Brunos On The Boulevard 40356151
58ada47de5a51ddfcd5ed522 { "building" : "2206", "coord" : [-74.1377286, 40.6119572], "street" : "Victory Boulevard", "zipcode" : "10314" } Staten Island Jewish/Kosher Kosher Island 40356442
58ada47de5a51ddfcd5ed523 { "building" : "7114", "coord" : [-73.9068506, 40.6199034], "street" : "Avenue U", "zipcode" : "11234" } Brooklyn Delicatessen Wilken'S Fine Food 40356483
58ada47de5a51ddfcd5ed524 { "building" : "6409", "coord" : [-74.00528899999999, 40.628886], "street" : "11 Avenue", "zipcode" : "11219" } Brooklyn American Regina Caterers 40356649
58ada47de5a51ddfcd5ed525 { "building" : "1839", "coord" : [-73.9482609, 40.6408271], "street" : "Nostrand Avenue", "zipcode" : "11226" } Brooklyn Ice Cream, Gelato, Yogurt, Ices Taste The Tropics Ice Cream 40356731
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3' ;
SELECT * FROM t1 LIMIT 1;
_id 58ada47de5a51ddfcd5ed51c
name Morris Park Bake Shop
cuisine Bakery
borough Bronx
street Morris Park Ave
building 1007
zipcode 10462
grade A
score 2
date 2014-03-03
restaurant_id 30075445
SELECT name, street, score, date FROM t1 LIMIT 5;
name street score date
Morris Park Bake Shop Morris Park Ave 2 2014-03-03
Wendy'S Flatbush Avenue 8 2014-12-30
Dj Reynolds Pub And Restaurant West 57 Street 2 2014-09-06
Riviera Caterer Stillwell Avenue 5 2014-06-10
Tov Kosher Kitchen 63 Road 20 2014-11-24
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
name cuisine borough
Morris Park Bake Shop Bakery Bronx
Wendy'S Hamburgers Brooklyn
Dj Reynolds Pub And Restaurant Irish Manhattan
Riviera Caterer American Brooklyn
Kosher Island Jewish/Kosher Staten Island
Wilken'S Fine Food Delicatessen Brooklyn
Regina Caterers American Brooklyn
Taste The Tropics Ice Cream Ice Cream, Gelato, Yogurt, Ices Brooklyn
Wild Asia American Bronx
C & C Catering Service American Brooklyn
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
COUNT(*)
20687
SELECT * FROM t1 WHERE cuisine = 'English';
_id name cuisine borough street building zipcode grade score date restaurant_id
58ada47de5a51ddfcd5ed83d Tea And Sympathy English Manhattan Greenwich Avenue 108 10011 A 8 2014-10-23 40391531
58ada47de5a51ddfcd5ed85c Tartine English Manhattan West 11 Street 253 10014 A 11 2014-08-14 40392496
58ada47de5a51ddfcd5ee1f3 The Park Slope Chipshop English Brooklyn 5 Avenue 383 11215 B 17 2014-09-29 40816202
58ada47de5a51ddfcd5ee7e4 Pound And Pence English Manhattan Liberty Street 55 10005 A 7 2014-02-11 41022701
58ada47de5a51ddfcd5ee999 Chip Shop English Brooklyn Atlantic Avenue 129 11201 A 9 2014-10-08 41076583
58ada47ee5a51ddfcd5efe3f The Breslin Bar & Dining Room English Manhattan West 29 Street 16 10001 A 13 2014-06-09 41443706
58ada47ee5a51ddfcd5efe99 Highlands Restaurant English Manhattan West 10 Street 150 10014 A 12 2014-10-22 41448559
58ada47ee5a51ddfcd5f0413 The Fat Radish English Manhattan Orchard Street 17 10002 A 12 2014-07-26 41513545
58ada47ee5a51ddfcd5f0777 Jones Wood Foundry English Manhattan East 76 Street 401 10021 A 12 2014-12-03 41557377
58ada47ee5a51ddfcd5f0ea2 Whitehall English Manhattan Greenwich Avenue 19 10014 Z 15 2015-01-16 41625263
58ada47ee5a51ddfcd5f1004 The Churchill Tavern English Manhattan East 28 Street 45 10016 A 13 2014-08-27 41633327
58ada47ee5a51ddfcd5f13d5 The Monro English Brooklyn 5 Avenue 481 11215 A 7 2014-06-03 41660253
58ada47ee5a51ddfcd5f1454 The Cock & Bull English Manhattan West 45 Street 23 10036 A 7 2014-08-07 41664704
58ada47ee5a51ddfcd5f176e Dear Bushwick English Brooklyn Wilson Avenue 41 11237 A 12 2014-12-27 41690534
58ada47ee5a51ddfcd5f1e91 Snowdonia Pub English Queens 32 Street 34-55 11106 A 12 2014-10-28 50000290
58ada47ee5a51ddfcd5f2ddc Oscar'S Place English Manhattan Hudson Street 466 10014 A 10 2014-08-18 50011097
SELECT * FROM t1 WHERE score = building;
_id name cuisine borough street building zipcode grade score date restaurant_id
DROP TABLE t1;
#
# Specifying Filter
#
CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
OPTION_LIST='Driver=Java,Version=3' ;
SELECT name FROM t1 WHERE borough = 'Queens';
name
La Baraka Restaurant
Air France Lounge
Tournesol
Winegasm
Cafe Henri
Bistro 33
Domaine Wine Bar
Cafe Triskell
Cannelle Patisserie
La Vie
Dirty Pierres Bistro
Fresca La Crepe
Bliss 46 Bistro
Bear
Cuisine By Claudette
Paris Baguette
The Baroness Bar
Francis Cafe
Madame Sou Sou
Crepe 'N' Tearia
Aperitif Bayside Llc
DROP TABLE t1;
#
# Testing pipeline
#
CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$match":{"cuisine":"French"}},{"$unwind":"$grades"},{"$project":{"_id":0,"name":1,"borough":1,"date":"$grades.date","grade":"$grades.grade","score":"$grades.score"}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=1' ;
SELECT * FROM t1 LIMIT 10;
name borough date grade score
Tout Va Bien Manhattan 2014-11-10 01:00:00 B 15
Tout Va Bien Manhattan 2014-04-03 02:00:00 A 13
Tout Va Bien Manhattan 2013-07-17 02:00:00 C 36
Tout Va Bien Manhattan 2013-02-06 01:00:00 B 22
Tout Va Bien Manhattan 2012-07-16 02:00:00 C 36
Tout Va Bien Manhattan 2012-03-08 01:00:00 C 7
La Grenouille Manhattan 2014-04-09 02:00:00 A 10
La Grenouille Manhattan 2013-03-05 01:00:00 A 9
La Grenouille Manhattan 2012-02-02 01:00:00 A 13
Le Perigord Manhattan 2014-07-14 02:00:00 B 14
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
name grade score date
Bistro Sk A 10 2014-11-21 01:00:00
Bistro Sk A 12 2014-02-19 01:00:00
Bistro Sk B 18 2013-06-12 02:00:00
DROP TABLE t1;
#
# try level 2 discovery
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"$ne":"Manhattan"}}'
COLIST='{"cuisine":0}'
OPTION_LIST='Driver=Java,level=2,version=3';
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`_id` char(24) NOT NULL,
`address_building` char(6) NOT NULL `FIELD_FORMAT`='address.building',
`address_coord_0` double(18,14) NOT NULL `FIELD_FORMAT`='address.coord.0',
`address_street` char(25) NOT NULL `FIELD_FORMAT`='address.street',
`address_zipcode` char(5) NOT NULL `FIELD_FORMAT`='address.zipcode',
`borough` char(13) NOT NULL,
`grades_0_date` datetime NOT NULL `FIELD_FORMAT`='grades.0.date',
`grades_0_grade` char(14) NOT NULL `FIELD_FORMAT`='grades.0.grade',
`grades_0_score` int(2) NOT NULL `FIELD_FORMAT`='grades.0.score',
`name` char(32) NOT NULL,
`restaurant_id` char(8) NOT NULL
) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`='MONGO' `TABNAME`='restaurants' `COLIST`='{"cuisine":0}' `FILTER`='{"cuisine":"French","borough":{"$ne":"Manhattan"}}' `OPTION_LIST`='Driver=Java,level=2,version=3'
SELECT name, borough, address_street, grades_0_score AS score FROM t1 WHERE grades_0_grade = 'B';
name borough address_street score
Le Gamin Brooklyn Vanderbilt Avenue 24
Bistro 33 Queens Ditmars Boulevard 15
Dirty Pierres Bistro Queens Station Square 22
Santos Anne Brooklyn Union Avenue 26
Le Paddock Brooklyn Prospect Avenue 17
La Crepe Et La Vie Brooklyn Foster Avenue 24
Francis Cafe Queens Ditmars Boulevard 19
DROP TABLE t1;
#
# try CRUD operations
#
false
CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
OPTION_LIST='Driver=Java,Version=3' ;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
_id msg
0 NULL
1 One
2 Two
3 Three
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
_id msg
1 One
2 Deux
3 Three
DELETE FROM t1;
DROP TABLE t1;
true
#
# List states whose population is equal or more than 10 millions
#
false
CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=Java,Version=3' DATA_CHARSET='utf8';
# Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
state totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
# Using a pipeline for grouping
CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"$group":{"_id":"$state","totalPop":{"$sum":"$pop"}}},{"$match":{"totalPop":{"$gte":10000000}}},{"$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=1' ;
SELECT * FROM t1;
_id totalPop
CA 29754890
NY 17990402
TX 16984601
FL 12686644
PA 11881643
IL 11427576
OH 10846517
DROP TABLE t1;
true
#
# Test making array
#
CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=Java,Version=3' ;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
_id item prices_0 prices_1 prices_2 prices_3 prices_4
1 journal 87 45 63 12 78
2 notebook 123 456 789 NULL NULL
3 paper 5 7 3 8 NULL
4 planner 25 71 NULL 44 27
5 postcard 5 7 3 8 NULL
DROP TABLE t1;
#
# Test array aggregation
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='testcoll'
COLIST='{"pipeline":[{"$project":{"_id":0,"item":1,"total":{"$sum":"$prices"},"average":{"$avg":"$prices"}}}]}'
OPTION_LIST='Driver=Java,Version=3,Pipeline=YES' ;
SELECT * FROM t1;
item total average
journal 285 57.00
notebook 1368 456.00
paper 23 5.75
planner 167 41.75
postcard 23 5.75
DROP TABLE t1;
true
......@@ -141,22 +141,3 @@ DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
#
# Checking thread TBL tables
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v';
SELECT * FROM t1;
v
11
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v';
SELECT * FROM t2;
v
22
CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=PORT';;
SELECT * FROM total order by v desc;
v
22
11
DROP TABLE total;
DROP TABLE t1;
DROP TABLE t2;
connect master,127.0.0.1,root,,test,$MASTER_MYPORT,;
connect slave,127.0.0.1,root,,test,$SLAVE_MYPORT,;
connection master;
CREATE DATABASE connect;
connection slave;
CREATE DATABASE connect;
connection default;
#
# Checking thread TBL tables
#
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
a b
0 test00
1 test01
2 test02
3 test03
connection master;
CREATE TABLE rt2 (a int, b char(10));
INSERT INTO rt2 VALUES (4,'test04'),(5,'test05'),(6,'test06'),(7,'test07');
SELECT * FROM rt2;
a b
4 test04
5 test05
6 test06
7 test07
connection slave;
CREATE TABLE rt3 (a int, b char(10));
INSERT INTO rt3 VALUES (8,'test08'),(9,'test09'),(10,'test10'),(11,'test11');
SELECT * FROM rt3;
a b
8 test08
9 test09
10 test10
11 test11
connection default;
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@localhost:MASTER_PORT/test/rt2';
SELECT * FROM t2;
a b
4 test04
5 test05
6 test06
7 test07
CREATE TABLE t3 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@localhost:SLAVE_PORT/test/rt3';
SELECT * FROM t3;
a b
8 test08
9 test09
10 test10
11 test11
CREATE TABLE total (a int, b char(10))
ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3'
OPTION_LIST='thread=yes,port=PORT';
SELECT * FROM total order by a desc;
a b
11 test11
10 test10
9 test09
8 test08
7 test07
6 test06
5 test05
4 test04
3 test03
2 test02
1 test01
0 test00
connection master;
DROP TABLE rt2;
connection slave;
DROP TABLE rt3;
connection default;
DROP TABLE t1,t2,t3,total;
#
# Old thread TBL tables test
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v' OPTION_LIST='port=MASTER_PORT';
SELECT * FROM t1;
v
11
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v' OPTION_LIST='port=SLAVE_PORT';
SELECT * FROM t2;
v
22
CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=PORT';;
SELECT * FROM total order by v desc;
v
22
11
DROP TABLE total;
DROP TABLE t1;
DROP TABLE t2;
connection master;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
connection slave;
DROP TABLE IF EXISTS connect.t1;
DROP DATABASE IF EXISTS connect;
This diff was suppressed by a .gitattributes entry.
This source diff could not be displayed because it is too large. You can view the blob instead.
-- source jdbconn.inc
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo3.jar';
CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants OPTION_LIST='Version=3' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
DROP TABLE t1;
#
# Test catfunc
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants CATFUNC=columns OPTION_LIST='Level=1,Version=3' DATA_CHARSET=utf8;
SELECT * from t1;
DROP TABLE t1;
#
# Explicit columns
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' DATA_CHARSET=utf8;
SELECT * FROM t1 LIMIT 10;
DROP TABLE t1;
#
# Test discovery
#
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants OPTION_LIST='Level=1,Version=3' DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
SELECT * FROM t1 LIMIT 5;
DROP TABLE t1;
#
# Dropping a column
#
CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME=restaurants DATA_CHARSET=utf8
COLIST='{"grades":0}' OPTION_LIST='Driver=java,level=0';
SELECT * FROM t1 LIMIT 10;
DROP TABLE t1;
#
# Specifying Jpath
#
CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=MONGO TABNAME='restaurants' DATA_CHARSET=utf8;
--vertical_results
SELECT * FROM t1 LIMIT 1;
--horizontal_results
SELECT name, street, score, date FROM t1 LIMIT 5;
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
SELECT * FROM t1 WHERE cuisine = 'English';
SELECT * FROM t1 WHERE score = building;
DROP TABLE t1;
-- source jdbconn_cleanup.inc
-- source jdbconn.inc
-- source mongo.inc
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo2.jar';
let $DRV= Java;
let $VERS= 2;
let $TYPE= JSON;
let $CONN= CONNECTION='mongodb://localhost:27017' LRECL=4096;
-- source mongo_test.inc
-- source jdbconn_cleanup.inc
-- source jdbconn.inc
-- source mongo.inc
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo3.jar';
let $DRV= Java;
let $VERS= 3;
let $TYPE= JSON;
let $CONN= CONNECTION='mongodb://localhost:27017' LRECL=4096;
-- source mongo_test.inc
-- source jdbconn_cleanup.inc
-- source mongo.inc
let $DRV= C;
let $VERS= 0;
let $PROJ= {"projection":;
let $ENDP= };
let $TYPE= JSON;
let $CONN= CONNECTION='mongodb://localhost:27017' LRECL=1024;
-- source mongo_test.inc
let $MONGO= C:/PROGRA~1/MongoDB/Server/3.4/bin/mongo;
let $MONGOIMPORT= C:/PROGRA~1/MongoDB/Server/3.4/bin/mongoimport;
-- source mongo.inc
let $DRV= C;
let $VERS= 0;
let $PROJ= {"projection":;
let $ENDP= };
let $TYPE= MONGO;
-- source mongo_test.inc
-- source jdbconn.inc
-- source mongo.inc
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo2.jar';
let $DRV= Java;
let $VERS= 2;
let $TYPE= MONGO;
-- source mongo_test.inc
-- source jdbconn_cleanup.inc
-- source jdbconn.inc
-- source mongo.inc
eval SET GLOBAL connect_class_path='$MTR_SUITE_DIR/std_data/Mongo3.jar';
let $DRV= Java;
let $VERS= 3;
let $TYPE= MONGO;
-- source mongo_test.inc
-- source jdbconn_cleanup.inc
--echo #
--echo # Test the MONGO table type
--echo #
eval CREATE TABLE t1 (Document varchar(1024) field_format='*')
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants $CONN
OPTION_LIST='Driver=$DRV,Version=$VERS' DATA_CHARSET=utf8;
SELECT * from t1 limit 3;
DROP TABLE t1;
--echo #
--echo # Test catfunc
--echo #
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants CATFUNC=columns
OPTION_LIST='Level=1,Driver=$DRV,Version=$VERS' DATA_CHARSET=utf8 $CONN;
SELECT * from t1;
DROP TABLE t1;
--echo #
--echo # Explicit columns
--echo #
eval CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(255) NOT NULL,
cuisine VARCHAR(255) NOT NULL,
borough VARCHAR(255) NOT NULL,
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants
CONNECTION='mongodb://localhost:27017' LRECL=1024 DATA_CHARSET=utf8
OPTION_LIST='Driver=$DRV,Version=$VERS';
SELECT * FROM t1 LIMIT 10;
DROP TABLE t1;
--echo #
--echo # Test discovery
--echo #
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants
OPTION_LIST='Level=1,Driver=$DRV,Version=$VERS' $CONN DATA_CHARSET=utf8;
SHOW CREATE TABLE t1;
SELECT * FROM t1 LIMIT 5;
DROP TABLE t1;
--echo #
--echo # Dropping a column
--echo #
let $COLIST= $PROJ{"grades":0}$ENDP;
eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants DATA_CHARSET=utf8
COLIST='$COLIST' OPTION_LIST='Driver=$DRV,Version=$VERS,level=0' $CONN;
SELECT * FROM t1 LIMIT 10;
DROP TABLE t1;
--echo #
--echo # Specifying Jpath
--echo #
eval CREATE TABLE t1 (
_id VARCHAR(24) NOT NULL,
name VARCHAR(64) NOT NULL,
cuisine CHAR(200) NOT NULL,
borough CHAR(16) NOT NULL,
street VARCHAR(65) FIELD_FORMAT='address.street',
building CHAR(16) FIELD_FORMAT='address.building',
zipcode CHAR(5) FIELD_FORMAT='address.zipcode',
grade CHAR(1) FIELD_FORMAT='grades.0.grade',
score INT(4) NOT NULL FIELD_FORMAT='grades.0.score',
`date` DATE FIELD_FORMAT='grades.0.date',
restaurant_id VARCHAR(255) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='restaurants' DATA_CHARSET=utf8
OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN;
--vertical_results
SELECT * FROM t1 LIMIT 1;
--horizontal_results
SELECT name, street, score, date FROM t1 LIMIT 5;
SELECT name, cuisine, borough FROM t1 WHERE grade = 'A' LIMIT 10;
SELECT COUNT(*) FROM t1 WHERE grade = 'A';
SELECT * FROM t1 WHERE cuisine = 'English';
SELECT * FROM t1 WHERE score = building;
DROP TABLE t1;
--echo #
--echo # Specifying Filter
--echo #
eval CREATE TABLE t1 (
_id CHAR(24) NOT NULL,
name CHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
restaurant_id CHAR(8) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants DATA_CHARSET=utf8
FILTER='{"cuisine":"French","borough":{"\$ne":"Manhattan"}}'
OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN;
SELECT name FROM t1 WHERE borough = 'Queens';
DROP TABLE t1;
--echo #
--echo # Testing pipeline
--echo #
eval CREATE TABLE t1 (
name VARCHAR(64) NOT NULL,
borough CHAR(16) NOT NULL,
date DATETIME NOT NULL,
grade CHAR(1) NOT NULL,
score INT(4) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='restaurants' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"\$match":{"cuisine":"French"}},{"\$unwind":"\$grades"},{"\$project":{"_id":0,"name":1,"borough":1,"date":"\$grades.date","grade":"\$grades.grade","score":"\$grades.score"}}]}'
OPTION_LIST='Driver=$DRV,Version=$VERS,Pipeline=1' $CONN;
SELECT * FROM t1 LIMIT 10;
SELECT name, grade, score, date FROM t1 WHERE borough = 'Bronx';
DROP TABLE t1;
--echo #
--echo # try level 2 discovery
--echo #
let $COLIST= $PROJ{"cuisine":0}$ENDP;
eval CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME=restaurants
FILTER='{"cuisine":"French","borough":{"\$ne":"Manhattan"}}'
COLIST='$COLIST' $CONN
OPTION_LIST='Driver=$DRV,level=2,version=$VERS';
SHOW CREATE TABLE t1;
IF ($TYPE == MONGO)
{
SELECT name, borough, address_street, grades_0_score AS score FROM t1 WHERE grades_0_grade = 'B';
}
IF ($TYPE == JSON)
{
SELECT name, borough, address_street, grades_score AS score FROM t1 WHERE grades_grade = 'B';
}
DROP TABLE t1;
--echo #
--echo # try CRUD operations
--echo #
--exec $MONGO --eval "db.testcoll.drop()" --quiet
eval CREATE TABLE t1 (_id INT(4) NOT NULL, msg CHAR(64))
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='testcoll'
OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN;
DELETE FROM t1;
INSERT INTO t1 VALUES(0,NULL),(1,'One'),(2,'Two'),(3,'Three');
SELECT * FROM t1;
UPDATE t1 SET msg = 'Deux' WHERE _id = 2;
DELETE FROM t1 WHERE msg IS NULL;
SELECT * FROM t1;
DELETE FROM t1;
DROP TABLE t1;
--exec $MONGO --eval "db.testcoll.drop()" --quiet
--echo #
--echo # List states whose population is equal or more than 10 millions
--echo #
--exec $MONGO --eval "db.cities.drop()" --quiet
--exec $MONGOIMPORT --quiet $MTR_SUITE_DIR/std_data/cities.json
eval CREATE TABLE t1 (
_id char(5) NOT NULL,
city char(16) NOT NULL,
loc_0 double(12,6) NOT NULL `FIELD_FORMAT`='loc.0',
loc_1 char(12) NOT NULL `FIELD_FORMAT`='loc.1',
pop int(11) NOT NULL,
state char(2) NOT NULL)
ENGINE=CONNECT CONNECTION='mongodb://localhost:27017' TABLE_TYPE='MONGO' TABNAME='cities'
OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN DATA_CHARSET='utf8';
--echo # Using SQL for grouping
SELECT state, sum(pop) AS totalPop FROM t1 GROUP BY state HAVING totalPop >= 10000000 ORDER BY totalPop DESC;
DROP TABLE t1;
--echo # Using a pipeline for grouping
eval CREATE TABLE t1 (_id CHAR(2) NOT NULL, totalPop INT(11) NOT NULL)
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='cities' DATA_CHARSET=utf8
COLIST='{"pipeline":[{"\$group":{"_id":"\$state","totalPop":{"\$sum":"\$pop"}}},{"\$match":{"totalPop":{"\$gte":10000000}}},{"\$sort":{"totalPop":-1}}]}'
OPTION_LIST='Driver=$DRV,Version=$VERS,Pipeline=1' $CONN;
SELECT * FROM t1;
DROP TABLE t1;
--exec $MONGO --eval "db.cities.drop()" --quiet
--echo #
--echo # Test making array
--echo #
eval CREATE TABLE t1 (
_id int(4) NOT NULL,
item CHAR(8) NOT NULL,
prices_0 INT(6) FIELD_FORMAT='prices.0',
prices_1 INT(6) FIELD_FORMAT='prices.1',
prices_2 INT(6) FIELD_FORMAT='prices.2',
prices_3 INT(6) FIELD_FORMAT='prices.3',
prices_4 INT(6) FIELD_FORMAT='prices.4')
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='testcoll' DATA_CHARSET=utf8
OPTION_LIST='Driver=$DRV,Version=$VERS' $CONN;
INSERT INTO t1 VALUES
(1,'journal',87,45,63,12,78),
(2,'notebook',123,456,789,NULL,NULL),
(3,'paper',5,7,3,8,NULL),
(4,'planner',25,71,NULL,44,27),
(5,'postcard',5,7,3,8,NULL);
SELECT * FROM t1;
DROP TABLE t1;
--echo #
--echo # Test array aggregation
--echo #
eval CREATE TABLE t1
ENGINE=CONNECT TABLE_TYPE=$TYPE TABNAME='testcoll'
COLIST='{"pipeline":[{"\$project":{"_id":0,"item":1,"total":{"\$sum":"\$prices"},"average":{"\$avg":"\$prices"}}}]}'
OPTION_LIST='Driver=$DRV,Version=$VERS,Pipeline=YES' $CONN;
SELECT * FROM t1;
DROP TABLE t1;
--exec $MONGO --eval "db.testcoll.drop()" --quiet
-- source include/not_embedded.inc
--source include/not_embedded.inc
let $MYSQLD_DATADIR= `select @@datadir`;
let $PORT= `select @@port`;
......@@ -51,20 +51,3 @@ DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
--echo #
--echo # Checking thread TBL tables
--echo #
CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v';
SELECT * FROM t1;
CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v';
SELECT * FROM t2;
--replace_result $PORT PORT
--eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT';
SELECT * FROM total order by v desc;
DROP TABLE total;
DROP TABLE t1;
DROP TABLE t2;
-- source myconn.inc
connection default;
let $PORT= `select @@port`;
--echo #
--echo # Checking thread TBL tables
--echo #
CREATE TABLE t1 (a int, b char(10));
INSERT INTO t1 VALUES (0,'test00'),(1,'test01'),(2,'test02'),(3,'test03');
SELECT * FROM t1;
connection master;
CREATE TABLE rt2 (a int, b char(10));
INSERT INTO rt2 VALUES (4,'test04'),(5,'test05'),(6,'test06'),(7,'test07');
SELECT * FROM rt2;
connection slave;
CREATE TABLE rt3 (a int, b char(10));
INSERT INTO rt3 VALUES (8,'test08'),(9,'test09'),(10,'test10'),(11,'test11');
SELECT * FROM rt3;
connection default;
--replace_result $MASTER_MYPORT MASTER_PORT
eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@localhost:$MASTER_MYPORT/test/rt2';
SELECT * FROM t2;
--replace_result $SLAVE_MYPORT SLAVE_PORT
eval CREATE TABLE t3 ENGINE=CONNECT TABLE_TYPE=MYSQL
CONNECTION='mysql://root@localhost:$SLAVE_MYPORT/test/rt3';
SELECT * FROM t3;
--replace_result $PORT PORT
eval CREATE TABLE total (a int, b char(10))
ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2,t3'
OPTION_LIST='thread=yes,port=$PORT';
SELECT * FROM total order by a desc;
connection master;
DROP TABLE rt2;
connection slave;
DROP TABLE rt3;
connection default;
DROP TABLE t1,t2,t3,total;
--echo #
--echo # Old thread TBL tables test
--echo #
--replace_result $MASTER_MYPORT MASTER_PORT
--eval CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 11 as v' OPTION_LIST='port=$MASTER_MYPORT'
SELECT * FROM t1;
--replace_result $SLAVE_MYPORT SLAVE_PORT
--eval CREATE TABLE t2 ENGINE=CONNECT TABLE_TYPE=MYSQL SRCDEF='select 22 as v' OPTION_LIST='port=$SLAVE_MYPORT'
SELECT * FROM t2;
--replace_result $PORT PORT
--eval CREATE TABLE total (v BIGINT(20) UNSIGNED NOT NULL) ENGINE=CONNECT TABLE_TYPE=TBL TABLE_LIST='t1,t2' OPTION_LIST='thread=yes,port=$PORT';
SELECT * FROM total order by v desc;
DROP TABLE total;
DROP TABLE t1;
DROP TABLE t2;
-- source myconn_cleanup.inc
......@@ -968,6 +968,7 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp)
m_Catver = (tdbp) ? tdbp->Catver : 0;
m_Rows = 0;
m_Fetch = 0;
m_Fp = NULL;
m_Connect = NULL;
m_User = NULL;
m_Pwd = NULL;
......@@ -1137,6 +1138,24 @@ int ODBConn::Open(PCSZ ConnectString, POPARM sop, DWORD options)
} else // Connect using SQLConnect
Connect();
/*********************************************************************/
/* Link a Fblock. This make possible to automatically close it */
/* in case of error (throw). */
/*********************************************************************/
PDBUSER dbuserp = (PDBUSER)g->Activityp->Aptr;
m_Fp = (PFBLOCK)PlugSubAlloc(g, NULL, sizeof(FBLOCK));
m_Fp->Type = TYPE_FB_ODBC;
m_Fp->Fname = NULL;
m_Fp->Next = dbuserp->Openlist;
dbuserp->Openlist = m_Fp;
m_Fp->Count = 1;
m_Fp->Length = 0;
m_Fp->Memory = NULL;
m_Fp->Mode = MODE_ANY;
m_Fp->File = this;
m_Fp->Handle = 0;
/*ver = GetStringInfo(SQL_DRIVER_ODBC_VER);*/
// Verify support for required functionality and cache info
// VerifyConnect(); Deprecated
......@@ -2598,4 +2617,7 @@ void ODBConn::Close()
m_henv = SQL_NULL_HENV;
} // endif m_henv
if (m_Fp)
m_Fp->Count = 0;
} // end of Close
......@@ -27,7 +27,7 @@
//efine MAX_DNAME_LEN 256 // Max size of Recordset names
#define MAX_CONNECT_LEN 1024 // Max size of Connect string
//efine MAX_CURSOR_NAME 18 // Max size of a cursor name
#define DEFAULT_FIELD_TYPE SQL_TYPE_NULL // pick "C" data type to match SQL data type
//efine DEFAULT_FIELD_TYPE SQL_TYPE_NULL // pick "C" data type to match SQL data type
#if !defined(__WIN__)
typedef unsigned char *PUCHAR;
......@@ -169,7 +169,7 @@ class ODBConn : public BLOCK {
bool DriverConnect(DWORD Options);
void VerifyConnect(void);
void GetConnectInfo(void);
void Free(void);
//void Free(void);
protected:
// Static members
......@@ -187,6 +187,7 @@ class ODBConn : public BLOCK {
DWORD m_UpdateOptions;
DWORD m_RowsetSize;
char m_IDQuoteChar[2];
PFBLOCK m_Fp;
PCSZ m_Connect;
PCSZ m_User;
PCSZ m_Pwd;
......
......@@ -48,7 +48,10 @@ enum BLKTYP {TYPE_TABLE = 50, /* Table Name/Srcdef/... Block */
TYPE_FB_HANDLE = 24, /* File block (handle) */
TYPE_FB_XML = 21, /* DOM XML file block */
TYPE_FB_XML2 = 27, /* libxml2 XML file block */
TYPE_FB_ZIP = 28}; /* ZIP file block */
TYPE_FB_ODBC = 25, /* ODBC file block */
TYPE_FB_ZIP = 28, /* ZIP file block */
TYPE_FB_JAVA = 29, /* JAVA file block */
TYPE_FB_MONGO = 30}; /* MONGO file block */
enum TABTYPE {TAB_UNDEF = 0, /* Table of undefined type */
TAB_DOS = 1, /* Fixed column offset, variable LRECL */
......
......@@ -68,9 +68,20 @@
#include "tabcol.h" // header of XTAB and COLUMN classes
#include "valblk.h"
#include "rcmsg.h"
#if defined(ODBC_SUPPORT)
#include "tabext.h"
#include "odbccat.h"
#include "tabodbc.h"
#endif // ODBC_SUPPORT
#ifdef ZIP_SUPPORT
#include "filamzip.h"
#endif // ZIP_SUPPORT
#ifdef JDBC_SUPPORT
#include "javaconn.h"
#endif // JDBC_SUPPORT
#ifdef CMGO_SUPPORT
#include "cmgoconn.h"
#endif // MONGO_SUPPORT
/***********************************************************************/
/* DB static variables. */
......@@ -923,6 +934,13 @@ int PlugCloseFile(PGLOBAL g __attribute__((unused)), PFBLOCK fp, bool all)
CloseXML2File(g, fp, all);
break;
#endif // LIBXML2_SUPPORT
#ifdef ODBC_SUPPORT
case TYPE_FB_ODBC:
((ODBConn*)fp->File)->Close();
fp->Count = 0;
fp->File = NULL;
break;
#endif // ODBC_SUPPORT
#ifdef ZIP_SUPPORT
case TYPE_FB_ZIP:
if (fp->Mode == MODE_INSERT)
......@@ -936,6 +954,20 @@ int PlugCloseFile(PGLOBAL g __attribute__((unused)), PFBLOCK fp, bool all)
fp->File = NULL;
break;
#endif // ZIP_SUPPORT
#ifdef JDBC_SUPPORT
case TYPE_FB_JAVA:
((JAVAConn*)fp->File)->Close();
fp->Count = 0;
fp->File = NULL;
break;
#endif // JDBC_SUPPORT
#ifdef CMGO_SUPPORT
case TYPE_FB_MONGO:
((CMgoConn*)fp->File)->Close();
fp->Count = 0;
fp->File = NULL;
break;
#endif // MONGO_SUPPORT
default:
rc = RC_FX;
} // endswitch Type
......
......@@ -309,6 +309,8 @@ bool TDBCMG::OpenDB(PGLOBAL g)
return true;
} // endif Pipe
Use = USE_OPEN; // Do it now in case we are recursively called
if (Init(g))
return true;
......
......@@ -312,6 +312,8 @@ bool TDBJMG::OpenDB(PGLOBAL g)
return true;
} // endif Pipe
Use = USE_OPEN; // Do it now in case we are recursively called
if (Init(g))
return true;
......
......@@ -34,7 +34,7 @@
#if defined(JDBC_SUPPORT)
#include "jmgfam.h"
#endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT)
#if defined(CMGO_SUPPORT)
#include "cmgfam.h"
#endif // MONGO_SUPPORT
#include "tabmul.h"
......@@ -129,8 +129,8 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
#endif // ZIP_SUPPORT
tdp->Fn = GetStringTableOption(g, topt, "Filename", NULL);
if (!(tdp->Database = SetPath(g, db)))
return NULL;
//if (!(tdp->Database = SetPath(g, db)))
// return NULL;
tdp->Objname = GetStringTableOption(g, topt, "Object", NULL);
tdp->Base = GetIntegerTableOption(g, topt, "Base", 0) ? 1 : 0;
......@@ -148,22 +148,23 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
if (tdp->Uri) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
tdp->Collname = GetStringTableOption(g, topt, "Name", NULL);
tdp->Collname = GetStringTableOption(g, topt, "Tabname", tdp->Collname);
tdp->Schema = GetStringTableOption(g, topt, "Dbname", "test");
tdp->Options = (PSZ)GetStringTableOption(g, topt, "Colist", "all");
tdp->Pipe = GetBooleanTableOption(g, topt, "Pipeline", false);
tdp->Driver = (PSZ)GetStringTableOption(g, topt, "Driver", NULL);
tdp->Version = GetIntegerTableOption(g, topt, "Version", 3);
#if defined(JDBC_SUPPORT)
tdp->Wrapname = (PSZ)GetStringTableOption(g, topt, "Wrapper",
(tdp->Version == 2) ? "Mongo2Interface" : "Mongo3Interface");
#endif // JDBC_SUPPORT
tdp->Pretty = 0;
#else // !MONGO_SUPPORT || JDBC_SUPPORT
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return NULL;
#endif // !MONGO_SUPPORT || JDBC_SUPPORT
#endif // !MONGO_SUPPORT
} // endif Uri
if (tdp->Pretty == 2) {
......@@ -199,21 +200,32 @@ PQRYRES JSONColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt, bool info)
return NULL;
#endif // !ZIP_SUPPORT
} else if (tdp->Uri) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if !defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
if (tdp->Driver && toupper(*tdp->Driver) == 'C') {
#if defined(CMGO_SUPPORT)
tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp));
#elif !defined(MONGO_SUPPORT)
#else
sprintf(g->Message, "Mongo %s Driver not available", "C");
return NULL;
#endif
} else if (tdp->Driver && toupper(*tdp->Driver) == 'J') {
#if defined(JDBC_SUPPORT)
tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp));
#else
if (tdp->Driver && toupper(*tdp->Driver) == 'C')
sprintf(g->Message, "Mongo %s Driver not available", "Java");
return NULL;
#endif
} else { // Driver not specified
#if defined(CMGO_SUPPORT)
tjnp = new(g) TDBJSN(tdp, new(g) CMGFAM(tdp));
else
#else
tjnp = new(g) TDBJSN(tdp, new(g) JMGFAM(tdp));
#endif
#else // !MONGO_SUPPORT && !JDBC_SUPPORT
sprintf(g->Message, "No MongoDB support");
} // endif Driver
#else
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return NULL;
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
} else
tjnp = new(g) TDBJSN(tdp, new(g) DOSFAM(tdp));
......@@ -484,16 +496,16 @@ JSONDEF::JSONDEF(void)
Base = 0;
Strict = false;
Sep = '.';
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
Uri = NULL;
Collname = Schema = Options = Filter = NULL;
Pipe = false;
Driver = NULL;
Version = 0;
#endif // MONGO_SUPPORT
#if defined(JDBC_SUPPORT)
Wrapname = NULL;
#endif // JDBC_SUPPORT
#endif // !MONGO_SUPPORT && !JDBC_SUPPORT
} // end of JSONDEF constructor
/***********************************************************************/
......@@ -510,7 +522,7 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Sep = *GetStringCatInfo(g, "Separator", ".");
if (Uri = GetStringCatInfo(g, "Connect", NULL)) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
Collname = GetStringCatInfo(g, "Name",
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
Collname = GetStringCatInfo(g, "Tabname", Collname);
......@@ -527,10 +539,10 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
else
Wrapname = GetStringCatInfo(g, "Wrapper", "Mongo3Interface");
#endif // JDBC_SUPPORT
#else // !MONGO_SUPPORT && !JDBC_SUPPORT
#else // !MONGO_SUPPORT
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return true;
#endif // !MONGO_SUPPORT && !JDBC_SUPPORT
#endif // !MONGO_SUPPORT
} // endif Uri
return DOSDEF::DefineAM(g, (Uri ? "XMGO" : "DOS"), poff);
......@@ -556,18 +568,32 @@ PTDB JSONDEF::GetTable(PGLOBAL g, MODE m)
(m == MODE_UPDATE || m == MODE_DELETE));
if (Uri) {
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if !defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
if (Driver && toupper(*Driver) == 'C') {
#if defined(CMGO_SUPPORT)
txfp = new(g) CMGFAM(this);
#elif !defined(MONGO_SUPPORT)
#else
sprintf(g->Message, "Mongo %s Driver not available", "C");
return NULL;
#endif
} else if (Driver && toupper(*Driver) == 'J') {
#if defined(JDBC_SUPPORT)
txfp = new(g) JMGFAM(this);
#else
if (Driver && toupper(*Driver) == 'C')
sprintf(g->Message, "Mongo %s Driver not available", "Java");
return NULL;
#endif
} else { // Driver not specified
#if defined(CMGO_SUPPORT)
txfp = new(g) CMGFAM(this);
else
#else
txfp = new(g) JMGFAM(this);
#endif
#endif // MONGO_SUPPORT || JDBC_SUPPORT
} // endif Driver
#else
sprintf(g->Message, MSG(NO_FEAT_SUPPORT), "MONGO");
return NULL;
#endif // MONGO_SUPPORT
} else if (Zipped) {
#if defined(ZIP_SUPPORT)
if (m == MODE_READ || m == MODE_ANY || m == MODE_ALTER) {
......@@ -2250,7 +2276,11 @@ void TDBJSON::CloseDB(PGLOBAL g)
TDBJCL::TDBJCL(PJDEF tdp) : TDBCAT(tdp)
{
Topt = tdp->GetTopt();
Db = tdp->GetDB();
#if defined(MONGO_SUPPORT)
Db = tdp->Schema;
#else
Db = NULL;
#endif
Dsn = tdp->Uri;
} // end of TDBJCL constructor
......
......@@ -36,11 +36,11 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
friend class TDBJSON;
friend class TDBJSN;
friend class TDBJCL;
#if defined(MONGO_SUPPORT)
friend class CMGFAM;
#if defined(JDBC_SUPPORT)
friend class JMGFAM;
#endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT)
friend class CMGFAM;
#endif // MONGO_SUPPORT
friend PQRYRES JSONColumns(PGLOBAL, PCSZ, PCSZ, PTOS, bool);
public:
......@@ -66,7 +66,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
bool Strict; /* Strict syntax checking */
char Sep; /* The Jpath separator */
const char *Uri; /* MongoDB connection URI */
#if defined(MONGO_SUPPORT) || defined(JDBC_SUPPORT)
#if defined(MONGO_SUPPORT)
PCSZ Collname; /* External collection name */
PCSZ Schema; /* External schema (DB) name */
PSZ Options; /* Colist ; Pipe */
......@@ -77,7 +77,7 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
#if defined(JDBC_SUPPORT)
PSZ Wrapname; /* MongoDB java wrapper name */
#endif // JDBC_SUPPORT
#endif // MONGO_SUPPORT || JDBC_SUPPORT
#endif // MONGO_SUPPORT
}; // end of JSONDEF
/* -------------------------- TDBJSN class --------------------------- */
......@@ -89,11 +89,11 @@ class DllExport JSONDEF : public DOSDEF { /* Table description */
class DllExport TDBJSN : public TDBDOS {
friend class JSONCOL;
friend class JSONDEF;
#if defined(MONGO_SUPPORT)
friend class CMGFAM;
#if defined(JDBC_SUPPORT)
friend class JMGFAM;
#endif // JDBC_SUPPORT
#if defined(MONGO_SUPPORT)
friend class CMGFAM;
#endif // MONGO_SUPPORT
public:
// Constructor
......
......@@ -84,6 +84,8 @@
#define SYSEXIT void *
#endif // !__WIN__
extern pthread_mutex_t tblmut;
/* ---------------------------- Class TBLDEF ---------------------------- */
/**************************************************************************/
......@@ -575,7 +577,9 @@ pthread_handler_t ThreadOpen(void *p)
// Try to open the connection
if (!cmp->Tap->GetTo_Tdb()->OpenDB(cmp->G)) {
pthread_mutex_lock(&tblmut);
cmp->Ready = true;
pthread_mutex_unlock(&tblmut);
} else
cmp->Rc = RC_FX;
......@@ -792,14 +796,19 @@ int TDBTBM::ReadNextRemote(PGLOBAL g)
retry:
// Search for a remote table having its result set
pthread_mutex_lock(&tblmut);
for (PTBMT tp = Tmp; tp; tp = tp->Next)
if (tp->Ready) {
if (!tp->Complete)
if (!tp->Complete) {
Cmp = tp;
break;
} // endif Complete
} else
b = true;
pthread_mutex_unlock(&tblmut);
if (!Cmp) {
if (b) { // more result to come
// sleep(20);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment