提交 472d52a2 编写于 作者: H Hongze Cheng

add more

上级 44a099b5
......@@ -3,7 +3,6 @@
#include <stdint.h>
#include "type.h"
#include "schema.h"
// ----------------- Data row structure
......@@ -63,4 +62,6 @@ typedef char * SDataCols;
#define TD_DATACOLS_LEN(pDataCols) (*(int32_t *)(pDataCols))
#define TD_DATACOLS_NPOINTS(pDataCols) (*(int32_t *)(pDataCols + sizeof(int32_t)))
// ----
#endif // _TD_DATA_FORMAT_H_
......@@ -12,6 +12,7 @@ typedef struct {
td_datatype_t type; // Column type
int32_t colId; // column ID
int32_t bytes; // column bytes
int32_t offset; // point offset in a row data
char * colName; // the column name
} SColumn;
......@@ -40,6 +41,7 @@ typedef char *SISchema;
#define TD_COLUMN_TYPE(pCol) ((pCol)->type) // column type
#define TD_COLUMN_ID(pCol) ((pCol)->colId) // column ID
#define TD_COLUMN_BYTES(pCol) ((pCol)->bytes) // column bytes
#define TD_COLUMN_OFFSET(pCol) ((pCol)->offset) // column bytes
#define TD_COLUMN_NAME(pCol) ((pCol)->colName) // column name
#define TD_COLUMN_INLINE_SIZE(pCol) (sizeof(SColumn) + TD_COLUMN_NAME(pCol) + 1)
......@@ -66,6 +68,6 @@ SISchema tdConvertSchemaToInline(SSchema *pSchema);
int32_t tdGetColumnIdxByName(SSchema *pSchema, char *colName);
int32_t tdGetColumnIdxById(SSchema *pSchema, int32_t colId);
// ---- TODO: operations to change schema
// ---- TODO: operations to modify schema
#endif // _TD_SCHEMA_H_
......@@ -4,19 +4,31 @@
#include <stdint.h>
typedef enum {
TD_DATATYPE_INVLD = 0, // invalid data type
TD_DATATYPE_BOOL,
TD_DATATYPE_TINYINT,
TD_DATATYPE_SMALLINT,
TD_DATATYPE_INT,
TD_DATATYPE_BIGINT,
TD_DATATYPE_FLOAT,
TD_DATATYPE_DOUBLE,
TD_DATATYPE_VARCHAR,
TD_DATATYPE_NCHAR,
TD_DATATYPE_BINARY
TD_DATATYPE_BOOL = 0,
TD_DATATYPE_TINYINT,
TD_DATATYPE_SMALLINT,
TD_DATATYPE_INT,
TD_DATATYPE_BIGINT,
TD_DATATYPE_FLOAT,
TD_DATATYPE_DOUBLE,
TD_DATATYPE_VARCHAR,
TD_DATATYPE_NCHAR,
TD_DATATYPE_BINARY
} td_datatype_t;
const int32_t rowDataLen[] = {
sizeof(int8_t), // TD_DATATYPE_BOOL,
sizeof(int8_t), // TD_DATATYPE_TINYINT,
sizeof(int16_t), // TD_DATATYPE_SMALLINT,
sizeof(int32_t), // TD_DATATYPE_INT,
sizeof(int64_t), // TD_DATATYPE_BIGINT,
sizeof(float), // TD_DATATYPE_FLOAT,
sizeof(double), // TD_DATATYPE_DOUBLE,
sizeof(int32_t), // TD_DATATYPE_VARCHAR,
sizeof(int32_t), // TD_DATATYPE_NCHAR,
sizeof(int32_t) // TD_DATATYPE_BINARY
};
// TODO: finish below
#define TD_DATATYPE_BOOL_NULL
#define TD_DATATYPE_TINYINT_NULL
......@@ -31,4 +43,4 @@ typedef enum {
#define TD_IS_VALID_DATATYPE(type) (((type) > TD_DATA_TYPE_INVLD) && ((type) <= TD_DATATYPE_BINARY))
#endif // _TD_TYPE_H_
#endif // _TD_TYPE_H_
#include <stdlib.h>
#include "dataformat.h"
......@@ -15,6 +15,23 @@ static size_t tdGetEstimatedISchemaLen(SSchema *pSchema) {
return TD_ISCHEMA_HEADER_SIZE + (size_t)TD_SCHEMA_TOTAL_COLS(pSchema) + colNameLen;
}
static void tdUpdateColumnOffsets(SSchema *pSchema) {
int32_t offset = 0;
for (size_t i = 0; i < TD_SCHEMA_NCOLS(pSchema); i++)
{
SColumn *pCol = TD_SCHEMA_COLUMN_AT(pSchema, i);
TD_COLUMN_OFFSET(pCol) = offset;
offset += rowDataLen[TD_COLUMN_TYPE(pCol)];
}
offset = 0;
for (size_t i = 0; i < TD_SCHEMA_NTAGS(pSchema); i++) {
SColumn *pCol = TD_SCHEMA_TAG_AT(pSchema, i);
TD_COLUMN_OFFSET(pCol) = offset;
offset += rowDataLen[TD_COLUMN_TYPE(pCol)];
}
}
SISchema tdConvertSchemaToInline(SSchema *pSchema) {
size_t len = tdGetEstimatedISchemaLen(pSchema);
int32_t totalCols = TD_SCHEMA_TOTAL_COLS(pSchema);
......@@ -61,7 +78,7 @@ int32_t tdGetColumnIdxById(SSchema *pSchema, int32_t colId) {
for (int32_t i = 0; i < TD_SCHEMA_TOTAL_COLS(pSchema); i++) {
SColumn *pCol = TD_SCHEMA_COLUMN_AT(pSchema, i);
if (TD_COLUMN_ID(pCol) == colId) {
return i;
return i;
}
}
return -1;
......
......@@ -4,7 +4,6 @@
#include <stdint.h>
#include "cache.h"
#include "dlist.h"
#define TSDB_DEFAULT_CACHE_BLOCK_SIZE 16*1024*1024 /* 16M */
......
......@@ -5,13 +5,20 @@
typedef int32_t file_id_t;
typedef enum : uint8_t {
TSDB_FILE_TYPE_HEAD,
TSDB_FILE_TYPE_DATA,
TSDB_FILE_TYPE_LAST,
TSDB_FILE_TYPE_META
typedef enum {
TSDB_FILE_TYPE_HEAD, // .head file type
TSDB_FILE_TYPE_DATA, // .data file type
TSDB_FILE_TYPE_LAST, // .last file type
TSDB_FILE_TYPE_META // .meta file type
} TSDB_FILE_TYPE;
const char *tsdbFileSuffix[] = {
".head", // TSDB_FILE_TYPE_HEAD
".data", // TSDB_FILE_TYPE_DATA
".last", // TSDB_FILE_TYPE_LAST
".meta" // TSDB_FILE_TYPE_META
};
typedef struct {
int64_t fileSize;
} SFileInfo;
......@@ -28,9 +35,6 @@ typedef struct {
int16_t numOfBlocks;
} SDataBlock;
tstring_t tdGetHeadFileName(/* TODO */);
tstring_t tdGetDataFileName(/* TODO */);
tstring_t tdGetLastFileName(/* TODO */);
tstring_t tdGetMetaFileName(/* TODO */);
char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type);
#endif // _TD_TSDB_FILE_H_
#include "tsdbFile.h"
char *tsdbGetFileName(char *dirName, char *fname, TSDB_FILE_TYPE type){
char *suffix = tsdbFileSuffix[type];
// TODO
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册