Commit aa10789f authored by Olivier Bertrand's avatar Olivier Bertrand

BSON development

parent 4eeadedc
......@@ -145,7 +145,7 @@ class BJSON : public BLOCK {
void SetBigint(PBVAL vlp, longlong ll);
void SetFloat(PBVAL vlp, double f);
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 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,
ssize_t len, newloc;
size_t lrecl, binszp;
PBVAL jsp;
PBJNX bnxp;
PGLOBAL g = (PGLOBAL)initid->ptr;
BDOC doc(g);
......
This diff is collapsed.
......@@ -215,16 +215,16 @@ class DllExport BLKFAM : public DOSFAM {
/* This is the DOS/UNIX Access Method class declaration for binary */
/* files with variable record format (BJSON) */
/***********************************************************************/
class DllExport BINFAM : public TXTFAM {
class DllExport BINFAM : public DOSFAM {
public:
// Constructor
BINFAM(PDOSDEF tdp) : TXTFAM(tdp) {BStream = NULL; Recsize = 0;}
BINFAM(PBINFAM txfp) : TXTFAM(txfp) {BStream = txfp->BStream;}
BINFAM(PDOSDEF tdp) : DOSFAM(tdp) {Recsize = 0;}
BINFAM(PBINFAM txfp) : DOSFAM(txfp) {Recsize = txfp->Recsize;}
// Implementation
virtual AMT GetAmType(void) {return TYPE_AM_BIN;}
virtual int GetPos(void);
virtual int GetNextPos(void);
//virtual int GetPos(void);
//virtual int GetNextPos(void);
virtual PTXF Duplicate(PGLOBAL g) { return (PTXF)new(g) BINFAM(this); }
// Methods
......@@ -233,23 +233,22 @@ class DllExport BINFAM : public TXTFAM {
virtual int Cardinality(PGLOBAL g);
virtual int MaxBlkSize(PGLOBAL g, int s) {return s;}
virtual bool AllocateBuffer(PGLOBAL g);
virtual int GetRowID(void);
virtual bool RecordPos(PGLOBAL g);
virtual bool SetPos(PGLOBAL g, int recpos);
//virtual int GetRowID(void);
//virtual bool RecordPos(PGLOBAL g);
//virtual bool SetPos(PGLOBAL g, int recpos);
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 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 Rewind(void);
protected:
//protected:
//virtual int InitDelete(PGLOBAL g, int fpos, int spos);
// Members
FILE *BStream; // Points to Bin file structure
size_t Recsize; // Length of last read record
size_t Recsize; // Length of last read or next written record
}; // end of class BINFAM
#endif // __FILAMTXT_H
......@@ -1012,7 +1012,7 @@ PBVAL BCUTIL::GetRow(PGLOBAL g)
PBVAL nwr, row = Tp->Row;
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;
else switch (row->Type) {
case TYPE_JOB:
......@@ -1411,28 +1411,30 @@ int TDBBSN::EstimatedLength(void)
/***********************************************************************/
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) {
/*******************************************************************/
/* Table already open replace it at its beginning. */
/* Table already open replace it at its beginning. ??? */
/*******************************************************************/
Fpos = -1;
NextSame = 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);
} // endif Use
/*********************************************************************/
/* Open according to logical input/output mode required. */
/*********************************************************************/
if (TDBDOS::OpenDB(g))
return true;
} // endswitch Jmode
} // endif Use
if (use == USE_OPEN)
return false;
if (Pretty < 0) {
/*******************************************************************/
......@@ -1441,45 +1443,45 @@ bool TDBBSN::OpenDB(PGLOBAL g)
xtrc(1, "JSN OpenDB: tdbp=%p tdb=R%d use=%d mode=%d\n",
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. */
/*********************************************************************/
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);
if (Mode == MODE_INSERT)
Bp->SubSet(true);
else
Bp->MemSave();
To_Line = Txfp->GetBuf();
memset(To_Line, 0, linelen);
Bp->MemSave();
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;
} // endswitch Jmode
Bp->MemSave();
} // endif Mode
if (Xcol)
To_Filter = NULL; // Imcompatible
return false;
} // end of OpenDB
/***********************************************************************/
......@@ -1564,6 +1566,7 @@ int TDBBSN::ReadDB(PGLOBAL g)
/***********************************************************************/
bool TDBBSN::PrepareWriting(PGLOBAL g)
{
if (Pretty >= 0) {
PSZ s;
if (!(Top = Bp->MakeTopTree(g, Row)))
......@@ -1583,7 +1586,10 @@ bool TDBBSN::PrepareWriting(PGLOBAL g)
return false;
} else
return true;
} else
((BINFAM*)Txfp)->Recsize = ((size_t)PlugSubAlloc(Bp->G, NULL, 0)
- (size_t)To_Line);
return false;
} // end of PrepareWriting
/***********************************************************************/
......@@ -2034,6 +2040,7 @@ void BSONCOL::WriteColumn(PGLOBAL g)
else
Cp->AddArrayValue(row, jsp);
break;
case TYPE_JOB:
if (Nodes[Nod - 1].Key)
Cp->SetKeyValue(row, jsp, Nodes[Nod - 1].Key);
......
......@@ -2148,6 +2148,9 @@ bool TDBDOS::OpenDB(PGLOBAL g)
} // endif use
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) {
// Delete all lines. Not handled in MAP or block mode
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