提交 7e0ece01 编写于 作者: H hzcheng

refactor and add more

上级 14bbe488
...@@ -79,14 +79,17 @@ void tdUpdateSchema(STSchema *pSchema); ...@@ -79,14 +79,17 @@ void tdUpdateSchema(STSchema *pSchema);
*/ */
typedef void *SDataRow; typedef void *SDataRow;
#define TD_DATA_ROW_HEAD_SIZE sizeof(int32_t)
#define dataRowLen(r) (*(int32_t *)(r)) #define dataRowLen(r) (*(int32_t *)(r))
#define dataRowTuple(r) ((char *)(r) + sizeof(int32_t)) #define dataRowTuple(r) ((char *)(r) + TD_DATA_ROW_HEAD_SIZE)
#define dataRowSetLen(r, l) (dataRowLen(r) = (l)) #define dataRowSetLen(r, l) (dataRowLen(r) = (l))
#define dataRowIdx(r, i) ((char *)(r) + i) #define dataRowIdx(r, i) ((char *)(r) + i)
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r)) #define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
SDataRow tdNewDataRow(int32_t bytes); SDataRow tdNewDataRow(int32_t bytes);
// SDataRow tdNewDdataFromSchema(SSchema *pSchema); int tdMaxRowBytesFromSchema(STSchema *pSchema);
SDataRow tdNewDataRowFromSchema(STSchema *pSchema);
void tdFreeDataRow(SDataRow row); void tdFreeDataRow(SDataRow row);
// int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset); // int32_t tdAppendColVal(SDataRow row, void *value, SColumn *pCol, int32_t suffixOffset);
void tdDataRowCpy(void *dst, SDataRow row); void tdDataRowCpy(void *dst, SDataRow row);
......
...@@ -178,10 +178,33 @@ SDataRow tdNewDataRow(int32_t bytes) { ...@@ -178,10 +178,33 @@ SDataRow tdNewDataRow(int32_t bytes) {
return row; return row;
} }
// SDataRow tdNewDdataFromSchema(SSchema *pSchema) { /**
// int32_t bytes = tdMaxRowDataBytes(pSchema); * Get maximum bytes a data row from a schema
// return tdNewDataRow(bytes); * ASSUMPTIONS: VALID PARAMETER
// } */
int tdMaxRowBytesFromSchema(STSchema *pSchema) {
// TODO
int bytes = TD_DATA_ROW_HEAD_SIZE;
for (int i = 0; i < schemaNCols(pSchema); i++) {
STColumn *pCol = schemaColAt(pSchema, i);
bytes += TYPE_BYTES[pCol->type];
if (pCol->type == TSDB_DATA_TYPE_BINARY || pCol->type == TSDB_DATA_TYPE_NCHAR) {
bytes += pCol->bytes;
}
}
return bytes;
}
SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
int bytes = 0;
{
// TODO: estimiate size from schema
}
return tdNewDataRow(bytes);
}
/** /**
* Free the SDataRow object * Free the SDataRow object
......
...@@ -26,9 +26,9 @@ const int32_t TYPE_BYTES[11] = { ...@@ -26,9 +26,9 @@ const int32_t TYPE_BYTES[11] = {
sizeof(int64_t), // TSDB_DATA_TYPE_BIGINT sizeof(int64_t), // TSDB_DATA_TYPE_BIGINT
sizeof(float), // TSDB_DATA_TYPE_FLOAT sizeof(float), // TSDB_DATA_TYPE_FLOAT
sizeof(double), // TSDB_DATA_TYPE_DOUBLE sizeof(double), // TSDB_DATA_TYPE_DOUBLE
-1, // TSDB_DATA_TYPE_BINARY sizeof(int32_t), // TSDB_DATA_TYPE_BINARY
sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP sizeof(TSKEY), // TSDB_DATA_TYPE_TIMESTAMP
-1 // TSDB_DATA_TYPE_NCHAR sizeof(int32_t) // TSDB_DATA_TYPE_NCHAR
}; };
tDataTypeDescriptor tDataTypeDesc[11] = { tDataTypeDescriptor tDataTypeDesc[11] = {
......
...@@ -34,5 +34,8 @@ TEST(TsdbTest, createRepo) { ...@@ -34,5 +34,8 @@ TEST(TsdbTest, createRepo) {
tsdbCreateTable(pRepo, &tCfg); tsdbCreateTable(pRepo, &tCfg);
// 3. Loop to write some simple data // 3. Loop to write some simple data
SDataRow row = tdNewDataRowFromSchema(schema);
for (int i = 0; i < nCols; i++) {
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册