add more code
This commit is contained in:
parent
7d66dbc412
commit
d0e32fbdea
|
@ -12,7 +12,7 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if !defined(_TD_DATA_FORMAT_H_)
|
||||
#ifndef _TD_DATA_FORMAT_H_
|
||||
#define _TD_DATA_FORMAT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
@ -24,14 +24,26 @@ extern "C" {
|
|||
#endif
|
||||
// ----------------- Data row structure
|
||||
|
||||
/* A data row, the format of it is like below:
|
||||
/* A data row, the format is like below:
|
||||
* +---------+---------------------------------+
|
||||
* | int32_t | |
|
||||
* +---------+---------------------------------+
|
||||
* | len | data |
|
||||
* | len | row |
|
||||
* +---------+---------------------------------+
|
||||
* len: the length including sizeof(row) + sizeof(len)
|
||||
* row: actual row data encoding
|
||||
*/
|
||||
typedef char* SDataRow;
|
||||
typedef void *SDataRow;
|
||||
|
||||
#define dataRowLen(r) (*(int32_t *)(r))
|
||||
#define dataRowTuple(r) ((char *)(r) + sizeof(int32_t))
|
||||
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
|
||||
#define dataRowIdx(r, i) ((char *)(r) + i)
|
||||
|
||||
SDataRow tdNewDataRow(int32_t bytes);
|
||||
SDataRow tdNewDdataFromSchema(SSchema *pSchema);
|
||||
void tdFreeDataRow(SDataRow row);
|
||||
int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset);
|
||||
|
||||
/* Data rows definition, the format of it is like below:
|
||||
* +---------+---------+-----------------------+--------+-----------------------+
|
||||
|
@ -40,7 +52,7 @@ typedef char* SDataRow;
|
|||
* | len | nrows | SDataRow | .... | SDataRow |
|
||||
* +---------+---------+-----------------------+--------+-----------------------+
|
||||
*/
|
||||
typedef char * SDataRows;
|
||||
typedef void *SDataRows;
|
||||
|
||||
/* Data column definition
|
||||
* +---------+---------+-----------------------+
|
||||
|
@ -49,7 +61,7 @@ typedef char * SDataRows;
|
|||
* | len | npoints | data |
|
||||
* +---------+---------+-----------------------+
|
||||
*/
|
||||
typedef char * SDataCol;
|
||||
typedef char *SDataCol;
|
||||
|
||||
/* Data columns definition
|
||||
* +---------+---------+-----------------------+--------+-----------------------+
|
||||
|
@ -58,24 +70,24 @@ typedef char * SDataCol;
|
|||
* | len | npoints | SDataCol | .... | SDataCol |
|
||||
* +---------+---------+-----------------------+--------+-----------------------+
|
||||
*/
|
||||
typedef char * SDataCols;
|
||||
typedef char *SDataCols;
|
||||
|
||||
typedef struct {
|
||||
int32_t rowCounter;
|
||||
int32_t totalRows;
|
||||
SDataRow row;
|
||||
int32_t rowCounter;
|
||||
int32_t totalRows;
|
||||
SDataRow row;
|
||||
} SDataRowsIter;
|
||||
|
||||
// ----------------- Data column structure
|
||||
|
||||
// ---- operation on SDataRow;
|
||||
#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t)
|
||||
#define TD_DATA_ROW_HEADER_SIZE sizeof(int32_t)
|
||||
#define TD_DATAROW_LEN(pDataRow) (*(int32_t *)(pDataRow))
|
||||
#define TD_DATAROW_DATA(pDataRow) ((pDataRow) + sizeof(int32_t))
|
||||
|
||||
SDataRow tdSDataRowDup(SDataRow rdata);
|
||||
void tdSDataRowCpy(SDataRow src, void *dst);
|
||||
void tdFreeSDataRow(SDataRow rdata);
|
||||
void tdSDataRowCpy(SDataRow src, void *dst);
|
||||
void tdFreeSDataRow(SDataRow rdata);
|
||||
|
||||
// ---- operation on SDataRows
|
||||
#define TD_DATAROWS_LEN(pDataRows) (*(int32_t *)(pDataRows))
|
||||
|
@ -91,18 +103,12 @@ void tdFreeSDataRow(SDataRow rdata);
|
|||
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))
|
||||
|
||||
// ---- operation on SDataRowIter
|
||||
int32_t tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
|
||||
void tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
|
||||
int32_t tdRdataIterEnd(SDataRowsIter *pIter);
|
||||
void tdRdataIterNext(SDataRowsIter *pIter);
|
||||
|
||||
// ----
|
||||
/**
|
||||
* Get the maximum
|
||||
*/
|
||||
int32_t tdGetMaxDataRowSize(SSchema *pSchema);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TD_DATA_FORMAT_H_
|
||||
#endif // _TD_DATA_FORMAT_H_
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
#if !defined(_TD_KEY_H_)
|
||||
#define _TD_KEY_H_
|
||||
|
||||
typedef struct {
|
||||
|
||||
} key;
|
||||
|
||||
|
||||
|
||||
#endif // _TD_KEY_H_
|
|
@ -1,20 +0,0 @@
|
|||
#if !defined(_TD_LIST_H_)
|
||||
#define _TD_LIST_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum { TD_LIST_ORDERED, TD_LIST_UNORDERED } TLIST_TYPE;
|
||||
|
||||
typedef int32_t (* comparefn(void *key1, void *key2));
|
||||
|
||||
struct _list_type {
|
||||
TLIST_TYPE type;
|
||||
};
|
||||
|
||||
typedef struct _list_node {
|
||||
} SListNode;
|
||||
|
||||
typedef struct _list {
|
||||
} SList;
|
||||
|
||||
#endif // _TD_LIST_H_
|
|
@ -2,7 +2,82 @@
|
|||
|
||||
#include "dataformat.h"
|
||||
|
||||
int32_t tdGetMaxDataRowSize(SSchema *pSchema) {
|
||||
static int32_t tdGetMaxDataRowSize(SSchema *pSchema);
|
||||
|
||||
/**
|
||||
* Create a data row with maximum row length bytes.
|
||||
*
|
||||
* NOTE: THE AAPLICATION SHOULD MAKE SURE BYTES IS LARGE ENOUGH TO
|
||||
* HOLD THE WHOE ROW.
|
||||
*
|
||||
* @param bytes max bytes a row can take
|
||||
* @return SDataRow object for success
|
||||
* NULL for failure
|
||||
*/
|
||||
SDataRow tdNewDataRow(int32_t bytes) {
|
||||
int32_t size = sizeof(int32_t) + bytes;
|
||||
|
||||
SDataRow row = malloc(size);
|
||||
if (row == NULL) return NULL;
|
||||
|
||||
dataRowSetLen(row, sizeof(int32_t));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
SDataRow tdNewDdataFromSchema(SSchema *pSchema) {
|
||||
int32_t bytes = tdGetMaxDataRowSize(pSchema);
|
||||
return tdNewDataRow(bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the SDataRow object
|
||||
*/
|
||||
void tdFreeDataRow(SDataRow row) {
|
||||
if (row) free(row);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a column value to a SDataRow object.
|
||||
* NOTE: THE APPLICATION SHOULD MAKE SURE VALID PARAMETERS. THE FUNCTION ASSUMES
|
||||
* THE ROW OBJECT HAS ENOUGH SPACE TO HOLD THE VALUE.
|
||||
*
|
||||
* @param row the row to append value to
|
||||
* @param value value pointer to append
|
||||
* @param pSchema schema
|
||||
* @param colIdx column index
|
||||
*
|
||||
* @return 0 for success and -1 for failure
|
||||
*/
|
||||
int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset) {
|
||||
int32_t offset;
|
||||
|
||||
switch (pCol->type) {
|
||||
case TD_DATATYPE_BOOL:
|
||||
case TD_DATATYPE_TINYINT:
|
||||
case TD_DATATYPE_SMALLINT:
|
||||
case TD_DATATYPE_INT:
|
||||
case TD_DATATYPE_BIGINT:
|
||||
case TD_DATATYPE_FLOAT:
|
||||
case TD_DATATYPE_DOUBLE:
|
||||
memcpy(dataRowIdx(row, pCol->offset + sizeof(int32_t)), value, rowDataLen[pCol->type]);
|
||||
if (dataRowLen(row) > suffixOffset + sizeof(int32_t))
|
||||
dataRowSetLen(row, dataRowLen(row) + rowDataLen[pCol->type]);
|
||||
break;
|
||||
case TD_DATATYPE_VARCHAR:
|
||||
offset = dataRowLen(row) > suffixOffset ? dataRowLen(row) : suffixOffset;
|
||||
memcpy(dataRowIdx(row, pCol->offset+sizeof(int32_t)), (void *)(&offset), sizeof(offset));
|
||||
case TD_DATATYPE_NCHAR:
|
||||
case TD_DATATYPE_BINARY:
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tdGetMaxDataRowSize(SSchema *pSchema) {
|
||||
int32_t nbytes = 0;
|
||||
|
||||
for (int32_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++) {
|
||||
|
@ -37,7 +112,7 @@ void tdFreeSDataRow(SDataRow rdata) {
|
|||
free(rdata);
|
||||
}
|
||||
|
||||
int32_t tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter) {
|
||||
void tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter) {
|
||||
pIter->totalRows = TD_DATAROWS_ROWS(rows);
|
||||
pIter->rowCounter = 1;
|
||||
pIter->row = TD_DATAROWS_DATA(rows);
|
||||
|
@ -48,10 +123,7 @@ void tdRdataIterNext(SDataRowsIter *pIter) {
|
|||
pIter->row = pIter->row + TD_DATAROW_LEN(pIter->row);
|
||||
}
|
||||
|
||||
int32_t tdRdataIterEnd(SDataRowsIter *pIter) {
|
||||
return pIter->rowCounter >= pIter->totalRows;
|
||||
|
||||
}
|
||||
int32_t tdRdataIterEnd(SDataRowsIter *pIter) { return pIter->rowCounter >= pIter->totalRows; }
|
||||
|
||||
/**
|
||||
* Copy it
|
||||
|
|
Loading…
Reference in New Issue