未验证 提交 08ae2881 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #7146 from taosdata/feature/devTomaster_1

Merge the uncommitted part of the develop into master
......@@ -340,7 +340,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild);
uint32_t tscGetTableMetaSize(STableMeta* pTableMeta);
CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta);
uint32_t tscGetTableMetaMaxSize();
int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, void* buf);
int32_t tscCreateTableMetaFromSTableMeta(STableMeta** pChild, const char* name, size_t *tableMetaCapacity);
STableMeta* tscTableMetaDup(STableMeta* pTableMeta);
SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo);
......
......@@ -84,8 +84,6 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
int64_t useconds = 0;
char * pTokenEnd = *next;
index = 0;
if (pToken->type == TK_NOW) {
useconds = taosGetTimestamp(timePrec);
} else if (strncmp(pToken->z, "0", 1) == 0 && pToken->n == 1) {
......@@ -130,7 +128,8 @@ int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int1
return tscInvalidOperationMsg(error, "value expected in timestamp", sToken.z);
}
if (parseAbsoluteDuration(valueToken.z, valueToken.n, &interval, timePrec) != TSDB_CODE_SUCCESS) {
char unit = 0;
if (parseAbsoluteDuration(valueToken.z, valueToken.n, &interval, &unit, timePrec) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
......
......@@ -458,9 +458,9 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema, SSm
schema->tagHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
schema->fieldHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
uint32_t size = tscGetTableMetaMaxSize();
STableMeta* tableMeta = calloc(1, size);
taosHashGetClone(tscTableMetaMap, fullTableName, strlen(fullTableName), NULL, tableMeta);
size_t size = 0;
STableMeta* tableMeta = NULL;
taosHashGetCloneExt(tscTableMetaMap, fullTableName, strlen(fullTableName), NULL, (void **)&tableMeta, &size);
tstrncpy(schema->sTableName, tableName, strlen(tableName)+1);
schema->precision = tableMeta->tableInfo.precision;
......@@ -1417,7 +1417,7 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) {
return false;
}
static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str) {
static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) {
errno = 0;
uint8_t type = pVal->type;
int16_t length = pVal->length;
......@@ -1436,7 +1436,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str) {
}
if (errno == ERANGE) {
tscError("Converted number out of range");
tscError("SML:0x%"PRIx64" Convert number(%s) out of range", info->id, str);
return false;
}
......@@ -1518,7 +1518,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str) {
}
//len does not include '\0' from value.
static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
uint16_t len) {
uint16_t len, SSmlLinesInfo* info) {
if (len <= 0) {
return false;
}
......@@ -1528,7 +1528,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_TINYINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 2] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1537,7 +1537,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_UTINYINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 2] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1546,7 +1546,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_SMALLINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1555,7 +1555,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_USMALLINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1564,7 +1564,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_INT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1573,7 +1573,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_UINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1582,7 +1582,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_BIGINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1591,7 +1591,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_UBIGINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value) || !convertStrToNumber(pVal, value)) {
if (!isValidInteger(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1601,7 +1601,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_FLOAT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidFloat(value) || !convertStrToNumber(pVal, value)) {
if (!isValidFloat(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1610,7 +1610,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
pVal->type = TSDB_DATA_TYPE_DOUBLE;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidFloat(value) || !convertStrToNumber(pVal, value)) {
if (!isValidFloat(value) || !convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1646,7 +1646,7 @@ static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
if (isValidInteger(value) || isValidFloat(value)) {
pVal->type = TSDB_DATA_TYPE_FLOAT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
if (!convertStrToNumber(pVal, value)) {
if (!convertStrToNumber(pVal, value, info)) {
return false;
}
return true;
......@@ -1702,7 +1702,7 @@ static int32_t getTimeStampValue(char *value, uint16_t len,
}
static int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
uint16_t len) {
uint16_t len, SSmlLinesInfo* info) {
int32_t ret;
SMLTimeStampType type;
int64_t tsVal;
......@@ -1715,7 +1715,7 @@ static int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
if (ret) {
return ret;
}
tscDebug("Timestamp after conversion:%"PRId64, tsVal);
tscDebug("SML:0x%"PRIx64"Timestamp after conversion:%"PRId64, info->id, tsVal);
pVal->type = TSDB_DATA_TYPE_TIMESTAMP;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
......@@ -1724,7 +1724,7 @@ static int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
return TSDB_CODE_SUCCESS;
}
static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index) {
static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index, SSmlLinesInfo* info) {
const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
int len = 0;
......@@ -1744,7 +1744,7 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index) {
memcpy(value, start, len);
}
ret = convertSmlTimeStamp(*pTS, value, len);
ret = convertSmlTimeStamp(*pTS, value, len, info);
if (ret) {
free(value);
free(*pTS);
......@@ -1757,7 +1757,7 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index) {
return ret;
}
static bool checkDuplicateKey(char *key, SHashObj *pHash) {
static bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info) {
char *val = NULL;
char *cur = key;
char keyLower[TSDB_COL_NAME_LEN];
......@@ -1771,7 +1771,7 @@ static bool checkDuplicateKey(char *key, SHashObj *pHash) {
val = taosHashGet(pHash, keyLower, keyLen);
if (val) {
tscError("Duplicate key:%s", keyLower);
tscError("SML:0x%"PRIx64" Duplicate key detected:%s", info->id, keyLower);
return true;
}
......@@ -1781,19 +1781,19 @@ static bool checkDuplicateKey(char *key, SHashObj *pHash) {
return false;
}
static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash) {
static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash, SSmlLinesInfo* info) {
const char *cur = *index;
char key[TSDB_COL_NAME_LEN + 1]; // +1 to avoid key[len] over write
uint16_t len = 0;
//key field cannot start with digit
if (isdigit(*cur)) {
tscError("Tag key cannnot start with digit\n");
tscError("SML:0x%"PRIx64" Tag key cannnot start with digit", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN) {
tscDebug("Key field cannot exceeds 65 characters");
tscError("SML:0x%"PRIx64" Key field cannot exceeds 65 characters", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
//unescaped '=' identifies a tag key
......@@ -1810,20 +1810,20 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
}
key[len] = '\0';
if (checkDuplicateKey(key, pHash)) {
if (checkDuplicateKey(key, pHash, info)) {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
pKV->key = calloc(len + 1, 1);
memcpy(pKV->key, key, len + 1);
//tscDebug("Key:%s|len:%d", pKV->key, len);
//tscDebug("SML:0x%"PRIx64" Key:%s|len:%d", info->id, pKV->key, len);
*index = cur + 1;
return TSDB_CODE_SUCCESS;
}
static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
bool *is_last_kv) {
bool *is_last_kv, SSmlLinesInfo* info) {
const char *start, *cur;
char *value = NULL;
uint16_t len = 0;
......@@ -1847,7 +1847,9 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
value = calloc(len + 1, 1);
memcpy(value, start, len);
value[len] = '\0';
if (!convertSmlValueType(pKV, value, len)) {
if (!convertSmlValueType(pKV, value, len, info)) {
tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type",
info->id, value);
//free previous alocated key field
free(pKV->key);
pKV->key = NULL;
......@@ -1861,7 +1863,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
}
static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index,
uint8_t *has_tags) {
uint8_t *has_tags, SSmlLinesInfo* info) {
const char *cur = *index;
uint16_t len = 0;
......@@ -1870,7 +1872,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
if (isdigit(*cur)) {
tscError("Measurement field cannnot start with digit");
tscError("SML:0x%"PRIx64" Measurement field cannnot start with digit", info->id);
free(pSml->stableName);
pSml->stableName = NULL;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
......@@ -1878,7 +1880,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
while (*cur != '\0') {
if (len > TSDB_TABLE_NAME_LEN) {
tscError("Measurement field cannot exceeds 193 characters");
tscError("SML:0x%"PRIx64" Measurement field cannot exceeds 193 characters", info->id);
free(pSml->stableName);
pSml->stableName = NULL;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
......@@ -1902,7 +1904,7 @@ static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index
}
pSml->stableName[len] = '\0';
*index = cur + 1;
tscDebug("Stable name in measurement:%s|len:%d", pSml->stableName, len);
tscDebug("SML:0x%"PRIx64" Stable name in measurement:%s|len:%d", info->id, pSml->stableName, len);
return TSDB_CODE_SUCCESS;
}
......@@ -1921,7 +1923,8 @@ static int32_t isValidChildTableName(const char *pTbName, int16_t len) {
static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
const char **index, bool isField,
TAOS_SML_DATA_POINT* smlData, SHashObj *pHash) {
TAOS_SML_DATA_POINT* smlData, SHashObj *pHash,
SSmlLinesInfo* info) {
const char *cur = *index;
int32_t ret = TSDB_CODE_SUCCESS;
TAOS_SML_KV *pkv;
......@@ -1941,14 +1944,14 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
}
while (*cur != '\0') {
ret = parseSmlKey(pkv, &cur, pHash);
ret = parseSmlKey(pkv, &cur, pHash, info);
if (ret) {
tscError("Unable to parse key field");
tscError("SML:0x%"PRIx64" Unable to parse key", info->id);
goto error;
}
ret = parseSmlValue(pkv, &cur, &is_last_kv);
ret = parseSmlValue(pkv, &cur, &is_last_kv, info);
if (ret) {
tscError("Unable to parse value field");
tscError("SML:0x%"PRIx64" Unable to parse value", info->id);
goto error;
}
if (!isField &&
......@@ -1966,7 +1969,6 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
*num_kvs += 1;
}
if (is_last_kv) {
//tscDebug("last key-value field detected");
goto done;
}
......@@ -2024,50 +2026,50 @@ static void moveTimeStampToFirstKv(TAOS_SML_DATA_POINT** smlData, TAOS_SML_KV *t
free(ts);
}
int32_t tscParseLine(const char* sql, TAOS_SML_DATA_POINT* smlData) {
int32_t tscParseLine(const char* sql, TAOS_SML_DATA_POINT* smlData, SSmlLinesInfo* info) {
const char* index = sql;
int32_t ret = TSDB_CODE_SUCCESS;
uint8_t has_tags = 0;
TAOS_SML_KV *timestamp = NULL;
SHashObj *keyHashTable = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
ret = parseSmlMeasurement(smlData, &index, &has_tags);
ret = parseSmlMeasurement(smlData, &index, &has_tags, info);
if (ret) {
tscError("Unable to parse measurement");
tscError("SML:0x%"PRIx64" Unable to parse measurement", info->id);
taosHashCleanup(keyHashTable);
return ret;
}
tscDebug("Parse measurement finished, has_tags:%d", has_tags);
tscDebug("SML:0x%"PRIx64" Parse measurement finished, has_tags:%d", info->id, has_tags);
//Parse Tags
if (has_tags) {
ret = parseSmlKvPairs(&smlData->tags, &smlData->tagNum, &index, false, smlData, keyHashTable);
ret = parseSmlKvPairs(&smlData->tags, &smlData->tagNum, &index, false, smlData, keyHashTable, info);
if (ret) {
tscError("Unable to parse tag");
tscError("SML:0x%"PRIx64" Unable to parse tag", info->id);
taosHashCleanup(keyHashTable);
return ret;
}
}
tscDebug("Parse tags finished, num of tags:%d", smlData->tagNum);
tscDebug("SML:0x%"PRIx64" Parse tags finished, num of tags:%d", info->id, smlData->tagNum);
//Parse fields
ret = parseSmlKvPairs(&smlData->fields, &smlData->fieldNum, &index, true, smlData, keyHashTable);
ret = parseSmlKvPairs(&smlData->fields, &smlData->fieldNum, &index, true, smlData, keyHashTable, info);
if (ret) {
tscError("Unable to parse field");
tscError("SML:0x%"PRIx64" Unable to parse field", info->id);
taosHashCleanup(keyHashTable);
return ret;
}
tscDebug("Parse fields finished, num of fields:%d", smlData->fieldNum);
tscDebug("SML:0x%"PRIx64" Parse fields finished, num of fields:%d", info->id, smlData->fieldNum);
taosHashCleanup(keyHashTable);
//Parse timestamp
ret = parseSmlTimeStamp(&timestamp, &index);
ret = parseSmlTimeStamp(&timestamp, &index, info);
if (ret) {
tscError("Unable to parse timestamp");
tscError("SML:0x%"PRIx64" Unable to parse timestamp", info->id);
return ret;
}
moveTimeStampToFirstKv(&smlData, timestamp);
tscDebug("Parse timestamp finished");
tscDebug("SML:0x%"PRIx64" Parse timestamp finished", info->id);
return TSDB_CODE_SUCCESS;
}
......@@ -2104,7 +2106,7 @@ void destroySmlDataPoint(TAOS_SML_DATA_POINT* point) {
int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* failedLines, SSmlLinesInfo* info) {
for (int32_t i = 0; i < numLines; ++i) {
TAOS_SML_DATA_POINT point = {0};
int32_t code = tscParseLine(lines[i], &point);
int32_t code = tscParseLine(lines[i], &point, info);
if (code != TSDB_CODE_SUCCESS) {
tscError("SML:0x%"PRIx64" data point line parse failed. line %d : %s", info->id, i, lines[i]);
destroySmlDataPoint(&point);
......
......@@ -1289,35 +1289,31 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
SInterval* pInterval = &pQueryInfo->interval;
if (pSliding->n == 0) {
pQueryInfo->interval.slidingUnit = pQueryInfo->interval.intervalUnit;
pQueryInfo->interval.sliding = pQueryInfo->interval.interval;
pInterval->slidingUnit = pInterval->intervalUnit;
pInterval->sliding = pInterval->interval;
return TSDB_CODE_SUCCESS;
}
if (pQueryInfo->interval.intervalUnit == 'n' || pQueryInfo->interval.intervalUnit == 'y') {
if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
parseAbsoluteDuration(pSliding->z, pSliding->n, &pQueryInfo->interval.sliding, tinfo.precision);
parseAbsoluteDuration(pSliding->z, pSliding->n, &pInterval->sliding, &pInterval->slidingUnit, tinfo.precision);
if (pQueryInfo->interval.sliding <
convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, tinfo.precision)) {
if (pInterval->sliding < convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, tinfo.precision)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0);
}
if (pQueryInfo->interval.sliding > pQueryInfo->interval.interval) {
if (pInterval->sliding > pInterval->interval) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if ((pQueryInfo->interval.interval != 0) && (pQueryInfo->interval.interval/pQueryInfo->interval.sliding > INTERVAL_SLIDING_FACTOR)) {
if ((pInterval->interval != 0) && (pInterval->interval/pInterval->sliding > INTERVAL_SLIDING_FACTOR)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
// if (pQueryInfo->interval.sliding != pQueryInfo->interval.interval && pSql->pStream == NULL) {
// return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
// }
return TSDB_CODE_SUCCESS;
}
......@@ -8093,6 +8089,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
SArray* pVgroupList = NULL;
SArray* plist = NULL;
STableMeta* pTableMeta = NULL;
size_t tableMetaCapacity = 0;
SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd);
pCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
......@@ -8119,18 +8116,14 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
}
uint32_t maxSize = tscGetTableMetaMaxSize();
char name[TSDB_TABLE_FNAME_LEN] = {0};
assert(maxSize < 80 * TSDB_MAX_COLUMNS);
if (!pSql->pBuf) {
if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) {
code = TSDB_CODE_TSC_OUT_OF_MEMORY;
goto _end;
}
}
pTableMeta = calloc(1, maxSize);
//if (!pSql->pBuf) {
// if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) {
// code = TSDB_CODE_TSC_OUT_OF_MEMORY;
// goto _end;
// }
//}
plist = taosArrayInit(4, POINTER_BYTES);
pVgroupList = taosArrayInit(4, POINTER_BYTES);
......@@ -8144,16 +8137,16 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tNameExtractFullName(pname, name);
size_t len = strlen(name);
memset(pTableMeta, 0, maxSize);
taosHashGetClone(tscTableMetaMap, name, len, NULL, pTableMeta);
if (pTableMeta->id.uid > 0) {
taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&pTableMeta, &tableMetaCapacity);
if (pTableMeta && pTableMeta->id.uid > 0) {
tscDebug("0x%"PRIx64" retrieve table meta %s from local buf", pSql->self, name);
// avoid mem leak, may should update pTableMeta
void* pVgroupIdList = NULL;
if (pTableMeta->tableType == TSDB_CHILD_TABLE) {
code = tscCreateTableMetaFromSTableMeta(pTableMeta, name, pSql->pBuf);
code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity);
// create the child table meta from super table failed, try load it from mnode
if (code != TSDB_CODE_SUCCESS) {
......@@ -8309,6 +8302,7 @@ static int32_t doLoadAllTableMeta(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNod
STableMetaVgroupInfo* p = taosHashGet(pCmd->pTableMetaMap, fname, strnlen(fname, TSDB_TABLE_FNAME_LEN));
pTableMetaInfo->pTableMeta = tscTableMetaDup(p->pTableMeta);
pTableMetaInfo->tableMetaCapacity = tscGetTableMetaSize(pTableMetaInfo->pTableMeta);
assert(pTableMetaInfo->pTableMeta != NULL);
if (p->vgroupIdList != NULL) {
......@@ -8409,6 +8403,7 @@ static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pS
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
pTableMetaInfo1->pTableMeta = extractTempTableMetaFromSubquery(pSub);
pTableMetaInfo1->tableMetaCapacity = tscGetTableMetaSize(pTableMetaInfo1->pTableMeta);
if (subInfo->aliasName.n > 0) {
if (subInfo->aliasName.n >= TSDB_TABLE_FNAME_LEN) {
......@@ -8775,8 +8770,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
#if 0
SQueryNode* p = qCreateQueryPlan(pQueryInfo);
char* s = queryPlanToString(p);
printf("%s\n", s);
tfree(s);
qDestroyQueryPlan(p);
#endif
......
......@@ -401,10 +401,8 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) {
// single table query error need to be handled here.
if ((cmd == TSDB_SQL_SELECT || cmd == TSDB_SQL_UPDATE_TAGS_VAL) &&
(((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID ||
rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) ||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL ||
rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
(((rpcMsg->code == TSDB_CODE_TDB_INVALID_TABLE_ID || rpcMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID)) ||
rpcMsg->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || rpcMsg->code == TSDB_CODE_APP_NOT_READY)) {
// 1. super table subquery
// 2. nest queries are all not updated the tablemeta and retry parse the sql after cleanup local tablemeta/vgroup id buffer
......@@ -2842,43 +2840,22 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) {
assert(tIsValidName(&pTableMetaInfo->name));
uint32_t size = tscGetTableMetaMaxSize();
if (pTableMetaInfo->pTableMeta == NULL) {
pTableMetaInfo->pTableMeta = calloc(1, size);
pTableMetaInfo->tableMetaSize = size;
} else if (pTableMetaInfo->tableMetaSize < size) {
char *tmp = realloc(pTableMetaInfo->pTableMeta, size);
if (tmp == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
pTableMetaInfo->pTableMeta = (STableMeta *)tmp;
}
memset(pTableMetaInfo->pTableMeta, 0, size);
pTableMetaInfo->tableMetaSize = size;
pTableMetaInfo->pTableMeta->tableType = -1;
pTableMetaInfo->pTableMeta->tableInfo.numOfColumns = -1;
char name[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(&pTableMetaInfo->name, name);
size_t len = strlen(name);
taosHashGetClone(tscTableMetaMap, name, len, NULL, pTableMetaInfo->pTableMeta);
// TODO resize the tableMeta
assert(size < 80 * TSDB_MAX_COLUMNS);
if (!pSql->pBuf) {
if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) {
return TSDB_CODE_TSC_OUT_OF_MEMORY;
if (pTableMetaInfo->tableMetaCapacity != 0) {
if (pTableMetaInfo->pTableMeta != NULL) {
memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity);
}
}
taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity);
STableMeta* pMeta = pTableMetaInfo->pTableMeta;
if (pMeta->id.uid > 0) {
if (pMeta && pMeta->id.uid > 0) {
// in case of child table, here only get the
if (pMeta->tableType == TSDB_CHILD_TABLE) {
int32_t code = tscCreateTableMetaFromSTableMeta(pTableMetaInfo->pTableMeta, name, pSql->pBuf);
int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity);
if (code != TSDB_CODE_SUCCESS) {
return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate);
}
......
......@@ -1635,6 +1635,8 @@ void tscFetchDatablockForSubquery(SSqlObj* pSql) {
continue;
}
SSqlRes* pRes1 = &pSql1->res;
if (pRes1->row >= pRes1->numOfRows) {
subquerySetState(pSql1, &pSql->subState, i, 0);
......
......@@ -1657,6 +1657,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
pTableMetaInfo->pTableMeta = tscTableMetaDup(pDataBlock->pTableMeta);
pTableMetaInfo->tableMetaSize = tscGetTableMetaSize(pDataBlock->pTableMeta);
pTableMetaInfo->tableMetaCapacity = (size_t)(pTableMetaInfo->tableMetaSize);
}
/*
......@@ -3414,6 +3415,8 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, SName* name, STableM
} else {
pTableMetaInfo->tableMetaSize = tscGetTableMetaSize(pTableMeta);
}
pTableMetaInfo->tableMetaCapacity = (size_t)(pTableMetaInfo->tableMetaSize);
if (vgroupList != NULL) {
pTableMetaInfo->vgroupList = tscVgroupInfoClone(vgroupList);
......@@ -3646,7 +3649,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
if (pQueryInfo->fillType != TSDB_FILL_NONE) {
//just make memory memory sanitizer happy
//refator later
//refactor later
pNewQueryInfo->fillVal = calloc(1, pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t));
if (pNewQueryInfo->fillVal == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
......@@ -4445,24 +4448,36 @@ CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta) {
return cMeta;
}
int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, void* buf) {
assert(pChild != NULL && buf != NULL);
int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity) {
assert(*ppChild != NULL);
STableMeta* p = NULL;
size_t sz = 0;
STableMeta* pChild = *ppChild;
STableMeta* p = buf;
taosHashGetClone(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, p);
taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz);
// tableMeta exists, build child table meta according to the super table meta
// the uid need to be checked in addition to the general name of the super table.
if (p->id.uid > 0 && pChild->suid == p->id.uid) {
if (p && p->id.uid > 0 && pChild->suid == p->id.uid) {
int32_t totalBytes = (p->tableInfo.numOfColumns + p->tableInfo.numOfTags) * sizeof(SSchema);
int32_t tableMetaSize = sizeof(STableMeta) + totalBytes;
if (*tableMetaCapacity < tableMetaSize) {
pChild = realloc(pChild, tableMetaSize);
*tableMetaCapacity = (size_t)tableMetaSize;
}
pChild->sversion = p->sversion;
pChild->tversion = p->tversion;
memcpy(&pChild->tableInfo, &p->tableInfo, sizeof(STableComInfo));
int32_t total = pChild->tableInfo.numOfColumns + pChild->tableInfo.numOfTags;
memcpy(pChild->schema, p->schema, totalBytes);
memcpy(pChild->schema, p->schema, sizeof(SSchema) *total);
*ppChild = pChild;
tfree(p);
return TSDB_CODE_SUCCESS;
} else { // super table has been removed, current tableMeta is also expired. remove it here
tfree(p);
taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
return -1;
}
......
......@@ -325,7 +325,9 @@ typedef struct SDataCol {
#define isAllRowsNull(pCol) ((pCol)->len == 0)
static FORCE_INLINE void dataColReset(SDataCol *pDataCol) { pDataCol->len = 0; }
void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints);
int tdAllocMemForCol(SDataCol *pCol, int maxPoints);
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints);
void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints);
void dataColSetOffset(SDataCol *pCol, int nEle);
......@@ -358,12 +360,10 @@ typedef struct {
int maxRowSize;
int maxCols; // max number of columns
int maxPoints; // max number of points
int bufSize;
int numOfRows;
int numOfCols; // Total number of cols
int sversion; // TODO: set sversion
void * buf;
SDataCol *cols;
} SDataCols;
......
......@@ -22,6 +22,29 @@
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
int limit2, int tRows, bool forceSetNull);
//TODO: change caller to use return val
int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
int spaceNeeded = pCol->bytes * maxPoints;
if(IS_VAR_DATA_TYPE(pCol->type)) {
spaceNeeded += sizeof(VarDataOffsetT) * maxPoints;
}
if(pCol->spaceSize < spaceNeeded) {
void* ptr = realloc(pCol->pData, spaceNeeded);
if(ptr == NULL) {
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)pCol->spaceSize,
strerror(errno));
return -1;
} else {
pCol->pData = ptr;
pCol->spaceSize = spaceNeeded;
}
}
if(IS_VAR_DATA_TYPE(pCol->type)) {
pCol->dataOff = POINTER_SHIFT(pCol->pData, pCol->bytes * maxPoints);
}
return 0;
}
/**
* Duplicate the schema and return a new object
*/
......@@ -207,24 +230,13 @@ SMemRow tdMemRowDup(SMemRow row) {
return trow;
}
void dataColInit(SDataCol *pDataCol, STColumn *pCol, void **pBuf, int maxPoints) {
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
pDataCol->type = colType(pCol);
pDataCol->colId = colColId(pCol);
pDataCol->bytes = colBytes(pCol);
pDataCol->offset = colOffset(pCol) + TD_DATA_ROW_HEAD_SIZE;
pDataCol->len = 0;
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
pDataCol->dataOff = (VarDataOffsetT *)(*pBuf);
pDataCol->pData = POINTER_SHIFT(*pBuf, sizeof(VarDataOffsetT) * maxPoints);
pDataCol->spaceSize = pDataCol->bytes * maxPoints;
*pBuf = POINTER_SHIFT(*pBuf, pDataCol->spaceSize + sizeof(VarDataOffsetT) * maxPoints);
} else {
pDataCol->spaceSize = pDataCol->bytes * maxPoints;
pDataCol->dataOff = NULL;
pDataCol->pData = *pBuf;
*pBuf = POINTER_SHIFT(*pBuf, pDataCol->spaceSize);
}
}
// value from timestamp should be TKEY here instead of TSKEY
void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints) {
......@@ -239,6 +251,8 @@ void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxP
if (numOfRows > 0) {
// Find the first not null value, fill all previouse values as NULL
dataColSetNEleNull(pCol, numOfRows, maxPoints);
} else {
tdAllocMemForCol(pCol, maxPoints);
}
}
......@@ -257,13 +271,14 @@ void dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxP
}
bool isNEleNull(SDataCol *pCol, int nEle) {
if(isAllRowsNull(pCol)) return true;
for (int i = 0; i < nEle; i++) {
if (!isNull(tdGetColDataOfRow(pCol, i), pCol->type)) return false;
}
return true;
}
FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) {
static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) {
if (IS_VAR_DATA_TYPE(pCol->type)) {
pCol->dataOff[index] = pCol->len;
char *ptr = POINTER_SHIFT(pCol->pData, pCol->len);
......@@ -276,6 +291,7 @@ FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) {
}
void dataColSetNEleNull(SDataCol *pCol, int nEle, int maxPoints) {
tdAllocMemForCol(pCol, maxPoints);
if (IS_VAR_DATA_TYPE(pCol->type)) {
pCol->len = 0;
......@@ -319,56 +335,63 @@ SDataCols *tdNewDataCols(int maxRowSize, int maxCols, int maxRows) {
tdFreeDataCols(pCols);
return NULL;
}
int i;
for(i = 0; i < maxCols; i++) {
pCols->cols[i].spaceSize = 0;
pCols->cols[i].len = 0;
pCols->cols[i].pData = NULL;
pCols->cols[i].dataOff = NULL;
}
pCols->maxCols = maxCols;
}
pCols->maxRowSize = maxRowSize;
pCols->bufSize = maxRowSize * maxRows;
if (pCols->bufSize > 0) {
pCols->buf = malloc(pCols->bufSize);
if (pCols->buf == NULL) {
uDebug("malloc failure, size:%" PRId64 " failed, reason:%s", (int64_t)sizeof(SDataCol) * maxCols,
strerror(errno));
tdFreeDataCols(pCols);
return NULL;
}
}
return pCols;
}
int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
if (schemaNCols(pSchema) > pCols->maxCols) {
int i;
int oldMaxCols = pCols->maxCols;
if (schemaNCols(pSchema) > oldMaxCols) {
pCols->maxCols = schemaNCols(pSchema);
pCols->cols = (SDataCol *)realloc(pCols->cols, sizeof(SDataCol) * pCols->maxCols);
if (pCols->cols == NULL) return -1;
for(i = oldMaxCols; i < pCols->maxCols; i++) {
pCols->cols[i].pData = NULL;
pCols->cols[i].dataOff = NULL;
pCols->cols[i].spaceSize = 0;
}
}
if (schemaTLen(pSchema) > pCols->maxRowSize) {
pCols->maxRowSize = schemaTLen(pSchema);
pCols->bufSize = schemaTLen(pSchema) * pCols->maxPoints;
pCols->buf = realloc(pCols->buf, pCols->bufSize);
if (pCols->buf == NULL) return -1;
}
tdResetDataCols(pCols);
pCols->numOfCols = schemaNCols(pSchema);
void *ptr = pCols->buf;
for (int i = 0; i < schemaNCols(pSchema); i++) {
dataColInit(pCols->cols + i, schemaColAt(pSchema, i), &ptr, pCols->maxPoints);
ASSERT((char *)ptr - (char *)(pCols->buf) <= pCols->bufSize);
for (i = 0; i < schemaNCols(pSchema); i++) {
dataColInit(pCols->cols + i, schemaColAt(pSchema, i), pCols->maxPoints);
}
return 0;
}
SDataCols *tdFreeDataCols(SDataCols *pCols) {
int i;
if (pCols) {
tfree(pCols->buf);
tfree(pCols->cols);
if(pCols->cols) {
int maxCols = pCols->maxCols;
for(i = 0; i < maxCols; i++) {
SDataCol *pCol = &pCols->cols[i];
tfree(pCol->pData);
}
free(pCols->cols);
pCols->cols = NULL;
}
free(pCols);
}
return NULL;
......@@ -388,21 +411,14 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
pRet->cols[i].bytes = pDataCols->cols[i].bytes;
pRet->cols[i].offset = pDataCols->cols[i].offset;
pRet->cols[i].spaceSize = pDataCols->cols[i].spaceSize;
pRet->cols[i].pData = (void *)((char *)pRet->buf + ((char *)(pDataCols->cols[i].pData) - (char *)(pDataCols->buf)));
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
ASSERT(pDataCols->cols[i].dataOff != NULL);
pRet->cols[i].dataOff =
(int32_t *)((char *)pRet->buf + ((char *)(pDataCols->cols[i].dataOff) - (char *)(pDataCols->buf)));
}
if (keepData) {
pRet->cols[i].len = pDataCols->cols[i].len;
if (pDataCols->cols[i].len > 0) {
tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints);
pRet->cols[i].len = pDataCols->cols[i].len;
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, sizeof(VarDataOffsetT) * pDataCols->maxPoints);
int dataOffSize = sizeof(VarDataOffsetT) * pDataCols->maxPoints;
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize);
}
}
}
......@@ -426,20 +442,9 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols
int rcol = 0;
int dcol = 0;
if (dataRowDeleted(row)) {
for (; dcol < pCols->numOfCols; dcol++) {
SDataCol *pDataCol = &(pCols->cols[dcol]);
if (dcol == 0) {
dataColAppendVal(pDataCol, dataRowTuple(row), pCols->numOfRows, pCols->maxPoints);
} else {
dataColSetNullAt(pDataCol, pCols->numOfRows);
}
}
} else {
while (dcol < pCols->numOfCols) {
SDataCol *pDataCol = &(pCols->cols[dcol]);
if (rcol >= schemaNCols(pSchema)) {
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
dcol++;
continue;
......@@ -455,13 +460,11 @@ static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols
rcol++;
} else {
if(forceSetNull) {
//dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
}
dcol++;
}
}
}
pCols->numOfRows++;
}
......@@ -471,22 +474,11 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo
int rcol = 0;
int dcol = 0;
if (kvRowDeleted(row)) {
for (; dcol < pCols->numOfCols; dcol++) {
SDataCol *pDataCol = &(pCols->cols[dcol]);
if (dcol == 0) {
dataColAppendVal(pDataCol, kvRowValues(row), pCols->numOfRows, pCols->maxPoints);
} else {
dataColSetNullAt(pDataCol, pCols->numOfRows);
}
}
} else {
int nRowCols = kvRowNCols(row);
while (dcol < pCols->numOfCols) {
SDataCol *pDataCol = &(pCols->cols[dcol]);
if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) {
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
++dcol;
continue;
......@@ -503,13 +495,11 @@ static void tdAppendKvRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCo
++rcol;
} else {
if (forceSetNull) {
// dataColSetNullAt(pDataCol, pCols->numOfRows);
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
}
++dcol;
}
}
}
pCols->numOfRows++;
}
......
......@@ -97,7 +97,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision);
int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision);
int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision);
int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts, int32_t timePrecision);
int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* ts, char* unit, int32_t timePrecision);
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision);
int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t dayligth);
......
......@@ -397,7 +397,7 @@ static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t time
* n - Months (30 days)
* y - Years (365 days)
*/
int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration, int32_t timePrecision) {
int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration, char* unit, int32_t timePrecision) {
errno = 0;
char* endPtr = NULL;
......@@ -408,12 +408,12 @@ int32_t parseAbsoluteDuration(char* token, int32_t tokenlen, int64_t* duration,
}
/* natual month/year are not allowed in absolute duration */
char unit = token[tokenlen - 1];
if (unit == 'n' || unit == 'y') {
*unit = token[tokenlen - 1];
if (*unit == 'n' || *unit == 'y') {
return -1;
}
return getDuration(timestamp, unit, duration, timePrecision);
return getDuration(timestamp, *unit, duration, timePrecision);
}
int32_t parseNatualDuration(const char* token, int32_t tokenLen, int64_t* duration, char* unit, int32_t timePrecision) {
......
......@@ -72,6 +72,7 @@ typedef struct STableMeta {
typedef struct STableMetaInfo {
STableMeta *pTableMeta; // table meta, cached in client side and acquired by name
uint32_t tableMetaSize;
size_t tableMetaCapacity;
SVgroupsInfo *vgroupList;
SArray *pVgroupTables; // SArray<SVgroupTableInfo>
......
......@@ -479,7 +479,7 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). {
//////////////////////// The SELECT statement /////////////////////////////////
%type select {SSqlNode*}
%destructor select {destroySqlNode($$);}
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) session_option(H) windowstate_option(D) fill_opt(F) sliding_opt(S) groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). {
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_opt(K) sliding_opt(S) session_option(H) windowstate_option(D) fill_opt(F)groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). {
A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N);
}
......
......@@ -32,8 +32,8 @@ typedef struct SJoinCond {
SColumn *colCond[2];
} SJoinCond;
static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev,
int32_t numOfPrev, SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo,
static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev, int32_t numOfPrev,
SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo,
void* pExtInfo) {
SQueryNode* pNode = calloc(1, sizeof(SQueryNode));
......@@ -112,8 +112,8 @@ static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo*
}
STimeWindow* window = &pQueryInfo->window;
SQueryNode* pNode = createQueryNode(QNODE_TABLESCAN, "TableScan", NULL, 0, NULL, 0,
info, window);
SQueryNode* pNode = createQueryNode(QNODE_TABLESCAN, "TableScan", NULL, 0, NULL, 0, info, window);
if (pQueryInfo->projectionQuery) {
int32_t numOfOutput = (int32_t) taosArrayGetSize(pExprs);
pNode = createQueryNode(QNODE_PROJECT, "Projection", &pNode, 1, pExprs->pData, numOfOutput, info, NULL);
......@@ -149,23 +149,26 @@ static SQueryNode* doCreateQueryPlanForOneTableImpl(SQueryInfo* pQueryInfo, SQue
SArray* pExprs) {
// check for aggregation
if (pQueryInfo->interval.interval > 0) {
int32_t numOfOutput = (int32_t) taosArrayGetSize(pExprs);
int32_t numOfOutput = (int32_t)taosArrayGetSize(pExprs);
pNode = createQueryNode(QNODE_TIMEWINDOW, "TimeWindowAgg", &pNode, 1, pExprs->pData, numOfOutput, info,
&pQueryInfo->interval);
if (pQueryInfo->groupbyExpr.numOfGroupCols != 0) {
pNode = createQueryNode(QNODE_GROUPBY, "Groupby", &pNode, 1, pExprs->pData, numOfOutput, info, &pQueryInfo->groupbyExpr);
}
} else if (pQueryInfo->groupbyColumn) {
int32_t numOfOutput = (int32_t) taosArrayGetSize(pExprs);
int32_t numOfOutput = (int32_t)taosArrayGetSize(pExprs);
pNode = createQueryNode(QNODE_GROUPBY, "Groupby", &pNode, 1, pExprs->pData, numOfOutput, info,
&pQueryInfo->groupbyExpr);
} else if (pQueryInfo->sessionWindow.gap > 0) {
pNode = createQueryNode(QNODE_SESSIONWINDOW, "SessionWindowAgg", &pNode, 1, NULL, 0, info, NULL);
} else if (pQueryInfo->simpleAgg) {
int32_t numOfOutput = (int32_t) taosArrayGetSize(pExprs);
int32_t numOfOutput = (int32_t)taosArrayGetSize(pExprs);
pNode = createQueryNode(QNODE_AGGREGATE, "Aggregate", &pNode, 1, pExprs->pData, numOfOutput, info, NULL);
}
if (pQueryInfo->havingFieldNum > 0 || pQueryInfo->arithmeticOnAgg) {
int32_t numOfExpr = (int32_t) taosArrayGetSize(pQueryInfo->exprList1);
int32_t numOfExpr = (int32_t)taosArrayGetSize(pQueryInfo->exprList1);
pNode =
createQueryNode(QNODE_PROJECT, "Projection", &pNode, 1, pQueryInfo->exprList1->pData, numOfExpr, info, NULL);
}
......@@ -179,7 +182,6 @@ static SQueryNode* doCreateQueryPlanForOneTableImpl(SQueryInfo* pQueryInfo, SQue
pNode = createQueryNode(QNODE_FILL, "Fill", &pNode, 1, NULL, 0, info, pInfo);
}
if (pQueryInfo->limit.limit != -1 || pQueryInfo->limit.offset != 0) {
pNode = createQueryNode(QNODE_LIMIT, "Limit", &pNode, 1, NULL, 0, info, &pQueryInfo->limit);
}
......@@ -330,7 +332,7 @@ static int32_t doPrintPlan(char* buf, SQueryNode* pQueryNode, int32_t level, int
switch(pQueryNode->info.type) {
case QNODE_TABLESCAN: {
STimeWindow* win = (STimeWindow*)pQueryNode->pExtInfo;
len1 = sprintf(buf + len, "%s #0x%" PRIx64 ") time_range: %" PRId64 " - %" PRId64 "\n",
len1 = sprintf(buf + len, "%s #%" PRIu64 ") time_range: %" PRId64 " - %" PRId64 "\n",
pQueryNode->tableInfo.tableName, pQueryNode->tableInfo.id.uid, win->skey, win->ekey);
len += len1;
break;
......@@ -401,8 +403,8 @@ static int32_t doPrintPlan(char* buf, SQueryNode* pQueryNode, int32_t level, int
len += len1;
SInterval* pInterval = pQueryNode->pExtInfo;
len1 = sprintf(buf + len, "interval:%" PRId64 "(%c), sliding:%" PRId64 "(%c), offset:%" PRId64 "\n",
pInterval->interval, pInterval->intervalUnit, pInterval->sliding, pInterval->slidingUnit,
len1 = sprintf(buf + len, "interval:%" PRId64 "(%s), sliding:%" PRId64 "(%s), offset:%" PRId64 "\n",
pInterval->interval, TSDB_TIME_PRECISION_MILLI_STR, pInterval->sliding, TSDB_TIME_PRECISION_MILLI_STR,
pInterval->offset);
len += len1;
......
......@@ -166,7 +166,8 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
// use nanosecond by default
// TODO set value after getting database precision
if (pToken) {
int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, TSDB_TIME_PRECISION_NANO);
char unit = 0;
int32_t ret = parseAbsoluteDuration(pToken->z, pToken->n, &pSqlExpr->value.i64, &unit, TSDB_TIME_PRECISION_NANO);
if (ret != TSDB_CODE_SUCCESS) {
terrno = TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
}
......
......@@ -257,27 +257,27 @@ static const YYACTIONTYPE yy_action[] = {
/* 480 */ 208, 211, 205, 212, 213, 217, 218, 219, 216, 202,
/* 490 */ 1143, 1082, 1135, 236, 267, 1079, 1078, 237, 338, 151,
/* 500 */ 1035, 1046, 47, 1065, 1043, 149, 1064, 1025, 1028, 1044,
/* 510 */ 274, 1048, 153, 170, 157, 1009, 278, 283, 171, 1007,
/* 510 */ 274, 1048, 153, 170, 158, 1009, 278, 285, 171, 1007,
/* 520 */ 172, 233, 166, 280, 161, 757, 160, 173, 162, 922,
/* 530 */ 163, 299, 300, 301, 304, 305, 287, 292, 45, 290,
/* 530 */ 163, 299, 300, 301, 304, 305, 282, 292, 45, 290,
/* 540 */ 75, 200, 288, 813, 272, 41, 72, 49, 316, 164,
/* 550 */ 916, 323, 1142, 110, 1141, 1138, 286, 179, 330, 1134,
/* 560 */ 284, 116, 1133, 1130, 180, 282, 942, 42, 39, 46,
/* 570 */ 201, 904, 279, 126, 48, 902, 128, 129, 900, 899,
/* 560 */ 284, 116, 1133, 1130, 180, 281, 942, 42, 39, 46,
/* 570 */ 201, 904, 279, 126, 303, 902, 128, 129, 900, 899,
/* 580 */ 259, 191, 897, 896, 895, 894, 893, 892, 891, 194,
/* 590 */ 196, 888, 886, 884, 882, 198, 879, 199, 303, 81,
/* 600 */ 86, 348, 281, 1066, 121, 340, 341, 342, 343, 344,
/* 590 */ 196, 888, 886, 884, 882, 198, 879, 199, 48, 81,
/* 600 */ 86, 348, 283, 1066, 121, 340, 341, 342, 343, 344,
/* 610 */ 223, 345, 346, 356, 855, 243, 298, 260, 261, 854,
/* 620 */ 263, 220, 221, 264, 853, 836, 104, 921, 920, 105,
/* 630 */ 835, 268, 273, 10, 293, 734, 275, 84, 30, 87,
/* 640 */ 898, 890, 182, 943, 186, 181, 184, 140, 183, 187,
/* 650 */ 185, 141, 142, 889, 4, 143, 980, 881, 880, 944,
/* 660 */ 759, 165, 167, 168, 155, 169, 762, 156, 2, 990,
/* 670 */ 88, 235, 764, 89, 285, 31, 768, 158, 11, 12,
/* 680 */ 13, 32, 27, 295, 28, 96, 98, 101, 35, 100,
/* 630 */ 835, 268, 273, 10, 293, 734, 275, 84, 30, 898,
/* 640 */ 890, 183, 182, 943, 187, 181, 184, 185, 2, 140,
/* 650 */ 186, 141, 142, 889, 4, 143, 980, 881, 87, 944,
/* 660 */ 759, 165, 167, 168, 169, 880, 155, 157, 768, 156,
/* 670 */ 235, 762, 88, 89, 990, 764, 287, 31, 11, 32,
/* 680 */ 12, 13, 27, 295, 28, 96, 98, 101, 35, 100,
/* 690 */ 632, 36, 102, 667, 665, 664, 663, 661, 660, 659,
/* 700 */ 656, 314, 622, 106, 7, 320, 812, 814, 8, 321,
/* 710 */ 109, 111, 68, 69, 115, 704, 703, 38, 117, 700,
/* 700 */ 656, 314, 622, 106, 7, 320, 812, 321, 8, 109,
/* 710 */ 814, 111, 68, 69, 115, 704, 703, 38, 117, 700,
/* 720 */ 648, 646, 638, 644, 640, 642, 636, 634, 670, 669,
/* 730 */ 668, 666, 662, 658, 657, 190, 620, 585, 583, 859,
/* 740 */ 858, 858, 858, 858, 858, 858, 858, 858, 858, 858,
......@@ -338,24 +338,24 @@ static const YYCODETYPE yy_lookahead[] = {
/* 510 */ 246, 199, 199, 250, 199, 246, 269, 199, 199, 199,
/* 520 */ 199, 269, 254, 269, 259, 124, 260, 199, 258, 199,
/* 530 */ 257, 199, 199, 199, 199, 199, 269, 130, 199, 134,
/* 540 */ 136, 199, 129, 117, 200, 199, 138, 135, 199, 256,
/* 550 */ 199, 199, 199, 199, 199, 199, 128, 199, 199, 199,
/* 560 */ 127, 199, 199, 199, 199, 126, 199, 199, 199, 199,
/* 570 */ 199, 199, 125, 199, 140, 199, 199, 199, 199, 199,
/* 540 */ 136, 199, 128, 117, 200, 199, 138, 135, 199, 256,
/* 550 */ 199, 199, 199, 199, 199, 199, 127, 199, 199, 199,
/* 560 */ 126, 199, 199, 199, 199, 129, 199, 199, 199, 199,
/* 570 */ 199, 199, 125, 199, 89, 199, 199, 199, 199, 199,
/* 580 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199,
/* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 89, 200,
/* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 140, 200,
/* 600 */ 200, 113, 200, 200, 96, 95, 51, 92, 94, 55,
/* 610 */ 200, 93, 91, 84, 5, 200, 200, 153, 5, 5,
/* 620 */ 153, 200, 200, 5, 5, 100, 206, 210, 210, 206,
/* 630 */ 99, 142, 120, 82, 115, 83, 97, 121, 82, 97,
/* 640 */ 200, 200, 217, 219, 215, 218, 216, 201, 213, 212,
/* 650 */ 214, 201, 201, 200, 202, 201, 237, 200, 200, 221,
/* 660 */ 83, 255, 253, 252, 82, 251, 83, 97, 207, 237,
/* 670 */ 82, 1, 83, 82, 82, 97, 83, 82, 131, 131,
/* 680 */ 82, 97, 82, 115, 82, 116, 78, 71, 87, 86,
/* 630 */ 99, 142, 120, 82, 115, 83, 97, 121, 82, 200,
/* 640 */ 200, 213, 217, 219, 212, 218, 216, 214, 207, 201,
/* 650 */ 215, 201, 201, 200, 202, 201, 237, 200, 97, 221,
/* 660 */ 83, 255, 253, 252, 251, 200, 82, 97, 83, 82,
/* 670 */ 1, 83, 82, 82, 237, 83, 82, 97, 131, 97,
/* 680 */ 131, 82, 82, 115, 82, 116, 78, 71, 87, 86,
/* 690 */ 5, 87, 86, 9, 5, 5, 5, 5, 5, 5,
/* 700 */ 5, 15, 85, 78, 82, 24, 83, 117, 82, 59,
/* 710 */ 147, 147, 16, 16, 147, 5, 5, 97, 147, 83,
/* 700 */ 5, 15, 85, 78, 82, 24, 83, 59, 82, 147,
/* 710 */ 117, 147, 16, 16, 147, 5, 5, 97, 147, 83,
/* 720 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
/* 730 */ 5, 5, 5, 5, 5, 97, 85, 61, 60, 0,
/* 740 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276,
......@@ -399,9 +399,9 @@ static const unsigned short int yy_shift_ofst[] = {
/* 120 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
/* 130 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
/* 140 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
/* 150 */ 143, 444, 444, 444, 401, 401, 401, 444, 401, 444,
/* 160 */ 404, 408, 407, 412, 405, 413, 428, 433, 439, 447,
/* 170 */ 434, 444, 444, 444, 509, 509, 488, 12, 12, 444,
/* 150 */ 143, 444, 444, 444, 401, 401, 401, 401, 444, 444,
/* 160 */ 404, 408, 407, 412, 405, 414, 429, 434, 436, 447,
/* 170 */ 458, 444, 444, 444, 485, 485, 488, 12, 12, 444,
/* 180 */ 444, 508, 510, 555, 515, 514, 554, 518, 521, 488,
/* 190 */ 13, 444, 529, 529, 444, 529, 444, 529, 444, 444,
/* 200 */ 753, 753, 54, 81, 81, 108, 81, 134, 188, 205,
......@@ -411,12 +411,12 @@ static const unsigned short int yy_shift_ofst[] = {
/* 240 */ 345, 347, 348, 343, 350, 357, 431, 375, 426, 366,
/* 250 */ 118, 308, 314, 459, 460, 324, 327, 361, 331, 373,
/* 260 */ 609, 464, 613, 614, 467, 618, 619, 525, 531, 489,
/* 270 */ 512, 519, 551, 516, 552, 556, 539, 542, 577, 582,
/* 280 */ 583, 570, 588, 589, 591, 670, 592, 593, 595, 578,
/* 290 */ 547, 584, 548, 598, 519, 600, 568, 602, 569, 608,
/* 270 */ 512, 519, 551, 516, 552, 556, 539, 561, 577, 584,
/* 280 */ 585, 587, 588, 570, 590, 592, 591, 669, 594, 580,
/* 290 */ 547, 582, 549, 599, 519, 600, 568, 602, 569, 608,
/* 300 */ 601, 603, 616, 685, 604, 606, 684, 689, 690, 691,
/* 310 */ 692, 693, 694, 695, 617, 686, 625, 622, 623, 590,
/* 320 */ 626, 681, 650, 696, 563, 564, 620, 620, 620, 620,
/* 310 */ 692, 693, 694, 695, 617, 686, 625, 622, 623, 593,
/* 320 */ 626, 681, 648, 696, 562, 564, 620, 620, 620, 620,
/* 330 */ 697, 567, 571, 620, 620, 620, 710, 711, 636, 620,
/* 340 */ 715, 716, 717, 718, 719, 720, 721, 722, 723, 724,
/* 350 */ 725, 726, 727, 728, 729, 638, 651, 730, 731, 676,
......@@ -424,7 +424,7 @@ static const unsigned short int yy_shift_ofst[] = {
};
#define YY_REDUCE_COUNT (201)
#define YY_REDUCE_MIN (-265)
#define YY_REDUCE_MAX (461)
#define YY_REDUCE_MAX (465)
static const short yy_reduce_ofst[] = {
/* 0 */ -27, -33, -33, -193, -193, -76, -203, -199, -175, -184,
/* 10 */ -130, -134, 93, 24, 67, 119, 126, 135, 142, 148,
......@@ -441,12 +441,12 @@ static const short yy_reduce_ofst[] = {
/* 120 */ 365, 367, 368, 369, 370, 371, 372, 374, 376, 377,
/* 130 */ 378, 379, 380, 381, 382, 383, 384, 385, 386, 387,
/* 140 */ 388, 389, 390, 391, 392, 393, 394, 395, 396, 397,
/* 150 */ 398, 344, 399, 400, 247, 252, 254, 402, 267, 403,
/* 150 */ 398, 344, 399, 400, 247, 252, 254, 267, 402, 403,
/* 160 */ 246, 266, 265, 270, 273, 293, 406, 268, 409, 411,
/* 170 */ 414, 410, 415, 416, 417, 418, 419, 420, 423, 421,
/* 180 */ 422, 424, 427, 425, 435, 430, 436, 429, 437, 432,
/* 190 */ 438, 440, 446, 450, 441, 451, 453, 454, 457, 458,
/* 200 */ 461, 452,
/* 170 */ 413, 410, 415, 416, 417, 418, 419, 420, 423, 421,
/* 180 */ 422, 424, 427, 425, 428, 430, 433, 435, 432, 437,
/* 190 */ 438, 439, 448, 450, 440, 451, 453, 454, 457, 465,
/* 200 */ 441, 452,
};
static const YYACTIONTYPE yy_default[] = {
/* 0 */ 856, 979, 918, 989, 905, 915, 1126, 1126, 1126, 856,
......@@ -464,8 +464,8 @@ static const YYACTIONTYPE yy_default[] = {
/* 120 */ 856, 856, 856, 856, 856, 856, 903, 856, 901, 856,
/* 130 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856,
/* 140 */ 856, 856, 856, 856, 887, 856, 856, 856, 856, 856,
/* 150 */ 856, 878, 878, 878, 856, 856, 856, 878, 856, 878,
/* 160 */ 1076, 1080, 1062, 1074, 1070, 1061, 1057, 1055, 1053, 1052,
/* 150 */ 856, 878, 878, 878, 856, 856, 856, 856, 878, 878,
/* 160 */ 1076, 1080, 1062, 1074, 1070, 1057, 1055, 1053, 1061, 1052,
/* 170 */ 1084, 878, 878, 878, 923, 923, 919, 915, 915, 878,
/* 180 */ 878, 941, 939, 937, 929, 935, 931, 933, 927, 906,
/* 190 */ 856, 878, 913, 913, 878, 913, 878, 913, 878, 878,
......@@ -1039,10 +1039,10 @@ static const char *const yyTokenName[] = {
/* 250 */ "from",
/* 251 */ "where_opt",
/* 252 */ "interval_opt",
/* 253 */ "session_option",
/* 254 */ "windowstate_option",
/* 255 */ "fill_opt",
/* 256 */ "sliding_opt",
/* 253 */ "sliding_opt",
/* 254 */ "session_option",
/* 255 */ "windowstate_option",
/* 256 */ "fill_opt",
/* 257 */ "groupby_opt",
/* 258 */ "having_opt",
/* 259 */ "orderby_opt",
......@@ -1235,7 +1235,7 @@ static const char *const yyRuleName[] = {
/* 163 */ "tagitem ::= MINUS FLOAT",
/* 164 */ "tagitem ::= PLUS INTEGER",
/* 165 */ "tagitem ::= PLUS FLOAT",
/* 166 */ "select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt",
/* 166 */ "select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt",
/* 167 */ "select ::= LP select RP",
/* 168 */ "union ::= select",
/* 169 */ "union ::= union UNION ALL select",
......@@ -1490,7 +1490,7 @@ tSqlExprListDestroy((yypminor->yy525));
case 243: /* columnlist */
case 244: /* tagitemlist */
case 245: /* tagNamelist */
case 255: /* fill_opt */
case 256: /* fill_opt */
case 257: /* groupby_opt */
case 259: /* orderby_opt */
case 270: /* sortlist */
......@@ -1991,7 +1991,7 @@ static const struct {
{ 248, -2 }, /* (163) tagitem ::= MINUS FLOAT */
{ 248, -2 }, /* (164) tagitem ::= PLUS INTEGER */
{ 248, -2 }, /* (165) tagitem ::= PLUS FLOAT */
{ 246, -14 }, /* (166) select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */
{ 246, -14 }, /* (166) select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */
{ 246, -3 }, /* (167) select ::= LP select RP */
{ 262, -1 }, /* (168) union ::= select */
{ 262, -4 }, /* (169) union ::= union UNION ALL select */
......@@ -2019,15 +2019,15 @@ static const struct {
{ 252, -4 }, /* (191) interval_opt ::= INTERVAL LP tmvar RP */
{ 252, -6 }, /* (192) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */
{ 252, 0 }, /* (193) interval_opt ::= */
{ 253, 0 }, /* (194) session_option ::= */
{ 253, -7 }, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */
{ 254, 0 }, /* (196) windowstate_option ::= */
{ 254, -4 }, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */
{ 255, 0 }, /* (198) fill_opt ::= */
{ 255, -6 }, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ 255, -4 }, /* (200) fill_opt ::= FILL LP ID RP */
{ 256, -4 }, /* (201) sliding_opt ::= SLIDING LP tmvar RP */
{ 256, 0 }, /* (202) sliding_opt ::= */
{ 254, 0 }, /* (194) session_option ::= */
{ 254, -7 }, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */
{ 255, 0 }, /* (196) windowstate_option ::= */
{ 255, -4 }, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */
{ 256, 0 }, /* (198) fill_opt ::= */
{ 256, -6 }, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{ 256, -4 }, /* (200) fill_opt ::= FILL LP ID RP */
{ 253, -4 }, /* (201) sliding_opt ::= SLIDING LP tmvar RP */
{ 253, 0 }, /* (202) sliding_opt ::= */
{ 259, 0 }, /* (203) orderby_opt ::= */
{ 259, -3 }, /* (204) orderby_opt ::= ORDER BY sortlist */
{ 270, -4 }, /* (205) sortlist ::= sortlist COMMA item sortorder */
......@@ -2723,9 +2723,9 @@ static void yy_reduce(
}
yymsp[-1].minor.yy506 = yylhsminor.yy506;
break;
case 166: /* select ::= SELECT selcollist from where_opt interval_opt session_option windowstate_option fill_opt sliding_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */
case 166: /* select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */
{
yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy525, yymsp[-11].minor.yy412, yymsp[-10].minor.yy370, yymsp[-4].minor.yy525, yymsp[-2].minor.yy525, &yymsp[-9].minor.yy520, &yymsp[-8].minor.yy259, &yymsp[-7].minor.yy144, &yymsp[-5].minor.yy0, yymsp[-6].minor.yy525, &yymsp[0].minor.yy126, &yymsp[-1].minor.yy126, yymsp[-3].minor.yy370);
yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy525, yymsp[-11].minor.yy412, yymsp[-10].minor.yy370, yymsp[-4].minor.yy525, yymsp[-2].minor.yy525, &yymsp[-9].minor.yy520, &yymsp[-7].minor.yy259, &yymsp[-6].minor.yy144, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy525, &yymsp[0].minor.yy126, &yymsp[-1].minor.yy126, yymsp[-3].minor.yy370);
}
yymsp[-13].minor.yy464 = yylhsminor.yy464;
break;
......
......@@ -29,7 +29,9 @@ typedef void* SMergeBuf;
SDataRow tsdbMergeTwoRows(SMergeBuf *pBuf, SMemRow row1, SMemRow row2, STSchema *pSchema1, STSchema *pSchema2);
static FORCE_INLINE int tsdbMergeBufMakeSureRoom(SMergeBuf *pBuf, STSchema* pSchema1, STSchema* pSchema2) {
return tsdbMakeRoom(pBuf, MAX(dataRowMaxBytesFromSchema(pSchema1), dataRowMaxBytesFromSchema(pSchema2)));
size_t len1 = dataRowMaxBytesFromSchema(pSchema1);
size_t len2 = dataRowMaxBytesFromSchema(pSchema2);
return tsdbMakeRoom(pBuf, MAX(len1, len2));
}
static FORCE_INLINE void tsdbFreeMergeBuf(SMergeBuf buf) {
......
......@@ -1035,6 +1035,8 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
}
}
}
pMeta->maxCols = maxCols;
pMeta->maxRowBytes = maxRowBytes;
if (lock) tsdbUnlockRepoMeta(pRepo);
tsdbDebug("vgId:%d table %s uid %" PRIu64 " is removed from meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_UID(pTable));
......
......@@ -1234,7 +1234,6 @@ static int32_t doCopyRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, int32_t c
static void moveDataToFront(STsdbQueryHandle* pQueryHandle, int32_t numOfRows, int32_t numOfCols);
static void doCheckGeneratedBlockRange(STsdbQueryHandle* pQueryHandle);
static void copyAllRemainRowsFromFileBlock(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SDataBlockInfo* pBlockInfo, int32_t endPos);
static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, int32_t update);
static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo){
SQueryFilePos* cur = &pQueryHandle->cur;
......@@ -1244,7 +1243,6 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p
int32_t code = TSDB_CODE_SUCCESS;
/*bool hasData = */ initTableMemIterator(pQueryHandle, pCheckInfo);
assert(cur->pos >= 0 && cur->pos <= binfo.rows);
key = extractFirstTraverseKey(pCheckInfo, pQueryHandle->order, pCfg->update);
......@@ -1255,7 +1253,6 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p
tsdbDebug("%p no data in mem, 0x%"PRIx64, pQueryHandle, pQueryHandle->qId);
}
if ((ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) ||
(!ASCENDING_TRAVERSE(pQueryHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) {
......@@ -2708,7 +2705,7 @@ static bool loadBlockOfActiveTable(STsdbQueryHandle* pQueryHandle) {
}
if (exists) {
tsdbRetrieveDataBlock((TsdbQueryHandleT) pQueryHandle, NULL);
tsdbRetrieveDataBlock((TsdbQueryHandleT*) pQueryHandle, NULL);
if (pQueryHandle->currentLoadExternalRows && pQueryHandle->window.skey == pQueryHandle->window.ekey) {
SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, 0);
assert(*(int64_t*)pColInfo->pData == pQueryHandle->window.skey);
......
......@@ -518,6 +518,8 @@ static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32
return -1;
}
tdAllocMemForCol(pDataCol, maxPoints);
// Decode the data
if (comp) {
// Need to decompress
......
......@@ -127,6 +127,16 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen);
*/
void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void* d);
/**
* @param pHashObj
* @param key
* @param keyLen
* @param fp
* @param d
* @param sz
* @return
*/
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz);
/**
* remove item with the specified key
* @param pHashObj
......
......@@ -18,6 +18,8 @@
#include "tulog.h"
#include "taosdef.h"
#define EXT_SIZE 1024
#define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR)
#define DO_FREE_HASH_NODE(_n) \
......@@ -296,6 +298,68 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da
void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen) {
return taosHashGetClone(pHashObj, key, keyLen, NULL, NULL);
}
//TODO(yihaoDeng), merge with taosHashGetClone
void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void** d, size_t *sz) {
if (taosHashTableEmpty(pHashObj) || keyLen == 0 || key == NULL) {
return NULL;
}
uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen);
// only add the read lock to disable the resize process
__rd_lock(&pHashObj->lock, pHashObj->type);
int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity);
SHashEntry *pe = pHashObj->hashList[slot];
// no data, return directly
if (atomic_load_32(&pe->num) == 0) {
__rd_unlock(&pHashObj->lock, pHashObj->type);
return NULL;
}
char *data = NULL;
// lock entry
if (pHashObj->type == HASH_ENTRY_LOCK) {
taosRLockLatch(&pe->latch);
}
if (pe->num > 0) {
assert(pe->next != NULL);
} else {
assert(pe->next == NULL);
}
SHashNode *pNode = doSearchInEntryList(pHashObj, pe, key, keyLen, hashVal);
if (pNode != NULL) {
if (fp != NULL) {
fp(GET_HASH_NODE_DATA(pNode));
}
if (*d == NULL) {
*sz = pNode->dataLen + EXT_SIZE;
*d = calloc(1, *sz);
} else if (*sz < pNode->dataLen){
*sz = pNode->dataLen + EXT_SIZE;
*d = realloc(*d, *sz);
}
memcpy((char *)(*d), GET_HASH_NODE_DATA(pNode), pNode->dataLen);
// just make runtime happy
if ((*sz) - pNode->dataLen > 0) {
memset((char *)(*d) + pNode->dataLen, 0, (*sz) - pNode->dataLen);
}
data = GET_HASH_NODE_DATA(pNode);
}
if (pHashObj->type == HASH_ENTRY_LOCK) {
taosRUnLockLatch(&pe->latch);
}
__rd_unlock(&pHashObj->lock, pHashObj->type);
return data;
}
void* taosHashGetClone(SHashObj *pHashObj, const void *key, size_t keyLen, void (*fp)(void *), void* d) {
if (taosHashTableEmpty(pHashObj) || keyLen == 0 || key == NULL) {
......
......@@ -26,6 +26,7 @@ extern "C" {
#include "vnode.h"
extern int32_t vDebugFlag;
extern int32_t vNumOfExistedQHandle; // current initialized and existed query handle in current dnode
#define vFatal(...) { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", 255, __VA_ARGS__); }}
#define vError(...) { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", 255, __VA_ARGS__); }}
......
......@@ -21,6 +21,8 @@
#include "query.h"
#include "vnodeStatus.h"
int32_t vNumOfExistedQHandle; // current initialized and existed query handle in current dnode
static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *pVnode, SVReadMsg *pRead);
static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead);
static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead);
......@@ -247,7 +249,8 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
if (handle == NULL) { // failed to register qhandle
pRsp->code = terrno;
terrno = 0;
vError("vgId:%d, QInfo:0x%"PRIx64 "-%p register qhandle failed, return to app, code:%s", pVnode->vgId, qId, (void *)pQInfo,
vError("vgId:%d, QInfo:0x%"PRIx64 "-%p register qhandle failed, return to app, code:%s,", pVnode->vgId, qId, (void *)pQInfo,
tstrerror(pRsp->code));
qDestroyQueryInfo(pQInfo); // destroy it directly
return pRsp->code;
......@@ -260,10 +263,12 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
vnodeNotifyCurrentQhandle(pRead->rpcHandle, qId, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
vError("vgId:%d, QInfo:0x%"PRIx64 "-%p, query discarded since link is broken, %p", pVnode->vgId, qId, *handle,
pRead->rpcHandle);
pRsp->code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
return pRsp->code;
}
} else {
assert(pQInfo == NULL);
}
......@@ -277,6 +282,9 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
return pRsp->code;
}
}
int32_t remain = atomic_add_fetch_32(&vNumOfExistedQHandle, 1);
vTrace("vgId:%d, new qhandle created, total qhandle:%d", pVnode->vgId, remain);
} else {
assert(pCont != NULL);
void **qhandle = (void **)pRead->qhandle;
......@@ -318,8 +326,14 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// NOTE: if the qhandle is not put into vread queue or query is completed, free the qhandle.
// If the building of result is not required, simply free it. Otherwise, mandatorily free the qhandle
if (freehandle || (!buildRes)) {
if (freehandle) {
int32_t remain = atomic_sub_fetch_32(&vNumOfExistedQHandle, 1);
vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *qhandle, remain);
}
qReleaseQInfo(pVnode->qMgmt, (void **)&qhandle, freehandle);
}
}
}
......@@ -357,7 +371,10 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// kill current query and free corresponding resources.
if (pRetrieve->free == 1) {
vWarn("vgId:%d, QInfo:%"PRIx64 "-%p, retrieve msg received to kill query and free qhandle", pVnode->vgId, pRetrieve->qId, *handle);
int32_t remain = atomic_sub_fetch_32(&vNumOfExistedQHandle, 1);
vWarn("vgId:%d, QInfo:%"PRIx64 "-%p, retrieve msg received to kill query and free qhandle, remain qhandle:%d", pVnode->vgId, pRetrieve->qId,
*handle, remain);
qKillQuery(*handle);
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
......@@ -368,7 +385,10 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// register the qhandle to connect to quit query immediate if connection is broken
if (vnodeNotifyCurrentQhandle(pRead->rpcHandle, pRetrieve->qId, *handle, pVnode->vgId) != TSDB_CODE_SUCCESS) {
vError("vgId:%d, QInfo:%"PRIu64 "-%p, retrieve discarded since link is broken, conn:%p", pVnode->vgId, pRetrieve->qhandle, *handle, pRead->rpcHandle);
int32_t remain = atomic_sub_fetch_32(&vNumOfExistedQHandle, 1);
vError("vgId:%d, QInfo:%"PRIu64 "-%p, retrieve discarded since link is broken, conn:%p, remain qhandle:%d", pVnode->vgId, pRetrieve->qhandle,
*handle, pRead->rpcHandle, remain);
code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
qKillQuery(*handle);
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
......@@ -390,7 +410,6 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
if (!tsRetrieveBlockingModel) {
if (!buildRes) {
assert(pRead->rpcHandle != NULL);
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, false);
return TSDB_CODE_QRY_NOT_READY;
}
......@@ -403,6 +422,8 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pRead) {
// If qhandle is not added into vread queue, the query should be completed already or paused with error.
// Here free qhandle immediately
if (freeHandle) {
int32_t remain = atomic_sub_fetch_32(&vNumOfExistedQHandle, 1);
vTrace("vgId:%d, QInfo:%p, start to free qhandle, remain qhandle:%d", pVnode->vgId, *handle, remain);
qReleaseQInfo(pVnode->qMgmt, (void **)&handle, true);
}
......
......@@ -148,6 +148,9 @@ python3 ./test.py -f import_merge/importTPORestart.py
python3 ./test.py -f import_merge/importTRestart.py
python3 ./test.py -f import_merge/importInsertThenImport.py
python3 ./test.py -f import_merge/importCSV.py
python3 ./test.py -f import_merge/import_update_0.py
python3 ./test.py -f import_merge/import_update_1.py
python3 ./test.py -f import_merge/import_update_2.py
#======================p1-end===============
#======================p2-start===============
# tools
......@@ -376,6 +379,7 @@ python3 test.py -f alter/alter_cacheLastRow.py
python3 ./test.py -f query/querySession.py
python3 test.py -f alter/alter_create_exception.py
python3 ./test.py -f insert/flushwhiledrop.py
python3 ./test.py -f insert/schemalessInsert.py
#======================p4-end===============
python3 test.py -f tools/taosdemoAllTest/pytest.py
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -65,7 +65,7 @@ class TDSql:
self.queryResult = None
tdLog.info("sql:%s, expect error occured" % (sql))
def query(self, sql):
def query(self, sql, row_tag=None):
self.sql = sql
try:
self.cursor.execute(sql)
......@@ -77,21 +77,27 @@ class TDSql:
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
raise Exception(repr(e))
if row_tag:
return self.queryResult
return self.queryRows
def getColNameList(self, sql):
def getColNameList(self, sql, col_tag=None):
self.sql = sql
try:
col_name_list = []
col_type_list = []
self.cursor.execute(sql)
self.queryCols = self.cursor.description
for query_col in self.queryCols:
col_name_list.append(query_col[0])
col_type_list.append(query_col[1])
except Exception as e:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
raise Exception(repr(e))
if col_tag:
return col_name_list, col_type_list
return col_name_list
def waitedQuery(self, sql, expectRows, timeout):
......@@ -245,6 +251,22 @@ class TDSql:
args = (caller.filename, caller.lineno, self.sql, col_name_list, expect_col_name_list)
tdLog.exit("%s(%d) failed: sql:%s, col_name_list:%s != expect_col_name_list:%s" % args)
def checkEqual(self, elm, expect_elm):
if elm == expect_elm:
tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm))
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, elm, expect_elm)
tdLog.exit("%s(%d) failed: sql:%s, elm:%s != expect_elm:%s" % args)
def checkNotEqual(self, elm, expect_elm):
if elm != expect_elm:
tdLog.info("sql:%s, elm:%s != expect_elm:%s" % (self.sql, elm, expect_elm))
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, elm, expect_elm)
tdLog.exit("%s(%d) failed: sql:%s, elm:%s == expect_elm:%s" % args)
def taosdStatus(self, state):
tdLog.sleep(5)
pstate = 0
......
......@@ -30,7 +30,7 @@ while $i < 5
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , 0, 0 )
sql insert into $tb values (1626739200000 + $ms , 0, 0 )
$x = $x + 1
endw
$i = $i + 1
......@@ -41,7 +41,7 @@ while $i < 10
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , 1, 1 )
sql insert into $tb values (1626739200000 + $ms , 1, 1 )
$x = $x + 1
endw
$i = $i + 1
......@@ -116,103 +116,104 @@ if $rows != 100 then
endi
print =============== step4
sql select * from $mt where ts > now + 4m and tbcol = 1
# sql select * from $mt where ts > 1626739440001 and tbcol = 1
sql select * from $mt where ts > 1626739440001 and tbcol = 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol <> 1
sql select * from $mt where ts > 1626739440001 and tbcol <> 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol = 0
sql select * from $mt where ts < 1626739440001 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol <> 0
sql select * from $mt where ts < 1626739440001 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol = 0
sql select * from $mt where ts <= 1626739440001 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts > now + 4m and ts < now + 5m and tbcol <> 0
sql select * from $mt where ts >= 1626739440001 and ts < 1626739500001 and tbcol <> 0
if $rows != 5 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol <> 0 and ts < now + 5m
sql select * from $mt where ts >= 1626739440001 and tbcol <> 0 and ts < 1626739500001
if $rows != 5 then
return -1
endi
print =============== step5
sql select * from $mt where ts > now + 4m and tbcol2 = 1
sql select * from $mt where ts > 1626739440001 and tbcol2 = 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol2 <> 1
sql select * from $mt where ts > 1626739440001 and tbcol2 <> 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol2 = 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol2 <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol2 = 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol2 <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts > now + 4m and ts < now + 5m and tbcol2 <> 0
sql select * from $mt where ts >= 1626739440001 and ts < 1626739500001 and tbcol2 <> 0
if $rows != 5 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol2 <> 0 and ts < now + 5m
sql select * from $mt where ts >= 1626739440001 and tbcol2 <> 0 and ts < 1626739500001
if $rows != 5 then
return -1
endi
print =============== step6
sql select * from $mt where ts > now + 4m and tbcol2 = 1 and tbcol = 1
sql select * from $mt where ts > 1626739440001 and tbcol2 = 1 and tbcol = 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol2 <> 1 and tbcol <> 1
sql select * from $mt where ts > 1626739440001 and tbcol2 <> 1 and tbcol <> 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol2 = 0 and tbcol = 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 = 0 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol2 <> 0 and tbcol <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 <> 0 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol2 = 0 and tbcol = 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 = 0 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol2 <> 0 and tbcol <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol2 <> 0 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts > now + 4m and ts < now + 5m and tbcol2 <> 0 and tbcol <> 0
sql select * from $mt where ts >= 1626739440001 and ts < 1626739500001 and tbcol2 <> 0 and tbcol <> 0
if $rows != 5 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol2 <> 0 and ts < now + 5m and ts < now + 5m and tbcol <> 0
sql select * from $mt where ts >= 1626739440001 and tbcol2 <> 0 and ts < 1626739500001 and ts < 1626739500001 and tbcol <> 0
if $rows != 5 then
return -1
endi
......@@ -246,7 +247,7 @@ if $data00 != 100 then
endi
print =============== step9
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts <= 1626739440001
print $data00 $data01 $data02 $data03 $data04 $data05 $data06
if $data00 != 50 then
return -1
......@@ -272,7 +273,7 @@ if $data00 != 100 then
endi
print =============== step11
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m and tbcol = 1 group by tgcol
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts <= 1626739440001 and tbcol = 1 group by tgcol
print $data00 $data01 $data02 $data03 $data04 $data05 $data06
if $data00 != 25 then
return -1
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -30,7 +30,7 @@ while $i < 5
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , 0 )
sql insert into $tb values (1626739200000 + $ms , 0 )
$x = $x + 1
endw
$i = $i + 1
......@@ -41,7 +41,7 @@ while $i < 10
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , 1 )
sql insert into $tb values (1626739200000 + $ms , 1 )
$x = $x + 1
endw
$i = $i + 1
......@@ -82,35 +82,35 @@ if $rows != 100 then
endi
print =============== step3
sql select * from $mt where ts > now + 4m and tbcol = 1
sql select * from $mt where ts > 1626739440001 and tbcol = 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol <> 1
sql select * from $mt where ts > 1626739440001 and tbcol <> 1
if $rows != 75 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol = 0
sql select * from $mt where ts < 1626739440001 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts < now + 4m and tbcol <> 0
sql select * from $mt where ts < 1626739440001 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol = 0
sql select * from $mt where ts <= 1626739440001 and tbcol = 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts <= now + 4m and tbcol <> 0
sql select * from $mt where ts <= 1626739440001 and tbcol <> 0
if $rows != 25 then
return -1
endi
sql select * from $mt where ts > now + 4m and ts < now + 5m and tbcol <> 0
sql select * from $mt where ts > 1626739440001 and ts < 1626739500001 and tbcol <> 0
if $rows != 5 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol <> 0 and ts < now + 5m
sql select * from $mt where ts > 1626739440001 and tbcol <> 0 and ts < 1626739500001
if $rows != 5 then
return -1
endi
......@@ -139,7 +139,7 @@ if $data00 != 100 then
endi
print =============== step7
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m and tbcol = 1 group by tgcol
sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1626739440001 and tbcol = 1 group by tgcol
print $data00 $data01 $data02 $data03 $data04 $data05 $data06
if $data00 != 25 then
return -1
......
......@@ -30,7 +30,7 @@ while $i < 5
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , '0' )
sql insert into $tb values (1626739200000 + $ms , '0' )
$x = $x + 1
endw
$i = $i + 1
......@@ -41,7 +41,7 @@ while $i < 10
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , '1' )
sql insert into $tb values (1626739200000 + $ms , '1' )
$x = $x + 1
endw
$i = $i + 1
......@@ -55,14 +55,14 @@ if $rows != 100 then
return -1
endi
sql select * from $mt where ts > now + 4m and tbcol = '1'
sql select * from $mt where ts > 1626739440001 and tbcol = '1'
if $rows != 75 then
return -1
endi
print select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = '1'
sql_error select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = '1' group by tgcol
sql_error select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < now + 4m and tbcol = '1' group by tgcol
sql_error select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where ts < 1626739440001 and tbcol = '1' group by tgcol
sql_error select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = '1' interval(1d) group by tgcol
#can't filter binary fields
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册