Merge branch '3.0' of https://github.com/taosdata/TDengine into enh/TD-30987-5
This commit is contained in:
commit
2327319c14
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "taoserror.h"
|
||||
#include "tcoding.h"
|
||||
#include "tutil.h"
|
||||
|
||||
struct SBuffer {
|
||||
uint32_t size;
|
||||
|
@ -67,8 +68,7 @@ static FORCE_INLINE int32_t tBufferEnsureCapacity(SBuffer *buffer, uint32_t capa
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPut(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferEnsureCapacity(buffer, buffer->size + size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferEnsureCapacity(buffer, buffer->size + size));
|
||||
memcpy((char *)buffer->data + buffer->size, data, size);
|
||||
buffer->size += size;
|
||||
return 0;
|
||||
|
@ -119,10 +119,8 @@ static FORCE_INLINE int32_t tBufferPutU16v(SBuffer *buffer, uint16_t value) { re
|
|||
static FORCE_INLINE int32_t tBufferPutU32v(SBuffer *buffer, uint32_t value) { return tBufferPutU64v(buffer, value); }
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutU64v(SBuffer *buffer, uint64_t value) {
|
||||
int32_t code;
|
||||
while (value >= 0x80) {
|
||||
code = tBufferPutU8(buffer, (value & 0x7F) | 0x80);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU8(buffer, (value & 0x7F) | 0x80));
|
||||
value >>= 7;
|
||||
}
|
||||
return tBufferPutU8(buffer, value);
|
||||
|
@ -141,8 +139,7 @@ static FORCE_INLINE int32_t tBufferPutI64v(SBuffer *buffer, int64_t value) {
|
|||
}
|
||||
|
||||
static FORCE_INLINE int32_t tBufferPutBinary(SBuffer *buffer, const void *data, uint32_t size) {
|
||||
int32_t code = tBufferPutU32v(buffer, size);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutU32v(buffer, size));
|
||||
return tBufferPut(buffer, data, size);
|
||||
}
|
||||
|
||||
|
@ -324,8 +321,7 @@ static int32_t tBufferGetF32(SBufferReader *reader, float *value) {
|
|||
float f;
|
||||
uint32_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU32(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU32(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
@ -337,8 +333,7 @@ static int32_t tBufferGetF64(SBufferReader *reader, double *value) {
|
|||
double f;
|
||||
uint64_t u;
|
||||
} u;
|
||||
int32_t code = tBufferGetU64(reader, &u.u);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetU64(reader, &u.u));
|
||||
if (value) {
|
||||
*value = u.f;
|
||||
}
|
||||
|
|
|
@ -172,6 +172,8 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define TAOS_UNUSED(expr) (void)(expr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -147,7 +147,6 @@ int32_t tsdbRowKeyCmpr(const STsdbRowKey *key1, const STsdbRowKey *key2);
|
|||
void tsdbRowGetKey(TSDBROW *row, STsdbRowKey *key);
|
||||
void tColRowGetPrimaryKey(SBlockData *pBlock, int32_t irow, SRowKey *key);
|
||||
|
||||
|
||||
// STSDBRowIter
|
||||
int32_t tsdbRowIterOpen(STSDBRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema);
|
||||
void tsdbRowClose(STSDBRowIter *pIter);
|
||||
|
|
|
@ -17,17 +17,24 @@
|
|||
|
||||
// SDelBlock ----------
|
||||
int32_t tTombBlockInit(STombBlock *tombBlock) {
|
||||
int32_t code;
|
||||
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferInit(&tombBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&tombBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tTombBlockDestroy(tombBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferDestroy(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -35,15 +42,14 @@ int32_t tTombBlockDestroy(STombBlock *tombBlock) {
|
|||
int32_t tTombBlockClear(STombBlock *tombBlock) {
|
||||
tombBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
tBufferClear(&tombBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&tombBlock->buffers[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tTombBlockPut(STombBlock *tombBlock, const STombRecord *record) {
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
int32_t code = tBufferPutI64(&tombBlock->buffers[i], record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&tombBlock->buffers[i], record->data[i]));
|
||||
}
|
||||
tombBlock->numOfRecords++;
|
||||
return 0;
|
||||
|
@ -56,8 +62,7 @@ int32_t tTombBlockGet(STombBlock *tombBlock, int32_t idx, STombRecord *record) {
|
|||
|
||||
for (int32_t i = 0; i < TOMB_RECORD_ELEM_NUM; ++i) {
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * idx, &tombBlock->buffers[i]);
|
||||
int32_t code = tBufferGetI64(&br, &record->data[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &record->data[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,27 +79,34 @@ int32_t tTombRecordCompare(const STombRecord *r1, const STombRecord *r2) {
|
|||
|
||||
// STbStatisBlock ----------
|
||||
int32_t tStatisBlockInit(STbStatisBlock *statisBlock) {
|
||||
int32_t code;
|
||||
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferInit(&statisBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&statisBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&statisBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tStatisBlockDestroy(statisBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tStatisBlockDestroy(STbStatisBlock *statisBlock) {
|
||||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferDestroy(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,17 +115,16 @@ int32_t tStatisBlockClear(STbStatisBlock *statisBlock) {
|
|||
statisBlock->numOfPKs = 0;
|
||||
statisBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) {
|
||||
tBufferClear(&statisBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&statisBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&statisBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&statisBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&statisBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
||||
int32_t code;
|
||||
STsdbRowKey key;
|
||||
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
@ -129,14 +140,14 @@ static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) {
|
|||
}
|
||||
}
|
||||
|
||||
if ((code = tBufferPutI64(&block->suids, row->suid))) return code;
|
||||
if ((code = tBufferPutI64(&block->uids, row->uid))) return code;
|
||||
if ((code = tBufferPutI64(&block->firstKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->lastKeyTimestamps, key.key.ts))) return code;
|
||||
if ((code = tBufferPutI64(&block->counts, 1))) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->suids, row->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->uids, row->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->firstKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->lastKeyTimestamps, key.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&block->counts, 1));
|
||||
for (int32_t i = 0; i < block->numOfPKs; ++i) {
|
||||
if ((code = tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i))) return code;
|
||||
if ((code = tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i))) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->firstKeyPKs + i, key.key.pks + i));
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(block->lastKeyPKs + i, key.key.pks + i));
|
||||
}
|
||||
|
||||
block->numOfRecords++;
|
||||
|
@ -147,9 +158,8 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
STbStatisRecord record;
|
||||
STsdbRowKey key;
|
||||
int32_t c;
|
||||
int32_t code;
|
||||
|
||||
tStatisBlockGet(block, block->numOfRecords - 1, &record);
|
||||
TAOS_CHECK_RETURN(tStatisBlockGet(block, block->numOfRecords - 1, &record));
|
||||
tsdbRowGetKey(&row->row, &key);
|
||||
|
||||
c = tRowKeyCompare(&record.lastKey, &key.key);
|
||||
|
@ -157,21 +167,18 @@ static int32_t tStatisBlockUpdate(STbStatisBlock *block, SRowInfo *row) {
|
|||
return 0;
|
||||
} else if (c < 0) {
|
||||
// last ts
|
||||
code = tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts), &key.key.ts,
|
||||
sizeof(key.key.ts));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->lastKeyTimestamps, (block->numOfRecords - 1) * sizeof(record.lastKey.ts),
|
||||
&key.key.ts, sizeof(key.key.ts)));
|
||||
|
||||
// last primary keys
|
||||
for (int i = 0; i < block->numOfPKs; i++) {
|
||||
code = tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnUpdate(&block->lastKeyPKs[i], block->numOfRecords - 1, &key.key.pks[i]));
|
||||
}
|
||||
|
||||
// count
|
||||
record.count++;
|
||||
code = tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count));
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutAt(&block->counts, (block->numOfRecords - 1) * sizeof(record.count), &record.count,
|
||||
sizeof(record.count)));
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -183,8 +190,7 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
if (block->numOfRecords > 0) {
|
||||
int64_t lastUid;
|
||||
SBufferReader br = BUFFER_READER_INITIALIZER(sizeof(int64_t) * (block->numOfRecords - 1), &block->uids);
|
||||
int32_t code = tBufferGetI64(&br, &lastUid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&br, &lastUid));
|
||||
|
||||
if (lastUid == row->uid) {
|
||||
return tStatisBlockUpdate(block, row);
|
||||
|
@ -196,7 +202,6 @@ int32_t tStatisBlockPut(STbStatisBlock *block, SRowInfo *row, int32_t maxRecords
|
|||
}
|
||||
|
||||
int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= statisBlock->numOfRecords) {
|
||||
|
@ -204,36 +209,29 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->suid), &statisBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->uid), &statisBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->firstKey.ts), &statisBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->lastKey.ts), &statisBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(record->count), &statisBlock->counts);
|
||||
code = tBufferGetI64(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.numOfPKs = 0; record->firstKey.numOfPKs < statisBlock->numOfPKs; record->firstKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->firstKeyPKs[record->firstKey.numOfPKs], idx,
|
||||
&record->firstKey.pks[record->firstKey.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.numOfPKs = 0; record->lastKey.numOfPKs < statisBlock->numOfPKs; record->lastKey.numOfPKs++) {
|
||||
code = tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&statisBlock->lastKeyPKs[record->lastKey.numOfPKs], idx,
|
||||
&record->lastKey.pks[record->lastKey.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -241,27 +239,34 @@ int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecor
|
|||
|
||||
// SBrinRecord ----------
|
||||
int32_t tBrinBlockInit(SBrinBlock *brinBlock) {
|
||||
int32_t code;
|
||||
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferInit(&brinBlock->buffers[i]);
|
||||
TAOS_CHECK_GOTO(tBufferInit(&brinBlock->buffers[i]), NULL, _exit);
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnInit(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnInit(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->firstKeyPKs[i]), NULL, _exit);
|
||||
TAOS_CHECK_GOTO(tValueColumnInit(&brinBlock->lastKeyPKs[i]), NULL, _exit);
|
||||
}
|
||||
return 0;
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
TAOS_UNUSED(tBrinBlockDestroy(brinBlock));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockDestroy(SBrinBlock *brinBlock) {
|
||||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferDestroy(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferDestroy(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnDestroy(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnDestroy(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -270,18 +275,16 @@ int32_t tBrinBlockClear(SBrinBlock *brinBlock) {
|
|||
brinBlock->numOfPKs = 0;
|
||||
brinBlock->numOfRecords = 0;
|
||||
for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) {
|
||||
tBufferClear(&brinBlock->buffers[i]);
|
||||
TAOS_UNUSED(tBufferClear(&brinBlock->buffers[i]));
|
||||
}
|
||||
for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) {
|
||||
tValueColumnClear(&brinBlock->firstKeyPKs[i]);
|
||||
tValueColumnClear(&brinBlock->lastKeyPKs[i]);
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i]));
|
||||
TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i]));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
||||
int32_t code;
|
||||
|
||||
ASSERT(record->firstKey.key.numOfPKs == record->lastKey.key.numOfPKs);
|
||||
|
||||
if (brinBlock->numOfRecords == 0) { // the first row
|
||||
|
@ -298,60 +301,29 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
}
|
||||
|
||||
code = tBufferPutI64(&brinBlock->suids, record->suid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->uids, record->uid);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->minVers, record->minVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->maxVers, record->maxVer);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockSizes, record->blockSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->smaSizes, record->smaSize);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->numRows, record->numRow);
|
||||
if (code) return code;
|
||||
|
||||
code = tBufferPutI32(&brinBlock->counts, record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->suids, record->suid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->uids, record->uid));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyTimestamps, record->firstKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->firstKeyVersions, record->firstKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyTimestamps, record->lastKey.key.ts));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->lastKeyVersions, record->lastKey.version));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->minVers, record->minVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->maxVers, record->maxVer));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->blockOffsets, record->blockOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI64(&brinBlock->smaOffsets, record->smaOffset));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockSizes, record->blockSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->blockKeySizes, record->blockKeySize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->smaSizes, record->smaSize));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->numRows, record->numRow));
|
||||
TAOS_CHECK_RETURN(tBufferPutI32(&brinBlock->counts, record->count));
|
||||
|
||||
if (brinBlock->numOfPKs > 0) {
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->firstKeyPKs[i], &record->firstKey.key.pks[i]));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < brinBlock->numOfPKs; ++i) {
|
||||
code = tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnAppend(&brinBlock->lastKeyPKs[i], &record->lastKey.key.pks[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -361,7 +333,6 @@ int32_t tBrinBlockPut(SBrinBlock *brinBlock, const SBrinRecord *record) {
|
|||
}
|
||||
|
||||
int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
||||
int32_t code;
|
||||
SBufferReader reader;
|
||||
|
||||
if (idx < 0 || idx >= brinBlock->numOfRecords) {
|
||||
|
@ -369,78 +340,61 @@ int32_t tBrinBlockGet(SBrinBlock *brinBlock, int32_t idx, SBrinRecord *record) {
|
|||
}
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->suids);
|
||||
code = tBufferGetI64(&reader, &record->suid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->suid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->uids);
|
||||
code = tBufferGetI64(&reader, &record->uid);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->uid));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->firstKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->firstKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->firstKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyTimestamps);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.key.ts);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.key.ts));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->lastKeyVersions);
|
||||
code = tBufferGetI64(&reader, &record->lastKey.version);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->lastKey.version));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->minVers);
|
||||
code = tBufferGetI64(&reader, &record->minVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->minVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->maxVers);
|
||||
code = tBufferGetI64(&reader, &record->maxVer);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->maxVer));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->blockOffsets);
|
||||
code = tBufferGetI64(&reader, &record->blockOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->blockOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int64_t), &brinBlock->smaOffsets);
|
||||
code = tBufferGetI64(&reader, &record->smaOffset);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI64(&reader, &record->smaOffset));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockSizes);
|
||||
code = tBufferGetI32(&reader, &record->blockSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->blockKeySizes);
|
||||
code = tBufferGetI32(&reader, &record->blockKeySize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->blockKeySize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->smaSizes);
|
||||
code = tBufferGetI32(&reader, &record->smaSize);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->smaSize));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->numRows);
|
||||
code = tBufferGetI32(&reader, &record->numRow);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->numRow));
|
||||
|
||||
reader = BUFFER_READER_INITIALIZER(idx * sizeof(int32_t), &brinBlock->counts);
|
||||
code = tBufferGetI32(&reader, &record->count);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tBufferGetI32(&reader, &record->count));
|
||||
|
||||
// primary keys
|
||||
for (record->firstKey.key.numOfPKs = 0; record->firstKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->firstKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->firstKeyPKs[record->firstKey.key.numOfPKs], idx,
|
||||
&record->firstKey.key.pks[record->firstKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
for (record->lastKey.key.numOfPKs = 0; record->lastKey.key.numOfPKs < brinBlock->numOfPKs;
|
||||
record->lastKey.key.numOfPKs++) {
|
||||
code = tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]);
|
||||
if (code) return code;
|
||||
TAOS_CHECK_RETURN(tValueColumnGet(&brinBlock->lastKeyPKs[record->lastKey.key.numOfPKs], idx,
|
||||
&record->lastKey.key.pks[record->lastKey.key.numOfPKs]));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -11,61 +11,216 @@ class TDTestCase(TBase):
|
|||
def init(self, conn, logSql, replicaVar=1):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
self.dbname = "cast_db"
|
||||
self._datetime_epoch = datetime.datetime.fromtimestamp(0)
|
||||
|
||||
def cast_without_from(self):
|
||||
def cast_from_int_to_other(self):
|
||||
# int
|
||||
int_num = 2147483648
|
||||
tdSql.query(f"select cast({int_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num)
|
||||
int_num1 = 2147483647
|
||||
int_num2 = 2147483648
|
||||
tdSql.query(f"select cast({int_num1} as int) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast(2147483647 as int) re;")
|
||||
tdSql.checkData(0, 0, 2147483647)
|
||||
tdSql.query(f"select cast({int_num2} as int) re;")
|
||||
tdSql.checkData(0, 0, -int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num2)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, int_num1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.query(f"select cast({int_num1} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as float) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as float) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as double) re;")
|
||||
tdSql.checkData(0, 0, '2147483648.0')
|
||||
tdSql.query(f"select cast({int_num2} as double) re;")
|
||||
tdSql.checkData(0, 0, "2147483648.0")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as bool) as re;")
|
||||
tdSql.query(f"select cast({int_num2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({int_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num) / 1000))
|
||||
tdSql.query(f"select cast({int_num2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(int_num2) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({int_num} as varchar(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
tdSql.query(f"select cast({int_num} as binary(10)) as re;")
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
sql = f"select cast({int_num} as nchar(10));"
|
||||
tdSql.query(sql)
|
||||
tdSql.checkData(0, 0, int_num)
|
||||
tdSql.query(f"select cast({int_num1} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "21474")
|
||||
|
||||
def cast_from_bigint_to_other(self):
|
||||
# bigint
|
||||
bigint_num = 9223372036854775807
|
||||
bigint_num2 = 9223372036854775808
|
||||
tdSql.query(f"select cast({bigint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 4294967295)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, bigint_num)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, -bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, bigint_num2)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 65535)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, 9.2233720e18)
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
# WARN: datetime overflow dont worry
|
||||
tdSql.query(f"select cast({bigint_num} as timestamp) as re;")
|
||||
# tdSql.checkData(0, 0, "292278994-08-17 15:12:55.807")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as varchar(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
tdSql.query(f"select cast({bigint_num} as nchar(5));")
|
||||
tdSql.checkData(0, 0, "92233")
|
||||
|
||||
def cast_from_smallint_to_other(self):
|
||||
smallint_num = 32767
|
||||
smallint_num2 = 32768
|
||||
tdSql.query(f"select cast({smallint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, smallint_num)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, -smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, smallint_num2)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -1)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 255)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "32767.0")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(smallint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as varchar(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
tdSql.query(f"select cast({smallint_num} as nchar(3));")
|
||||
tdSql.checkData(0, 0, "327")
|
||||
|
||||
def cast_from_tinyint_to_other(self):
|
||||
tinyint_num = 127
|
||||
tinyint_num2 = 128
|
||||
tdSql.query(f"select cast({tinyint_num} as int) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bigint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, -tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, tinyint_num2)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as float) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as double) re;")
|
||||
tdSql.checkData(0, 0, "127.0")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(tinyint_num) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({tinyint_num} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_from_float_to_other(self):
|
||||
# float
|
||||
float_1001 = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019
|
||||
|
||||
|
@ -116,22 +271,31 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast({float_1001} as nchar(5));")
|
||||
tdSql.checkData(0, 0, 3.141)
|
||||
|
||||
def cast_from_str_to_other(self):
|
||||
# str
|
||||
str_410 = "bcdefghigk" * 41
|
||||
big_str = "bcdefghigk" * 6552
|
||||
_str = "bcdefghigk"
|
||||
str_410 = _str * 41
|
||||
str_401 = _str * 40 + "b"
|
||||
big_str = _str * 6552
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as binary(3)) as re;")
|
||||
tdSql.checkData(0, 0, "bcd")
|
||||
tdSql.query(f"select cast('{str_410}' as binary(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "bc")
|
||||
tdSql.query(f"select cast('{str_410}' as varchar(401)) as re;")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "bcdefghigk")
|
||||
tdSql.query(f"select cast('{big_str}' as varchar(420)) as re;")
|
||||
tdSql.checkData(0, 0, _str * 42)
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as nchar(401));")
|
||||
tdSql.checkData(0, 0, str_401)
|
||||
|
||||
tdSql.query(f"select cast('北京' as nchar(10));")
|
||||
tdSql.checkData(0, 0, "北京")
|
||||
|
||||
# tdSql.query(f"select cast('北京涛思数据有限公司' as nchar(6));")
|
||||
# tdSql.checkData(0, 0, "北京涛思数据")
|
||||
|
||||
tdSql.query(f"select cast('{str_410}' as int) as re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
|
||||
|
@ -168,12 +332,229 @@ class TDTestCase(TBase):
|
|||
tdSql.query(f"select cast('{str_410}' as timestamp) as re")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
|
||||
def cast_from_bool_to_other(self):
|
||||
true_val = True
|
||||
false_val = False
|
||||
tdSql.query(f"select cast({false_val} as int) re, cast({true_val} as int) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as int unsigned) re, cast({true_val} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bigint) re, cast({true_val} as bigint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as bigint unsigned) re, cast({true_val} as bigint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as smallint unsigned) re, cast({true_val} as smallint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as tinyint) re, cast({true_val} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(
|
||||
f"select cast({false_val} as tinyint unsigned) re, cast({true_val} as tinyint unsigned) re;"
|
||||
)
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as smallint) re, cast({true_val} as smallint) re;")
|
||||
tdSql.checkData(0, 0, 0)
|
||||
tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as float) re, cast({true_val} as float) re;")
|
||||
tdSql.checkData(0, 0, 0.0000000)
|
||||
tdSql.checkData(0, 1, 1.0000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as double) re, cast({true_val} as double) re;")
|
||||
tdSql.checkData(0, 0, 0.000000000000000)
|
||||
tdSql.checkData(0, 1, 1.000000000000000)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as bool) re, cast({true_val} as bool) re;")
|
||||
tdSql.checkData(0, 0, false_val)
|
||||
tdSql.checkData(0, 1, true_val)
|
||||
|
||||
tdSql.query(f"select cast({false_val} as timestamp) re, cast({true_val} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, "1970-01-01 08:00:00.000")
|
||||
tdSql.checkData(0, 1, "1970-01-01 08:00:00.001")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as varchar(3)) re, cast({true_val} as varchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as binary(3)) re, cast({true_val} as binary(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
tdSql.query(f"select cast({false_val} as nchar(3)) re, cast({true_val} as nchar(3)) re;")
|
||||
tdSql.checkData(0, 0, "fal")
|
||||
tdSql.checkData(0, 1, "tru")
|
||||
|
||||
def cast_from_timestamp_to_other(self):
|
||||
# ts = self._datetime_epoch
|
||||
# tdSql.query(f"select cast({ts} as int) re;")
|
||||
# tdSql.checkData(0, 0, None)
|
||||
# todo
|
||||
pass
|
||||
|
||||
def cast_from_null_to_other(self):
|
||||
tdSql.query(f"select cast(null as int) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as float) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as double) re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as bool) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as varchar(55)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as binary(5)) as re;")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
tdSql.query(f"select cast(null as nchar(5));")
|
||||
tdSql.checkData(0, 0, None)
|
||||
|
||||
def cast_from_compute_to_other(self):
|
||||
add1 = 123
|
||||
add2 = 456
|
||||
re = 579
|
||||
tdSql.query(f"select cast({add1}+{add2} as int) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as int unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bigint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as smallint unsigned) re;")
|
||||
tdSql.checkData(0, 0, re)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as tinyint unsigned) re;")
|
||||
tdSql.checkData(0, 0, 67)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as float) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as double) re;")
|
||||
tdSql.checkData(0, 0, "579.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as bool) as re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as timestamp) as re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(re) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as varchar(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as binary(2)) as re;")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{add2} as nchar(2));")
|
||||
tdSql.checkData(0, 0, "57")
|
||||
|
||||
test_str = "'!@#'"
|
||||
tdSql.query(f"select cast({add1}+{test_str} as int) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bigint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as smallint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as tinyint) re;")
|
||||
tdSql.checkData(0, 0, add1)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as float) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as double) re;")
|
||||
tdSql.checkData(0, 0, "123.0")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as bool) re;")
|
||||
tdSql.checkData(0, 0, True)
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as timestamp) re;")
|
||||
tdSql.checkData(0, 0, self._datetime_epoch + datetime.timedelta(seconds=int(add1) / 1000))
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as varchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as binary(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
tdSql.query(f"select cast({add1}+{test_str} as nchar(2)) re;")
|
||||
tdSql.checkData(0, 0, "12")
|
||||
|
||||
def cast_without_from(self):
|
||||
self.cast_from_int_to_other()
|
||||
self.cast_from_bigint_to_other()
|
||||
self.cast_from_smallint_to_other()
|
||||
self.cast_from_tinyint_to_other()
|
||||
self.cast_from_float_to_other()
|
||||
self.cast_from_str_to_other()
|
||||
self.cast_from_bool_to_other()
|
||||
self.cast_from_timestamp_to_other()
|
||||
self.cast_from_compute_to_other()
|
||||
# self.cast_from_null_to_other()
|
||||
|
||||
def run(self):
|
||||
# self.prepare_data()
|
||||
# self.all_test()
|
||||
# tdSql.execute(f"flush database {self.dbname}")
|
||||
# self.all_test()
|
||||
# 'from table' case see system-test/2-query/cast.py
|
||||
self.cast_without_from()
|
||||
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
|
|
@ -297,7 +297,8 @@ class TDTestCase:
|
|||
'mysql':'MySQL',
|
||||
'postgres':'PostgreSQL',
|
||||
'oracle':'Oracle',
|
||||
'mssql':'SqlServer'
|
||||
'mssql':'SqlServer',
|
||||
'mongodb':'MongoDB',
|
||||
}
|
||||
|
||||
tdSql.execute('drop database if exists db2')
|
||||
|
|
Loading…
Reference in New Issue