Commit 46edfd63 authored by Olivier Bertrand's avatar Olivier Bertrand

- Getting text of json items now includes all array members

  modified:   storage/connect/json.cpp
  modified:   storage/connect/json.h
  modified:   storage/connect/jsonudf.cpp
  modified:   storage/connect/jsonudf.h
  modified:   storage/connect/mysql-test/connect/r/json.result
  modified:   storage/connect/mysql-test/connect/r/json_java_2.result
  modified:   storage/connect/mysql-test/connect/r/json_mongo_c.result
  modified:   storage/connect/mysql-test/connect/r/json_udf.result
  modified:   storage/connect/mysql-test/connect/r/json_udf_bin.result
  modified:   storage/connect/mysql-test/connect/r/zip.result
  modified:   storage/connect/mysql-test/connect/t/zip.test
  modified:   storage/connect/tabjson.cpp
  modified:   storage/connect/tabjson.h
  modified:   storage/connect/xobject.h
parent d3372258
......@@ -1045,48 +1045,57 @@ PJVAL JOBJECT::GetValue(const char* key)
/***********************************************************************/
/* Return the text corresponding to all keys (XML like). */
/***********************************************************************/
PSZ JOBJECT::GetText(PGLOBAL g, PSZ text)
PSZ JOBJECT::GetText(PGLOBAL g, PSTRG text)
{
int n;
if (!First)
return text;
if (First) {
bool b;
if (!text) {
text = (PSZ)malloc(1024); // TODO: get size
text[0] = 0;
n = 1;
} else
n = 0;
text = new(g) STRING(g, 256);
b = true;
} else {
if (text->GetLastChar() != ' ')
text->Append(' ');
b = false;
} // endif text
if (n == 1 && !First->Next && !strcmp(First->Key, "$date")) {
if (b && !First->Next && !strcmp(First->Key, "$date")) {
int i;
PSZ s;
First->Val->GetText(g, text);
i = (text[1] == '-' ? 2 : 1);
s = text->GetStr();
i = (s[1] == '-' ? 2 : 1);
if (IsNum(text + i)) {
if (IsNum(s + i)) {
// Date is in milliseconds
int j = (int)strlen(text);
int j = text->GetLength();
if (j >= 4 + i)
text[j - 3] = 0; // Change it to seconds
else
strcpy(text, " 0");
if (j >= 4 + i) {
s[j - 3] = 0; // Change it to seconds
text->SetLength((uint)strlen(s));
} else
text->Set(" 0");
} // endif text
} else for (PJPR jp = First; jp; jp = jp->Next)
} else for (PJPR jp = First; jp; jp = jp->Next) {
jp->Val->GetText(g, text);
if (n) {
PSZ txt = (PSZ)PlugSubAlloc(g, NULL, strlen(text));
strcpy(txt, text + 1); // Remove leading blank
free(text);
text = txt;
} // endif n
if (jp->Next)
text->Append(' ');
} // endfor jp
if (b) {
text->Trim();
return text->GetStr();
} // endif b
} // endif First
return text;
return NULL;
} // end of GetText;
/***********************************************************************/
......@@ -1288,29 +1297,42 @@ bool JARRAY::SetValue(PGLOBAL g, PJVAL jvp, int n)
/***********************************************************************/
/* Return the text corresponding to all values. */
/***********************************************************************/
PSZ JARRAY::GetText(PGLOBAL g, PSZ text)
PSZ JARRAY::GetText(PGLOBAL g, PSTRG text)
{
int n;
if (First) {
bool b;
PJVAL jp;
if (!text) {
text = (char*)malloc(1024); // Should be large enough
text[0] = 0;
n = 1;
} else
n = 0;
text = new(g) STRING(g, 256);
b = true;
} else {
if (text->GetLastChar() != ' ')
text->Append(" (");
else
text->Append('(');
for (jp = First; jp; jp = jp->Next)
b = false;
}
for (jp = First; jp; jp = jp->Next) {
jp->GetText(g, text);
if (n) {
PSZ txt = (PSZ)PlugSubAlloc(g, NULL, strlen(text));
strcpy(txt, text + 1); // Remove leading blank
free(text);
text = txt;
} // endif n
if (jp->Next)
text->Append(", ");
else if (!b)
text->Append(')');
} // endfor jp
if (b) {
text->Trim();
return text->GetStr();
} // endif b
return text;
} // endif First
return NULL;
} // end of GetText;
/***********************************************************************/
......@@ -1520,10 +1542,10 @@ double JVALUE::GetFloat(void)
/***********************************************************************/
/* Return the Value's String value. */
/***********************************************************************/
PSZ JVALUE::GetString(PGLOBAL g)
PSZ JVALUE::GetString(PGLOBAL g, char *buff)
{
char buf[32];
char *p = buf;
char *p = (buff) ? buff : buf;
if (Val) {
switch (Val->Type) {
......@@ -1532,19 +1554,19 @@ PSZ JVALUE::GetString(PGLOBAL g)
p = Val->Strp;
break;
case TYPE_INTG:
sprintf(buf, "%d", Val->N);
sprintf(p, "%d", Val->N);
break;
case TYPE_BINT:
sprintf(buf, "%lld", Val->LLn);
sprintf(p, "%lld", Val->LLn);
break;
case TYPE_DBL:
sprintf(buf, "%.*lf", Val->Nd, Val->F);
sprintf(p, "%.*lf", Val->Nd, Val->F);
break;
case TYPE_BOOL:
p = (char*)PlugDup(g, (Val->B) ? "true" : "false");
p = (char*)((Val->B) ? "true" : "false");
break;
case TYPE_NULL:
p = (char*)PlugDup(g, "null");
p = (char*)"null";
break;
default:
p = NULL;
......@@ -1559,19 +1581,20 @@ PSZ JVALUE::GetString(PGLOBAL g)
/***********************************************************************/
/* Return the Value's String value. */
/***********************************************************************/
PSZ JVALUE::GetText(PGLOBAL g, PSZ text)
PSZ JVALUE::GetText(PGLOBAL g, PSTRG text)
{
if (Jsp)
return Jsp->GetText(g, text);
PSZ s = (Val) ? GetString(g) : NULL;
char buff[32];
PSZ s = (Val) ? GetString(g, buff) : NULL;
if (s)
strcat(strcat(text, " "), s);
text->Append(s);
else if (GetJsonNull())
strcat(strcat(text, " "), GetJsonNull());
text->Append(GetJsonNull());
return text;
return NULL;
} // end of GetText
void JVALUE::SetValue(PJSON jsp)
......
......@@ -7,6 +7,7 @@
/***********************************************************************/
#include <mysql_com.h>
#include "value.h"
#include "xobject.h"
#if defined(_DEBUG)
#define X assert(false);
......@@ -157,8 +158,8 @@ class JSON : public BLOCK {
virtual PJPR GetFirst(void) { X return NULL; }
virtual int GetInteger(void) { X return 0; }
virtual double GetFloat() { X return 0.0; }
virtual PSZ GetString(PGLOBAL g) { X return NULL; }
virtual PSZ GetText(PGLOBAL g, PSZ text) { X return NULL; }
virtual PSZ GetString(PGLOBAL g, char *buff = NULL) { X return NULL; }
virtual PSZ GetText(PGLOBAL g, PSTRG text) { X return NULL; }
virtual bool Merge(PGLOBAL g, PJSON jsp) { X return true; }
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i) { X return true; }
virtual void SetValue(PGLOBAL g, PJVAL jvp, PCSZ key) { X }
......@@ -198,7 +199,7 @@ class JOBJECT : public JSON {
virtual PJVAL GetValue(const char* key);
virtual PJAR GetKeyList(PGLOBAL g);
virtual PJAR GetValList(PGLOBAL g);
virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual void SetValue(PGLOBAL g, PJVAL jvp, PCSZ key);
virtual void DeleteKey(PCSZ k);
......@@ -229,7 +230,7 @@ class JARRAY : public JSON {
PJVAL AddValue(PGLOBAL g, PJVAL jvp = NULL, int *x = NULL);
virtual void InitArray(PGLOBAL g);
virtual PJVAL GetValue(int i);
virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual bool Merge(PGLOBAL g, PJSON jsp);
virtual bool SetValue(PGLOBAL g, PJVAL jvp, int i);
virtual bool DeleteValue(int n);
......@@ -277,8 +278,8 @@ class JVALUE : public JSON {
virtual int GetInteger(void);
virtual long long GetBigint(void);
virtual double GetFloat(void);
virtual PSZ GetString(PGLOBAL g);
virtual PSZ GetText(PGLOBAL g, PSZ text);
virtual PSZ GetString(PGLOBAL g, char *buff = NULL);
virtual PSZ GetText(PGLOBAL g, PSTRG text);
virtual void SetValue(PJSON jsp);
virtual void SetValue(PGLOBAL g, PVAL valp);
inline void SetVal(PVL vlp) { Val = vlp; }
......
......@@ -347,7 +347,7 @@ PVAL JSNX::MakeJson(PGLOBAL g, PJSON jsp)
/*********************************************************************************/
/* SetValue: Set a value from a JVALUE contains. */
/*********************************************************************************/
void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val)
{
if (val) {
vp->SetNull(false);
......@@ -378,14 +378,11 @@ void JSNX::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
break;
case TYPE_JAR:
SetJsonValue(g, vp, val->GetArray()->GetValue(0), n);
vp->SetValue_psz(val->GetArray()->GetText(g, NULL));
break;
case TYPE_JOB:
// if (!vp->IsTypeNum() || !Strict) {
vp->SetValue_psz(val->GetObject()->GetText(g, NULL));
break;
// } // endif Type
case TYPE_NULL:
vp->SetNull(true);
default:
......@@ -420,11 +417,10 @@ void JSNX::ReadValue(PGLOBAL g)
/*********************************************************************************/
PVAL JSNX::GetColumnValue(PGLOBAL g, PJSON row, int i)
{
int n = Nod - 1;
PJVAL val = NULL;
val = GetRowValue(g, row, i);
SetJsonValue(g, Value, val, n);
SetJsonValue(g, Value, val);
return Value;
} // end of GetColumnValue
......@@ -497,7 +493,7 @@ PJVAL JSNX::GetRowValue(PGLOBAL g, PJSON row, int i, my_bool b)
} // endfor i
// SetJsonValue(g, Value, val, n);
// SetJsonValue(g, Value, val);
return val;
} // end of GetRowValue
......@@ -548,10 +544,10 @@ PVAL JSNX::CalculateArray(PGLOBAL g, PJAR arp, int n)
jvp->GetString(g), jvp->IsNull() ? 1 : 0);
if (!nv++) {
SetJsonValue(g, vp, jvp, n);
SetJsonValue(g, vp, jvp);
continue;
} else
SetJsonValue(g, MulVal, jvp, n);
SetJsonValue(g, MulVal, jvp);
if (!MulVal->IsNull()) {
switch (op) {
......
......@@ -294,7 +294,7 @@ class JSNX : public BLOCK {
PVAL ExpandArray(PGLOBAL g, PJAR arp, int n);
PVAL CalculateArray(PGLOBAL g, PJAR arp, int n);
PVAL MakeJson(PGLOBAL g, PJSON jsp);
void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n);
void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val);
PJSON GetRow(PGLOBAL g);
my_bool CompareValues(PVL v1, PVL v2);
my_bool LocateArray(PGLOBAL g, PJAR jarp);
......
......@@ -15,7 +15,7 @@ DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='biblio.json';
SELECT * FROM t1;
ISBN LANG SUBJECT AUTHOR TITLE TRANSLATION TRANSLATOR PUBLISHER DATEPUB
9782212090819 fr applications Jean-Christophe Bernadac Construire une application XML NULL NULL Eyrolles Paris 1999
9782212090819 fr applications Jean-Christophe Bernadac, Franois Knab Construire une application XML NULL NULL Eyrolles Paris 1999
9782840825685 fr applications William J. Pardi XML en Action adapt de l'anglais par James Guerin Microsoft Press Paris 1999
DROP TABLE t1;
#
......
......@@ -80,11 +80,11 @@ t1 CREATE TABLE `t1` (
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Depth=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_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856077 Morris Park Ave 10462 Bronx Bakery 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704 Flatbush Avenue 11225 Brooklyn Hamburgers 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999 West 57 Street 10019 Manhattan Irish 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999 Stillwell Avenue 11224 Brooklyn American 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152 63 Road 11374 Queens Jewish/Kosher 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed51c 1007 -73.856077, 40.848447 Morris Park Ave 10462 Bronx Bakery 2014-03-03T00:00:00.000Z A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.961704, 40.662942 Flatbush Avenue 11225 Brooklyn Hamburgers 2014-12-30T00:00:00.000Z A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.98513559999999, 40.7676919 West 57 Street 10019 Manhattan Irish 2014-09-06T00:00:00.000Z A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.98241999999999, 40.579505 Stillwell Avenue 11224 Brooklyn American 2014-06-10T00:00:00.000Z A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.8601152, 40.7311739 63 Road 11374 Queens Jewish/Kosher 2014-11-24T00:00:00.000Z Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
......@@ -93,16 +93,16 @@ CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=
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
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
......
......@@ -80,11 +80,11 @@ t1 CREATE TABLE `t1` (
) ENGINE=CONNECT DEFAULT CHARSET=latin1 CONNECTION='mongodb://localhost:27017' `TABLE_TYPE`='JSON' `TABNAME`='restaurants' `OPTION_LIST`='Depth=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_date grades_grade grades_score name restaurant_id
58ada47de5a51ddfcd5ed51c 1007 -73.856076999999999089 Morris Park Ave 10462 Bronx Bakery 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745 Flatbush Avenue 11225 Brooklyn Hamburgers 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451 West 57 Street 10019 Manhattan Irish 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523 Stillwell Avenue 11224 Brooklyn American 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639 63 Road 11374 Queens Jewish/Kosher 1416787200 Z 20 Tov Kosher Kitchen 40356068
58ada47de5a51ddfcd5ed51c 1007 -73.856076999999999089, 40.848447000000000173 Morris Park Ave 10462 Bronx Bakery 1393804800 A 2 Morris Park Bake Shop 30075445
58ada47de5a51ddfcd5ed51d 469 -73.96170399999999745, 40.66294200000000103 Flatbush Avenue 11225 Brooklyn Hamburgers 1419897600 A 8 Wendy'S 30112340
58ada47de5a51ddfcd5ed51e 351 -73.985135599999992451, 40.767691900000002647 West 57 Street 10019 Manhattan Irish 1409961600 A 2 Dj Reynolds Pub And Restaurant 30191841
58ada47de5a51ddfcd5ed51f 2780 -73.982419999999990523, 40.579504999999997494 Stillwell Avenue 11224 Brooklyn American 1402358400 A 5 Riviera Caterer 40356018
58ada47de5a51ddfcd5ed520 97-22 -73.860115199999995639, 40.731173900000001709 63 Road 11374 Queens Jewish/Kosher 1416787200 Z 20 Tov Kosher Kitchen 40356068
DROP TABLE t1;
#
# Dropping a column
......@@ -93,16 +93,16 @@ CREATE TABLE t1 ENGINE=CONNECT TABLE_TYPE=JSON TABNAME=restaurants DATA_CHARSET=
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
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
......
......@@ -187,11 +187,11 @@ DATEPUB int(4)
) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='biblio.json';
SELECT Json_Make_Array(AUTHOR, TITLE, DATEPUB) FROM t2;
Json_Make_Array(AUTHOR, TITLE, DATEPUB)
["Jean-Christophe Bernadac","Construire une application XML",1999]
[" Jean-Christophe Bernadac, Franois Knab","Construire une application XML",1999]
["William J. Pardi","XML en Action",1999]
SELECT Json_Make_Object(AUTHOR, TITLE, DATEPUB) FROM t2;
Json_Make_Object(AUTHOR, TITLE, DATEPUB)
{"AUTHOR":"Jean-Christophe Bernadac","TITLE":"Construire une application XML","DATEPUB":1999}
{"AUTHOR":" Jean-Christophe Bernadac, Franois Knab","TITLE":"Construire une application XML","DATEPUB":1999}
{"AUTHOR":"William J. Pardi","TITLE":"XML en Action","DATEPUB":1999}
SELECT Json_Array_Grp(TITLE, DATEPUB) FROM t2;
ERROR HY000: Can't initialize function 'json_array_grp'; This function can only accept 1 argument
......@@ -610,7 +610,7 @@ JsonGet_String(Json_File('test/fx.json'), '1.*')
{"_id":6,"type":"car","item":"roadster","mileage":56000,"ratings":[6,9]}
SELECT JsonGet_String(Json_File('test/fx.json'), '1');
JsonGet_String(Json_File('test/fx.json'), '1')
6 car roadster 56000 6 9
6 car roadster 56000 (6, 9)
SELECT JsonGet_Int(Json_File('test/fx.json'), '1.mileage') AS Mileage;
Mileage
56000
......
......@@ -87,7 +87,7 @@ Json_Get_Item(Jbin_File('gloss.json'),'$.glossary.GlossDiv')
{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}
SELECT JsonGet_String(Json_File('gloss.json'),'$.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso') lang;
lang
GML
GML, XML
SELECT Json_Get_Item(Jbin_File('gloss.json'),'$.glossary.GlossDiv.GlossList.GlossEntry.GlossDef.GlossSeeAlso') "See also";
See also
["GML","XML"]
......
......@@ -171,32 +171,32 @@ DROP TABLE t1,t2,t3,t4;
#
CREATE TABLE t1 (
_id INT(2) NOT NULL,
name_first CHAR(9) NOT NULL FIELD_FORMAT='$.name.first',
name_aka CHAR(4) DEFAULT NULL FIELD_FORMAT='$.name.aka',
name_last CHAR(10) NOT NULL FIELD_FORMAT='$.name.last',
name_first CHAR(9) NOT NULL JPATH='$.name.first',
name_aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
name_last CHAR(10) NOT NULL JPATH='$.name.last',
title CHAR(12) DEFAULT NULL,
birth CHAR(20) DEFAULT NULL,
death CHAR(20) DEFAULT NULL,
contribs CHAR(7) NOT NULL FIELD_FORMAT='$.contribs',
awards_award CHAR(42) DEFAULT NULL FIELD_FORMAT='$.awards.award',
awards_year CHAR(4) DEFAULT NULL FIELD_FORMAT='$.awards.year',
awards_by CHAR(38) DEFAULT NULL FIELD_FORMAT='$.awards.by'
contribs CHAR(50) NOT NULL JPATH='$.contribs',
awards_award CHAR(42) DEFAULT NULL JPATH='$.awards.award',
awards_year CHAR(4) DEFAULT NULL JPATH='$.awards.year',
awards_by CHAR(38) DEFAULT NULL JPATH='$.awards.by'
) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.zip' OPTION_LIST='ENTRY=bios.json,LOAD=bios.json' ZIPPED=YES;
SELECT * FROM t1;
_id name_first name_aka name_last title birth death contribs awards_award awards_year awards_by
1 John NULL Backus NULL 1924-12-03T05:00:00Z 2007-03-17T04:00:00Z Fortran W.W. McDowell Award 1967 IEEE Computer Society
2 John NULL McCarthy NULL 1927-09-04T04:00:00Z 2011-12-24T05:00:00Z Lisp Turing Award 1971 ACM
3 Grace NULL Hopper Rear Admiral 1906-12-09T05:00:00Z 1992-01-01T05:00:00Z UNIVAC Computer Sciences Man of the Year 1969 Data Processing Management Association
4 Kristen NULL Nygaard NULL 1926-08-27T04:00:00Z 2002-08-10T04:00:00Z OOP Rosing Prize 1999 Norwegian Data Association
5 Ole-Johan NULL Dahl NULL 1931-10-12T04:00:00Z 2002-06-29T04:00:00Z OOP Rosing Prize 1999 Norwegian Data Association
1 John NULL Backus NULL 1924-12-03T05:00:00Z 2007-03-17T04:00:00Z Fortran, ALGOL, Backus-Naur Form, FP W.W. McDowell Award 1967 IEEE Computer Society
2 John NULL McCarthy NULL 1927-09-04T04:00:00Z 2011-12-24T05:00:00Z Lisp, Artificial Intelligence, ALGOL Turing Award 1971 ACM
3 Grace NULL Hopper Rear Admiral 1906-12-09T05:00:00Z 1992-01-01T05:00:00Z UNIVAC, compiler, FLOW-MATIC, COBOL Computer Sciences Man of the Year 1969 Data Processing Management Association
4 Kristen NULL Nygaard NULL 1926-08-27T04:00:00Z 2002-08-10T04:00:00Z OOP, Simula Rosing Prize 1999 Norwegian Data Association
5 Ole-Johan NULL Dahl NULL 1931-10-12T04:00:00Z 2002-06-29T04:00:00Z OOP, Simula Rosing Prize 1999 Norwegian Data Association
6 Guido NULL van Rossum NULL 1956-01-31T05:00:00Z NULL Python Award for the Advancement of Free Software 2001 Free Software Foundation
7 Dennis NULL Ritchie NULL 1941-09-09T04:00:00Z 2011-10-12T04:00:00Z UNIX Turing Award 1983 ACM
7 Dennis NULL Ritchie NULL 1941-09-09T04:00:00Z 2011-10-12T04:00:00Z UNIX, C Turing Award 1983 ACM
8 Yukihiro Matz Matsumoto NULL 1965-04-14T04:00:00Z NULL Ruby Award for the Advancement of Free Software 2011 Free Software Foundation
9 James NULL Gosling NULL 1955-05-19T04:00:00Z NULL Java The Economist Innovation Award 2002 The Economist
10 Martin NULL Odersky NULL NULL NULL Scala NULL NULL NULL
CREATE TABLE t2
ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.zip' ZIPPED=1
OPTION_LIST='LEVEL=5';
OPTION_LIST='DEPTH=5';
SELECT * FROM t2;
_id name_first name_aka name_last title birth death contribs awards_award awards_year awards_by
1 John NULL Backus NULL 1924-12-03T05:00:00Z 2007-03-17T04:00:00Z Fortran W.W. McDowell Award 1967 IEEE Computer Society
......@@ -211,16 +211,16 @@ _id name_first name_aka name_last title birth death contribs awards_award awards
10 Martin NULL Odersky NULL NULL NULL Scala NULL NULL NULL
CREATE TABLE t3 (
_id INT(2) NOT NULL,
firstname CHAR(9) NOT NULL FIELD_FORMAT='$.name.first',
aka CHAR(4) DEFAULT NULL FIELD_FORMAT='$.name.aka',
lastname CHAR(10) NOT NULL FIELD_FORMAT='$.name.last',
firstname CHAR(9) NOT NULL JPATH='$.name.first',
aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
lastname CHAR(10) NOT NULL JPATH='$.name.last',
title CHAR(12) DEFAULT NULL,
birth date DEFAULT NULL date_format="YYYY-DD-MM'T'hh:mm:ss'Z'",
death date DEFAULT NULL date_format="YYYY-DD-MM'T'hh:mm:ss'Z'",
contribs CHAR(64) NOT NULL FIELD_FORMAT='$.contribs.[", "]',
award CHAR(42) DEFAULT NULL FIELD_FORMAT='$.awards[*].award',
year CHAR(4) DEFAULT NULL FIELD_FORMAT='$.awards[*].year',
`by` CHAR(38) DEFAULT NULL FIELD_FORMAT='$.awards[*].by'
contribs CHAR(64) NOT NULL JPATH='$.contribs.[", "]',
award CHAR(42) DEFAULT NULL JPATH='$.awards[*].award',
year CHAR(4) DEFAULT NULL JPATH='$.awards[*].year',
`by` CHAR(38) DEFAULT NULL JPATH='$.awards[*].by'
) ENGINE=CONNECT TABLE_TYPE='json' FILE_NAME='bios.zip' ZIPPED=YES;
SELECT * FROM t3 WHERE _id = 1;
_id firstname aka lastname title birth death contribs award year by
......
......@@ -83,37 +83,37 @@ DROP TABLE t1,t2,t3,t4;
--echo #
CREATE TABLE t1 (
_id INT(2) NOT NULL,
name_first CHAR(9) NOT NULL FIELD_FORMAT='$.name.first',
name_aka CHAR(4) DEFAULT NULL FIELD_FORMAT='$.name.aka',
name_last CHAR(10) NOT NULL FIELD_FORMAT='$.name.last',
name_first CHAR(9) NOT NULL JPATH='$.name.first',
name_aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
name_last CHAR(10) NOT NULL JPATH='$.name.last',
title CHAR(12) DEFAULT NULL,
birth CHAR(20) DEFAULT NULL,
death CHAR(20) DEFAULT NULL,
contribs CHAR(7) NOT NULL FIELD_FORMAT='$.contribs',
awards_award CHAR(42) DEFAULT NULL FIELD_FORMAT='$.awards.award',
awards_year CHAR(4) DEFAULT NULL FIELD_FORMAT='$.awards.year',
awards_by CHAR(38) DEFAULT NULL FIELD_FORMAT='$.awards.by'
contribs CHAR(50) NOT NULL JPATH='$.contribs',
awards_award CHAR(42) DEFAULT NULL JPATH='$.awards.award',
awards_year CHAR(4) DEFAULT NULL JPATH='$.awards.year',
awards_by CHAR(38) DEFAULT NULL JPATH='$.awards.by'
) ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.zip' OPTION_LIST='ENTRY=bios.json,LOAD=bios.json' ZIPPED=YES;
SELECT * FROM t1;
# Test discovery
CREATE TABLE t2
ENGINE=CONNECT TABLE_TYPE=JSON FILE_NAME='bios.zip' ZIPPED=1
OPTION_LIST='LEVEL=5';
OPTION_LIST='DEPTH=5';
SELECT * FROM t2;
CREATE TABLE t3 (
_id INT(2) NOT NULL,
firstname CHAR(9) NOT NULL FIELD_FORMAT='$.name.first',
aka CHAR(4) DEFAULT NULL FIELD_FORMAT='$.name.aka',
lastname CHAR(10) NOT NULL FIELD_FORMAT='$.name.last',
firstname CHAR(9) NOT NULL JPATH='$.name.first',
aka CHAR(4) DEFAULT NULL JPATH='$.name.aka',
lastname CHAR(10) NOT NULL JPATH='$.name.last',
title CHAR(12) DEFAULT NULL,
birth date DEFAULT NULL date_format="YYYY-DD-MM'T'hh:mm:ss'Z'",
death date DEFAULT NULL date_format="YYYY-DD-MM'T'hh:mm:ss'Z'",
contribs CHAR(64) NOT NULL FIELD_FORMAT='$.contribs.[", "]',
award CHAR(42) DEFAULT NULL FIELD_FORMAT='$.awards[*].award',
year CHAR(4) DEFAULT NULL FIELD_FORMAT='$.awards[*].year',
`by` CHAR(38) DEFAULT NULL FIELD_FORMAT='$.awards[*].by'
contribs CHAR(64) NOT NULL JPATH='$.contribs.[", "]',
award CHAR(42) DEFAULT NULL JPATH='$.awards[*].award',
year CHAR(4) DEFAULT NULL JPATH='$.awards[*].year',
`by` CHAR(38) DEFAULT NULL JPATH='$.awards[*].by'
) ENGINE=CONNECT TABLE_TYPE='json' FILE_NAME='bios.zip' ZIPPED=YES;
SELECT * FROM t3 WHERE _id = 1;
......
......@@ -1595,7 +1595,7 @@ PVAL JSONCOL::MakeJson(PGLOBAL g, PJSON jsp)
/***********************************************************************/
/* SetValue: Set a value from a JVALUE contains. */
/***********************************************************************/
void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val)
{
if (val) {
vp->SetNull(false);
......@@ -1640,7 +1640,8 @@ void JSONCOL::SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n)
break;
case TYPE_JAR:
SetJsonValue(g, vp, val->GetArray()->GetValue(0), n);
// SetJsonValue(g, vp, val->GetArray()->GetValue(0));
vp->SetValue_psz(val->GetArray()->GetText(g, NULL));
break;
case TYPE_JOB:
// if (!vp->IsTypeNum() || !Strict) {
......@@ -1736,7 +1737,7 @@ PVAL JSONCOL::GetColumnValue(PGLOBAL g, PJSON row, int i)
} // endfor i
SetJsonValue(g, Value, val, n);
SetJsonValue(g, Value, val);
return Value;
} // end of GetColumnValue
......@@ -1776,7 +1777,7 @@ PVAL JSONCOL::ExpandArray(PGLOBAL g, PJAR arp, int n)
Tjp->NextSame = Xnod;
} // endif NextSame
SetJsonValue(g, Value, jvp, n);
SetJsonValue(g, Value, jvp);
return Value;
} // end of ExpandArray
......@@ -1822,10 +1823,10 @@ PVAL JSONCOL::CalculateArray(PGLOBAL g, PJAR arp, int n)
jvp->GetString(g), jvp->IsNull() ? 1 : 0);
if (!nv++) {
SetJsonValue(g, vp, jvp, n);
SetJsonValue(g, vp, jvp);
continue;
} else
SetJsonValue(g, MulVal, jvp, n);
SetJsonValue(g, MulVal, jvp);
if (!MulVal->IsNull()) {
switch (op) {
......
......@@ -228,7 +228,7 @@ class DllExport JSONCOL : public DOSCOL {
PVAL ExpandArray(PGLOBAL g, PJAR arp, int n);
PVAL CalculateArray(PGLOBAL g, PJAR arp, int n);
PVAL MakeJson(PGLOBAL g, PJSON jsp);
void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val, int n);
void SetJsonValue(PGLOBAL g, PVAL vp, PJVAL val);
PJSON GetRow(PGLOBAL g);
// Default constructor not to be used
......
......@@ -130,6 +130,7 @@ class DllExport STRING : public BLOCK {
inline void SetLength(uint n) {Length = n;}
inline PSZ GetStr(void) {return Strp;}
inline uint32 GetSize(void) {return Size;}
inline char GetLastChar(void) {return Length ? Strp[Length - 1] : 0;}
inline bool IsTruncated(void) {return Trc;}
// Methods
......
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