From ebcb9be39fcf2a29d1e3866015187a49d0f638bc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 22 Dec 2021 12:20:59 +0800 Subject: [PATCH] update tindex write --- source/libs/index/src/index_fst.c | 2 +- source/libs/index/src/index_tfile.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 3106c1116e..18514cd0d5 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -757,7 +757,7 @@ bool fstBuilderInsert(FstBuilder* b, FstSlice bs, Output in) { fstBuilderInsertOutput(b, bs, in); return true; } - indexInfo("key must be ordered"); + indexInfo("fst write key must be ordered"); return false; } diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index 79d4432180..fb1974a04c 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -65,6 +65,21 @@ static FORCE_INLINE int tfileWriteHeader(TFileWriter* writer) { writer->offset = offset; return 0; } +static int tfileWriteData(TFileWriter* write, TFileValue* tval) { + TFileHeader* header = &write->header; + uint8_t colType = header->colType; + if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { + FstSlice key = fstSliceCreate((uint8_t*)(tval->colVal), (size_t)strlen(tval->colVal)); + if (fstBuilderInsert(write->fb, key, tval->offset)) { + fstSliceDestroy(&key); + return 0; + } + fstSliceDestroy(&key); + return -1; + } else { + // handle other type later + } +} static FORCE_INLINE int tfileReadLoadHeader(TFileReader* reader) { // TODO simple tfile header later char buf[TFILE_HADER_PRE_SIZE]; @@ -305,6 +320,16 @@ int TFileWriterPut(TFileWriter* tw, void* data) { tw->ctx->write(tw->ctx, buf, offset); } + // write fst + for (size_t i = 0; i < sz; i++) { + // TODO, fst batch write later + TFileValue* v = taosArrayGetP((SArray*)data, i); + if (tfileWriteData(tw, v) == 0) { + // + // + } + } + tfree(buf); return 0; }