fix compile problem
This commit is contained in:
parent
4eabc8afe3
commit
8d5508a7a6
|
@ -57,9 +57,9 @@ const static uint8_t BIT2_MAP[4] = {0b11111100, 0b11110011, 0b11001111, 0b001111
|
|||
#define ONE ((uint8_t)1)
|
||||
#define THREE ((uint8_t)3)
|
||||
#define DIV_8(i) ((i) >> 3)
|
||||
#define MOD_8(i) ((i)&7)
|
||||
#define MOD_8(i) ((i) & 7)
|
||||
#define DIV_4(i) ((i) >> 2)
|
||||
#define MOD_4(i) ((i)&3)
|
||||
#define MOD_4(i) ((i) & 3)
|
||||
#define MOD_4_TIME_2(i) (MOD_4(i) << 1)
|
||||
#define BIT1_SIZE(n) (DIV_8((n)-1) + 1)
|
||||
#define BIT2_SIZE(n) (DIV_4((n)-1) + 1)
|
||||
|
@ -174,6 +174,7 @@ typedef struct {
|
|||
} SColDataCompressInfo;
|
||||
|
||||
typedef void *(*xMallocFn)(void *, int32_t);
|
||||
typedef int32_t (*formatGeometryFn)(char *geoStr, int32_t lenght, int32_t buffMaxLen, char **out, int32_t *size);
|
||||
|
||||
void tColDataDestroy(void *ph);
|
||||
void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t cflag);
|
||||
|
@ -192,7 +193,7 @@ int32_t tColDataCompress(SColData *colData, SColDataCompressInfo *info, SBuffer
|
|||
int32_t tColDataDecompress(void *input, SColDataCompressInfo *info, SColData *colData, SBuffer *assist);
|
||||
|
||||
// for stmt bind
|
||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen);
|
||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen, formatGeometryFn fg);
|
||||
int32_t tColDataSortMerge(SArray **arr);
|
||||
|
||||
// for raw block
|
||||
|
@ -379,7 +380,7 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted,
|
|||
SArray *rowArray);
|
||||
|
||||
// stmt2 binding
|
||||
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen);
|
||||
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen, formatGeometryFn fg);
|
||||
|
||||
typedef struct {
|
||||
int32_t columnId;
|
||||
|
|
|
@ -49,7 +49,6 @@ target_link_libraries(
|
|||
PUBLIC os
|
||||
PUBLIC util
|
||||
INTERFACE api
|
||||
PRIVATE geometry
|
||||
)
|
||||
|
||||
if(${BUILD_S3})
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tdataformat.h"
|
||||
#include "geosWrapper.h"
|
||||
#include "tRealloc.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tlog.h"
|
||||
|
@ -3037,36 +3036,7 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t formatGeometry(SColData *pColData, int8_t *buf, int32_t lenght, int32_t buffMaxLen) {
|
||||
int32_t code = 0;
|
||||
unsigned char *output = NULL;
|
||||
size_t size = 0;
|
||||
uint8_t *g = NULL;
|
||||
code = tRealloc(&g, lenght);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
(void)memcpy(g, buf, lenght);
|
||||
code = doGeomFromText(g, &output, &size);
|
||||
tFree(g);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
if (size > buffMaxLen) {
|
||||
code = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, output, size);
|
||||
|
||||
_exit:
|
||||
geosFreeBuffer(output);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen) {
|
||||
int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32_t buffMaxLen, formatGeometryFn fg) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (!(pBind->num == 1 && pBind->is_null && *pBind->is_null)) {
|
||||
|
@ -3076,13 +3046,6 @@ int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32
|
|||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) { // var-length data type
|
||||
if (pColData->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
code = initCtxGeomFromText();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("init geom from text failed, code:%d", code);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < pBind->num; ++i) {
|
||||
if (pBind->is_null && pBind->is_null[i]) {
|
||||
if (pColData->cflag & COL_IS_KEY) {
|
||||
|
@ -3095,8 +3058,16 @@ int32_t tColDataAddValueByBind(SColData *pColData, TAOS_MULTI_BIND *pBind, int32
|
|||
return TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||
} else {
|
||||
if (pColData->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
code = formatGeometry(pColData, (uint8_t *)pBind->buffer + pBind->buffer_length * i, pBind->length[i],
|
||||
buffMaxLen);
|
||||
int32_t size = 0;
|
||||
char *out = NULL;
|
||||
code = fg((char *)pBind->buffer + pBind->buffer_length * i, pBind->length[i], buffMaxLen, &out, &size);
|
||||
if (code) {
|
||||
taosMemoryFree(out);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, out, size);
|
||||
taosMemoryFree(out);
|
||||
} else {
|
||||
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](
|
||||
pColData, (uint8_t *)pBind->buffer + pBind->buffer_length * i, pBind->length[i]);
|
||||
|
@ -3149,7 +3120,7 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen) {
|
||||
int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int32_t buffMaxLen, formatGeometryFn fg) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (!(pBind->num == 1 && pBind->is_null && *pBind->is_null)) {
|
||||
|
@ -3160,13 +3131,6 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3
|
|||
|
||||
if (IS_VAR_DATA_TYPE(pColData->type)) { // var-length data type
|
||||
uint8_t *buf = pBind->buffer;
|
||||
if (pColData->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
code = initCtxGeomFromText();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("init geom from text failed, code:%d", code);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < pBind->num; ++i) {
|
||||
if (pBind->is_null && pBind->is_null[i]) {
|
||||
if (pColData->cflag & COL_IS_KEY) {
|
||||
|
@ -3184,7 +3148,16 @@ int32_t tColDataAddValueByBind2(SColData *pColData, TAOS_STMT2_BIND *pBind, int3
|
|||
return TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||
} else {
|
||||
if (pColData->type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||
code = formatGeometry(pColData, buf, pBind->length[i], buffMaxLen);
|
||||
int32_t size = 0;
|
||||
char *out = NULL;
|
||||
code = fg((char *)buf, pBind->length[i], buffMaxLen, &out, &size);
|
||||
if (code) {
|
||||
taosMemoryFree(out);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, out, size);
|
||||
taosMemoryFree(out);
|
||||
} else {
|
||||
code = tColDataAppendValueImpl[pColData->flag][CV_FLAG_VALUE](pColData, buf, pBind->length[i]);
|
||||
}
|
||||
|
|
|
@ -321,6 +321,39 @@ int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t formatGeometry(char* geoStr, int32_t lenght, int32_t buffMaxLen, char** out, int32_t* size) {
|
||||
int32_t code = 0;
|
||||
unsigned char* output = NULL;
|
||||
char* tmp = NULL;
|
||||
code = initCtxGeomFromText();
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
uError("init geom from text failed, code:%d", code);
|
||||
return code;
|
||||
}
|
||||
|
||||
code = doGeomFromText(geoStr, &output, (size_t*)size);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
if (*size > buffMaxLen) {
|
||||
code = TSDB_CODE_PAR_VALUE_TOO_LONG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
tmp = taosMemoryCalloc(1, *size);
|
||||
if (NULL == tmp) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
memcpy(tmp, output, *size);
|
||||
*out = tmp;
|
||||
|
||||
_exit:
|
||||
geosFreeBuffer(output);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t qBindStmtStbColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen,
|
||||
STSchema** pTSchema, SBindInfo* pBindInfos) {
|
||||
STableDataCxt* pDataBlock = (STableDataCxt*)pBlock;
|
||||
|
@ -425,8 +458,8 @@ int32_t qBindStmtColsValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bind, c
|
|||
pBind = bind + c;
|
||||
}
|
||||
|
||||
code = tColDataAddValueByBind(pCol, pBind,
|
||||
IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1);
|
||||
code = tColDataAddValueByBind(
|
||||
pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1, formatGeometry);
|
||||
if (code) {
|
||||
goto _return;
|
||||
}
|
||||
|
@ -477,8 +510,8 @@ int32_t qBindStmtSingleColValue(void* pBlock, SArray* pCols, TAOS_MULTI_BIND* bi
|
|||
pBind = bind;
|
||||
}
|
||||
|
||||
code = tColDataAddValueByBind(pCol, pBind,
|
||||
IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1);
|
||||
code = tColDataAddValueByBind(
|
||||
pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1, formatGeometry);
|
||||
|
||||
qDebug("stmt col %d bind %d rows data", colIdx, rowNum);
|
||||
|
||||
|
@ -856,8 +889,8 @@ int32_t qBindStmtColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bind,
|
|||
pBind = bind + c;
|
||||
}
|
||||
|
||||
code = tColDataAddValueByBind2(pCol, pBind,
|
||||
IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1);
|
||||
code = tColDataAddValueByBind2(
|
||||
pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1, formatGeometry);
|
||||
if (code) {
|
||||
goto _return;
|
||||
}
|
||||
|
@ -908,8 +941,8 @@ int32_t qBindStmtSingleColValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* b
|
|||
pBind = bind;
|
||||
}
|
||||
|
||||
code = tColDataAddValueByBind2(pCol, pBind,
|
||||
IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1);
|
||||
code = tColDataAddValueByBind2(
|
||||
pCol, pBind, IS_VAR_DATA_TYPE(pColSchema->type) ? pColSchema->bytes - VARSTR_HEADER_SIZE : -1, formatGeometry);
|
||||
|
||||
qDebug("stmt col %d bind %d rows data", colIdx, rowNum);
|
||||
|
||||
|
|
|
@ -15,12 +15,13 @@ void do_query(TAOS* taos, const char* sql) {
|
|||
taos_free_result(result);
|
||||
}
|
||||
|
||||
void execute_test(TAOS* taos, const char* tbname, const char* tag2, const char* col2, const char* case_desc) {
|
||||
void execute_test(TAOS* taos, const char* tbname1, const char* tbname2, const char* tag2, const char* col2,
|
||||
const char* case_desc) {
|
||||
// prepare stmt
|
||||
TAOS_STMT2_OPTION option = {0, true, false, NULL, NULL};
|
||||
TAOS_STMT2* stmt = taos_stmt2_init(taos, &option);
|
||||
const char* sql;
|
||||
if (tbname == "tb4") {
|
||||
if (tbname1 == "tb41") {
|
||||
sql = "insert into db.? using db.stb2 tags(?, ?) values(?,?)";
|
||||
} else {
|
||||
sql = "insert into db.? using db.stb tags(?, ?) values(?,?)";
|
||||
|
@ -35,17 +36,22 @@ void execute_test(TAOS* taos, const char* tbname, const char* tag2, const char*
|
|||
}
|
||||
|
||||
// prepare data
|
||||
int t1_val = 0;
|
||||
int64_t ts = 1591060628000;
|
||||
int32_t length[5] = {sizeof(int), 2, sizeof(int64_t), (int32_t)strlen(tag2), (int32_t)strlen(col2)};
|
||||
TAOS_STMT2_BIND tags[2] = {{TSDB_DATA_TYPE_INT, &t1_val, &length[0], NULL, 1},
|
||||
{TSDB_DATA_TYPE_GEOMETRY, (void*)tag2, &length[3], NULL, 1}};
|
||||
TAOS_STMT2_BIND params[2] = {{TSDB_DATA_TYPE_TIMESTAMP, &ts, &length[2], NULL, 1},
|
||||
{TSDB_DATA_TYPE_GEOMETRY, (void*)col2, &length[4], NULL, 1}};
|
||||
TAOS_STMT2_BIND* tagv[1] = {&tags[0]};
|
||||
TAOS_STMT2_BIND* paramv[1] = {¶ms[0]};
|
||||
int t1_val = 0;
|
||||
int64_t ts = 1591060628000;
|
||||
const char* tbname[2] = {tbname1, tbname2};
|
||||
int32_t length[5] = {sizeof(int), 2, sizeof(int64_t), (int32_t)strlen(tag2), (int32_t)strlen(col2)};
|
||||
TAOS_STMT2_BIND tags[2][2] = {
|
||||
{{TSDB_DATA_TYPE_INT, &t1_val, &length[0], NULL, 2}, {TSDB_DATA_TYPE_GEOMETRY, (void*)tag2, &length[3], NULL, 2}},
|
||||
{{TSDB_DATA_TYPE_INT, &t1_val, &length[0], NULL, 2},
|
||||
{TSDB_DATA_TYPE_GEOMETRY, (void*)tag2, &length[3], NULL, 2}}};
|
||||
TAOS_STMT2_BIND params[2][2] = {{{TSDB_DATA_TYPE_TIMESTAMP, &ts, &length[2], NULL, 1},
|
||||
{TSDB_DATA_TYPE_GEOMETRY, (void*)col2, &length[4], NULL, 1}},
|
||||
{{TSDB_DATA_TYPE_TIMESTAMP, &ts, &length[2], NULL, 1},
|
||||
{TSDB_DATA_TYPE_GEOMETRY, (void*)col2, &length[4], NULL, 1}}};
|
||||
TAOS_STMT2_BIND* tagv[2] = {&tags[0][0], &tags[1][0]};
|
||||
TAOS_STMT2_BIND* paramv[2] = {¶ms[0][0], ¶ms[1][0]};
|
||||
|
||||
TAOS_STMT2_BINDV bindv = {1, &tbname, &tagv[0], ¶mv[0]};
|
||||
TAOS_STMT2_BINDV bindv = {2, &tbname[0], &tagv[0], ¶mv[0]};
|
||||
code = taos_stmt2_bind_param(stmt, &bindv, -1);
|
||||
if (code != 0) {
|
||||
printf(" failed to bind param. error:%s\n", taos_stmt2_error(stmt));
|
||||
|
@ -64,17 +70,19 @@ void execute_test(TAOS* taos, const char* tbname, const char* tag2, const char*
|
|||
}
|
||||
|
||||
void test1(TAOS* taos) {
|
||||
execute_test(taos, "tb1", "POINT(1.0 1.0)", "LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "[normal]case 1");
|
||||
execute_test(taos, "tb11", "tb12", "POINT(1.0 1.0)", "LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "[normal]case 1");
|
||||
}
|
||||
|
||||
void test2(TAOS* taos) {
|
||||
execute_test(taos, "tb2", "hello", "LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "[wrong tag]case 2");
|
||||
execute_test(taos, "tb21", "tb22", "hello", "LINESTRING(1.0 1.0, 2.0 2.0, 3.0 3.0)", "[wrong tag]case 2");
|
||||
}
|
||||
|
||||
void test3(TAOS* taos) { execute_test(taos, "tb3", "POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))", "1", "[wrong col]case 3"); }
|
||||
void test3(TAOS* taos) {
|
||||
execute_test(taos, "tb31", "tb32", "POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))", "1", "[wrong col]case 3");
|
||||
}
|
||||
|
||||
void test4(TAOS* taos) {
|
||||
execute_test(taos, "tb4", "POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))", "POINT(1.0 1.0)", "[wrong size]case 4");
|
||||
execute_test(taos, "tb41", "tb42", "POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))", "POINT(1.0 1.0)", "[wrong size]case 4");
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
|
Loading…
Reference in New Issue