提交 ba5d069a 编写于 作者: D dapan1121

support interp

上级 bfcee759
...@@ -147,6 +147,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i ...@@ -147,6 +147,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
* @return * @return
*/ */
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo); bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
bool tscGetPointInterpQuery(SQueryInfo* pQueryInfo);
bool tscIsTWAQuery(SQueryInfo* pQueryInfo); bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
bool tscIsIrateQuery(SQueryInfo* pQueryInfo); bool tscIsIrateQuery(SQueryInfo* pQueryInfo);
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId); bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId);
......
...@@ -101,6 +101,7 @@ static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQuery ...@@ -101,6 +101,7 @@ static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQuery
static int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql); static int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql);
static int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); static int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode);
static int32_t validateRangeNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode);
static int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSchema* pSchema); static int32_t validateOrderbyNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSchema* pSchema);
static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd, SQueryInfo* pQueryInfo);
...@@ -116,7 +117,6 @@ static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killTy ...@@ -116,7 +117,6 @@ static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killTy
static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo); static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static int32_t validateOneTag(SSqlCmd* pCmd, TAOS_FIELD* pTagField); static int32_t validateOneTag(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
static bool hasNormalColumnFilter(SQueryInfo* pQueryInfo); static bool hasNormalColumnFilter(SQueryInfo* pQueryInfo);
static int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql); static int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql);
...@@ -1120,7 +1120,8 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS ...@@ -1120,7 +1120,8 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS
const char* msg1 = "sliding cannot be used without interval"; const char* msg1 = "sliding cannot be used without interval";
const char* msg2 = "interval cannot be less than 1 us"; const char* msg2 = "interval cannot be less than 1 us";
const char* msg3 = "interval value is too small"; const char* msg3 = "interval value is too small";
const char* msg4 = "only point interpolation query requires keyword EVERY"; const char* msg4 = "invalid usage of EVERY";
const char* msg5 = "EVERY instead of INTERVAL required for interp clause";
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
...@@ -1132,6 +1133,12 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS ...@@ -1132,6 +1133,12 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
bool interpQuery = tscGetPointInterpQuery(pQueryInfo);
if (interpQuery) {
return addPrimaryTsColumnForTimeWindowQuery(pQueryInfo, pCmd);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -1166,11 +1173,15 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS ...@@ -1166,11 +1173,15 @@ int32_t validateIntervalNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pS
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
bool interpQuery = tscIsPointInterpQuery(pQueryInfo); bool interpQuery = tscGetPointInterpQuery(pQueryInfo);
if ((pSqlNode->interval.token == TK_EVERY && (!interpQuery)) || (pSqlNode->interval.token == TK_INTERVAL && interpQuery)) { if (pSqlNode->interval.token == TK_EVERY && (!interpQuery)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
} }
if (pSqlNode->interval.token == TK_INTERVAL && interpQuery) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
// The following part is used to check for the invalid query expression. // The following part is used to check for the invalid query expression.
return checkInvalidExprForTimeWindow(pCmd, pQueryInfo); return checkInvalidExprForTimeWindow(pCmd, pQueryInfo);
} }
...@@ -1182,6 +1193,7 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS ...@@ -1182,6 +1193,7 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
const char* msg3 = "not support state_window with group by "; const char* msg3 = "not support state_window with group by ";
const char* msg4 = "function not support for super table query"; const char* msg4 = "function not support for super table query";
const char* msg5 = "not support state_window on tag column"; const char* msg5 = "not support state_window on tag column";
const char* msg6 = "function not support for state_window";
SStrToken *col = &(pSqlNode->windowstateVal.col) ; SStrToken *col = &(pSqlNode->windowstateVal.col) ;
if (col->z == NULL || col->n <= 0) { if (col->z == NULL || col->n <= 0) {
...@@ -1227,6 +1239,11 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS ...@@ -1227,6 +1239,11 @@ static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
bool interpQuery = tscGetPointInterpQuery(pQueryInfo);
if (interpQuery) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema); tscColumnListInsert(pQueryInfo->colList, index.columnIndex, pTableMeta->id.uid, pSchema);
SColIndex colIndex = { .colIndex = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId }; SColIndex colIndex = { .colIndex = index.columnIndex, .flag = TSDB_COL_NORMAL, .colId = pSchema->colId };
taosArrayPush(pGroupExpr->columnInfo, &colIndex); taosArrayPush(pGroupExpr->columnInfo, &colIndex);
...@@ -1240,6 +1257,7 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS ...@@ -1240,6 +1257,7 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS
const char* msg2 = "only one type time window allowed"; const char* msg2 = "only one type time window allowed";
const char* msg3 = "invalid column name"; const char* msg3 = "invalid column name";
const char* msg4 = "invalid time window"; const char* msg4 = "invalid time window";
const char* msg5 = "function not support for session";
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
...@@ -1275,6 +1293,11 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS ...@@ -1275,6 +1293,11 @@ int32_t validateSessionNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode * pS
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
bool interpQuery = tscGetPointInterpQuery(pQueryInfo);
if (interpQuery) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
pQueryInfo->sessionWindow.primaryColId = PRIMARYKEY_TIMESTAMP_COL_INDEX; pQueryInfo->sessionWindow.primaryColId = PRIMARYKEY_TIMESTAMP_COL_INDEX;
// The following part is used to check for the invalid query expression. // The following part is used to check for the invalid query expression.
...@@ -1285,6 +1308,7 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of ...@@ -1285,6 +1308,7 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of
const char* msg1 = "interval offset cannot be negative"; const char* msg1 = "interval offset cannot be negative";
const char* msg2 = "interval offset should be shorter than interval"; const char* msg2 = "interval offset should be shorter than interval";
const char* msg3 = "cannot use 'year' as offset when interval is 'month'"; const char* msg3 = "cannot use 'year' as offset when interval is 'month'";
const char* msg4 = "wrong every format";
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta); STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
...@@ -1296,6 +1320,11 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of ...@@ -1296,6 +1320,11 @@ int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* of
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool interpQuery = tscIsPointInterpQuery(pQueryInfo);
if (interpQuery) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.offset, if (parseNatualDuration(t->z, t->n, &pQueryInfo->interval.offset,
&pQueryInfo->interval.offsetUnit, tinfo.precision) != TSDB_CODE_SUCCESS) { &pQueryInfo->interval.offsetUnit, tinfo.precision) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
...@@ -1334,6 +1363,7 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl ...@@ -1334,6 +1363,7 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl
const char* msg1 = "sliding value no larger than the interval value"; const char* msg1 = "sliding value no larger than the interval value";
const char* msg2 = "sliding value can not less than 1% of interval value"; const char* msg2 = "sliding value can not less than 1% of interval value";
const char* msg3 = "does not support sliding when interval is natural month/year"; const char* msg3 = "does not support sliding when interval is natural month/year";
const char* msg4 = "sliding not support for interp query";
const static int32_t INTERVAL_SLIDING_FACTOR = 100; const static int32_t INTERVAL_SLIDING_FACTOR = 100;
...@@ -1347,6 +1377,11 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl ...@@ -1347,6 +1377,11 @@ int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSl
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool interpQuery = tscIsPointInterpQuery(pQueryInfo);
if (interpQuery) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') { if (pInterval->intervalUnit == 'n' || pInterval->intervalUnit == 'y') {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
} }
...@@ -2346,6 +2381,12 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS ...@@ -2346,6 +2381,12 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return -1; return -1;
} }
} else if (f == TSDB_FUNC_INTERP) {
int32_t t1 = pSchema->type;
if (!IS_NUMERIC_TYPE(t1)) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return -1;
}
} }
int16_t resType = 0; int16_t resType = 0;
...@@ -3485,8 +3526,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) { ...@@ -3485,8 +3526,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) {
} }
bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) { bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE are not allowed to apply to super table directly"; const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE/INTERP are not allowed to apply to super table directly";
const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE only support group by tbname for super table query"; const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE/INTERP only support group by tbname for super table query";
const char* msg3 = "functions not support for super table query"; const char* msg3 = "functions not support for super table query";
// filter sql function not supported by metric query yet. // filter sql function not supported by metric query yet.
...@@ -3504,7 +3545,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) ...@@ -3504,7 +3545,7 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
} }
if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivLikeQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo) || if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivLikeQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo) ||
tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE)) { tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE) || tscGetPointInterpQuery(pQueryInfo)) {
if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) { if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return true; return true;
...@@ -3515,6 +3556,11 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) ...@@ -3515,6 +3556,11 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
return true; return true;
} }
if (tscGetPointInterpQuery(pQueryInfo) && taosArrayGetSize(pQueryInfo->groupbyExpr.columnInfo) > 1) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
return true;
}
} else if (tscIsSessionWindowQuery(pQueryInfo)) { } else if (tscIsSessionWindowQuery(pQueryInfo)) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return true; return true;
...@@ -5591,9 +5637,9 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5591,9 +5637,9 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
const char* msg3 = "top/bottom/sample not support fill"; const char* msg3 = "top/bottom/sample not support fill";
const char* msg4 = "illegal value or data overflow"; const char* msg4 = "illegal value or data overflow";
const char* msg5 = "fill only available for interval query"; const char* msg5 = "fill only available for interval query";
const char* msg6 = "not supported function now";
if ((!isTimeWindowQuery(pQueryInfo)) && (!tscIsPointInterpQuery(pQueryInfo))) { bool pointInterp = tscIsPointInterpQuery(pQueryInfo);
if ((!isTimeWindowQuery(pQueryInfo)) && (!pointInterp)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
} }
...@@ -5601,11 +5647,10 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5601,11 +5647,10 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
* fill options are set at the end position, when all columns are set properly * fill options are set at the end position, when all columns are set properly
* the columns may be increased due to group by operation * the columns may be increased due to group by operation
*/ */
if (checkQueryRangeForFill(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) { if ((!pointInterp) && checkQueryRangeForFill(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
if (pItem->pVar.nType != TSDB_DATA_TYPE_BINARY) { if (pItem->pVar.nType != TSDB_DATA_TYPE_BINARY) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
...@@ -5630,9 +5675,6 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5630,9 +5675,6 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
} }
} else if (strncasecmp(pItem->pVar.pz, "prev", 4) == 0 && pItem->pVar.nLen == 4) { } else if (strncasecmp(pItem->pVar.pz, "prev", 4) == 0 && pItem->pVar.nLen == 4) {
pQueryInfo->fillType = TSDB_FILL_PREV; pQueryInfo->fillType = TSDB_FILL_PREV;
if (tscIsPointInterpQuery(pQueryInfo) && pQueryInfo->order.order == TSDB_ORDER_DESC) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
} else if (strncasecmp(pItem->pVar.pz, "next", 4) == 0 && pItem->pVar.nLen == 4) { } else if (strncasecmp(pItem->pVar.pz, "next", 4) == 0 && pItem->pVar.nLen == 4) {
pQueryInfo->fillType = TSDB_FILL_NEXT; pQueryInfo->fillType = TSDB_FILL_NEXT;
} else if (strncasecmp(pItem->pVar.pz, "linear", 6) == 0 && pItem->pVar.nLen == 6) { } else if (strncasecmp(pItem->pVar.pz, "linear", 6) == 0 && pItem->pVar.nLen == 6) {
...@@ -5649,7 +5691,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5649,7 +5691,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
int32_t numOfFillVal = (int32_t)(num - 1); int32_t numOfFillVal = (int32_t)(num - 1);
/* for point interpolation query, we do not have the timestamp column */ /* for point interpolation query, we do not have the timestamp column */
if (tscIsPointInterpQuery(pQueryInfo)) { if (pointInterp) {
startPos = 0; startPos = 0;
if (numOfFillVal > numOfFields) { if (numOfFillVal > numOfFields) {
...@@ -5676,7 +5718,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5676,7 +5718,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
} }
} }
if ((num < numOfFields) || ((num - 1 < numOfFields) && (tscIsPointInterpQuery(pQueryInfo)))) { if ((num < numOfFields) || ((num - 1 < numOfFields) && pointInterp)) {
tVariantListItem* lastItem = taosArrayGetLast(pFillToken); tVariantListItem* lastItem = taosArrayGetLast(pFillToken);
for (int32_t i = numOfFillVal; i < numOfFields; ++i) { for (int32_t i = numOfFillVal; i < numOfFields; ++i) {
...@@ -5705,6 +5747,55 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo ...@@ -5705,6 +5747,55 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t validateRangeNode(SSqlObj* pSql, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode) {
const char *msg0 = "invalid usage of range clause";
const char* msg1 = "invalid timestamp in range";
SSqlCmd* pCmd = &pSql->cmd;
bool interpQuery = tscIsPointInterpQuery(pQueryInfo);
if ((!interpQuery) && (pSqlNode->pRange.start || pSqlNode->pRange.end)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0);
}
if (pSqlNode->pRange.start == NULL || pSqlNode->pRange.end == NULL) {
pQueryInfo->range.skey = INT64_MIN;
pQueryInfo->range.ekey = INT64_MIN;
tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"]", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey);
return TSDB_CODE_SUCCESS;
}
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
STableComInfo tinfo = tscGetTableInfo(pTableMetaInfo->pTableMeta);
if (getTimeRange(&pQueryInfo->range, pSqlNode->pRange.start, TK_GE, tinfo.precision) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if (getTimeRange(&pQueryInfo->range, pSqlNode->pRange.end, TK_LE, tinfo.precision) != TSDB_CODE_SUCCESS) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if (pQueryInfo->range.ekey < pQueryInfo->range.skey) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if ((pQueryInfo->range.skey > pQueryInfo->window.ekey && (pQueryInfo->fillType == TSDB_FILL_NONE || pQueryInfo->fillType == TSDB_FILL_LINEAR || pQueryInfo->fillType == TSDB_FILL_NEXT))
|| (pQueryInfo->range.ekey < pQueryInfo->window.skey && (pQueryInfo->fillType == TSDB_FILL_NONE || pQueryInfo->fillType == TSDB_FILL_LINEAR || pQueryInfo->fillType == TSDB_FILL_PREV))) {
tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"], no output result", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey);
pQueryInfo->command = TSDB_SQL_RETRIEVE_EMPTY_RESULT;
return TSDB_CODE_SUCCESS;
}
tscDebug("0x%"PRIx64" range [%"PRId64",%"PRId64"], ts [%"PRId64",%"PRId64"]", pSql->self, pQueryInfo->range.skey, pQueryInfo->range.ekey, pQueryInfo->window.skey, pQueryInfo->window.ekey);
return TSDB_CODE_SUCCESS;
}
static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) { static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) {
/* set default timestamp order information for all queries */ /* set default timestamp order information for all queries */
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
...@@ -6655,18 +6746,6 @@ int32_t validateColumnName(char* name) { ...@@ -6655,18 +6746,6 @@ int32_t validateColumnName(char* name) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo) {
if (!tscIsPointInterpQuery(pQueryInfo)) {
return true;
}
if (pQueryInfo->window.skey == INT64_MIN || pQueryInfo->window.ekey == INT64_MAX) {
return false;
}
return !(pQueryInfo->window.skey != pQueryInfo->window.ekey && pQueryInfo->interval.interval == 0);
}
int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql) { int32_t validateLimitNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, SSqlObj* pSql) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
...@@ -7143,7 +7222,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { ...@@ -7143,7 +7222,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
continue; continue;
} }
if ((functionId == TSDB_FUNC_LAST_ROW) || if ((functionId == TSDB_FUNC_LAST_ROW) || (functionId == TSDB_FUNC_INTERP) ||
(functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) { (functionId == TSDB_FUNC_LAST_DST && (pExpr->base.colInfo.flag & TSDB_COL_NULL) != 0)) {
// do nothing // do nothing
} else { } else {
...@@ -8866,7 +8945,6 @@ static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pS ...@@ -8866,7 +8945,6 @@ static int32_t doValidateSubquery(SSqlNode* pSqlNode, int32_t index, SSqlObj* pS
int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInfo) { int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInfo) {
assert(pSqlNode != NULL && (pSqlNode->from == NULL || taosArrayGetSize(pSqlNode->from->list) > 0)); assert(pSqlNode != NULL && (pSqlNode->from == NULL || taosArrayGetSize(pSqlNode->from->list) > 0));
const char* msg1 = "point interpolation query needs timestamp";
const char* msg2 = "too many tables in from clause"; const char* msg2 = "too many tables in from clause";
const char* msg3 = "start(end) time of query range required or time range too large"; const char* msg3 = "start(end) time of query range required or time range too large";
const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column"; const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column";
...@@ -9039,6 +9117,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf ...@@ -9039,6 +9117,10 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) {
return code; return code;
} }
if ((code = validateRangeNode(pSql, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) {
return code;
}
} else { } else {
pQueryInfo->command = TSDB_SQL_SELECT; pQueryInfo->command = TSDB_SQL_SELECT;
...@@ -9146,10 +9228,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf ...@@ -9146,10 +9228,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (!hasTimestampForPointInterpQuery(pQueryInfo)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
// in case of join query, time range is required. // in case of join query, time range is required.
if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) { if (QUERY_IS_JOIN_QUERY(pQueryInfo->type)) {
uint64_t timeRange = (uint64_t)pQueryInfo->window.ekey - pQueryInfo->window.skey; uint64_t timeRange = (uint64_t)pQueryInfo->window.ekey - pQueryInfo->window.skey;
...@@ -9173,6 +9251,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf ...@@ -9173,6 +9251,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) { if ((code = validateFillNode(pCmd, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) {
return code; return code;
} }
if ((code = validateRangeNode(pSql, pQueryInfo, pSqlNode)) != TSDB_CODE_SUCCESS) {
return code;
}
} }
{ // set the query info { // set the query info
......
...@@ -916,7 +916,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -916,7 +916,9 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg->window.skey = htobe64(query.window.skey); pQueryMsg->window.skey = htobe64(query.window.skey);
pQueryMsg->window.ekey = htobe64(query.window.ekey); pQueryMsg->window.ekey = htobe64(query.window.ekey);
pQueryMsg->range.skey = htobe64(query.range.skey);
pQueryMsg->range.ekey = htobe64(query.range.ekey);
pQueryMsg->order = htons(query.order.order); pQueryMsg->order = htons(query.order.order);
pQueryMsg->orderColId = htons(query.order.orderColId); pQueryMsg->orderColId = htons(query.order.orderColId);
pQueryMsg->fillType = htons(query.fillType); pQueryMsg->fillType = htons(query.fillType);
......
...@@ -367,7 +367,7 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) { ...@@ -367,7 +367,7 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) {
assert(pExpr != NULL); assert(pExpr != NULL);
int32_t functionId = pExpr->base.functionId; int32_t functionId = pExpr->base.functionId;
if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS) { if (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS || functionId == TSDB_FUNC_TS_DUMMY) {
continue; continue;
} }
...@@ -379,6 +379,23 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) { ...@@ -379,6 +379,23 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo) {
return true; return true;
} }
bool tscGetPointInterpQuery(SQueryInfo* pQueryInfo) {
size_t size = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < size; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
assert(pExpr != NULL);
int32_t functionId = pExpr->base.functionId;
if (functionId == TSDB_FUNC_INTERP) {
return true;
}
}
return false;
}
bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo) { bool tsIsArithmeticQueryOnAggResult(SQueryInfo* pQueryInfo) {
if (tscIsProjectionQuery(pQueryInfo)) { if (tscIsProjectionQuery(pQueryInfo)) {
return false; return false;
...@@ -3796,6 +3813,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t ...@@ -3796,6 +3813,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
memcpy(&pNewQueryInfo->interval, &pQueryInfo->interval, sizeof(pNewQueryInfo->interval)); memcpy(&pNewQueryInfo->interval, &pQueryInfo->interval, sizeof(pNewQueryInfo->interval));
pNewQueryInfo->type = pQueryInfo->type; pNewQueryInfo->type = pQueryInfo->type;
pNewQueryInfo->window = pQueryInfo->window; pNewQueryInfo->window = pQueryInfo->window;
pNewQueryInfo->range = pQueryInfo->range;
pNewQueryInfo->limit = pQueryInfo->limit; pNewQueryInfo->limit = pQueryInfo->limit;
pNewQueryInfo->slimit = pQueryInfo->slimit; pNewQueryInfo->slimit = pQueryInfo->slimit;
pNewQueryInfo->order = pQueryInfo->order; pNewQueryInfo->order = pQueryInfo->order;
...@@ -5015,6 +5033,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt ...@@ -5015,6 +5033,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr->fillType = pQueryInfo->fillType; pQueryAttr->fillType = pQueryInfo->fillType;
pQueryAttr->havingNum = pQueryInfo->havingFieldNum; pQueryAttr->havingNum = pQueryInfo->havingFieldNum;
pQueryAttr->pUdfInfo = pQueryInfo->pUdfInfo; pQueryAttr->pUdfInfo = pQueryInfo->pUdfInfo;
pQueryAttr->range = pQueryInfo->range;
if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor if (pQueryInfo->order.order == TSDB_ORDER_ASC) { // TODO refactor
pQueryAttr->window = pQueryInfo->window; pQueryAttr->window = pQueryInfo->window;
......
...@@ -479,6 +479,7 @@ typedef struct { ...@@ -479,6 +479,7 @@ typedef struct {
bool stateWindow; // state window flag bool stateWindow; // state window flag
STimeWindow window; STimeWindow window;
STimeWindow range;
int32_t numOfTables; int32_t numOfTables;
int16_t order; int16_t order;
int16_t orderColId; int16_t orderColId;
......
...@@ -405,6 +405,7 @@ void tsdbDestroyCommitQueue(); ...@@ -405,6 +405,7 @@ void tsdbDestroyCommitQueue();
int tsdbSyncCommit(STsdbRepo *repo); int tsdbSyncCommit(STsdbRepo *repo);
void tsdbIncCommitRef(int vgId); void tsdbIncCommitRef(int vgId);
void tsdbDecCommitRef(int vgId); void tsdbDecCommitRef(int vgId);
void tsdbSwitchTable(TsdbQueryHandleT pQueryHandle);
// For TSDB file sync // For TSDB file sync
int tsdbSyncSend(void *pRepo, SOCKET socketFd); int tsdbSyncSend(void *pRepo, SOCKET socketFd);
......
...@@ -142,76 +142,81 @@ ...@@ -142,76 +142,81 @@
#define TK_DISTINCT 124 #define TK_DISTINCT 124
#define TK_FROM 125 #define TK_FROM 125
#define TK_VARIABLE 126 #define TK_VARIABLE 126
#define TK_INTERVAL 127 #define TK_RANGE 127
#define TK_EVERY 128 #define TK_INTERVAL 128
#define TK_SESSION 129 #define TK_EVERY 129
#define TK_STATE_WINDOW 130 #define TK_SESSION 130
#define TK_FILL 131 #define TK_STATE_WINDOW 131
#define TK_SLIDING 132 #define TK_FILL 132
#define TK_ORDER 133 #define TK_SLIDING 133
#define TK_BY 134 #define TK_ORDER 134
#define TK_ASC 135 #define TK_BY 135
#define TK_GROUP 136 #define TK_ASC 136
#define TK_HAVING 137 #define TK_GROUP 137
#define TK_LIMIT 138 #define TK_HAVING 138
#define TK_OFFSET 139 #define TK_LIMIT 139
#define TK_SLIMIT 140 #define TK_OFFSET 140
#define TK_SOFFSET 141 #define TK_SLIMIT 141
#define TK_WHERE 142 #define TK_SOFFSET 142
#define TK_RESET 143 #define TK_WHERE 143
#define TK_QUERY 144 #define TK_RESET 144
#define TK_SYNCDB 145 #define TK_QUERY 145
#define TK_ADD 146 #define TK_SYNCDB 146
#define TK_COLUMN 147 #define TK_ADD 147
#define TK_MODIFY 148 #define TK_COLUMN 148
#define TK_TAG 149 #define TK_MODIFY 149
#define TK_CHANGE 150 #define TK_TAG 150
#define TK_SET 151 #define TK_CHANGE 151
#define TK_KILL 152 #define TK_SET 152
#define TK_CONNECTION 153 #define TK_KILL 153
#define TK_STREAM 154 #define TK_CONNECTION 154
#define TK_COLON 155 #define TK_STREAM 155
#define TK_ABORT 156 #define TK_COLON 156
#define TK_AFTER 157 #define TK_ABORT 157
#define TK_ATTACH 158 #define TK_AFTER 158
#define TK_BEFORE 159 #define TK_ATTACH 159
#define TK_BEGIN 160 #define TK_BEFORE 160
#define TK_CASCADE 161 #define TK_BEGIN 161
#define TK_CLUSTER 162 #define TK_CASCADE 162
#define TK_CONFLICT 163 #define TK_CLUSTER 163
#define TK_COPY 164 #define TK_CONFLICT 164
#define TK_DEFERRED 165 #define TK_COPY 165
#define TK_DELIMITERS 166 #define TK_DEFERRED 166
#define TK_DETACH 167 #define TK_DELIMITERS 167
#define TK_EACH 168 #define TK_DETACH 168
#define TK_END 169 #define TK_EACH 169
#define TK_EXPLAIN 170 #define TK_END 170
#define TK_FAIL 171 #define TK_EXPLAIN 171
#define TK_FOR 172 #define TK_FAIL 172
#define TK_IGNORE 173 #define TK_FOR 173
#define TK_IMMEDIATE 174 #define TK_IGNORE 174
#define TK_INITIALLY 175 #define TK_IMMEDIATE 175
#define TK_INSTEAD 176 #define TK_INITIALLY 176
#define TK_KEY 177 #define TK_INSTEAD 177
#define TK_OF 178 #define TK_KEY 178
#define TK_RAISE 179 #define TK_OF 179
#define TK_REPLACE 180 #define TK_RAISE 180
#define TK_RESTRICT 181 #define TK_REPLACE 181
#define TK_ROW 182 #define TK_RESTRICT 182
#define TK_STATEMENT 183 #define TK_ROW 183
#define TK_TRIGGER 184 #define TK_STATEMENT 184
#define TK_VIEW 185 #define TK_TRIGGER 185
#define TK_IPTOKEN 186 #define TK_VIEW 186
#define TK_SEMI 187 #define TK_IPTOKEN 187
#define TK_NONE 188 #define TK_SEMI 188
#define TK_PREV 189 #define TK_NONE 189
#define TK_LINEAR 190 #define TK_PREV 190
#define TK_IMPORT 191 #define TK_LINEAR 191
#define TK_TBNAME 192 #define TK_IMPORT 192
#define TK_JOIN 193 #define TK_TBNAME 193
#define TK_INSERT 194 #define TK_JOIN 194
#define TK_INTO 195 #define TK_INSERT 195
#define TK_VALUES 196 #define TK_INTO 196
#define TK_VALUES 197
#define TK_FILE 198
...@@ -223,7 +228,7 @@ ...@@ -223,7 +228,7 @@
#define TK_HEX 303 // hex number 0x123 #define TK_HEX 303 // hex number 0x123
#define TK_OCT 304 // oct number #define TK_OCT 304 // oct number
#define TK_BIN 305 // bin format data 0b111 #define TK_BIN 305 // bin format data 0b111
#define TK_FILE 306 //#define TK_FILE 306
#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query #define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
#endif #endif
......
...@@ -192,6 +192,7 @@ typedef struct SQLFunctionCtx { ...@@ -192,6 +192,7 @@ typedef struct SQLFunctionCtx {
char * pOutput; // final result output buffer, point to sdata->data char * pOutput; // final result output buffer, point to sdata->data
uint8_t currentStage; // record current running step, default: 0 uint8_t currentStage; // record current running step, default: 0
int64_t startTs; // timestamp range of current query when function is executed on a specific data block int64_t startTs; // timestamp range of current query when function is executed on a specific data block
int64_t endTs;
int32_t numOfParams; int32_t numOfParams;
tVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param tVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param
int64_t *ptsList; // corresponding timestamp array list int64_t *ptsList; // corresponding timestamp array list
......
...@@ -61,6 +61,10 @@ enum { ...@@ -61,6 +61,10 @@ enum {
QUERY_OVER = 0x4u, QUERY_OVER = 0x4u,
}; };
enum {
OPTION_SWITCH_TABLE = 1,
};
typedef struct SResultRowPool { typedef struct SResultRowPool {
int32_t elemSize; int32_t elemSize;
int32_t blockSize; int32_t blockSize;
...@@ -238,6 +242,7 @@ typedef struct SQueryAttr { ...@@ -238,6 +242,7 @@ typedef struct SQueryAttr {
int16_t numOfTags; int16_t numOfTags;
STimeWindow window; STimeWindow window;
STimeWindow range;
SInterval interval; SInterval interval;
SSessionWindow sw; SSessionWindow sw;
int16_t precision; int16_t precision;
...@@ -274,6 +279,7 @@ typedef struct SQueryAttr { ...@@ -274,6 +279,7 @@ typedef struct SQueryAttr {
} SQueryAttr; } SQueryAttr;
typedef SSDataBlock* (*__operator_fn_t)(void* param, bool* newgroup); typedef SSDataBlock* (*__operator_fn_t)(void* param, bool* newgroup);
typedef void (*__operator_notify_fn_t)(void* param, int32_t option);
typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num); typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
struct SOperatorInfo; struct SOperatorInfo;
...@@ -345,7 +351,7 @@ enum OPERATOR_TYPE_E { ...@@ -345,7 +351,7 @@ enum OPERATOR_TYPE_E {
OP_Distinct = 20, OP_Distinct = 20,
OP_Join = 21, OP_Join = 21,
OP_StateWindow = 22, OP_StateWindow = 22,
OP_AllTimeWindow = 23, OP_TimeEvery = 23,
OP_AllMultiTableTimeInterval = 24, OP_AllMultiTableTimeInterval = 24,
OP_Order = 25, OP_Order = 25,
}; };
...@@ -362,8 +368,9 @@ typedef struct SOperatorInfo { ...@@ -362,8 +368,9 @@ typedef struct SOperatorInfo {
struct SOperatorInfo **upstream; // upstream pointer list struct SOperatorInfo **upstream; // upstream pointer list
int32_t numOfUpstream; // number of upstream. The value is always ONE expect for join operator int32_t numOfUpstream; // number of upstream. The value is always ONE expect for join operator
__operator_fn_t exec; __operator_fn_t exec;
__optr_cleanup_fn_t cleanup; __operator_notify_fn_t notify;
__optr_cleanup_fn_t cleanup;
} SOperatorInfo; } SOperatorInfo;
enum { enum {
...@@ -475,6 +482,19 @@ typedef struct SProjectOperatorInfo { ...@@ -475,6 +482,19 @@ typedef struct SProjectOperatorInfo {
SSDataBlock *existDataBlock; SSDataBlock *existDataBlock;
} SProjectOperatorInfo; } SProjectOperatorInfo;
typedef struct STableEveryOperatorInfo {
SOptrBasicInfo binfo;
int32_t bufCapacity;
uint32_t seed;
int64_t tableEndKey;
SSDataBlock *lastBlock;
bool groupDone;
bool allDone;
SSDataBlock *existDataBlock;
} STableEveryOperatorInfo;
typedef struct SLimitOperatorInfo { typedef struct SLimitOperatorInfo {
int64_t limit; int64_t limit;
int64_t total; int64_t total;
...@@ -595,13 +615,12 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera ...@@ -595,13 +615,12 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera
SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream); SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream);
SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult); SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput, bool multigroupResult);
SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTimeEveryOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createTagScanOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTagScanOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput);
SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv); SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv);
......
...@@ -85,6 +85,11 @@ typedef struct SIntervalVal { ...@@ -85,6 +85,11 @@ typedef struct SIntervalVal {
SStrToken offset; SStrToken offset;
} SIntervalVal; } SIntervalVal;
typedef struct SRangeVal {
void *start;
void *end;
} SRangeVal;
typedef struct SSessionWindowVal { typedef struct SSessionWindowVal {
SStrToken col; SStrToken col;
SStrToken gap; SStrToken gap;
...@@ -111,6 +116,7 @@ typedef struct SSqlNode { ...@@ -111,6 +116,7 @@ typedef struct SSqlNode {
SLimitVal slimit; // group limit offset [optional] SLimitVal slimit; // group limit offset [optional]
SStrToken sqlstr; // sql string in select clause SStrToken sqlstr; // sql string in select clause
struct tSqlExpr *pHaving; // having clause [optional] struct tSqlExpr *pHaving; // having clause [optional]
SRangeVal pRange; // range clause [optional]
} SSqlNode; } SSqlNode;
typedef struct SRelElementPair { typedef struct SRelElementPair {
...@@ -272,6 +278,7 @@ typedef struct tSqlExprItem { ...@@ -272,6 +278,7 @@ typedef struct tSqlExprItem {
bool distinct; bool distinct;
} tSqlExprItem; } tSqlExprItem;
SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder); SArray *tVariantListAppend(SArray *pList, tVariant *pVar, uint8_t sortOrder);
SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index); SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int32_t index);
SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder); SArray *tVariantListAppendToken(SArray *pList, SStrToken *pAliasToken, uint8_t sortOrder);
...@@ -282,6 +289,7 @@ SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrT ...@@ -282,6 +289,7 @@ SRelationInfo *addSubqueryElem(SRelationInfo* pRelationInfo, SArray* pSub, SStrT
// sql expr leaf node // sql expr leaf node
tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType); tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType);
tSqlExpr *tSqlExprCreateTimestamp(SStrToken *pToken, int32_t optrType);
tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType); tSqlExpr *tSqlExprCreateFunction(SArray *pParam, SStrToken *pFuncToken, SStrToken *endToken, int32_t optType);
SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken); SArray *tStrTokenAppend(SArray *pList, SStrToken *pToken);
...@@ -296,7 +304,7 @@ void tSqlExprListDestroy(SArray *pList); ...@@ -296,7 +304,7 @@ void tSqlExprListDestroy(SArray *pList);
SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere,
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, SWindowStateVal *pw, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SSessionWindowVal *ps, SWindowStateVal *pw,
SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit, tSqlExpr *pHaving); SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SLimitVal *pgLimit, tSqlExpr *pHaving, SRangeVal *pRange);
int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right); int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right);
SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type); SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSelect, int32_t type);
......
...@@ -144,6 +144,8 @@ typedef struct SQueryInfo { ...@@ -144,6 +144,8 @@ typedef struct SQueryInfo {
bool udfCopy; bool udfCopy;
SArray *pUdfInfo; SArray *pUdfInfo;
STimeWindow range; // range for interp
struct SQInfo *pQInfo; // global merge operator struct SQInfo *pQInfo; // global merge operator
struct SQueryAttr *pQueryAttr; // query object struct SQueryAttr *pQueryAttr; // query object
......
...@@ -483,8 +483,8 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). { ...@@ -483,8 +483,8 @@ tagitem(A) ::= PLUS(X) FLOAT(Y). {
//////////////////////// The SELECT statement ///////////////////////////////// //////////////////////// The SELECT statement /////////////////////////////////
%type select {SSqlNode*} %type select {SSqlNode*}
%destructor select {destroySqlNode($$);} %destructor select {destroySqlNode($$);}
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) interval_option(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). { select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) range_option(R) interval_option(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); A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N, &R);
} }
select(A) ::= LP select(B) RP. {A = B;} select(A) ::= LP select(B) RP. {A = B;}
...@@ -502,7 +502,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); } ...@@ -502,7 +502,7 @@ cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
// select client_version() // select client_version()
// select server_state() // select server_state()
select(A) ::= SELECT(T) selcollist(W). { select(A) ::= SELECT(T) selcollist(W). {
A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
} }
// selcollist is a list of expressions that are to become the return // selcollist is a list of expressions that are to become the return
...@@ -573,6 +573,22 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). { ...@@ -573,6 +573,22 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
%type tmvar {SStrToken} %type tmvar {SStrToken}
tmvar(A) ::= VARIABLE(X). {A = X;} tmvar(A) ::= VARIABLE(X). {A = X;}
%type timestamp {tSqlExpr*}
%destructor timestamp {tSqlExprDestroy($$);}
timestamp(A) ::= INTEGER(X). { A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= PLUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= STRING(X). { A = tSqlExprCreateTimestamp(&X, TK_STRING);}
timestamp(A) ::= NOW(X). { A = tSqlExprCreateTimestamp(&X, TK_NOW); }
timestamp(A) ::= NOW PLUS VARIABLE(Y). {A = tSqlExprCreateTimestamp(&Y, TK_PLUS); }
timestamp(A) ::= NOW MINUS VARIABLE(Y). {A = tSqlExprCreateTimestamp(&Y, TK_MINUS); }
%type range_option {SRangeVal}
range_option(N) ::= . {N.start = 0; N.end = 0;}
range_option(N) ::= RANGE LP timestamp(E) COMMA timestamp(X) RP. {N.start = E; N.end = X;}
%type interval_option {SIntervalVal} %type interval_option {SIntervalVal}
interval_option(N) ::= intervalKey(A) LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.token = A;} interval_option(N) ::= intervalKey(A) LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.token = A;}
interval_option(N) ::= intervalKey(A) LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X; N.token = A;} interval_option(N) ::= intervalKey(A) LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X; N.token = A;}
...@@ -922,4 +938,4 @@ cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); s ...@@ -922,4 +938,4 @@ cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); s
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED %fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES. NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES FILE.
...@@ -3879,183 +3879,84 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) { ...@@ -3879,183 +3879,84 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
doFinalizer(pCtx); doFinalizer(pCtx);
} }
/** static void interp_function(SQLFunctionCtx *pCtx) {
* int32_t fillType = (int32_t) pCtx->param[2].i64;
* @param pCtx //bool ascQuery = (pCtx->order == TSDB_ORDER_ASC);
*/
static void interp_function_impl(SQLFunctionCtx *pCtx) { if (pCtx->start.key == pCtx->startTs) {
int32_t type = (int32_t) pCtx->param[2].i64; assert(pCtx->start.key != INT64_MIN);
if (type == TSDB_FILL_NONE) {
return; SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val);
goto interp_success_exit;
} else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val);
goto interp_success_exit;
} }
bool ascQuery = (pCtx->order == TSDB_ORDER_ASC); switch (fillType) {
case TSDB_FILL_NULL:
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
break;
case TSDB_FILL_SET_VALUE:
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
break;
case TSDB_FILL_LINEAR:
if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs
|| pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) {
goto interp_exit;
}
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val};
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
if (pCtx->colId == 0 && pCtx->inputType == TSDB_DATA_TYPE_TIMESTAMP) { int32_t srcType = pCtx->inputType;
*(TSKEY *)pCtx->pOutput = pCtx->startTs; if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
} else if (type == TSDB_FILL_NULL) { setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); } else {
} else if (type == TSDB_FILL_SET_VALUE) { taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE);
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
} else {
if (pCtx->start.key != INT64_MIN && ((ascQuery && pCtx->start.key <= pCtx->startTs && pCtx->end.key >= pCtx->startTs) || ((!ascQuery) && pCtx->start.key >= pCtx->startTs && pCtx->end.key <= pCtx->startTs))) {
if (type == TSDB_FILL_PREV) {
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->start.val);
} else {
assignVal(pCtx->pOutput, pCtx->start.ptr, pCtx->outputBytes, pCtx->inputType);
}
} else if (type == TSDB_FILL_NEXT) {
if (IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL) {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, pCtx->end.val);
} else {
assignVal(pCtx->pOutput, pCtx->end.ptr, pCtx->outputBytes, pCtx->inputType);
}
} else if (type == TSDB_FILL_LINEAR) {
SPoint point1 = {.key = pCtx->start.key, .val = &pCtx->start.val};
SPoint point2 = {.key = pCtx->end.key, .val = &pCtx->end.val};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
int32_t srcType = pCtx->inputType;
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data?
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else {
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE);
}
} else {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
}
} }
} else { break;
if (GET_RES_INFO(pCtx)->numOfRes > 0) {
return; case TSDB_FILL_PREV:
if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs) {
goto interp_exit;
} }
// no data generated yet SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->start.val);
if (pCtx->size < 1) { break;
return;
case TSDB_FILL_NEXT:
if (pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) {
goto interp_exit;
} }
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)&pCtx->end.val);
break;
// check the timestamp in input buffer case TSDB_FILL_NONE:
TSKEY skey = GET_TS_DATA(pCtx, 0); default:
goto interp_exit;
}
if (type == TSDB_FILL_PREV) {
if ((ascQuery && skey > pCtx->startTs) || ((!ascQuery) && skey < pCtx->startTs)) {
return;
}
if (pCtx->size > 1) { interp_success_exit:
TSKEY ekey = GET_TS_DATA(pCtx, 1);
if ((ascQuery && ekey > skey && ekey <= pCtx->startTs) ||
((!ascQuery) && ekey < skey && ekey >= pCtx->startTs)){
skey = ekey;
}
}
assignVal(pCtx->pOutput, pCtx->pInput, pCtx->outputBytes, pCtx->inputType);
} else if (type == TSDB_FILL_NEXT) {
TSKEY ekey = skey;
char* val = NULL;
if ((ascQuery && ekey < pCtx->startTs) || ((!ascQuery) && ekey > pCtx->startTs)) {
if (pCtx->size > 1) {
ekey = GET_TS_DATA(pCtx, 1);
if ((ascQuery && ekey < pCtx->startTs) || ((!ascQuery) && ekey > pCtx->startTs)) {
setNull(pCtx->pOutput, pCtx->inputType, pCtx->inputBytes);
SET_VAL(pCtx, 1, 1);
return;
}
val = ((char*)pCtx->pInput) + pCtx->inputBytes; *(TSKEY*)pCtx->ptsOutputBuf = pCtx->startTs;
} else {
setNull(pCtx->pOutput, pCtx->inputType, pCtx->inputBytes);
SET_VAL(pCtx, 1, 1);
return;
}
} else {
val = (char*)pCtx->pInput;
}
assignVal(pCtx->pOutput, val, pCtx->outputBytes, pCtx->inputType);
} else if (type == TSDB_FILL_LINEAR) {
if (pCtx->size <= 1) {
return;
}
TSKEY ekey = GET_TS_DATA(pCtx, 1);
// no data generated yet
if ((ascQuery && !(skey <= pCtx->startTs && ekey >= pCtx->startTs))
|| ((!ascQuery) && !(skey >= pCtx->startTs && ekey <= pCtx->startTs))) {
return;
}
char *start = GET_INPUT_DATA(pCtx, 0);
char *end = GET_INPUT_DATA(pCtx, 1);
SPoint point1 = {.key = skey, .val = start}; INC_INIT_VAL(pCtx, 1);
SPoint point2 = {.key = ekey, .val = end};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
int32_t srcType = pCtx->inputType; interp_exit:
if (IS_NUMERIC_TYPE(srcType)) { // TODO should find the not null data?
if (isNull(start, srcType) || isNull(end, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else {
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, srcType);
}
} else {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
}
}
}
}
SET_VAL(pCtx, 1, 1); pCtx->start.key = INT64_MIN;
} pCtx->end.key = INT64_MIN;
pCtx->endTs = pCtx->startTs;
static void interp_function(SQLFunctionCtx *pCtx) { return;
// at this point, the value is existed, return directly
if (pCtx->size > 0) {
bool ascQuery = (pCtx->order == TSDB_ORDER_ASC);
TSKEY key;
char *pData;
int32_t typedData = 0;
if (ascQuery) {
key = GET_TS_DATA(pCtx, 0);
pData = GET_INPUT_DATA(pCtx, 0);
} else {
key = pCtx->start.key;
if (key == INT64_MIN) {
key = GET_TS_DATA(pCtx, 0);
pData = GET_INPUT_DATA(pCtx, 0);
} else {
if (!(IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL)) {
pData = pCtx->start.ptr;
} else {
typedData = 1;
pData = (char *)&pCtx->start.val;
}
}
}
//if (key == pCtx->startTs && (ascQuery || !(IS_NUMERIC_TYPE(pCtx->inputType) || pCtx->inputType == TSDB_DATA_TYPE_BOOL))) {
if (key == pCtx->startTs) {
if (typedData) {
SET_TYPED_DATA(pCtx->pOutput, pCtx->inputType, *(double *)pData);
} else {
assignVal(pCtx->pOutput, pData, pCtx->inputBytes, pCtx->inputType);
}
SET_VAL(pCtx, 1, 1);
} else {
interp_function_impl(pCtx);
}
} else { //no qualified data rows and interpolation is required
interp_function_impl(pCtx);
}
} }
static bool ts_comp_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) { static bool ts_comp_function_setup(SQLFunctionCtx *pCtx, SResultRowCellInfo* pResInfo) {
...@@ -5376,7 +5277,7 @@ SAggFunctionInfo aAggs[] = {{ ...@@ -5376,7 +5277,7 @@ SAggFunctionInfo aAggs[] = {{
"interp", "interp",
TSDB_FUNC_INTERP, TSDB_FUNC_INTERP,
TSDB_FUNC_INTERP, TSDB_FUNC_INTERP,
TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS , TSDB_FUNCSTATE_SO | TSDB_FUNCSTATE_OF | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS | TSDB_FUNCSTATE_SELECTIVITY,
function_setup, function_setup,
interp_function, interp_function,
doFinalizer, doFinalizer,
......
此差异已折叠。
...@@ -564,20 +564,15 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { ...@@ -564,20 +564,15 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) {
op = OP_Distinct; op = OP_Distinct;
taosArrayPush(plan, &op); taosArrayPush(plan, &op);
} }
} else if (pQueryAttr->pointInterpQuery) {
op = OP_TimeEvery;
taosArrayPush(plan, &op);
} else if (pQueryAttr->interval.interval > 0) { } else if (pQueryAttr->interval.interval > 0) {
if (pQueryAttr->stableQuery) { if (pQueryAttr->stableQuery) {
if (pQueryAttr->pointInterpQuery) { op = OP_MultiTableTimeInterval;
op = OP_AllMultiTableTimeInterval;
} else {
op = OP_MultiTableTimeInterval;
}
taosArrayPush(plan, &op); taosArrayPush(plan, &op);
} else { } else {
if (pQueryAttr->pointInterpQuery) { op = OP_TimeWindow;
op = OP_AllTimeWindow;
} else {
op = OP_TimeWindow;
}
taosArrayPush(plan, &op); taosArrayPush(plan, &op);
if (pQueryAttr->pExpr2 != NULL) { if (pQueryAttr->pExpr2 != NULL) {
...@@ -704,7 +699,7 @@ SArray* createGlobalMergePlan(SQueryAttr* pQueryAttr) { ...@@ -704,7 +699,7 @@ SArray* createGlobalMergePlan(SQueryAttr* pQueryAttr) {
} }
// fill operator // fill operator
if (pQueryAttr->fillType != TSDB_FILL_NONE && pQueryAttr->interval.interval > 0) { if (pQueryAttr->fillType != TSDB_FILL_NONE && pQueryAttr->interval.interval > 0 && !pQueryAttr->pointInterpQuery) {
op = OP_Fill; op = OP_Fill;
taosArrayPush(plan, &op); taosArrayPush(plan, &op);
} }
......
...@@ -192,6 +192,65 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) { ...@@ -192,6 +192,65 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
return pSqlExpr; return pSqlExpr;
} }
tSqlExpr *tSqlExprCreateTimestamp(SStrToken *pToken, int32_t optrType) {
tSqlExpr *pSqlExpr = calloc(1, sizeof(tSqlExpr));
if (pToken != NULL) {
pSqlExpr->exprToken = *pToken;
}
if (optrType == TK_INTEGER || optrType == TK_STRING) {
if (pToken) {
toTSDBType(pToken->type);
tVariantCreate(&pSqlExpr->value, pToken);
}
pSqlExpr->tokenId = optrType;
pSqlExpr->type = SQL_NODE_VALUE;
} else if (optrType == TK_NOW) {
// use nanosecond by default TODO set value after getting database precision
pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO);
pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pSqlExpr->tokenId = TK_TIMESTAMP; // TK_TIMESTAMP used to denote the time value is in microsecond
pSqlExpr->type = SQL_NODE_VALUE;
pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP;
} else if (optrType == TK_PLUS || optrType == TK_MINUS) {
// use nanosecond by default
// TODO set value after getting database precision
if (pToken) {
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;
}
}
if (optrType == TK_PLUS) {
pSqlExpr->value.i64 += taosGetTimestamp(TSDB_TIME_PRECISION_NANO);
} else {
pSqlExpr->value.i64 = taosGetTimestamp(TSDB_TIME_PRECISION_NANO) - pSqlExpr->value.i64;
}
pSqlExpr->flags |= 1 << EXPR_FLAG_NS_TIMESTAMP;
pSqlExpr->value.nType = TSDB_DATA_TYPE_BIGINT;
pSqlExpr->tokenId = TK_TIMESTAMP;
pSqlExpr->type = SQL_NODE_VALUE;
} else {
// Here it must be the column name (tk_id) if it is not a number or string.
assert(optrType == TK_ID || optrType == TK_ALL);
if (pToken != NULL) {
pSqlExpr->columnName = *pToken;
}
pSqlExpr->tokenId = optrType;
pSqlExpr->type = SQL_NODE_TABLE_COLUMN;
}
return pSqlExpr;
}
/* /*
* pList is the parameters for function with id(optType) * pList is the parameters for function with id(optType)
* function name is denoted by pFunctionToken * function name is denoted by pFunctionToken
...@@ -751,7 +810,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { ...@@ -751,7 +810,7 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere, SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelationInfo *pFrom, tSqlExpr *pWhere,
SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval, SArray *pGroupby, SArray *pSortOrder, SIntervalVal *pInterval,
SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit, SSessionWindowVal *pSession, SWindowStateVal *pWindowStateVal, SStrToken *pSliding, SArray *pFill, SLimitVal *pLimit,
SLimitVal *psLimit, tSqlExpr *pHaving) { SLimitVal *psLimit, tSqlExpr *pHaving, SRangeVal *pRange) {
assert(pSelNodeList != NULL); assert(pSelNodeList != NULL);
SSqlNode *pSqlNode = calloc(1, sizeof(SSqlNode)); SSqlNode *pSqlNode = calloc(1, sizeof(SSqlNode));
...@@ -767,6 +826,7 @@ SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelat ...@@ -767,6 +826,7 @@ SSqlNode *tSetQuerySqlNode(SStrToken *pSelectToken, SArray *pSelNodeList, SRelat
pSqlNode->pWhere = pWhere; pSqlNode->pWhere = pWhere;
pSqlNode->fillType = pFill; pSqlNode->fillType = pFill;
pSqlNode->pHaving = pHaving; pSqlNode->pHaving = pHaving;
pSqlNode->pRange = *pRange;
if (pLimit != NULL) { if (pLimit != NULL) {
pSqlNode->limit = *pLimit; pSqlNode->limit = *pLimit;
......
此差异已折叠。
...@@ -657,8 +657,8 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) { ...@@ -657,8 +657,8 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) {
TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdbRepo *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, uint64_t qId, SMemRef* pRef) { TsdbQueryHandleT tsdbQueryRowsInExternalWindow(STsdbRepo *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, uint64_t qId, SMemRef* pRef) {
STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pRef); STsdbQueryHandle *pQueryHandle = (STsdbQueryHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, pRef);
pQueryHandle->loadExternalRow = true; //pQueryHandle->loadExternalRow = true;
pQueryHandle->currentLoadExternalRows = true; //pQueryHandle->currentLoadExternalRows = true;
return pQueryHandle; return pQueryHandle;
} }
...@@ -2883,6 +2883,22 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) { ...@@ -2883,6 +2883,22 @@ static bool loadCachedLast(STsdbQueryHandle* pQueryHandle) {
return false; return false;
} }
void tsdbSwitchTable(TsdbQueryHandleT queryHandle) {
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*) queryHandle;
STableCheckInfo* pCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, pQueryHandle->activeIndex);
pCheckInfo->numOfBlocks = 0;
pQueryHandle->locateStart = false;
pQueryHandle->checkFiles = true;
pQueryHandle->cur.rows = 0;
pQueryHandle->currentLoadExternalRows = pQueryHandle->loadExternalRow;
terrno = TSDB_CODE_SUCCESS;
++pQueryHandle->activeIndex;
}
static bool loadDataBlockFromTableSeq(STsdbQueryHandle* pQueryHandle) { static bool loadDataBlockFromTableSeq(STsdbQueryHandle* pQueryHandle) {
size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo); size_t numOfTables = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
......
...@@ -229,7 +229,8 @@ static SKeyword keywordTable[] = { ...@@ -229,7 +229,8 @@ static SKeyword keywordTable[] = {
{"FUNCTIONS", TK_FUNCTIONS}, {"FUNCTIONS", TK_FUNCTIONS},
{"OUTPUTTYPE", TK_OUTPUTTYPE}, {"OUTPUTTYPE", TK_OUTPUTTYPE},
{"AGGREGATE", TK_AGGREGATE}, {"AGGREGATE", TK_AGGREGATE},
{"BUFSIZE", TK_BUFSIZE} {"BUFSIZE", TK_BUFSIZE},
{"RANGE", TK_RANGE}
}; };
static const char isIdChar[] = { static const char isIdChar[] = {
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/cfg.sh -n dnode1 -c minRows -v 10
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
sql create database db;
sql use db;
sql create stable stb1 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double)
sql create table tb1 using stb1 tags(1,'1',1.0)
sql create table tb2 using stb1 tags(2,'2',2.0)
sql create table tb3 using stb1 tags(3,'3',3.0)
sql create table tb4 using stb1 tags(4,'4',4.0)
sql insert into tb1 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb1 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb1 values ('2021-10-20 10:00:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb1 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb1 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb1 values ('2021-10-20 10:00:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb1 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb2 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb2 values ('2021-10-20 10:00:02',2,2.0,2,2,2,2.0,true ,'2','2')
sql insert into tb2 values ('2021-10-20 10:00:04',4,4.0,4,4,4,4.0,false,'4','4')
sql insert into tb2 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb2 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb2 values ('2021-10-20 10:00:12',12,12.0,12,12,12,12.0,true ,'12','12')
sql insert into tb2 values ('2021-10-20 10:00:14',14,14.0,14,14,14,14.0,false,'14','14')
sql insert into tb3 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb3 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb3 values ('2021-10-20 10:00:02',2,2.0,2,2,2,2.0,false,'2','2')
sql insert into tb3 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb3 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb3 values ('2021-10-20 10:00:18',18,18.0,18,18,18,18.0,true ,'18','18')
sql insert into tb3 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21')
sql create stable stb4 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double)
sql create table tb4_0 using stb4 tags(0,'0',0.0)
sql create table tb4_1 using stb4 tags(1,'1',1.0)
sql create table tb4_2 using stb4 tags(2,'2',2.0)
sql insert into tb4_0 values ('2021-10-20 10:00:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb4_0 values ('2021-10-20 10:00:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb4_0 values ('2021-10-20 10:00:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb4_0 values ('2021-10-20 10:00:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb4_0 values ('2021-10-20 10:00:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb4_0 values ('2021-10-20 10:00:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb4_0 values ('2021-10-20 10:00:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb4_0 values ('2021-10-20 10:00:28',28,28.0,28,28,28,28.0,false,'28','28')
sql insert into tb4_0 values ('2021-10-20 10:00:36',36,36.0,36,36,36,36.0,false,'36','36')
sql insert into tb4_0 values ('2021-10-20 10:00:45',45,45.0,45,45,45,45.0,false,'45','45')
sql insert into tb4_0 values ('2021-10-20 10:00:55',55,55.0,55,55,55,55.0,false,'55','55')
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tb4_0 values ('2021-10-20 10:01:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb4_0 values ('2021-10-20 10:01:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb4_0 values ('2021-10-20 10:01:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb4_0 values ('2021-10-20 10:01:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb4_0 values ('2021-10-20 10:01:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb4_0 values ('2021-10-20 10:01:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb4_0 values ('2021-10-20 10:01:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb4_0 values ('2021-10-20 10:01:28',28,28.0,28,28,28,28.0,false,'28','28')
sql insert into tb4_0 values ('2021-10-20 10:01:36',36,36.0,36,36,36,36.0,false,'36','36')
sql insert into tb4_0 values ('2021-10-20 10:01:45',45,45.0,45,45,45,45.0,false,'45','45')
sql insert into tb4_0 values ('2021-10-20 10:01:55',55,55.0,55,55,55,55.0,false,'55','55')
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tb4_0 values ('2021-10-20 10:02:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb4_0 values ('2021-10-20 10:02:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb4_0 values ('2021-10-20 10:02:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb4_0 values ('2021-10-20 10:02:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb4_0 values ('2021-10-20 10:02:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb4_0 values ('2021-10-20 10:02:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb4_0 values ('2021-10-20 10:02:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb4_0 values ('2021-10-20 10:02:28',28,28.0,28,28,28,28.0,false,'28','28')
sql insert into tb4_0 values ('2021-10-20 10:02:36',36,36.0,36,36,36,36.0,false,'36','36')
sql insert into tb4_0 values ('2021-10-20 10:02:45',45,45.0,45,45,45,45.0,false,'45','45')
sql insert into tb4_0 values ('2021-10-20 10:02:55',55,55.0,55,55,55,55.0,false,'55','55')
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tb4_0 values ('2021-10-20 10:03:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb4_0 values ('2021-10-20 10:03:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb4_0 values ('2021-10-20 10:03:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb4_0 values ('2021-10-20 10:03:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb4_0 values ('2021-10-20 10:03:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb4_0 values ('2021-10-20 10:03:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb4_0 values ('2021-10-20 10:03:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb4_0 values ('2021-10-20 10:03:28',28,28.0,28,28,28,28.0,false,'28','28')
sql insert into tb4_0 values ('2021-10-20 10:03:36',36,36.0,36,36,36,36.0,false,'36','36')
sql insert into tb4_0 values ('2021-10-20 10:03:45',45,45.0,45,45,45,45.0,false,'45','45')
sql insert into tb4_0 values ('2021-10-20 10:03:55',55,55.0,55,55,55,55.0,false,'55','55')
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql insert into tb4_0 values ('2021-10-20 10:04:00',0,0.0,0,0,0,0.0,true ,'0','0')
sql insert into tb4_0 values ('2021-10-20 10:04:01',1,1.0,1,1,1,1.0,true ,'1','1')
sql insert into tb4_0 values ('2021-10-20 10:04:03',3,3.0,3,3,3,3.0,false,'3','3')
sql insert into tb4_0 values ('2021-10-20 10:04:06',6,6.0,6,6,6,6.0,false,'6','6')
sql insert into tb4_0 values ('2021-10-20 10:04:10',10,10.0,10,10,10,10.0,true ,'10','10')
sql insert into tb4_0 values ('2021-10-20 10:04:15',15,15.0,15,15,15,15.0,true ,'15','15')
sql insert into tb4_0 values ('2021-10-20 10:04:21',21,21.0,21,21,21,21.0,false,'21','21')
sql insert into tb4_0 values ('2021-10-20 10:04:28',28,28.0,28,28,28,28.0,false,'28','28')
sql insert into tb4_0 values ('2021-10-20 10:04:36',36,36.0,36,36,36,36.0,false,'36','36')
sql insert into tb4_0 values ('2021-10-20 10:04:45',45,45.0,45,45,45,45.0,false,'45','45')
sql insert into tb4_0 values ('2021-10-20 10:04:55',55,55.0,55,55,55,55.0,false,'55','55')
run general/parser/interp_full_test.sim
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 500
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
run general/parser/interp_full_test.sim
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 100
sql connect
sql_error SELECT INTERP(c7) FROM tb1;
sql_error SELECT INTERP(c8) FROM tb1;
sql_error SELECT INTERP(c9) FROM tb1;
sql_error SELECT INTERP(c1,c8) FROM tb1;
sql_error SELECT INTERP(*) FROM tb1;
sql_error SELECT INTERP(c1),INTERP(c8) FROM tb1;
sql_error SELECT INTERP(c1),avg(c1) FROM tb1;
sql_error SELECT INTERP(c1),c1 FROM tb1;
sql_error SELECT INTERP(c1),top(c1,3) FROM tb1;
sql_error SELECT INTERP(c1),first(c1) FROM tb1;
sql_error SELECT INTERP(c1),count(c1) FROM tb1;
sql_error SELECT INTERP(c1),ceil(c1) FROM tb1;
sql_error SELECT c1,c2,interp(c1) FROM tb1;
sql_error SELECT INTERP(c1) FROM stb1;
sql_error SELECT interp(c1) FROM stb1 group by t1;
sql_error SELECT interp(c1) FROM stb1 group by tbname,t1;
sql_error SELECT interp(c1) FROM stb1 group by tbname,ts;
sql_error SELECT interp(c1) FROM stb1 group by tbname,c1;
sql_error SELECT INTERP(c1) FROM tb1 interval(1s);
sql_error SELECT avg(c1) FROM tb1 every(1s);
sql_error SELECT avg(c1) FROM tb1 range(0,1);
sql_error SELECT INTERP(c1) FROM tb1 STATE_WINDOW(c1);
sql_error SELECT INTERP(c1) FROM tb1 SESSION(ts,100s);
sql SELECT INTERP(c1) FROM tb1;
if $rows != 1 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
sql SELECT ts,INTERP(c1) FROM tb1;
if $rows != 1 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data02 != 0 then
return -1
endi
sql SELECT INTERP(c1) FROM tb1 where ts > '2021-10-20 10:00:03'
if $rows != 1 then
return -1
endi
if $data00 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data01 != 6 then
return -1
endi
sql SELECT INTERP(c1) FROM tb1 every(1s);
if $rows != 7 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data10 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data20 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data30 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data31 != 6 then
return -1
endi
if $data40 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data41 != 10 then
return -1
endi
if $data50 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data51 != 15 then
return -1
endi
if $data60 != @21-10-20 10:00:21.000@ then
return -1
endi
if $data61 != 21 then
return -1
endi
sql SELECT INTERP(c1,c2,c3,c4,c6,c5) FROM tb1 every(1s);
if $rows != 7 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data02 != 0.00000 then
return -1
endi
if $data03 != 0 then
return -1
endi
if $data04 != 0 then
return -1
endi
if $data05 != 0.000000000 then
return -1
endi
if $data06 != 0 then
return -1
endi
if $data10 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != 1.00000 then
return -1
endi
if $data13 != 1 then
return -1
endi
if $data14 != 1 then
return -1
endi
if $data15 != 1.000000000 then
return -1
endi
if $data16 != 1 then
return -1
endi
if $data20 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data22 != 3.00000 then
return -1
endi
if $data23 != 3 then
return -1
endi
if $data24 != 3 then
return -1
endi
if $data25 != 3.000000000 then
return -1
endi
if $data26 != 3 then
return -1
endi
if $data30 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data31 != 6 then
return -1
endi
if $data32 != 6.00000 then
return -1
endi
if $data33 != 6 then
return -1
endi
if $data34 != 6 then
return -1
endi
if $data35 != 6.000000000 then
return -1
endi
if $data36 != 6 then
return -1
endi
if $data40 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data41 != 10 then
return -1
endi
if $data42 != 10.00000 then
return -1
endi
if $data43 != 10 then
return -1
endi
if $data44 != 10 then
return -1
endi
if $data45 != 10.000000000 then
return -1
endi
if $data46 != 10 then
return -1
endi
if $data50 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data51 != 15 then
return -1
endi
if $data52 != 15.00000 then
return -1
endi
if $data53 != 15 then
return -1
endi
if $data54 != 15 then
return -1
endi
if $data55 != 15.000000000 then
return -1
endi
if $data56 != 15 then
return -1
endi
if $data60 != @21-10-20 10:00:21.000@ then
return -1
endi
if $data61 != 21 then
return -1
endi
if $data62 != 21.00000 then
return -1
endi
if $data63 != 21 then
return -1
endi
if $data64 != 21 then
return -1
endi
if $data65 != 21.000000000 then
return -1
endi
if $data66 != 21 then
return -1
endi
sql SELECT INTERP(c1),interp(c2),interp(c3) FROM tb1 every(1s);
if $rows != 7 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data02 != 0.00000 then
return -1
endi
if $data03 != 0 then
return -1
endi
if $data10 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != 1.00000 then
return -1
endi
if $data13 != 1 then
return -1
endi
if $data20 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data22 != 3.00000 then
return -1
endi
if $data23 != 3 then
return -1
endi
if $data30 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data31 != 6 then
return -1
endi
if $data32 != 6.00000 then
return -1
endi
if $data33 != 6 then
return -1
endi
if $data40 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data41 != 10 then
return -1
endi
if $data42 != 10.00000 then
return -1
endi
if $data43 != 10 then
return -1
endi
if $data50 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data51 != 15 then
return -1
endi
if $data52 != 15.00000 then
return -1
endi
if $data53 != 15 then
return -1
endi
if $data60 != @21-10-20 10:00:21.000@ then
return -1
endi
if $data61 != 21 then
return -1
endi
if $data62 != 21.00000 then
return -1
endi
if $data63 != 21 then
return -1
endi
sql SELECT INTERP(c1),ts FROM tb1 every(1s);
if $rows != 7 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data02 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data10 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data20 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data22 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data30 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data31 != 6 then
return -1
endi
if $data32 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data40 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data41 != 10 then
return -1
endi
if $data42 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data50 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data51 != 15 then
return -1
endi
if $data52 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data60 != @21-10-20 10:00:21.000@ then
return -1
endi
if $data61 != 21 then
return -1
endi
if $data62 != @21-10-20 10:00:21.000@ then
return -1
endi
sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname;
if $rows != 21 then
return -1
endi
if $data00 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data02 != tb1 then
return -1
endi
if $data10 != @21-10-20 10:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data12 != tb1 then
return -1
endi
if $data20 != @21-10-20 10:00:03.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data22 != tb1 then
return -1
endi
if $data30 != @21-10-20 10:00:06.000@ then
return -1
endi
if $data31 != 6 then
return -1
endi
if $data32 != tb1 then
return -1
endi
if $data40 != @21-10-20 10:00:10.000@ then
return -1
endi
if $data41 != 10 then
return -1
endi
if $data42 != tb1 then
return -1
endi
if $data50 != @21-10-20 10:00:15.000@ then
return -1
endi
if $data51 != 15 then
return -1
endi
if $data52 != tb1 then
return -1
endi
if $data60 != @21-10-20 10:00:21.000@ then
return -1
endi
if $data61 != 21 then
return -1
endi
if $data62 != tb1 then
return -1
endi
if $data70 != @21-10-20 10:00:00.000@ then
return -1
endi
if $data71 != 0 then
return -1
endi
if $data72 != tb2 then
return -1
endi
if $data80 != @21-10-20 10:00:02.000@ then
return -1
endi
if $data81 != 2 then
return -1
endi
if $data82 != tb2 then
return -1
endi
if $data90 != @21-10-20 10:00:04.000@ then
return -1
endi
if $data91 != 4 then
return -1
endi
if $data92 != tb2 then
return -1
endi
sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname limit 10;
sql SELECT INTERP(c1) FROM stb1 every(1s) group by tbname limit 10 offset 10;
sql SELECT INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(1s) group by tbname;
sql SELECT tbname,INTERP(c1),t1,interp(c2),t2,interp(c3) FROM stb1 every(1s) group by tbname;
SELECT INTERP(c1) FROM stb1 range('2021-10-20 10:00:00.000','2021-10-20 10:00:40.000') every(1s) fill(linear) group by tbname;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册