Skip to content

Commit

Permalink
- Fix a few bug mainly concerning discovery and call from OEM
Browse files Browse the repository at this point in the history
  (and prepare new table types)

  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  modified:   storage/connect/tabxml.cpp
  modified:   storage/connect/tabxml.h

- Fix wrong line estimate
  modified:   storage/connect/mysql-test/connect/r/part_table.result
  modified:   storage/connect/mysql-test/connect/t/part_table.test
  • Loading branch information
Buggynours committed Jan 2, 2019
1 parent c2482c7 commit 547ce1b
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 147 deletions.
7 changes: 4 additions & 3 deletions storage/connect/mysql-test/connect/r/part_table.result
Expand Up @@ -23,7 +23,7 @@ id msg
CREATE TABLE xt3 (
id INT KEY NOT NULL,
msg VARCHAR(32))
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5;
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
Warnings:
Warning 1105 No file name. Table will use xt3.csv
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
Expand Down Expand Up @@ -89,9 +89,10 @@ id msg
60 sixty
81 eighty one
72 seventy two
EXPLAIN PARTITIONS
SELECT * FROM t1 WHERE id = 81;
id msg
81 eighty one
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 3 ALL NULL NULL NULL NULL 6 Using where
DELETE FROM t1;
Warnings:
Note 1105 xt1: 4 affected rows
Expand Down
4 changes: 2 additions & 2 deletions storage/connect/mysql-test/connect/t/part_table.test
Expand Up @@ -22,7 +22,7 @@ SELECT * FROM xt2;
CREATE TABLE xt3 (
id INT KEY NOT NULL,
msg VARCHAR(32))
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=5;
ENGINE=CONNECT TABLE_TYPE=CSV AVG_ROW_LENGTH=6;
INSERT INTO xt3 VALUES(60,'sixty'),(81,'eighty one'),(72,'seventy two');
SELECT * FROM xt3;

Expand All @@ -47,7 +47,7 @@ INSERT INTO t1 VALUES(7,'seven'),(10,'ten'),(40,'forty'),(60,'sixty'),(81,'eight
INSERT INTO t1 VALUES(72,'seventy two'),(11,'eleven'),(1,'one'),(35,'thirty five'),(8,'eight');
SELECT partition_name, table_rows FROM information_schema.partitions WHERE table_name = 't1';
SELECT * FROM t1;
#EXPLAIN PARTITIONS deleted because it returns differeent key on Windows and Linux
EXPLAIN PARTITIONS
SELECT * FROM t1 WHERE id = 81;
DELETE FROM t1;
DROP TABLE t1;
Expand Down
42 changes: 27 additions & 15 deletions storage/connect/tabjson.cpp
@@ -1,6 +1,6 @@
/************* tabjson C++ Program Source Code File (.CPP) *************/
/* PROGRAM NAME: tabjson Version 1.5 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2017 */
/* PROGRAM NAME: tabjson Version 1.6 */
/* (C) Copyright to the author Olivier BERTRAND 2014 - 2018 */
/* This program are the JSON class DB execution routines. */
/***********************************************************************/

Expand Down Expand Up @@ -173,6 +173,7 @@ JSONDISC::JSONDISC(PGLOBAL g, uint *lg)

int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
{
char filename[_MAX_PATH];
bool mgo = (GetTypeID(topt->type) == TAB_MONGO);
PCSZ level = GetStringTableOption(g, topt, "Level", NULL);

Expand Down Expand Up @@ -209,6 +210,12 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
return 0;
} // endif Fn

if (tdp->Fn) {
// We used the file name relative to recorded datapath
PlugSetPath(filename, tdp->Fn, tdp->GetPath());
tdp->Fn = PlugDup(g, filename);
} // endif Fn

if (trace(1))
htrc("File %s objname=%s pretty=%d lvl=%d\n",
tdp->Fn, tdp->Objname, tdp->Pretty, lvl);
Expand Down Expand Up @@ -342,7 +349,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
strncpy(colname, jpp->GetKey(), 64);
fmt[bf] = 0;

if (Find(g, jpp->GetVal(), MY_MIN(lvl, 0)))
if (Find(g, jpp->GetVal(), colname, MY_MIN(lvl, 0)))
goto err;

} // endfor jpp
Expand Down Expand Up @@ -385,7 +392,7 @@ int JSONDISC::GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt)
return 0;
} // end of GetColumns

bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j)
{
char *p, *pc = colname + strlen(colname);
int ars;
Expand Down Expand Up @@ -413,12 +420,14 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
job = (PJOB)jsp;

for (PJPR jrp = job->GetFirst(); jrp; jrp = jrp->GetNext()) {
if (*jrp->GetKey() != '$') {
strncat(strncat(fmt, sep, 128), jrp->GetKey(), 128);
strncat(strncat(colname, "_", 64), jrp->GetKey(), 64);
PCSZ k = jrp->GetKey();

if (*k != '$') {
strncat(strncat(fmt, sep, 128), k, 128);
strncat(strncat(colname, "_", 64), k, 64);
} // endif Key

if (Find(g, jrp->GetVal(), j + 1))
if (Find(g, jrp->GetVal(), k, j + 1))
return true;

*p = *pc = 0;
Expand All @@ -428,13 +437,13 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
case TYPE_JAR:
jar = (PJAR)jsp;

if (all || (tdp->Xcol && !stricmp(tdp->Xcol, colname)))
if (all || (tdp->Xcol && !stricmp(tdp->Xcol, key)))
ars = jar->GetSize(false);
else
ars = MY_MIN(jar->GetSize(false), 1);

for (int k = 0; k < ars; k++) {
if (!tdp->Xcol || stricmp(tdp->Xcol, colname)) {
if (!tdp->Xcol || stricmp(tdp->Xcol, key)) {
sprintf(buf, "%d", k);

if (tdp->Uri)
Expand All @@ -448,7 +457,7 @@ bool JSONDISC::Find(PGLOBAL g, PJVAL jvp, int j)
} else
strncat(fmt, (tdp->Uri ? sep : "[*]"), 128);

if (Find(g, jar->GetValue(k), j))
if (Find(g, jar->GetValue(k), "", j))
return true;

*p = *pc = 0;
Expand Down Expand Up @@ -522,7 +531,9 @@ void JSONDISC::AddColumn(PGLOBAL g)
n++;
} // endif jcp

pjcp = jcp;
if (jcp)
pjcp = jcp;

} // end of AddColumn


Expand All @@ -549,7 +560,7 @@ JSONDEF::JSONDEF(void)
/***********************************************************************/
/* DefineAM: define specific AM block values. */
/***********************************************************************/
bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR am, int poff)
{
Schema = GetStringCatInfo(g, "DBname", Schema);
Jmode = (JMODE)GetIntCatInfo("Jmode", MODE_OBJECT);
Expand All @@ -561,7 +572,8 @@ bool JSONDEF::DefineAM(PGLOBAL g, LPCSTR, int poff)
Sep = *GetStringCatInfo(g, "Separator", ".");
Accept = GetBoolCatInfo("Accept", false);

if (Uri = GetStringCatInfo(g, "Connect", NULL)) {
// Don't use url as uri when called from REST OEM module
if (stricmp(am, "REST") && (Uri = GetStringCatInfo(g, "Connect", NULL))) {
#if defined(JAVA_SUPPORT) || defined(CMGO_SUPPORT)
Collname = GetStringCatInfo(g, "Name",
(Catfunc & (FNC_TABLE | FNC_COL)) ? NULL : Name);
Expand Down Expand Up @@ -2340,7 +2352,7 @@ void TDBJSON::CloseDB(PGLOBAL g)
TDBJCL::TDBJCL(PJDEF tdp) : TDBCAT(tdp)
{
Topt = tdp->GetTopt();
Db = tdp->Schema;
Db = tdp->Schema;
Dsn = tdp->Uri;
} // end of TDBJCL constructor

Expand Down
2 changes: 1 addition & 1 deletion storage/connect/tabjson.h
Expand Up @@ -52,7 +52,7 @@ class JSONDISC : public BLOCK {

// Functions
int GetColumns(PGLOBAL g, PCSZ db, PCSZ dsn, PTOS topt);
bool Find(PGLOBAL g, PJVAL jvp, int j);
bool Find(PGLOBAL g, PJVAL jvp, PCSZ key, int j);
void AddColumn(PGLOBAL g);

// Members
Expand Down

0 comments on commit 547ce1b

Please sign in to comment.