Commit aa10789f authored by Olivier Bertrand's avatar Olivier Bertrand

BSON development

parent 4eeadedc
...@@ -145,7 +145,7 @@ class BJSON : public BLOCK { ...@@ -145,7 +145,7 @@ class BJSON : public BLOCK {
void SetBigint(PBVAL vlp, longlong ll); void SetBigint(PBVAL vlp, longlong ll);
void SetFloat(PBVAL vlp, double f); void SetFloat(PBVAL vlp, double f);
void SetBool(PBVAL vlp, bool b); void SetBool(PBVAL vlp, bool b);
void Clear(PBVAL vlp) { vlp->N = 0; vlp->Nd = 0; vlp->Next = 0; vlp->Type = TYPE_NULL; } void Clear(PBVAL vlp) { vlp->N = 0; vlp->Nd = 0; vlp->Next = 0; }
bool IsValueNull(PBVAL vlp); bool IsValueNull(PBVAL vlp);
bool IsJson(PBVAL vlp) {return (vlp->Type == TYPE_JAR || vlp->Type == TYPE_JOB);} bool IsJson(PBVAL vlp) {return (vlp->Type == TYPE_JAR || vlp->Type == TYPE_JOB);}
......
...@@ -1737,7 +1737,6 @@ char *bfile_bjson(UDF_INIT *initid, UDF_ARGS *args, char *result, ...@@ -1737,7 +1737,6 @@ char *bfile_bjson(UDF_INIT *initid, UDF_ARGS *args, char *result,
ssize_t len, newloc; ssize_t len, newloc;
size_t lrecl, binszp; size_t lrecl, binszp;
PBVAL jsp; PBVAL jsp;
PBJNX bnxp;
PGLOBAL g = (PGLOBAL)initid->ptr; PGLOBAL g = (PGLOBAL)initid->ptr;
BDOC doc(g); BDOC doc(g);
......
This diff is collapsed.
...@@ -215,16 +215,16 @@ class DllExport BLKFAM : public DOSFAM { ...@@ -215,16 +215,16 @@ class DllExport BLKFAM : public DOSFAM {
/* This is the DOS/UNIX Access Method class declaration for binary */ /* This is the DOS/UNIX Access Method class declaration for binary */
/* files with variable record format (BJSON) */ /* files with variable record format (BJSON) */
/***********************************************************************/ /***********************************************************************/
class DllExport BINFAM : public TXTFAM { class DllExport BINFAM : public DOSFAM {
public: public:
// Constructor // Constructor
BINFAM(PDOSDEF tdp) : TXTFAM(tdp) {BStream = NULL; Recsize = 0;} BINFAM(PDOSDEF tdp) : DOSFAM(tdp) {Recsize = 0;}
BINFAM(PBINFAM txfp) : TXTFAM(txfp) {BStream = txfp->BStream;} BINFAM(PBINFAM txfp) : DOSFAM(txfp) {Recsize = txfp->Recsize;}
// Implementation // Implementation
virtual AMT GetAmType(void) {return TYPE_AM_BIN;} virtual AMT GetAmType(void) {return TYPE_AM_BIN;}
virtual int GetPos(void); //virtual int GetPos(void);
virtual int GetNextPos(void); //virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) BINFAM(this); } virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) BINFAM(this); }
// Methods // Methods
...@@ -233,23 +233,22 @@ class DllExport BINFAM : public TXTFAM { ...@@ -233,23 +233,22 @@ class DllExport BINFAM : public TXTFAM {
virtual int Cardinality(PGLOBAL g); virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s) {return s;} virtual int MaxBlkSize(PGLOBAL g, int s) {return s;}
virtual bool AllocateBuffer(PGLOBAL g); virtual bool AllocateBuffer(PGLOBAL g);
virtual int GetRowID(void); //virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g); //virtual bool RecordPos(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos); //virtual bool SetPos(PGLOBAL g, int recpos);
virtual int SkipRecord(PGLOBAL g, bool header) {return 0;} virtual int SkipRecord(PGLOBAL g, bool header) {return 0;}
virtual bool OpenTableFile(PGLOBAL g); //virtual bool OpenTableFile(PGLOBAL g);
virtual int ReadBuffer(PGLOBAL g); virtual int ReadBuffer(PGLOBAL g);
virtual int WriteBuffer(PGLOBAL g); virtual int WriteBuffer(PGLOBAL g);
virtual int DeleteRecords(PGLOBAL g, int irc) {return RC_FX;} //virtual int DeleteRecords(PGLOBAL g, int irc);
virtual void CloseTableFile(PGLOBAL g, bool abort); virtual void CloseTableFile(PGLOBAL g, bool abort);
virtual void Rewind(void); virtual void Rewind(void);
protected: //protected:
//virtual int InitDelete(PGLOBAL g, int fpos, int spos); //virtual int InitDelete(PGLOBAL g, int fpos, int spos);
// Members // Members
FILE *BStream; // Points to Bin file structure size_t Recsize; // Length of last read or next written record
size_t Recsize; // Length of last read record
}; // end of class BINFAM }; // end of class BINFAM
#endif // __FILAMTXT_H #endif // __FILAMTXT_H
...@@ -1012,7 +1012,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g) ...@@ -1012,7 +1012,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
PBVAL nwr, row = Tp->Row; PBVAL nwr, row = Tp->Row;
for (int i = 0; i < nod && row; i++) { for (int i = 0; i < nod && row; i++) {
if (nodes[i + 1].Op == OP_XX) if (i < nod-1 && nodes[i+1].Op == OP_XX)
break; break;
else switch (row->Type) { else switch (row->Type) {
case TYPE_JOB: case TYPE_JOB:
...@@ -1411,29 +1411,31 @@ int TDBBSN::EstimatedLength(void) ...@@ -1411,29 +1411,31 @@ int TDBBSN::EstimatedLength(void)
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::OpenDB(PGLOBAL g) bool TDBBSN::OpenDB(PGLOBAL g)
{ {
TUSE use = Use;
if (Pretty < 0 && Mode == MODE_UPDATE) {
sprintf(g->Message, "Mode %d NIY for Bjson", Mode);
return true;
} // endif Mode
if (Use == USE_OPEN) { if (Use == USE_OPEN) {
/*******************************************************************/ /*******************************************************************/
/* Table already open replace it at its beginning. */ /* Table already open replace it at its beginning. ??? */
/*******************************************************************/ /*******************************************************************/
Fpos = -1; Fpos = -1;
NextSame = 0; NextSame = 0;
SameRow = 0; SameRow = 0;
} else {
/*******************************************************************/
/* First opening. */
/*******************************************************************/
if (Mode == MODE_INSERT)
switch (Jmode) {
case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break;
case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break;
case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break;
default:
sprintf(g->Message, "Invalid Jmode %d", Jmode);
return true;
} // endswitch Jmode
} // endif Use } // endif Use
/*********************************************************************/
/* Open according to logical input/output mode required. */
/*********************************************************************/
if (TDBDOS::OpenDB(g))
return true;
if (use == USE_OPEN)
return false;
if (Pretty < 0) { if (Pretty < 0) {
/*******************************************************************/ /*******************************************************************/
/* Binary BJSON table. */ /* Binary BJSON table. */
...@@ -1441,45 +1443,45 @@ bool TDBBSN::OpenDB(PGLOBAL g) ...@@ -1441,45 +1443,45 @@ bool TDBBSN::OpenDB(PGLOBAL g)
xtrc(1, "JSN OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n", xtrc(1, "JSN OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n",
this, Tdb_No, Use, Mode); this, Tdb_No, Use, Mode);
if (Use == USE_OPEN) {
/*******************************************************************/
/* Table already open, just replace it at its beginning. */
/*******************************************************************/
if (!To_Kindex) {
Txfp->Rewind(); // see comment in Work.log
} else // Table is to be accessed through a sorted index table
To_Kindex->Reset(); // TODO: NIY
return false;
} // endif use
/*********************************************************************/ /*********************************************************************/
/* Open according to logical input/output mode required. */ /* Lrecl is Ok. */
/* Use conventionnal input/output functions. */
/*********************************************************************/
if (Txfp->OpenTableFile(g))
return true;
Use = USE_OPEN; // Do it now in case we are recursively called
/*********************************************************************/
/* Lrecl is Ok. */
/*********************************************************************/ /*********************************************************************/
size_t linelen = Lrecl; size_t linelen = Lrecl;
// Buffer should be the first allocated thing in G->Sarea // Buffer must be set to G->Sarea
Txfp->AllocateBuffer(Bp->G); Txfp->AllocateBuffer(Bp->G);
if (Mode == MODE_INSERT)
Bp->SubSet(true);
else
Bp->MemSave();
To_Line = Txfp->GetBuf(); To_Line = Txfp->GetBuf();
memset(To_Line, 0, linelen); memset(To_Line, 0, linelen);
Bp->MemSave();
xtrc(1, "OpenJSN: R%hd mode=%d To_Line=%p\n", Tdb_No, Mode, To_Line); xtrc(1, "OpenJSN: R%hd mode=%d To_Line=%p\n", Tdb_No, Mode, To_Line);
} else if (TDBDOS::OpenDB(g)) } // endif Pretty
return true;
/***********************************************************************/
/* First opening. */
/***********************************************************************/
if (Mode == MODE_INSERT) {
switch (Jmode) {
case MODE_OBJECT: Row = Bp->NewVal(TYPE_JOB); break;
case MODE_ARRAY: Row = Bp->NewVal(TYPE_JAR); break;
case MODE_VALUE: Row = Bp->NewVal(TYPE_JVAL); break;
default:
sprintf(g->Message, "Invalid Jmode %d", Jmode);
return true;
} // endswitch Jmode
Bp->MemSave();
} // endif Mode
if (Xcol) if (Xcol)
To_Filter = NULL; // Imcompatible To_Filter = NULL; // Imcompatible
return false; return false;
} // end of OpenDB } // end of OpenDB
/***********************************************************************/ /***********************************************************************/
...@@ -1564,26 +1566,30 @@ int TDBBSN::ReadDB(PGLOBAL g) ...@@ -1564,26 +1566,30 @@ int TDBBSN::ReadDB(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::PrepareWriting(PGLOBAL g) bool TDBBSN::PrepareWriting(PGLOBAL g)
{ {
PSZ s; if (Pretty >= 0) {
PSZ s;
if (!(Top = Bp->MakeTopTree(g, Row))) if (!(Top = Bp->MakeTopTree(g, Row)))
return true; return true;
if ((s = Bp->SerialVal(g, Top, Pretty))) { if ((s = Bp->SerialVal(g, Top, Pretty))) {
if (Comma) if (Comma)
strcat(s, ","); strcat(s, ",");
if ((signed)strlen(s) > Lrecl) { if ((signed)strlen(s) > Lrecl) {
strncpy(To_Line, s, Lrecl); strncpy(To_Line, s, Lrecl);
sprintf(g->Message, "Line truncated (lrecl=%d)", Lrecl); sprintf(g->Message, "Line truncated (lrecl=%d)", Lrecl);
return PushWarning(g, this); return PushWarning(g, this);
} else } else
strcpy(To_Line, s); strcpy(To_Line, s);
return false; return false;
} else
return true;
} else } else
return true; ((BINFAM*)Txfp)->Recsize = ((size_t)PlugSubAlloc(Bp->G, NULL, 0)
- (size_t)To_Line);
return false;
} // end of PrepareWriting } // end of PrepareWriting
/***********************************************************************/ /***********************************************************************/
...@@ -2034,6 +2040,7 @@ void BSONCOL::WriteColumn(PGLOBAL g) ...@@ -2034,6 +2040,7 @@ void BSONCOL::WriteColumn(PGLOBAL g)
else else
Cp->AddArrayValue(row, jsp); Cp->AddArrayValue(row, jsp);
break;
case TYPE_JOB: case TYPE_JOB:
if (Nodes[Nod - 1].Key) if (Nodes[Nod - 1].Key)
Cp->SetKeyValue(row, jsp, Nodes[Nod - 1].Key); Cp->SetKeyValue(row, jsp, Nodes[Nod - 1].Key);
......
...@@ -2148,6 +2148,9 @@ bool TDBDOS::OpenDB(PGLOBAL g) ...@@ -2148,6 +2148,9 @@ bool TDBDOS::OpenDB(PGLOBAL g)
} // endif use } // endif use
if (Mode == MODE_DELETE && !Next && Txfp->GetAmType() != TYPE_AM_DOS if (Mode == MODE_DELETE && !Next && Txfp->GetAmType() != TYPE_AM_DOS
#if defined(BSON_SUPPORT)
&& Txfp->GetAmType() != TYPE_AM_BIN
#endif // BSON_SUPPORT
&& Txfp->GetAmType() != TYPE_AM_MGO) { && Txfp->GetAmType() != TYPE_AM_MGO) {
// Delete all lines. Not handled in MAP or block mode // Delete all lines. Not handled in MAP or block mode
Txfp = new(g) DOSFAM((PDOSDEF)To_Def); Txfp = new(g) DOSFAM((PDOSDEF)To_Def);
......
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