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,28 +1411,30 @@ int TDBBSN::EstimatedLength(void) ...@@ -1411,28 +1411,30 @@ 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 { } // endif Use
/*******************************************************************/
/* First opening. */ /*********************************************************************/
/*******************************************************************/ /* Open according to logical input/output mode required. */
if (Mode == MODE_INSERT) /*********************************************************************/
switch (Jmode) { if (TDBDOS::OpenDB(g))
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; return true;
} // endswitch Jmode
} // endif Use if (use == USE_OPEN)
return false;
if (Pretty < 0) { if (Pretty < 0) {
/*******************************************************************/ /*******************************************************************/
...@@ -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. */
/* 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. */ /* 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
/***********************************************************************/
/* 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; 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,6 +1566,7 @@ int TDBBSN::ReadDB(PGLOBAL g) ...@@ -1564,6 +1566,7 @@ int TDBBSN::ReadDB(PGLOBAL g)
/***********************************************************************/ /***********************************************************************/
bool TDBBSN::PrepareWriting(PGLOBAL g) bool TDBBSN::PrepareWriting(PGLOBAL g)
{ {
if (Pretty >= 0) {
PSZ s; PSZ s;
if (!(Top = Bp->MakeTopTree(g, Row))) if (!(Top = Bp->MakeTopTree(g, Row)))
...@@ -1583,7 +1586,10 @@ bool TDBBSN::PrepareWriting(PGLOBAL g) ...@@ -1583,7 +1586,10 @@ bool TDBBSN::PrepareWriting(PGLOBAL g)
return false; return false;
} else } else
return true; return true;
} else
((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