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
|
* 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/>.
|
* 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_
|
#define _TD_DATA_FORMAT_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -24,14 +24,26 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
// ----------------- Data row structure
|
// ----------------- Data row structure
|
||||||
|
|
||||||
/* A data row, the format of it is like below:
|
/* A data row, the format is like below:
|
||||||
* +---------+---------------------------------+
|
* +---------+---------------------------------+
|
||||||
* | int32_t | |
|
* | 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:
|
/* Data rows definition, the format of it is like below:
|
||||||
* +---------+---------+-----------------------+--------+-----------------------+
|
* +---------+---------+-----------------------+--------+-----------------------+
|
||||||
|
@ -40,7 +52,7 @@ typedef char* SDataRow;
|
||||||
* | len | nrows | SDataRow | .... | SDataRow |
|
* | len | nrows | SDataRow | .... | SDataRow |
|
||||||
* +---------+---------+-----------------------+--------+-----------------------+
|
* +---------+---------+-----------------------+--------+-----------------------+
|
||||||
*/
|
*/
|
||||||
typedef char * SDataRows;
|
typedef void *SDataRows;
|
||||||
|
|
||||||
/* Data column definition
|
/* Data column definition
|
||||||
* +---------+---------+-----------------------+
|
* +---------+---------+-----------------------+
|
||||||
|
@ -91,16 +103,10 @@ void tdFreeSDataRow(SDataRow rdata);
|
||||||
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))
|
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))
|
||||||
|
|
||||||
// ---- operation on SDataRowIter
|
// ---- operation on SDataRowIter
|
||||||
int32_t tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
|
void tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter);
|
||||||
int32_t tdRdataIterEnd(SDataRowsIter *pIter);
|
int32_t tdRdataIterEnd(SDataRowsIter *pIter);
|
||||||
void tdRdataIterNext(SDataRowsIter *pIter);
|
void tdRdataIterNext(SDataRowsIter *pIter);
|
||||||
|
|
||||||
// ----
|
|
||||||
/**
|
|
||||||
* Get the maximum
|
|
||||||
*/
|
|
||||||
int32_t tdGetMaxDataRowSize(SSchema *pSchema);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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"
|
#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;
|
int32_t nbytes = 0;
|
||||||
|
|
||||||
for (int32_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++) {
|
for (int32_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++) {
|
||||||
|
@ -37,7 +112,7 @@ void tdFreeSDataRow(SDataRow rdata) {
|
||||||
free(rdata);
|
free(rdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter) {
|
void tdInitSDataRowsIter(SDataRows rows, SDataRowsIter *pIter) {
|
||||||
pIter->totalRows = TD_DATAROWS_ROWS(rows);
|
pIter->totalRows = TD_DATAROWS_ROWS(rows);
|
||||||
pIter->rowCounter = 1;
|
pIter->rowCounter = 1;
|
||||||
pIter->row = TD_DATAROWS_DATA(rows);
|
pIter->row = TD_DATAROWS_DATA(rows);
|
||||||
|
@ -48,10 +123,7 @@ void tdRdataIterNext(SDataRowsIter *pIter) {
|
||||||
pIter->row = pIter->row + TD_DATAROW_LEN(pIter->row);
|
pIter->row = pIter->row + TD_DATAROW_LEN(pIter->row);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tdRdataIterEnd(SDataRowsIter *pIter) {
|
int32_t tdRdataIterEnd(SDataRowsIter *pIter) { return pIter->rowCounter >= pIter->totalRows; }
|
||||||
return pIter->rowCounter >= pIter->totalRows;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy it
|
* Copy it
|
||||||
|
|
Loading…
Reference in New Issue