TDengine/source/libs/index/test/jsonUT.cc

674 lines
24 KiB
C++
Raw Normal View History

2022-03-02 09:09:22 +00:00
#include <gtest/gtest.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include "index.h"
2022-03-29 15:11:57 +00:00
#include "indexCache.h"
#include "indexFst.h"
#include "indexFstUtil.h"
2022-03-02 09:09:22 +00:00
#include "indexInt.h"
2022-03-29 15:11:57 +00:00
#include "indexTfile.h"
#include "indexUtil.h"
2022-03-02 09:09:22 +00:00
#include "tglobal.h"
#include "tskiplist.h"
#include "tutil.h"
static std::string dir = TD_TMP_DIR_PATH "json";
static std::string logDir = TD_TMP_DIR_PATH "log";
2022-05-14 12:52:46 +00:00
2022-06-05 11:44:44 +00:00
SIndexTerm* indexTermCreateT(int64_t suid, SIndexOperOnColumn oper, uint8_t colType, const char* colName,
int32_t nColName, const char* colVal, int32_t nColVal) {
char buf[256] = {0};
int16_t sz = nColVal;
memcpy(buf, (uint16_t*)&sz, 2);
memcpy(buf + 2, colVal, nColVal);
Feature/3.0 geometry (#21037) * Add GEOMETRY data type and make sql.c able to parse it. The GEMETRY works like BINARY so far. * add GEOMETRY type into gConvertTypes to fix some issues like DELETE calling * change some test cases to make sure no same timestamp is inserted, and add my smoketest.sh * Add a function MakePoint() and introduce a lib geometry * implement sql functions GeomFromText() and AsText() * Use GEOS *_r funcions instead for thread safety * Handle with TSDB_DATA_TYPE_GEOMETRY when INSERT geometry data by converting WKT. Add geosWrapper to wrap the basic GEOS functions for TDEngine. * refactor AsText and MakePoint functions to be like GeomFromText * Show WKT when print geometry data in screen Dump hex data when dump geometry data in a file * define TYPE_BYTES item for TSDB_DATA_TYPE_GEOMETRY, which casued some strange issues. * set number of decimals of WKT to 6 * Implement SQL function Intersects() * refactor geometry sql functions * Add geosErrMsgeHandler() to get the GEOS error detail * use threadlocal to instantiate SGeosContext call destroyGeosContext() only if the thread exists * remove SGeosContext *context param for all geometry functions since we use thread local one, so that all caller do not need to know the context. * Modify Intersects() to call PreparedIntersects() when one of param is a constant, which has higher performance. * rename prepareFn() to initCtxFn() to avoid confusion with PreparedFn * Add prefix "ST_" for all geometry functions * move getThreadLocalGeosCtx() and destroyThreadLocalGeosCtx() into util, so that all unit test tools can compile * Add unit test for geometry lib, only test MakePoint so far * refactor and enhance existing cases in geomFuncTest * implement NULL type and NULL value test for geomFuncTest * add test on geomFromText() * add unit test on AsText() in geomFuncTest * combine some makePointFunction test items * add intersectsFunctionTwoColumns test refactor on callGeomFromTextWrapper functions * enhance intersectsFunction test to add cases like input constant , NULL type, NULL value, or wrong content * add more cases into intersectsFunction test * Add basic test on geometry in system test * Add ST_GeomFromText and ST_AsText function test in system test on geometry * add ST_Intersects function test in system test on geometry * support to check expectedErrno in system test on geometry * adjust geomTest unit test and geometry system test * add geometry data type and functions in doc english version * implement touchesFunction() in geometry lib refactor geometry relation functions model * separate gemFuncTest into several src files * add unit test on touchesFunction * support sql function ST_Touches() add system test on ST_Touches * add docs for ST_Touches() * Add ST_Contains() * Add ST_Covers() * Add ST_Equals() * add swapAllowed param for geomRelationFunction() read geom2 earlier intead of at doGeosRelation() * Add ST_ContainsProperly() * build on windows * Merge from 3.0 to 3.0_geometry * change macro definition TSDB_DATA_TYPE_GEOMETRY as the last one for compatibility * change '\\NULL' to 'NULL' back in shellDumpFieldToFile() * add /usr/local/include into include directory * add /usr/local/inlcude and /usr/local/lib in cmake.platform for DARWIN
2023-05-24 07:36:46 +00:00
if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_GEOMETRY) {
2022-06-05 11:44:44 +00:00
return indexTermCreate(suid, oper, colType, colName, nColName, buf, sizeof(buf));
} else {
return indexTermCreate(suid, oper, colType, colName, nColName, colVal, nColVal);
}
}
2022-05-14 12:52:46 +00:00
static void initLog() {
const char* defaultLogFileNamePrefix = "taoslog";
const int32_t maxLogFileNum = 10;
tsAsyncLog = 0;
2022-05-24 07:17:14 +00:00
idxDebugFlag = 143;
2022-05-14 12:52:46 +00:00
strcpy(tsLogDir, logDir.c_str());
taosRemoveDir(tsLogDir);
taosMkDir(tsLogDir);
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
printf("failed to open log file in directory:%s\n", tsLogDir);
}
}
2022-03-02 09:09:22 +00:00
class JsonEnv : public ::testing::Test {
protected:
virtual void SetUp() {
2022-05-14 12:52:46 +00:00
taosRemoveDir(logDir.c_str());
taosMkDir(logDir.c_str());
2022-03-02 09:09:22 +00:00
taosRemoveDir(dir.c_str());
2022-03-02 14:06:02 +00:00
taosMkDir(dir.c_str());
2022-03-03 04:29:54 +00:00
printf("set up\n");
2022-05-14 12:52:46 +00:00
initLog();
2022-07-14 06:51:39 +00:00
opts = indexOptsCreate(1024 * 1024 * 4);
2022-06-09 05:50:18 +00:00
int ret = indexJsonOpen(opts, dir.c_str(), &index);
2022-03-02 09:09:22 +00:00
assert(ret == 0);
}
virtual void TearDown() {
2022-06-09 05:50:18 +00:00
indexJsonClose(index);
2023-10-26 13:06:08 +00:00
indexOptsDestroy(opts);
2022-03-03 04:29:54 +00:00
printf("destory\n");
2022-06-01 06:30:01 +00:00
taosMsleep(1000);
2022-03-02 09:09:22 +00:00
}
SIndexJsonOpts* opts;
SIndexJson* index;
};
2022-05-16 15:12:02 +00:00
static void WriteData(SIndexJson* index, const std::string& colName, int8_t dtype, void* data, int dlen, int tableId,
int8_t operType = ADD_VALUE) {
2022-06-05 11:44:44 +00:00
SIndexTerm* term = indexTermCreateT(1, (SIndexOperOnColumn)operType, dtype, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)data, dlen);
2022-05-16 15:12:02 +00:00
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, (int64_t)tableId);
2022-05-16 15:12:02 +00:00
indexMultiTermDestroy(terms);
}
2022-05-18 07:32:23 +00:00
static void delData(SIndexJson* index, const std::string& colName, int8_t dtype, void* data, int dlen, int tableId,
int8_t operType = DEL_VALUE) {
2022-06-05 11:44:44 +00:00
SIndexTerm* term = indexTermCreateT(1, (SIndexOperOnColumn)operType, dtype, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)data, dlen);
2022-05-18 07:32:23 +00:00
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, (int64_t)tableId);
2022-05-18 07:32:23 +00:00
indexMultiTermDestroy(terms);
}
2022-05-16 15:12:02 +00:00
static void Search(SIndexJson* index, const std::string& colNam, int8_t dtype, void* data, int dlen, int8_t filterType,
SArray** result) {
std::string colName(colNam);
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, dtype, colName.c_str(), colName.size(), (const char*)data, dlen);
2022-05-16 15:12:02 +00:00
SArray* res = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, (EIndexQueryType)filterType);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, res);
2022-05-16 15:12:02 +00:00
indexMultiTermQueryDestroy(mq);
*result = res;
}
2022-03-02 09:09:22 +00:00
TEST_F(JsonEnv, testWrite) {
{
2022-03-03 04:29:54 +00:00
std::string colName("test");
2022-03-02 09:09:22 +00:00
std::string colVal("ab");
2022-06-07 13:43:30 +00:00
for (int i = 0; i < 100; i++) {
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
colVal.c_str(), colVal.size());
2022-06-07 13:43:30 +00:00
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-02 09:09:22 +00:00
}
}
{
std::string colName("voltage");
std::string colVal("ab1");
2022-06-07 13:43:30 +00:00
for (int i = 0; i < 100; i++) {
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
2022-03-02 09:09:22 +00:00
2022-06-07 13:43:30 +00:00
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-02 09:09:22 +00:00
}
}
{
std::string colName("voltage");
std::string colVal("123");
for (size_t i = 0; i < 100; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-02 09:09:22 +00:00
}
}
{
2022-03-03 04:29:54 +00:00
std::string colName("test");
2022-03-02 09:09:22 +00:00
std::string colVal("ab");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
colVal.c_str(), colVal.size());
2022-03-02 09:09:22 +00:00
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
2022-06-07 13:43:30 +00:00
EXPECT_EQ(100, taosArrayGetSize(result));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
2022-03-02 09:09:22 +00:00
indexMultiTermQueryDestroy(mq);
}
2022-03-02 14:06:02 +00:00
}
TEST_F(JsonEnv, testWriteMillonData) {
2022-03-03 04:29:54 +00:00
{
std::string colName("test");
std::string colVal("ab");
2022-05-19 09:38:11 +00:00
for (size_t i = 0; i < 10; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-03 04:29:54 +00:00
}
}
2022-03-02 14:06:02 +00:00
{
std::string colName("voltagefdadfa");
2022-03-05 03:08:15 +00:00
std::string colVal("abxxxxxxxxxxxx");
2022-09-27 13:32:18 +00:00
for (int i = 0; i < 10000; i++) {
2022-03-05 03:08:15 +00:00
colVal[i % colVal.size()] = '0' + i % 128;
2022-09-27 13:32:18 +00:00
for (size_t i = 0; i < 10; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-05 03:08:15 +00:00
}
}
}
{
std::string colName("voltagefdadfa");
2022-03-02 14:06:02 +00:00
std::string colVal("abxxxxxxxxxxxx");
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-03-02 14:06:02 +00:00
}
}
{
2022-03-03 04:29:54 +00:00
std::string colName("test");
2022-03-02 14:06:02 +00:00
std::string colVal("ab");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
colVal.c_str(), colVal.size());
2022-03-02 14:06:02 +00:00
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
2022-05-19 09:38:11 +00:00
EXPECT_EQ(10, taosArrayGetSize(result));
2022-03-02 14:06:02 +00:00
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
2022-03-02 14:06:02 +00:00
}
{
{
std::string colName("test");
std::string colVal("ab");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
colVal.c_str(), colVal.size());
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
2022-06-08 05:21:07 +00:00
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
{
std::string colName("test");
std::string colVal("ab");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
colVal.c_str(), colVal.size());
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
2022-05-19 09:38:11 +00:00
EXPECT_EQ(10, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
}
}
2022-03-02 09:09:22 +00:00
}
TEST_F(JsonEnv, testWriteJsonNumberData) {
{
std::string colName("test");
2022-05-14 15:40:43 +00:00
// std::string colVal("10");
2022-06-07 13:43:30 +00:00
int val = 10;
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
std::string colName("test2");
2022-05-14 15:40:43 +00:00
int val = 20;
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
2022-05-14 15:40:43 +00:00
std::string colName("test");
int val = 15;
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
std::string colName("test2");
2022-05-14 15:40:43 +00:00
const char* val = "test";
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
(const char*)val, strlen(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
2022-05-14 15:40:43 +00:00
std::string colName("test");
int val = 15;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test");
2022-05-14 15:40:43 +00:00
int val = 15;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test");
2022-05-14 15:40:43 +00:00
int val = 10;
;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(int));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test");
2022-05-14 15:40:43 +00:00
int val = 10;
// std::string colVal("10");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_LESS_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test");
2022-05-14 15:40:43 +00:00
int val = 10;
// std::string colVal("10");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_LESS_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
}
2022-05-16 15:12:02 +00:00
TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT) {
{
std::string colName("test1");
2022-05-14 15:40:43 +00:00
int val = 10;
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
std::string colName("test");
std::string colVal("xxxxxxxxxxxxxxxxxxx");
2022-05-19 09:38:11 +00:00
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
colVal.c_str(), colVal.size());
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
}
}
{
std::string colName("test1");
2022-05-14 15:40:43 +00:00
int val = 10;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_TERM);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test1");
2022-05-14 15:40:43 +00:00
int val = 10;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(int));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test1");
2022-05-15 03:29:59 +00:00
// std::string colVal("10");
int val = 10;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test1");
2022-05-15 03:29:59 +00:00
int val = 10;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
{
std::string colName("test1");
2022-05-15 03:29:59 +00:00
int val = 10;
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_LESS_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(1000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
2022-05-13 15:30:46 +00:00
{
std::string colName("other_column");
2022-05-15 03:29:59 +00:00
int val = 100;
2022-05-14 15:40:43 +00:00
2022-05-13 15:30:46 +00:00
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-05-13 15:30:46 +00:00
}
}
{
std::string colName("test1");
2022-05-15 03:29:59 +00:00
int val = 10;
// std::string colVal("10");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_LESS_THAN);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
EXPECT_EQ(0, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
}
2022-05-15 15:29:13 +00:00
{
std::string colName("test1");
int val = 15;
for (size_t i = 0; i < 1000; i++) {
2022-06-07 13:43:30 +00:00
SIndexTerm* term = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
(const char*)&val, sizeof(val));
SIndexMultiTerm* terms = indexMultiTermCreate();
indexMultiTermAdd(terms, term);
2022-06-09 05:50:18 +00:00
indexJsonPut(index, terms, i + 1000);
2022-06-07 13:43:30 +00:00
indexMultiTermDestroy(terms);
2022-05-15 15:29:13 +00:00
}
}
{
std::string colName("test1");
int val = 8;
// std::string colVal("10");
SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST);
2022-06-05 11:44:44 +00:00
SIndexTerm* q = indexTermCreateT(1, ADD_VALUE, TSDB_DATA_TYPE_INT, colName.c_str(), colName.size(),
2022-07-14 06:51:39 +00:00
(const char*)&val, sizeof(val));
2022-05-15 15:29:13 +00:00
SArray* result = taosArrayInit(1, sizeof(uint64_t));
indexMultiTermQueryAdd(mq, q, QUERY_GREATER_EQUAL);
2022-06-09 05:50:18 +00:00
indexJsonSearch(index, mq, result);
2022-05-15 15:29:13 +00:00
EXPECT_EQ(2000, taosArrayGetSize(result));
indexMultiTermQueryDestroy(mq);
2023-10-26 13:06:08 +00:00
taosArrayDestroy(result);
2022-05-15 15:29:13 +00:00
}
}
2022-05-16 15:12:02 +00:00
TEST_F(JsonEnv, testWriteJsonTfileAndCache_INT2) {
{
int val = 10;
std::string colName("test1");
2022-05-19 09:38:11 +00:00
for (int i = 0; i < 1000; i++) {
2022-05-16 15:12:02 +00:00
val += 1;
WriteData(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), i);
}
}
{
int val = 10;
std::string colName("test2xxx");
std::string colVal("xxxxxxxxxxxxxxx");
2022-05-19 09:38:11 +00:00
for (int i = 0; i < 1000; i++) {
2022-05-16 15:12:02 +00:00
val += 1;
WriteData(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), i);
}
}
{
SArray* res = NULL;
std::string colName("test1");
int val = 9;
Search(index, colName, TSDB_DATA_TYPE_INT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
2022-05-19 09:38:11 +00:00
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-16 15:12:02 +00:00
}
{
SArray* res = NULL;
std::string colName("test2xxx");
std::string colVal("xxxxxxxxxxxxxxx");
Search(index, colName, TSDB_DATA_TYPE_BINARY, (void*)(colVal.c_str()), colVal.size(), QUERY_TERM, &res);
2022-05-19 09:38:11 +00:00
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-16 15:12:02 +00:00
}
}
TEST_F(JsonEnv, testWriteJsonTfileAndCache_FLOAT) {
{
float val = 10.0;
std::string colName("test1");
for (int i = 0; i < 1000; i++) {
WriteData(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), i);
}
}
{
float val = 2.0;
std::string colName("test1");
for (int i = 0; i < 1000; i++) {
WriteData(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), i + 1000);
2022-05-16 15:12:02 +00:00
}
}
{
SArray* res = NULL;
std::string colName("test1");
float val = 1.9;
Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
EXPECT_EQ(2000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-16 15:12:02 +00:00
}
{
SArray* res = NULL;
std::string colName("test1");
float val = 2.1;
Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-16 15:12:02 +00:00
}
{
std::string colName("test1");
SArray* res = NULL;
float val = 2.1;
Search(index, colName, TSDB_DATA_TYPE_FLOAT, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-16 15:12:02 +00:00
}
}
2022-05-18 06:11:23 +00:00
TEST_F(JsonEnv, testWriteJsonTfileAndCache_DOUBLE) {
{
2022-05-18 06:40:14 +00:00
double val = 10.0;
2022-05-18 06:11:23 +00:00
for (int i = 0; i < 1000; i++) {
2022-05-18 06:40:14 +00:00
WriteData(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), i);
2022-05-18 06:11:23 +00:00
}
}
{
2022-05-18 06:40:14 +00:00
double val = 2.0;
2022-05-18 06:11:23 +00:00
for (int i = 0; i < 1000; i++) {
2022-05-18 06:40:14 +00:00
WriteData(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), i + 1000);
2022-05-18 06:11:23 +00:00
}
}
{
SArray* res = NULL;
std::string colName("test1");
double val = 1.9;
2022-05-18 06:40:14 +00:00
Search(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
2022-05-18 06:11:23 +00:00
EXPECT_EQ(2000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-18 06:11:23 +00:00
}
{
2022-05-18 06:40:14 +00:00
SArray* res = NULL;
double val = 2.1;
Search(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
2022-05-18 06:11:23 +00:00
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-18 06:11:23 +00:00
}
{
2022-05-18 06:40:14 +00:00
SArray* res = NULL;
double val = 2.1;
Search(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_GREATER_EQUAL, &res);
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-18 06:40:14 +00:00
}
{
SArray* res = NULL;
double val = 10.0;
Search(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_LESS_EQUAL, &res);
EXPECT_EQ(2000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-18 06:40:14 +00:00
}
{
SArray* res = NULL;
double val = 10.0;
Search(index, "test1", TSDB_DATA_TYPE_DOUBLE, &val, sizeof(val), QUERY_LESS_THAN, &res);
2022-05-18 06:11:23 +00:00
EXPECT_EQ(1000, taosArrayGetSize(res));
2023-10-26 13:06:08 +00:00
taosArrayDestroy(res);
2022-05-18 06:11:23 +00:00
}
}