refactor:add schemaless function
This commit is contained in:
parent
990205d684
commit
a4629e56ce
|
@ -246,7 +246,13 @@ typedef struct {
|
|||
int32_t keyLen;
|
||||
uint8_t type;
|
||||
int16_t length;
|
||||
union{
|
||||
const char* value;
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
double d;
|
||||
float f;
|
||||
};
|
||||
int32_t valueLen;
|
||||
} SSmlKv;
|
||||
|
||||
|
|
|
@ -186,14 +186,14 @@ typedef struct {
|
|||
#define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t)))
|
||||
#define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP))
|
||||
|
||||
#define IS_VALID_TINYINT(_t) ((_t) > INT8_MIN && (_t) <= INT8_MAX)
|
||||
#define IS_VALID_SMALLINT(_t) ((_t) > INT16_MIN && (_t) <= INT16_MAX)
|
||||
#define IS_VALID_INT(_t) ((_t) > INT32_MIN && (_t) <= INT32_MAX)
|
||||
#define IS_VALID_BIGINT(_t) ((_t) > INT64_MIN && (_t) <= INT64_MAX)
|
||||
#define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) < UINT8_MAX)
|
||||
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) < UINT16_MAX)
|
||||
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) < UINT32_MAX)
|
||||
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) < UINT64_MAX)
|
||||
#define IS_VALID_TINYINT(_t) ((_t) >= INT8_MIN && (_t) <= INT8_MAX)
|
||||
#define IS_VALID_SMALLINT(_t) ((_t) >= INT16_MIN && (_t) <= INT16_MAX)
|
||||
#define IS_VALID_INT(_t) ((_t) >= INT32_MIN && (_t) <= INT32_MAX)
|
||||
#define IS_VALID_BIGINT(_t) ((_t) >= INT64_MIN && (_t) <= INT64_MAX)
|
||||
#define IS_VALID_UTINYINT(_t) ((_t) >= 0 && (_t) <= UINT8_MAX)
|
||||
#define IS_VALID_USMALLINT(_t) ((_t) >= 0 && (_t) <= UINT16_MAX)
|
||||
#define IS_VALID_UINT(_t) ((_t) >= 0 && (_t) <= UINT32_MAX)
|
||||
#define IS_VALID_UBIGINT(_t) ((_t) >= 0 && (_t) <= UINT64_MAX)
|
||||
#define IS_VALID_FLOAT(_t) ((_t) >= -FLT_MAX && (_t) <= FLT_MAX)
|
||||
#define IS_VALID_DOUBLE(_t) ((_t) >= -DBL_MAX && (_t) <= DBL_MAX)
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ typedef struct {
|
|||
int32_t measureTagsLen;
|
||||
int32_t tagsLen;
|
||||
int32_t colsLen;
|
||||
int32_t timestampLen;
|
||||
} TAOS_PARSE_ELEMENTS;
|
||||
|
||||
typedef struct {
|
||||
|
@ -45,7 +46,9 @@ typedef struct {
|
|||
uint64_t uid;
|
||||
|
||||
SArray *tags;
|
||||
SArray *cols;
|
||||
SArray *cols; // elements are SHashObj<key, SSmlKv*> for find by key quickly
|
||||
|
||||
SArray colsColumn; // elements are cols key string
|
||||
} TAOS_SML_DATA_POINT_TAGS;
|
||||
|
||||
typedef struct SSmlSTableMeta {
|
||||
|
@ -56,6 +59,11 @@ typedef struct SSmlSTableMeta {
|
|||
SHashObj *fieldHash;
|
||||
} SSmlSTableMeta;
|
||||
|
||||
typedef struct SMsgBuf {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
} SMsgBuf;
|
||||
|
||||
typedef struct {
|
||||
uint64_t id;
|
||||
|
||||
|
@ -76,8 +84,7 @@ typedef struct {
|
|||
SQuery *pQuery;
|
||||
|
||||
int32_t affectedRows;
|
||||
char *msgBuf;
|
||||
int16_t msgLen;
|
||||
SMsgBuf msgBuf;
|
||||
} SSmlLinesInfo;
|
||||
|
||||
int smlInsert(TAOS* taos, SSmlLinesInfo* info);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1539,7 +1539,7 @@ static int32_t smlBoundColumns(SArray *cols, SParsedDataColInfo* pColList, SSche
|
|||
col_id_t lastColIdx = -1; // last column found
|
||||
for (int i = 0; i < taosArrayGetSize(cols); ++i) {
|
||||
SSmlKv *kv = taosArrayGetP(cols, i);
|
||||
SToken sToken = {.n=kv->keyLen, .z=kv->key};
|
||||
SToken sToken = {.n=kv->keyLen, .z=(char*)kv->key};
|
||||
col_id_t t = lastColIdx + 1;
|
||||
col_id_t index = findCol(&sToken, t, nCols, pSchema);
|
||||
if (index < 0 && t > 0) {
|
||||
|
@ -1596,18 +1596,17 @@ static int32_t smlBoundColumns(SArray *cols, SParsedDataColInfo* pColList, SSche
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t smlParseTags(SArray *cols, SKVRowBuilder *tagsBuilder, SParsedDataColInfo* tags, SSchema* pSchema, SVCreateTbReq *createTblReq) {
|
||||
static int32_t smlParseTags(SArray *cols, SKVRowBuilder *tagsBuilder, SParsedDataColInfo* tags, SSchema* pSchema, SVCreateTbReq *createTblReq, SMsgBuf *msg) {
|
||||
if (tdInitKVRowBuilder(tagsBuilder) < 0) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SKvParam param = {.builder = tagsBuilder};
|
||||
for (int i = 0; i < tags->numOfBound; ++i) {
|
||||
|
||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i] - 1]; // colId starts with 1
|
||||
param.schema = pTagSchema;
|
||||
SSmlKv *kv = taosArrayGetP(cols, i);
|
||||
KvRowAppend(NULL, kv->value, kv->valueLen, ¶m) ;
|
||||
KvRowAppend(msg, kv->value, kv->valueLen, ¶m) ;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1630,18 +1629,33 @@ int32_t smlBind(void *handle, SArray *tags, SArray *cols, STableMeta *pTableMeta
|
|||
|
||||
SmlExecHandle *smlHandle = (SmlExecHandle *)handle;
|
||||
SSchema* pTagsSchema = getTableTagSchema(pTableMeta);
|
||||
smlBoundColumns(tags, &smlHandle->tags, pTagsSchema);
|
||||
smlParseTags(tags, &smlHandle->tagsBuilder, &smlHandle->tags, pTagsSchema, &smlHandle->createTblReq);
|
||||
setBoundColumnInfo(&smlHandle->tags, pTagsSchema, getNumOfTags(pTableMeta));
|
||||
int ret = smlBoundColumns(tags, &smlHandle->tags, pTagsSchema);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
buildInvalidOperationMsg(&pBuf, "bound tags error");
|
||||
return ret;
|
||||
}
|
||||
ret = smlParseTags(tags, &smlHandle->tagsBuilder, &smlHandle->tags, pTagsSchema, &smlHandle->createTblReq, &pBuf);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
return ret;
|
||||
}
|
||||
|
||||
STableDataBlocks* pDataBlock = NULL;
|
||||
getDataBlockFromList(smlHandle->pBlockHash, pTableMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||
ret = getDataBlockFromList(smlHandle->pBlockHash, pTableMeta->uid, TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||
sizeof(SSubmitBlk), getTableInfo(pTableMeta).rowSize, pTableMeta,
|
||||
&pDataBlock, NULL, &smlHandle->createTblReq);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
buildInvalidOperationMsg(&pBuf, "create data block error");
|
||||
return ret;
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTableColumnSchema(pTableMeta);
|
||||
|
||||
smlBoundColumns(taosArrayGetP(cols, 0), &pDataBlock->boundColumnInfo, pSchema);
|
||||
|
||||
ret = smlBoundColumns(taosArrayGetP(cols, 0), &pDataBlock->boundColumnInfo, pSchema);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
buildInvalidOperationMsg(&pBuf, "bound cols error");
|
||||
return ret;
|
||||
}
|
||||
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
SRowBuilder* pBuilder = &pDataBlock->rowBuilder;
|
||||
|
@ -1649,8 +1663,11 @@ int32_t smlBind(void *handle, SArray *tags, SArray *cols, STableMeta *pTableMeta
|
|||
|
||||
initRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo);
|
||||
|
||||
allocateMemForSize(pDataBlock, extendedRowSize * rowNum);
|
||||
|
||||
ret = allocateMemForSize(pDataBlock, extendedRowSize * rowNum);
|
||||
if(ret != TSDB_CODE_SUCCESS){
|
||||
buildInvalidOperationMsg(&pBuf, "allocate memory error");
|
||||
return ret;
|
||||
}
|
||||
for (int32_t r = 0; r < rowNum; ++r) {
|
||||
STSRow* row = (STSRow*)(pDataBlock->pData + pDataBlock->size); // skip the SSubmitBlk header
|
||||
tdSRowResetBuf(pBuilder, row);
|
||||
|
|
Loading…
Reference in New Issue