未验证 提交 b7db509f 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #10667 from taosdata/fix/TS-207-V24

[TS-207]<fix>(query): compare nchar and binary with strcmp
...@@ -810,7 +810,7 @@ SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup) { ...@@ -810,7 +810,7 @@ SSDataBlock* doMultiwayMergeSort(void* param, bool* newgroup) {
pOneDataSrc->rowIdx, pIndex->colIndex); pOneDataSrc->rowIdx, pIndex->colIndex);
char *data = pInfo->prevRow[i]; char *data = pInfo->prevRow[i];
int32_t ret = columnValueAscendingComparator(data, newRow, pColInfo->info.type, pColInfo->info.bytes); int32_t ret = columnValueAscendingComparator(data, newRow, pColInfo->info.type, pColInfo->info.bytes, true);
if (ret == 0) { if (ret == 0) {
continue; continue;
} else { } else {
...@@ -872,7 +872,7 @@ static bool isSameGroup(SArray* orderColumnList, SSDataBlock* pBlock, char** dat ...@@ -872,7 +872,7 @@ static bool isSameGroup(SArray* orderColumnList, SSDataBlock* pBlock, char** dat
assert(pIndex->colId == pColInfo->info.colId); assert(pIndex->colId == pColInfo->info.colId);
char *data = dataCols[i]; char *data = dataCols[i];
int32_t ret = columnValueAscendingComparator(data, pColInfo->pData, pColInfo->info.type, pColInfo->info.bytes); int32_t ret = columnValueAscendingComparator(data, pColInfo->pData, pColInfo->info.type, pColInfo->info.bytes, true);
if (ret == 0) { if (ret == 0) {
continue; continue;
} else { } else {
...@@ -1057,7 +1057,7 @@ static int32_t doSlimitImpl(SOperatorInfo* pOperator, SSLimitOperatorInfo* pInfo ...@@ -1057,7 +1057,7 @@ static int32_t doSlimitImpl(SOperatorInfo* pOperator, SSLimitOperatorInfo* pInfo
SColumnInfo *pColInfo = &pColInfoData->info; SColumnInfo *pColInfo = &pColInfoData->info;
char *d = rowIndex * pColInfo->bytes + (char *)pColInfoData->pData; char *d = rowIndex * pColInfo->bytes + (char *)pColInfoData->pData;
int32_t ret = columnValueAscendingComparator(pInfo->prevRow[i], d, pColInfo->type, pColInfo->bytes); int32_t ret = columnValueAscendingComparator(pInfo->prevRow[i], d, pColInfo->type, pColInfo->bytes, true);
if (ret != 0) { // it is a new group if (ret != 0) { // it is a new group
samegroup = false; samegroup = false;
break; break;
......
...@@ -1131,7 +1131,7 @@ public class JsonTagTest { ...@@ -1131,7 +1131,7 @@ public class JsonTagTest {
} }
Assert.assertEquals(8, count); Assert.assertEquals(8, count);
Assert.assertEquals("\"femail\"", s); Assert.assertEquals("\"收到货\"", s);
close(resultSet); close(resultSet);
} }
......
...@@ -93,9 +93,9 @@ int32_t twcslen(const wchar_t *wcs) { ...@@ -93,9 +93,9 @@ int32_t twcslen(const wchar_t *wcs) {
} }
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) { int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
for (int32_t i = 0; i < bytes; ++i) { for (int32_t i = 0; i < bytes; i += 4) {
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i * 4); int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i);
int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i * 4); int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i);
if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) { if ((f1 == 0 && f2 != 0) || (f1 != 0 && f2 == 0)) {
return f1 - f2; return f1 - f2;
......
...@@ -254,7 +254,7 @@ int32_t compare_d(tOrderDescriptor *, int32_t numOfRow1, int32_t s1, char *data1 ...@@ -254,7 +254,7 @@ int32_t compare_d(tOrderDescriptor *, int32_t numOfRow1, int32_t s1, char *data1
struct SSDataBlock; struct SSDataBlock;
int32_t compare_aRv(struct SSDataBlock* pBlock, SArray* colIndex, int32_t numOfCols, int32_t rowIndex, char** buffer, int32_t order); int32_t compare_aRv(struct SSDataBlock* pBlock, SArray* colIndex, int32_t numOfCols, int32_t rowIndex, char** buffer, int32_t order);
int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t bytes); int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t bytes, bool lenFirst);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -289,48 +289,24 @@ static int compareRowData(const void *a, const void *b, const void *userData) { ...@@ -289,48 +289,24 @@ static int compareRowData(const void *a, const void *b, const void *userData) {
} }
static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) { static void sortGroupResByOrderList(SGroupResInfo *pGroupResInfo, SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pDataBlock, SQLFunctionCtx *pCtx) {
SArray *columnOrderList = getOrderCheckColumns(pRuntimeEnv->pQueryAttr); // first groupby column is sort column
size_t size = taosArrayGetSize(columnOrderList); SColIndex* pFirstGroupCol = taosArrayGet(pRuntimeEnv->pQueryAttr->pGroupbyExpr->columnInfo, 0);
taosArrayDestroy(&columnOrderList); if (pFirstGroupCol == NULL) {
if (size <= 0) {
return;
}
int32_t orderId = pRuntimeEnv->pQueryAttr->order.orderColId;
if (orderId <= 0) {
return;
}
int32_t orderIndex = -1;
for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) {
if (pCtx[j].colId == orderId) {
orderIndex = j;
break;
}
}
if (orderIndex < 0) {
return; return;
} }
bool found = false; // get dataOffset and index on pRuntimeEnv->pQueryAttr->pExpr1
int16_t dataOffset = 0; int16_t dataOffset = 0;
int16_t type = 0;
for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) { for (int32_t j = 0; j < pDataBlock->info.numOfCols; ++j) {
SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j); SColumnInfoData* pColInfoData = (SColumnInfoData *)taosArrayGet(pDataBlock->pDataBlock, j);
if (orderIndex == j) { if (pCtx[j].colId == pFirstGroupCol->colId) {
found = true; type = pRuntimeEnv->pQueryAttr->pExpr1[j].base.resType;
break; break;
} }
dataOffset += pColInfoData->info.bytes; dataOffset += pColInfoData->info.bytes;
} }
if (found == false) {
return;
}
int16_t type = pRuntimeEnv->pQueryAttr->pExpr1[orderIndex].base.resType;
SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)}; SRowCompSupporter support = {.pRuntimeEnv = pRuntimeEnv, .dataOffset = dataOffset, .comFunc = getComparFunc(type, 0)};
taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support); taosArraySortPWithExt(pGroupResInfo->pRows, compareRowData, &support);
} }
...@@ -9547,7 +9523,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S ...@@ -9547,7 +9523,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
pQueryAttr->needTableSeqScan = pQueryMsg->needTableSeqScan; pQueryAttr->needTableSeqScan = pQueryMsg->needTableSeqScan;
pQueryAttr->needReverseScan = pQueryMsg->needReverseScan; pQueryAttr->needReverseScan = pQueryMsg->needReverseScan;
pQueryAttr->stateWindow = pQueryMsg->stateWindow; pQueryAttr->stateWindow = pQueryMsg->stateWindow;
pQueryAttr->vgId = vgId;
pQueryAttr->pFilters = pFilters; pQueryAttr->pFilters = pFilters;
pQueryAttr->range = pQueryMsg->range; pQueryAttr->range = pQueryMsg->range;
......
...@@ -366,7 +366,7 @@ static int32_t tsCompareFunc(TSKEY k1, TSKEY k2, int32_t order) { ...@@ -366,7 +366,7 @@ static int32_t tsCompareFunc(TSKEY k1, TSKEY k2, int32_t order) {
} }
} }
int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t bytes) { int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t bytes, bool lenFirst) {
if (type == TSDB_DATA_TYPE_JSON){ if (type == TSDB_DATA_TYPE_JSON){
bool canReturn = true; bool canReturn = true;
int32_t result = jsonCompareUnit(f1, f2, &canReturn); int32_t result = jsonCompareUnit(f1, f2, &canReturn);
...@@ -388,30 +388,47 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t ...@@ -388,30 +388,47 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
int32_t len1 = varDataLen(f1); int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2); int32_t len2 = varDataLen(f2);
if (len1 != len2) { // length first compare
return len1 > len2? 1:-1; if(lenFirst) {
} else { if(len1 > len2)
int32_t ret = strncmp(varDataVal(f1), varDataVal(f2), len1); return 1;
else if( len1 < len2)
return -1;
}
// compare context
int32_t ret = strncmp(varDataVal(f1), varDataVal(f2), len1>len2 ? len2:len1);
if (ret == 0) { if (ret == 0) {
if (len1 > len2)
return 1;
else if(len1 < len2)
return -1;
else
return 0; return 0;
} }
return (ret < 0) ? -1 : 1; return (ret < 0) ? -1 : 1;
}
}; };
case TSDB_DATA_TYPE_NCHAR: { // todo handle the var string compare case TSDB_DATA_TYPE_NCHAR: { // todo handle the var string compare
int32_t len1 = varDataLen(f1); int32_t len1 = varDataLen(f1);
int32_t len2 = varDataLen(f2); int32_t len2 = varDataLen(f2);
if (len1 != len2) { // length first compare
return len1 > len2 ? 1 : -1; if(lenFirst) {
} else { if(len1 > len2)
int32_t ret = tasoUcs4Compare(varDataVal(f1), varDataVal(f2), len1); return 1;
else if( len1 < len2)
return -1;
}
// compare context
int32_t ret = tasoUcs4Compare(varDataVal(f1), varDataVal(f2), len1>len2 ? len2:len1);
if (ret == 0) { if (ret == 0) {
if (len1 > len2)
return 1;
else if(len1 < len2)
return -1;
else
return 0; return 0;
} }
return (ret < 0) ? -1 : 1; return (ret < 0) ? -1 : 1;
}
}; };
case TSDB_DATA_TYPE_UTINYINT: DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_VAL(f2)); case TSDB_DATA_TYPE_UTINYINT: DEFAULT_COMP(GET_UINT8_VAL(f1), GET_UINT8_VAL(f2));
case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2)); case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2));
...@@ -442,7 +459,7 @@ int32_t compare_a(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1, ...@@ -442,7 +459,7 @@ int32_t compare_a(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1,
} }
} else { } else {
SSchemaEx *pSchema = &pDescriptor->pColumnModel->pFields[colIdx]; SSchemaEx *pSchema = &pDescriptor->pColumnModel->pFields[colIdx];
int32_t ret = columnValueAscendingComparator(f1, f2, pSchema->field.type, pSchema->field.bytes); int32_t ret = columnValueAscendingComparator(f1, f2, pSchema->field.type, pSchema->field.bytes, strcmp(pSchema->field.name, TSQL_TBNAME_L) == 0);
if (ret == 0) { if (ret == 0) {
continue; continue;
} else { } else {
...@@ -471,7 +488,7 @@ int32_t compare_aRv(SSDataBlock* pBlock, SArray* colIndex, int32_t numOfCols, in ...@@ -471,7 +488,7 @@ int32_t compare_aRv(SSDataBlock* pBlock, SArray* colIndex, int32_t numOfCols, in
return ret; return ret;
} }
} else { } else {
int32_t ret = columnValueAscendingComparator(data, buffer[i], pColInfo->info.type, pColInfo->info.bytes); int32_t ret = columnValueAscendingComparator(data, buffer[i], pColInfo->info.type, pColInfo->info.bytes, false);
if (ret == 0) { if (ret == 0) {
continue; continue;
} else { } else {
...@@ -503,7 +520,7 @@ int32_t compare_d(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1, ...@@ -503,7 +520,7 @@ int32_t compare_d(tOrderDescriptor *pDescriptor, int32_t numOfRows1, int32_t s1,
} }
} else { } else {
SSchemaEx *pSchema = &pDescriptor->pColumnModel->pFields[colIdx]; SSchemaEx *pSchema = &pDescriptor->pColumnModel->pFields[colIdx];
int32_t ret = columnValueAscendingComparator(f1, f2, pSchema->field.type, pSchema->field.bytes); int32_t ret = columnValueAscendingComparator(f1, f2, pSchema->field.type, pSchema->field.bytes, strcmp(pSchema->field.name, TSQL_TBNAME_L) == 0);
if (ret == 0) { if (ret == 0) {
continue; continue;
} else { } else {
......
...@@ -183,16 +183,16 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { ...@@ -183,16 +183,16 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft); int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1>len2 ? len2:len1);
return len1 > len2? 1:-1;
} else {
int32_t ret = strncmp(varDataVal(pLeft), varDataVal(pRight), len1);
if (ret == 0) { if (ret == 0) {
if (len1 > len2)
return 1;
else if(len1 < len2)
return -1;
else
return 0; return 0;
} else {
return ret > 0 ? 1:-1;
}
} }
return (ret < 0) ? -1 : 1;
} }
int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedStrDesc(const void* pLeft, const void* pRight) {
...@@ -203,16 +203,16 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) { ...@@ -203,16 +203,16 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
int32_t len1 = varDataLen(pLeft); int32_t len1 = varDataLen(pLeft);
int32_t len2 = varDataLen(pRight); int32_t len2 = varDataLen(pRight);
if (len1 != len2) { int32_t ret = memcmp(varDataVal(pLeft), varDataVal(pRight), len1>len2 ? len2:len1);
return len1 > len2? 1:-1;
} else {
int32_t ret = memcmp((wchar_t*) pLeft, (wchar_t*) pRight, len1);
if (ret == 0) { if (ret == 0) {
if (len1 > len2)
return 1;
else if(len1 < len2)
return -1;
else
return 0; return 0;
} else {
return ret > 0 ? 1 : -1;
}
} }
return (ret < 0) ? -1 : 1;
} }
int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) { int32_t compareLenPrefixedWStrDesc(const void* pLeft, const void* pRight) {
...@@ -772,33 +772,8 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) { ...@@ -772,33 +772,8 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2)); case TSDB_DATA_TYPE_USMALLINT: DEFAULT_COMP(GET_UINT16_VAL(f1), GET_UINT16_VAL(f2));
case TSDB_DATA_TYPE_UINT: DEFAULT_COMP(GET_UINT32_VAL(f1), GET_UINT32_VAL(f2)); case TSDB_DATA_TYPE_UINT: DEFAULT_COMP(GET_UINT32_VAL(f1), GET_UINT32_VAL(f2));
case TSDB_DATA_TYPE_UBIGINT: DEFAULT_COMP(GET_UINT64_VAL(f1), GET_UINT64_VAL(f2)); case TSDB_DATA_TYPE_UBIGINT: DEFAULT_COMP(GET_UINT64_VAL(f1), GET_UINT64_VAL(f2));
case TSDB_DATA_TYPE_NCHAR:{ case TSDB_DATA_TYPE_NCHAR: return compareLenPrefixedWStr(f1, f2);
tstr* t1 = (tstr*) f1; default: // BINARY AND NULL AND SO ON
tstr* t2 = (tstr*) f2; return compareLenPrefixedStr(f1, f2);
if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1;
}
int32_t ret = memcmp((wchar_t*) t1, (wchar_t*) t2, t2->len);
if (ret == 0) {
return ret;
}
return (ret < 0) ? -1 : 1;
}
default: { // todo refactor
tstr* t1 = (tstr*) f1;
tstr* t2 = (tstr*) f2;
if (t1->len != t2->len) {
return t1->len > t2->len? 1:-1;
} else {
int32_t ret = strncmp(t1->data, t2->data, t1->len);
if (ret == 0) {
return 0;
} else {
return ret < 0? -1:1;
}
}
}
} }
} }
...@@ -34,7 +34,6 @@ class TDTestCase: ...@@ -34,7 +34,6 @@ class TDTestCase:
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
print("============== STEP 1 ===== prepare data & validate json string") print("============== STEP 1 ===== prepare data & validate json string")
tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json, tagint int)") tdSql.error("create table if not exists jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50), dataStrBin binary(150)) tags(jtag json, tagint int)")
tdSql.error("create table if not exists jsons1(ts timestamp, data json) tags(tagint int)") tdSql.error("create table if not exists jsons1(ts timestamp, data json) tags(tagint int)")
...@@ -379,8 +378,8 @@ class TDTestCase: ...@@ -379,8 +378,8 @@ class TDTestCase:
tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag") tdSql.error("select count(*) from jsons1 group by jtag->'tag1' order by jtag")
tdSql.query("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc") tdSql.query("select count(*) from jsons1 group by jtag->'tag1' order by jtag->'tag1' desc")
tdSql.checkRows(8) tdSql.checkRows(8)
tdSql.checkData(0, 0, 2) tdSql.checkData(1, 0, 2)
tdSql.checkData(0, 1, '"femail"') tdSql.checkData(1, 1, '"femail"')
tdSql.checkData(2, 0, 1) tdSql.checkData(2, 0, 1)
tdSql.checkData(2, 1, 11) tdSql.checkData(2, 1, 11)
tdSql.checkData(5, 0, 1) tdSql.checkData(5, 0, 1)
...@@ -398,8 +397,8 @@ class TDTestCase: ...@@ -398,8 +397,8 @@ class TDTestCase:
tdSql.checkData(2, 1, "false") tdSql.checkData(2, 1, "false")
tdSql.checkData(5, 0, 1) tdSql.checkData(5, 0, 1)
tdSql.checkData(5, 1, 11) tdSql.checkData(5, 1, 11)
tdSql.checkData(7, 0, 2) tdSql.checkData(6, 0, 2)
tdSql.checkData(7, 1, '"femail"') tdSql.checkData(6, 1, '"femail"')
# test stddev with group by json tag # test stddev with group by json tag
tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1'") tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1'")
...@@ -407,8 +406,8 @@ class TDTestCase: ...@@ -407,8 +406,8 @@ class TDTestCase:
tdSql.checkData(0, 1, None) tdSql.checkData(0, 1, None)
tdSql.checkData(1, 0, 0) tdSql.checkData(1, 0, 0)
tdSql.checkData(1, 1, "null") tdSql.checkData(1, 1, "null")
tdSql.checkData(7, 0, 11) tdSql.checkData(6, 0, 11)
tdSql.checkData(7, 1, '"femail"') tdSql.checkData(6, 1, '"femail"')
res = tdSql.getColNameList("select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'") res = tdSql.getColNameList("select stddev(dataint) from jsons1 group by jsons1.jtag->'tag1'")
cname_list = [] cname_list = []
...@@ -422,8 +421,8 @@ class TDTestCase: ...@@ -422,8 +421,8 @@ class TDTestCase:
tdSql.checkData(0, 1, 4) tdSql.checkData(0, 1, 4)
tdSql.checkData(1, 1, 24) tdSql.checkData(1, 1, 24)
tdSql.checkData(1, 2, None) tdSql.checkData(1, 2, None)
tdSql.checkData(10, 1, 1) tdSql.checkData(8, 1, 1)
tdSql.checkData(10, 2, '"femail"') tdSql.checkData(8, 2, '"femail"')
# test having # test having
tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0") tdSql.query("select stddev(dataint) from jsons1 group by jtag->'tag1' having stddev(dataint) > 0")
...@@ -437,7 +436,7 @@ class TDTestCase: ...@@ -437,7 +436,7 @@ class TDTestCase:
tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") tdSql.query("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)")
tdSql.checkRows(11) tdSql.checkRows(11)
tdSql.checkData(0, 0, '"femail"') tdSql.checkData(1, 0, '"femail"')
tdSql.checkData(2, 0, 5) tdSql.checkData(2, 0, 5)
res = tdSql.getColNameList("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)") res = tdSql.getColNameList("select jtag->'tag1' from (select jtag->'tag1', dataint from jsons1)")
......
...@@ -135,9 +135,9 @@ class TDTestCase: ...@@ -135,9 +135,9 @@ class TDTestCase:
tdSql.execute("insert into std3 values(now + 5s, 4);") tdSql.execute("insert into std3 values(now + 5s, 4);")
tdSql.execute("insert into std3 values(now + 6s, 8);") tdSql.execute("insert into std3 values(now + 6s, 8);")
tdSql.query("select stddev(col1) from stdtable group by loc;") tdSql.query("select stddev(col1) from stdtable group by loc;")
tdSql.checkData(0, 0, 2.0) tdSql.checkData(2, 0, 2.0)
tdSql.checkData(1, 0, 0.5) tdSql.checkData(1, 0, 0.5)
tdSql.checkData(2, 0, 0.5) tdSql.checkData(0, 0, 0.5)
tdSql.execute("create table stdtableint(ts timestamp, col1 int) tags(num int)") tdSql.execute("create table stdtableint(ts timestamp, col1 int) tags(num int)")
tdSql.execute("create table stdint1 using stdtableint tags(1)") tdSql.execute("create table stdint1 using stdtableint tags(1)")
......
...@@ -49,13 +49,13 @@ class TDTestCase: ...@@ -49,13 +49,13 @@ class TDTestCase:
tdSql.query('select last(*) from mt0 group by c8') tdSql.query('select last(*) from mt0 group by c8')
tdSql.checkData(0,3,5) tdSql.checkData(0,3,5)
tdSql.checkData(0,4,20) tdSql.checkData(0,4,20)
tdSql.checkData(3,1,92) tdSql.checkData(3,1,57)
tdSql.checkData(3,9,'涛思8') tdSql.checkData(3,9,'涛思14')
tdSql.query('select last(*) from mt0 group by c9') tdSql.query('select last(*) from mt0 group by c9')
tdSql.checkData(0,3,0) tdSql.checkData(0,3,0)
tdSql.checkData(0,8,'taos38') tdSql.checkData(0,8,'taos38')
tdSql.checkData(40,1,83) tdSql.checkData(35,1,83)
tdSql.checkData(40,3,40) tdSql.checkData(35,3,40)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -51,19 +51,19 @@ class TDTestCase: ...@@ -51,19 +51,19 @@ class TDTestCase:
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c3 limit 70 offset 3') tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c3 limit 70 offset 3')
tdSql.checkRows(38) tdSql.checkRows(38)
tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c8 limit 3 offset 2') tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c8 limit 3 offset 12')
tdSql.checkData(0,0,91) tdSql.checkData(0,0,91)
tdSql.checkData(0,1,2) tdSql.checkData(0,1,2)
tdSql.checkData(0,2,2) tdSql.checkData(0,2,2)
tdSql.checkData(0,3,91) tdSql.checkData(0,3,91)
tdSql.checkData(1,0,92) tdSql.checkData(1,0,94)
tdSql.checkData(2,1,4) tdSql.checkData(2,1,7)
tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c9 limit 2 offset 9') tdSql.query('select max(c1),min(c1),first(c1),last(c1) from mt0 group by c9 limit 2 offset 39')
tdSql.checkData(0,0,96) tdSql.checkData(1,0,96)
tdSql.checkData(0,1,1) tdSql.checkData(1,1,1)
tdSql.checkData(0,2,9) tdSql.checkData(1,2,9)
tdSql.checkData(0,3,93) tdSql.checkData(0,3,92)
tdSql.checkData(1,0,97) tdSql.checkData(0,0,95)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
...@@ -303,11 +303,11 @@ class TDTestCase: ...@@ -303,11 +303,11 @@ class TDTestCase:
tdSql.checkRows(10) tdSql.checkRows(10)
# > for binary type on tag # > for binary type on tag
tdSql.query("select * from st where tagcol3 > '表'") tdSql.query("select * from st where tagcol3 < '表'")
tdSql.checkRows(10) tdSql.checkRows(10)
# >= for binary type on tag # >= for binary type on tag
tdSql.query("select * from st where tagcol3 >= '表'") tdSql.query("select * from st where tagcol3 <= '表'")
tdSql.checkRows(10) tdSql.checkRows(10)
# = for binary type on tag # = for binary type on tag
......
...@@ -18,6 +18,8 @@ from util.cases import * ...@@ -18,6 +18,8 @@ from util.cases import *
from util.sql import * from util.sql import *
import numpy as np import numpy as np
# constant define
WAITS = 5 # wait seconds
class TDTestCase: class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
...@@ -67,9 +69,7 @@ class TDTestCase: ...@@ -67,9 +69,7 @@ class TDTestCase:
"%s failed: sql:%s, the order provided for col:%d is not correct" % "%s failed: sql:%s, the order provided for col:%d is not correct" %
(callerFilename, tdSql.sql, col)) (callerFilename, tdSql.sql, col))
def run(self): def test_base(self):
tdSql.prepare()
print("======= step 1: create table and insert data =========") print("======= step 1: create table and insert data =========")
tdLog.debug( tdLog.debug(
''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double, ''' create table st(ts timestamp, tbcol1 tinyint, tbcol2 smallint, tbcol3 int, tbcol4 bigint, tbcol5 float, tbcol6 double,
...@@ -183,6 +183,44 @@ class TDTestCase: ...@@ -183,6 +183,44 @@ class TDTestCase:
tdSql.close() tdSql.close()
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)
def create_insert_data(self):
sql = "create table sb(ts timestamp, i1 int) tags(t_b1 binary(32), t_n1 nchar(64));"
tdSql.execute(sql)
for i in range(20):
value = "%s%s%s" % (chr(64+i),chr(64+i),chr(65+i))
if i%10 == 5:
value += "_%s" % (chr(66+i))
if i%10 == 0:
value += "_%s" % (chr(67+i))
sql = "insert into b%d using sb tags('A%s', 'B%s') values(now, %d);"%(i, value, value, i+1000)
tdSql.execute(sql)
def test_groupby_order(self):
# create and insert data
print("======= group order step 1: create table and insert data =========")
self.create_insert_data()
# do query
print("======= group order step 2: do query =========")
# ASC
sql = "select count(*) from sb group by t_b1 order by t_b1 asc;"
tdSql.execute(sql)
tdSql.waitedQuery(sql, 20, WAITS)
tdSql.checkData(0, 1, "A@@A_C")
tdSql.checkData(5, 1, "AEEF_G")
tdSql.checkData(19, 1, "ASST")
#DESC
sql = "select count(*) from sb group by t_b1 order by t_b1 desc;"
tdSql.execute(sql)
tdSql.waitedQuery(sql, 20, WAITS)
tdSql.checkData(19, 1, "A@@A_C")
tdSql.checkData(4, 1, "AOOP_Q")
tdSql.checkData(0, 1, "ASST")
def run(self):
tdSql.prepare()
self.test_base()
self.test_groupby_order()
tdCases.addWindows(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())
...@@ -116,7 +116,7 @@ if $data00 != NULL then ...@@ -116,7 +116,7 @@ if $data00 != NULL then
return -1 return -1
endi endi
sql select count(*), a from mt_unsigned_1 group by a; sql select count(*), a from mt_unsigned_1 group by a order by a desc;
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -137,7 +137,7 @@ if $data11 != 1 then ...@@ -137,7 +137,7 @@ if $data11 != 1 then
return -1 return -1
endi endi
sql select count(*), b from mt_unsigned_1 group by b; sql select count(*), b from mt_unsigned_1 group by b order by b desc;
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -158,7 +158,7 @@ if $data11 != 2 then ...@@ -158,7 +158,7 @@ if $data11 != 2 then
return -1 return -1
endi endi
sql select count(*), c from mt_unsigned_1 group by c; sql select count(*), c from mt_unsigned_1 group by c order by c desc;
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -179,7 +179,7 @@ if $data11 != 3 then ...@@ -179,7 +179,7 @@ if $data11 != 3 then
return -1 return -1
endi endi
sql select count(*), d from mt_unsigned_1 group by d; sql select count(*), d from mt_unsigned_1 group by d order by d desc;
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
......
...@@ -594,7 +594,8 @@ if $data10 != @{slop:0.000000, intercept:1.000000}@ then ...@@ -594,7 +594,8 @@ if $data10 != @{slop:0.000000, intercept:1.000000}@ then
return -1 return -1
endi endi
if $data90 != @{slop:0.000000, intercept:9.000000}@ then if $data90 != @{slop:0.000000, intercept:17.000000}@ then
print " data90 expect: {slop:0.000000, intercept:17.000000} real:"$data90
return -1 return -1
endi endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册