Commit 36206acc authored by Olivier Bertrand's avatar Olivier Bertrand

Work on new MONGO table type

Handle discovery, insert, update and delete
Add support for Pipeline
  modified:   storage/connect/tabmgo.cpp
  modified:   storage/connect/tabmgo.h

Handle double call to CondPush
Cond moved to TDB
  modified:   storage/connect/ha_connect.cc
  modified:   storage/connect/tabext.cpp
  modified:   storage/connect/tabext.h
  modified:   storage/connect/tabjdbc.cpp
  modified:   storage/connect/table.cpp
  modified:   storage/connect/tabmysql.cpp
  modified:   storage/connect/tabodbc.cpp
  modified:   storage/connect/xtable.h

Add building Mongo selector to FILTER
  modified:   storage/connect/filter.cpp
  modified:   storage/connect/filter.h

Change Print function of values (needed by FILTER)
  modified:   storage/connect/value.cpp
  modified:   storage/connect/value.h

Fix crash when dbname is null forJSON MGO tables
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h

Fix MDEV-12520: Decimal values can be truncated for JDBC tables
  modified:   storage/connect/jdbconn.cpp

Fix bug. Date value was null when retrieved from a json expanded array.
  modified:   storage/connect/tabjson.cpp
parent 0149f9c2
......@@ -38,6 +38,10 @@
//#include "token.h"
//#include "select.h"
#include "xindex.h"
#if defined(MONGO_SUPPORT)
#include "tabext.h"
#include "tabmgo.h"
#endif // MONGO_SUPPORT
/***********************************************************************/
/* Utility routines. */
......@@ -1405,6 +1409,88 @@ PFIL FILTER::Copy(PTABS t)
} // end of Copy
#endif // 0
/***********************************************************************/
/* Make selector json representation for Mongo tables. */
/***********************************************************************/
#if defined(MONGO_SUPPORT)
bool FILTER::MakeSelector(PGLOBAL g, PSTRG s)
{
s->Append('{');
if (Opc == OP_AND || Opc == OP_OR) {
if (GetArgType(0) != TYPE_FILTER || GetArgType(1) != TYPE_FILTER)
return true;
s->Append("\"$");
s->Append(Opc == OP_AND ? "and" : "or");
s->Append("\":[");
if (((PFIL)Arg(0))->MakeSelector(g, s))
return true;
s->Append(',');
if (((PFIL)Arg(1))->MakeSelector(g, s))
return true;
s->Append(']');
} else {
char buf[501];
if (GetArgType(0) != TYPE_COLBLK)
return true;
s->Append('"');
s->Append(((PMGOCOL)Arg(0))->Jpath);
s->Append("\":{\"$");
switch (Opc) {
case OP_EQ:
s->Append("eq");
break;
case OP_NE:
s->Append("ne");
break;
case OP_GT:
s->Append("gt");
break;
case OP_GE:
s->Append("gte");
break;
case OP_LT:
s->Append("lt");
break;
case OP_LE:
s->Append("lte");
break;
//case OP_NULL:
// s->Append("ne");
// break;
//case OP_LIKE:
// s->Append("ne");
// break;
//case OP_EXIST:
// s->Append("ne");
// break;
default:
return true;
} // endswitch Opc
s->Append("\":");
if (GetArgType(1) == TYPE_COLBLK)
return true;
Arg(1)->Print(g, buf, 500);
s->Append(buf);
s->Append('}');
} // endif Opc
s->Append('}');
return false;
} // end of MakeSelector
#endif // MONGO_SUPPORT
/*********************************************************************/
/* Make file output of FILTER contents. */
/*********************************************************************/
......
......@@ -61,7 +61,10 @@ class DllExport FILTER : public XOBJECT { /* Filter description block */
//virtual PXOB CheckSubQuery(PGLOBAL, PSQL);
//virtual bool CheckLocal(PTDB);
//virtual int CheckSpcCol(PTDB tdbp, int n);
virtual void Print(PGLOBAL g, FILE *f, uint n);
#if defined(MONGO_SUPPORT)
bool MakeSelector(PGLOBAL g, PSTRG s);
#endif // MONGO_SUPPORT
virtual void Print(PGLOBAL g, FILE *f, uint n);
virtual void Print(PGLOBAL g, char *ps, uint z);
// PFIL Linearize(bool nosep);
// PFIL Link(PGLOBAL g, PFIL fil2);
......
......@@ -211,6 +211,9 @@ PQRYRES OEMColumns(PGLOBAL g, PTOS topt, char *tab, char *db, bool info);
PQRYRES VirColumns(PGLOBAL g, bool info);
PQRYRES JSONColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info);
PQRYRES XMLColumns(PGLOBAL g, char *db, char *tab, PTOS topt, bool info);
#if defined(MONGO_SUPPORT)
PQRYRES MGOColumns(PGLOBAL g, char *db, char *dsn, PTOS topt, bool info);
#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, const char *host,
......@@ -3072,11 +3075,11 @@ const COND *ha_connect::cond_push(const COND *cond)
PCFIL filp;
int rc;
if ((filp = tdbp->GetCondFil()) && filp->Cond == cond &&
if ((filp = tdbp->GetCondFil()) && tdbp->GetCond() == cond &&
filp->Idx == active_index && filp->Type == tty)
goto fin;
filp = new(g) CONDFIL(cond, active_index, tty);
filp = new(g) CONDFIL(active_index, tty);
rc = filp->Init(g, this);
if (rc == RC_INFO) {
......@@ -3095,6 +3098,8 @@ const COND *ha_connect::cond_push(const COND *cond)
if (trace)
htrc("cond_push: %s\n", filp->Body);
tdbp->SetCond(cond);
if (!x)
PlugSubAlloc(g, NULL, strlen(filp->Body) + 1);
else
......@@ -3104,8 +3109,16 @@ const COND *ha_connect::cond_push(const COND *cond)
} else if (x && cond)
tdbp->SetCondFil(filp); // Wrong filter
} else if (tty != TYPE_AM_JSN && tty != TYPE_AM_JSON)
tdbp->SetFilter(CondFilter(g, (Item *)cond));
} else if (tty != TYPE_AM_JSN && tty != TYPE_AM_JSON) {
if (!tdbp->GetCond() || tdbp->GetCond() != cond) {
tdbp->SetFilter(CondFilter(g, (Item *)cond));
if (tdbp->GetFilter())
tdbp->SetCond(cond);
} // endif cond
} // endif tty
} catch (int n) {
if (trace)
......@@ -5545,6 +5558,17 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
ok = true;
break;
#if defined(MONGO_SUPPORT)
case TAB_MONGO:
dsn = strz(g, create_info->connect_string);
if (!dsn)
strcpy(g->Message, "Missing URI");
else
ok = true;
break;
#endif // MONGO_SUPPORT
case TAB_VIR:
ok = true;
break;
......@@ -5688,6 +5712,11 @@ static int connect_assisted_discovery(handlerton *, THD* thd,
case TAB_JSON:
qrp = JSONColumns(g, (char*)db, dsn, topt, fnc == FNC_COL);
break;
#if defined(MONGO_SUPPORT)
case TAB_MONGO:
qrp = MGOColumns(g, (char*)db, dsn, topt, fnc == FNC_COL);
break;
#endif // MONGO_SUPPORT
#if defined(LIBXML2_SUPPORT) || defined(DOMDOC_SUPPORT)
case TAB_XML:
qrp = XMLColumns(g, (char*)db, tab, topt, fnc == FNC_COL);
......
......@@ -1227,7 +1227,8 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
case 12: // VARCHAR
case -1: // LONGVARCHAR
case 1: // CHAR
if (jb)
case 3: // DECIMAL
if (jb && ctyp != 3)
cn = (jstring)jb;
else if (!gmID(g, chrfldid, "StringField", "(ILjava/lang/String;)Ljava/lang/String;"))
cn = (jstring)env->CallObjectMethod(job, chrfldid, (jint)rank, jn);
......@@ -1253,7 +1254,7 @@ void JDBConn::SetColumnValue(int rank, PSZ name, PVAL val)
break;
case 8: // DOUBLE
case 2: // NUMERIC
case 3: // DECIMAL
//case 3: // DECIMAL
if (!gmID(g, dblfldid, "DoubleField", "(ILjava/lang/String;)D"))
val->SetValue((double)env->CallDoubleMethod(job, dblfldid, rank, jn));
else
......
......@@ -35,9 +35,9 @@
/***********************************************************************/
/* CONDFIL Constructor. */
/***********************************************************************/
CONDFIL::CONDFIL(const Item *cond, uint idx, AMT type)
CONDFIL::CONDFIL(uint idx, AMT type)
{
Cond = cond;
//Cond = cond;
Idx = idx;
Type = type;
Op = OP_XX;
......
......@@ -28,14 +28,14 @@ class ALIAS : public BLOCK {
class CONDFIL : public BLOCK {
public:
// Constructor
CONDFIL(const Item *cond, uint idx, AMT type);
CONDFIL(uint idx, AMT type);
// Functions
int Init(PGLOBAL g, PHC hc);
const char *Chk(const char *cln, bool *h);
// Members
const Item *Cond;
//const Item *Cond;
AMT Type;
uint Idx;
OPVAL Op;
......
......@@ -750,7 +750,7 @@ bool TDBJDBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr)
To_CondFil->Body= (char*)PlugSubAlloc(g, NULL, 0);
*To_CondFil->Body= 0;
if ((To_CondFil = hc->CheckCond(g, To_CondFil, To_CondFil->Cond)))
if ((To_CondFil = hc->CheckCond(g, To_CondFil, Cond)))
PlugSubAlloc(g, NULL, strlen(To_CondFil->Body) + 1);
} // endif active_index
......
......@@ -47,6 +47,7 @@ TDB::TDB(PTABDEF tdp) : Tdb_No(++Tnum)
To_Orig = NULL;
To_Filter = NULL;
To_CondFil = NULL;
Cond = NULL;
Next = NULL;
Name = (tdp) ? tdp->GetName() : NULL;
To_Table = NULL;
......@@ -68,6 +69,7 @@ TDB::TDB(PTDB tdbp) : Tdb_No(++Tnum)
To_Orig = tdbp;
To_Filter = NULL;
To_CondFil = NULL;
Cond = NULL;
Next = NULL;
Name = tdbp->Name;
To_Table = tdbp->To_Table;
......
This diff is collapsed.
......@@ -19,6 +19,48 @@
typedef class MGODEF *PMGODEF;
typedef class TDBMGO *PTDBMGO;
typedef class MGOCOL *PMGOCOL;
typedef class INCOL *PINCOL;
typedef struct _bncol {
struct _bncol *Next;
char *Name;
char *Fmt;
int Type;
int Len;
int Scale;
bool Cbn;
bool Found;
} BCOL, *PBCOL;
typedef struct KEYCOL {
KEYCOL *Next;
PINCOL Incolp;
PCOL Colp;
char *Key;
} *PKC;
/***********************************************************************/
/* Class used to get the columns of a mongo collection. */
/***********************************************************************/
class MGODISC : public BLOCK {
public:
// Constructor
MGODISC(PGLOBAL g, int *lg);
// Functions
int GetColumns(PGLOBAL g, char *db, char *dsn, PTOS topt);
bool FindInDoc(PGLOBAL g, bson_iter_t *iter, const bson_t *doc,
char *pcn, char *pfmt, int i, int k, bool b);
// Members
BCOL bcol;
PBCOL bcp, fbcp, pbcp;
PMGODEF tdp;
TDBMGO *tmgp;
int *length;
int n, k, lvl;
bool all;
}; // end of MGODISC
/***********************************************************************/
/* MongoDB table. */
......@@ -26,6 +68,8 @@ typedef class MGOCOL *PMGOCOL;
class DllExport MGODEF : public EXTDEF { /* Table description */
friend class TDBMGO;
friend class MGOFAM;
friend class MGODISC;
friend PQRYRES MGOColumns(PGLOBAL, char *, char *, PTOS, bool);
public:
// Constructor
MGODEF(void);
......@@ -44,9 +88,26 @@ class DllExport MGODEF : public EXTDEF { /* Table description */
char *Filter; /* Filtering query */
int Level; /* Used for catalog table */
int Base; /* The array index base */
bool Pipe; /* True is Colist is a pipeline */
}; // end of MGODEF
/* -------------------------- TDBMGO class --------------------------- */
/* ------------------------- TDBMGO classes -------------------------- */
/***********************************************************************/
/* Used when inserting values in a MongoDB collection. */
/***********************************************************************/
class INCOL : public BLOCK {
public:
// Constructor
INCOL(void) { Klist = NULL; }
// Methods
void AddCol(PGLOBAL g, PCOL colp, char *jp);
//Members
bson_t Child;
PKC Klist;
}; // end of INCOL;
/***********************************************************************/
/* This is the MongoDB Access Method class declaration. */
......@@ -55,6 +116,8 @@ class DllExport MGODEF : public EXTDEF { /* Table description */
class DllExport TDBMGO : public TDBEXT {
friend class MGOCOL;
friend class MGODEF;
friend class MGODISC;
friend PQRYRES MGOColumns(PGLOBAL, char *, char *, PTOS, bool);
public:
// Constructor
TDBMGO(PMGODEF tdp);
......@@ -83,6 +146,8 @@ class DllExport TDBMGO : public TDBEXT {
protected:
bool Init(PGLOBAL g);
void ShowDocument(bson_iter_t *i, const bson_t *b, const char *k);
void MakeColumnGroups(PGLOBAL g);
bool DocWrite(PGLOBAL g, PINCOL icp);
// Members
mongoc_uri_t *Uri;
......@@ -95,6 +160,7 @@ class DllExport TDBMGO : public TDBEXT {
bson_t *Query; // MongoDB cursor filter
bson_t *Opts; // MongoDB cursor options
bson_error_t Error;
PINCOL Fpc; // To insert INCOL classes
const char *Uristr;
const char *Db_name;
const char *Coll_name;
......@@ -104,6 +170,7 @@ class DllExport TDBMGO : public TDBEXT {
int N; // The current Rownum
int B; // Array index base
bool Done; // Init done
bool Pipe; // True for pipeline
}; // end of class TDBMGO
/* --------------------------- MGOCOL class -------------------------- */
......@@ -113,6 +180,7 @@ class DllExport TDBMGO : public TDBEXT {
/***********************************************************************/
class DllExport MGOCOL : public EXTCOL {
friend class TDBMGO;
friend class FILTER;
public:
// Constructors
MGOCOL(PGLOBAL g, PCOLDEF cdp, PTDB tdbp, PCOL cprec, int i);
......@@ -122,19 +190,22 @@ class DllExport MGOCOL : public EXTCOL {
virtual int GetAmType(void) { return Tmgp->GetAmType(); }
// Methods
virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
//virtual bool SetBuffer(PGLOBAL g, PVAL value, bool ok, bool check);
virtual void ReadColumn(PGLOBAL g);
virtual void WriteColumn(PGLOBAL g);
bool AddValue(PGLOBAL g, bson_t *doc, char *key, bool upd);
protected:
// Default constructor not to be used
MGOCOL(void) {}
char *Mini(PGLOBAL g, const bson_t *bson, bool b);
// Members
TDBMGO *Tmgp; // To the MGO table block
bson_iter_t Iter; // Used to retrieve column value
bson_iter_t Desc; // Descendant iter
char *Jpath; // The json path
char *Mbuf; // The Mini buffer
}; // end of class MGOCOL
#if 0
......
......@@ -1096,7 +1096,7 @@ bool TDBMYSQL::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr)
To_CondFil->Body= (char*)PlugSubAlloc(g, NULL, 0);
*To_CondFil->Body= 0;
if ((To_CondFil = hc->CheckCond(g, To_CondFil, To_CondFil->Cond)))
if ((To_CondFil = hc->CheckCond(g, To_CondFil, Cond)))
PlugSubAlloc(g, NULL, strlen(To_CondFil->Body) + 1);
} // endif active_index
......
......@@ -733,7 +733,7 @@ bool TDBODBC::ReadKey(PGLOBAL g, OPVAL op, const key_range *kr)
To_CondFil->Body= (char*)PlugSubAlloc(g, NULL, 0);
*To_CondFil->Body= 0;
if ((To_CondFil = hc->CheckCond(g, To_CondFil, To_CondFil->Cond)))
if ((To_CondFil = hc->CheckCond(g, To_CondFil, Cond)))
PlugSubAlloc(g, NULL, strlen(To_CondFil->Body) + 1);
} // endif active_index
......
......@@ -558,6 +558,38 @@ bool VALUE::Compute(PGLOBAL g, PVAL *, int, OPVAL)
return true;
} // end of Compute
/***********************************************************************/
/* Make file output of an object value. */
/***********************************************************************/
void VALUE::Print(PGLOBAL g, FILE *f, uint n)
{
char m[64], buf[64];
memset(m, ' ', n); /* Make margin string */
m[n] = '\0';
if (Null)
fprintf(f, "%s<null>\n", m);
else
fprintf(f, strcat(strcat(GetCharString(buf), "\n"), m));
} /* end of Print */
/***********************************************************************/
/* Make string output of an object value. */
/***********************************************************************/
void VALUE::Print(PGLOBAL g, char *ps, uint z)
{
char *p, buf[64];
if (Null)
p = strcpy(buf, "<null>");
else
p = GetCharString(buf);
strncpy(ps, p, z);
} // end of Print
/* -------------------------- Class TYPVAL ---------------------------- */
/***********************************************************************/
......@@ -1192,37 +1224,6 @@ bool TYPVAL<TYPE>::SetConstFormat(PGLOBAL g, FORMAT& fmt)
return false;
} // end of SetConstFormat
/***********************************************************************/
/* Make file output of a typed object. */
/***********************************************************************/
template <class TYPE>
void TYPVAL<TYPE>::Print(PGLOBAL g, FILE *f, uint n)
{
char m[64], buf[12];
memset(m, ' ', n); /* Make margin string */
m[n] = '\0';
if (Null)
fprintf(f, "%s<null>\n", m);
else
fprintf(f, strcat(strcat(strcpy(buf, "%s"), Fmt), "\n"), m, Tval);
} /* end of Print */
/***********************************************************************/
/* Make string output of a int object. */
/***********************************************************************/
template <class TYPE>
void TYPVAL<TYPE>::Print(PGLOBAL g, char *ps, uint z)
{
if (Null)
strcpy(ps, "<null>");
else
sprintf(ps, Fmt, Tval);
} /* end of Print */
/* -------------------------- Class STRING --------------------------- */
/***********************************************************************/
......@@ -1708,6 +1709,18 @@ bool TYPVAL<PSZ>::SetConstFormat(PGLOBAL, FORMAT& fmt)
return false;
} // end of SetConstFormat
/***********************************************************************/
/* Make string output of an object value. */
/***********************************************************************/
void TYPVAL<PSZ>::Print(PGLOBAL g, char *ps, uint z)
{
if (Null)
strncpy(ps, "null", z);
else
strcat(strncat(strncpy(ps, "\"", z), Strp, z-2), "\"");
} // end of Print
/* -------------------------- Class DECIMAL -------------------------- */
/***********************************************************************/
......
......@@ -122,6 +122,8 @@ class DllExport VALUE : public BLOCK {
virtual bool IsEqual(PVAL vp, bool chktype) = 0;
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
virtual bool FormatValue(PVAL vp, char *fmt) = 0;
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *ps, uint z);
/**
Set value from a non-aligned in-memory value in the machine byte order.
......@@ -233,8 +235,6 @@ class DllExport TYPVAL : public VALUE {
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
virtual bool FormatValue(PVAL vp, char *fmt);
virtual void Print(PGLOBAL g, FILE *, uint);
virtual void Print(PGLOBAL g, char *, uint);
protected:
static TYPE MinMaxVal(bool b);
......@@ -308,6 +308,7 @@ class DllExport TYPVAL<PSZ>: public VALUE {
virtual bool Compute(PGLOBAL g, PVAL *vp, int np, OPVAL op);
virtual bool FormatValue(PVAL vp, char *fmt);
virtual bool SetConstFormat(PGLOBAL, FORMAT&);
virtual void Print(PGLOBAL g, char *ps, uint z);
protected:
// Members
......
......@@ -33,29 +33,6 @@ class CMD : public BLOCK {
char *Cmd;
}; // end of class CMD
#if 0
// Condition filter structure
class CONDFIL : public BLOCK {
public:
// Constructor
CONDFIL(const Item *cond, uint idx, AMT type)
{
Cond = cond; Idx = idx; Type = type; Op = OP_XX;
Cmds = NULL; All = true; Body = NULL, Having = NULL;
}
// Members
const Item *Cond;
AMT Type;
uint Idx;
OPVAL Op;
PCMD Cmds;
bool All;
char *Body;
char *Having;
}; // end of class CONDFIL
#endif // 0
typedef class EXTCOL *PEXTCOL;
typedef class CONDFIL *PCFIL;
typedef class TDBCAT *PTDBCAT;
......@@ -94,6 +71,8 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
inline void SetColumns(PCOL colp) {Columns = colp;}
inline void SetDegree(int degree) {Degree = degree;}
inline void SetMode(MODE mode) {Mode = mode;}
inline const Item *GetCond(void) {return Cond;}
inline void SetCond(const Item *cond) {Cond = cond;}
// Properties
virtual AMT GetAmType(void) {return TYPE_AM_ERROR;}
......@@ -157,6 +136,7 @@ class DllExport TDB: public BLOCK { // Table Descriptor Block.
TUSE Use;
PFIL To_Filter;
PCFIL To_CondFil; // To condition filter structure
const Item *Cond; // The condition used to make filters
static int Tnum; // Used to generate Tdb_no's
const int Tdb_No; // GetTdb_No() is always 0 for OPJOIN
PTDB Next; // Next in linearized queries
......
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