[td-10564] refactor and add test cases.
This commit is contained in:
parent
3f84c37db3
commit
a531411e06
|
@ -81,6 +81,7 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_ERR -1
|
||||
|
||||
#define TS_PATH_DELIMITER "."
|
||||
#define TS_ESCAPE_CHAR '`'
|
||||
|
||||
#define TSDB_TIME_PRECISION_MILLI 0
|
||||
#define TSDB_TIME_PRECISION_MICRO 1
|
||||
|
|
|
@ -26,6 +26,7 @@ extern "C" {
|
|||
#include "tdef.h"
|
||||
|
||||
int32_t strdequote(char *src);
|
||||
int32_t strndequote(char *dst, const char* z, int32_t len);
|
||||
int32_t strRmquote(char *z, int32_t len);
|
||||
size_t strtrim(char *src);
|
||||
char * strnchr(char *haystack, char needle, int32_t len, bool skipquote);
|
||||
|
|
|
@ -4349,10 +4349,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 1
|
||||
"sum",
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_SUM,
|
||||
FUNCTION_SUM,
|
||||
BASIC_FUNC_SO,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
sum_function,
|
||||
function_finalizer,
|
||||
|
@ -4362,10 +4362,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 2
|
||||
"avg",
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_AVG,
|
||||
FUNCTION_AVG,
|
||||
BASIC_FUNC_SO,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
avg_function,
|
||||
avg_finalizer,
|
||||
|
@ -4375,10 +4375,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 3
|
||||
"min",
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_MIN,
|
||||
FUNCTION_MIN,
|
||||
BASIC_FUNC_SO | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
min_func_setup,
|
||||
min_function,
|
||||
function_finalizer,
|
||||
|
@ -4388,10 +4388,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 4
|
||||
"max",
|
||||
FUNCTION_MAX,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_MAX,
|
||||
FUNCTION_MAX,
|
||||
BASIC_FUNC_SO | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
max_func_setup,
|
||||
max_function,
|
||||
function_finalizer,
|
||||
|
@ -4401,10 +4401,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 5
|
||||
"stddev",
|
||||
FUNCTION_STDDEV,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_STDDEV,
|
||||
FUNCTION_STDDEV_DST,
|
||||
FUNCSTATE_SO | FUNCSTATE_STREAM,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
stddev_function,
|
||||
stddev_finalizer,
|
||||
|
@ -4414,10 +4414,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 6
|
||||
"percentile",
|
||||
FUNCTION_PERCT,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_PERCT,
|
||||
FUNCTION_INVALID_ID,
|
||||
FUNCSTATE_SO | FUNCSTATE_STREAM,
|
||||
FUNCTION_AGG,
|
||||
percentile_function_setup,
|
||||
percentile_function,
|
||||
percentile_finalizer,
|
||||
|
@ -4427,10 +4427,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 7
|
||||
"apercentile",
|
||||
FUNCTION_APERCT,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_APERCT,
|
||||
FUNCTION_APERCT,
|
||||
FUNCSTATE_SO | FUNCSTATE_STREAM | FUNCSTATE_STABLE,
|
||||
FUNCTION_AGG,
|
||||
apercentile_function_setup,
|
||||
apercentile_function,
|
||||
apercentile_finalizer,
|
||||
|
@ -4440,10 +4440,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 8
|
||||
"first",
|
||||
FUNCTION_FIRST,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_FIRST,
|
||||
FUNCTION_FIRST_DST,
|
||||
BASIC_FUNC_SO | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
first_function,
|
||||
function_finalizer,
|
||||
|
@ -4453,10 +4453,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 9
|
||||
"last",
|
||||
FUNCTION_LAST,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_LAST,
|
||||
FUNCTION_LAST_DST,
|
||||
BASIC_FUNC_SO | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
last_function,
|
||||
function_finalizer,
|
||||
|
@ -4466,10 +4466,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 10
|
||||
"last_row",
|
||||
FUNCTION_LAST_ROW,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_LAST_ROW,
|
||||
FUNCTION_LAST_ROW,
|
||||
FUNCSTATE_SO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
first_last_function_setup,
|
||||
last_row_function,
|
||||
last_row_finalizer,
|
||||
|
@ -4479,10 +4479,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 11
|
||||
"top",
|
||||
FUNCTION_TOP,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TOP,
|
||||
FUNCTION_TOP,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
top_bottom_function_setup,
|
||||
top_function,
|
||||
top_bottom_func_finalizer,
|
||||
|
@ -4492,10 +4492,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 12
|
||||
"bottom",
|
||||
FUNCTION_BOTTOM,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_BOTTOM,
|
||||
FUNCTION_BOTTOM,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
top_bottom_function_setup,
|
||||
bottom_function,
|
||||
top_bottom_func_finalizer,
|
||||
|
@ -4505,10 +4505,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 13
|
||||
"spread",
|
||||
FUNCTION_SPREAD,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_SPREAD,
|
||||
FUNCTION_SPREAD,
|
||||
BASIC_FUNC_SO,
|
||||
FUNCTION_AGG,
|
||||
spread_function_setup,
|
||||
spread_function,
|
||||
spread_function_finalizer,
|
||||
|
@ -4518,10 +4518,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 14
|
||||
"twa",
|
||||
FUNCTION_TWA,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TWA,
|
||||
FUNCTION_TWA,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
twa_function_setup,
|
||||
twa_function,
|
||||
twa_function_finalizer,
|
||||
|
@ -4531,10 +4531,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 15
|
||||
"leastsquares",
|
||||
FUNCTION_LEASTSQR,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_LEASTSQR,
|
||||
FUNCTION_INVALID_ID,
|
||||
FUNCSTATE_SO | FUNCSTATE_STREAM,
|
||||
FUNCTION_AGG,
|
||||
leastsquares_function_setup,
|
||||
leastsquares_function,
|
||||
leastsquares_finalizer,
|
||||
|
@ -4544,10 +4544,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 16
|
||||
"ts",
|
||||
FUNCTION_TS,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TS,
|
||||
FUNCTION_TS,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
date_col_output_function,
|
||||
doFinalizer,
|
||||
|
@ -4557,10 +4557,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 17
|
||||
"ts",
|
||||
FUNCTION_TS_DUMMY,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TS_DUMMY,
|
||||
FUNCTION_TS_DUMMY,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
noop1,
|
||||
doFinalizer,
|
||||
|
@ -4570,10 +4570,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 18
|
||||
"tag_dummy",
|
||||
FUNCTION_TAG_DUMMY,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TAG_DUMMY,
|
||||
FUNCTION_TAG_DUMMY,
|
||||
BASIC_FUNC_SO,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
tag_function,
|
||||
doFinalizer,
|
||||
|
@ -4583,10 +4583,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 19
|
||||
"ts",
|
||||
FUNCTION_TS_COMP,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TS_COMP,
|
||||
FUNCTION_TS_COMP,
|
||||
FUNCSTATE_MO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
ts_comp_function_setup,
|
||||
ts_comp_function,
|
||||
ts_comp_finalize,
|
||||
|
@ -4596,10 +4596,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 20
|
||||
"tag",
|
||||
FUNCTION_TAG,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TAG,
|
||||
FUNCTION_TAG,
|
||||
BASIC_FUNC_SO,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
tag_function,
|
||||
doFinalizer,
|
||||
|
@ -4609,10 +4609,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{//TODO this is a scala function
|
||||
// 21, column project sql function
|
||||
"colprj",
|
||||
FUNCTION_PRJ,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_PRJ,
|
||||
FUNCTION_PRJ,
|
||||
BASIC_FUNC_MO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
col_project_function,
|
||||
doFinalizer,
|
||||
|
@ -4622,10 +4622,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 22, multi-output, tag function has only one result
|
||||
"tagprj",
|
||||
FUNCTION_TAGPRJ,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TAGPRJ,
|
||||
FUNCTION_TAGPRJ,
|
||||
BASIC_FUNC_MO,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
tag_project_function,
|
||||
doFinalizer,
|
||||
|
@ -4635,10 +4635,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 23
|
||||
"arithmetic",
|
||||
FUNCTION_ARITHM,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_ARITHM,
|
||||
FUNCTION_ARITHM,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
arithmetic_function,
|
||||
doFinalizer,
|
||||
|
@ -4648,10 +4648,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 24
|
||||
"diff",
|
||||
FUNCTION_DIFF,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_DIFF,
|
||||
FUNCTION_INVALID_ID,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
diff_function_setup,
|
||||
diff_function,
|
||||
doFinalizer,
|
||||
|
@ -4662,10 +4662,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 25
|
||||
"first_dist",
|
||||
FUNCTION_FIRST_DST,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_FIRST_DST,
|
||||
FUNCTION_FIRST_DST,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
first_last_function_setup,
|
||||
first_dist_function,
|
||||
function_finalizer,
|
||||
|
@ -4675,10 +4675,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 26
|
||||
"last_dist",
|
||||
FUNCTION_LAST_DST,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_LAST_DST,
|
||||
FUNCTION_LAST_DST,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
first_last_function_setup,
|
||||
last_dist_function,
|
||||
function_finalizer,
|
||||
|
@ -4688,10 +4688,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 27
|
||||
"stddev", // return table id and the corresponding tags for join match and subscribe
|
||||
FUNCTION_STDDEV_DST,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_STDDEV_DST,
|
||||
FUNCTION_AVG,
|
||||
FUNCSTATE_SO | FUNCSTATE_STABLE,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
stddev_dst_function,
|
||||
stddev_dst_finalizer,
|
||||
|
@ -4701,10 +4701,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 28
|
||||
"interp",
|
||||
FUNCTION_INTERP,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_INTERP,
|
||||
FUNCTION_INTERP,
|
||||
FUNCSTATE_SO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS ,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
interp_function,
|
||||
doFinalizer,
|
||||
|
@ -4714,10 +4714,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 29
|
||||
"rate",
|
||||
FUNCTION_RATE,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_RATE,
|
||||
FUNCTION_RATE,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
rate_function_setup,
|
||||
rate_function,
|
||||
rate_finalizer,
|
||||
|
@ -4727,10 +4727,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 30
|
||||
"irate",
|
||||
FUNCTION_IRATE,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_IRATE,
|
||||
FUNCTION_IRATE,
|
||||
BASIC_FUNC_SO | FUNCSTATE_NEED_TS,
|
||||
FUNCTION_AGG,
|
||||
rate_function_setup,
|
||||
irate_function,
|
||||
rate_finalizer,
|
||||
|
@ -4740,10 +4740,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 31
|
||||
"tbid", // return table id and the corresponding tags for join match and subscribe
|
||||
FUNCTION_TID_TAG,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_TID_TAG,
|
||||
FUNCTION_TID_TAG,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
noop1,
|
||||
noop1,
|
||||
|
@ -4752,10 +4752,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
},
|
||||
{ //32
|
||||
"derivative", // return table id and the corresponding tags for join match and subscribe
|
||||
FUNCTION_DERIVATIVE,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_DERIVATIVE,
|
||||
FUNCTION_INVALID_ID,
|
||||
FUNCSTATE_MO | FUNCSTATE_STABLE | FUNCSTATE_NEED_TS | FUNCSTATE_SELECTIVITY,
|
||||
FUNCTION_AGG,
|
||||
deriv_function_setup,
|
||||
deriv_function,
|
||||
doFinalizer,
|
||||
|
@ -4765,10 +4765,10 @@ SAggFunctionInfo aggFunc[34] = {{
|
|||
{
|
||||
// 33
|
||||
"_block_dist", // return table id and the corresponding tags for join match and subscribe
|
||||
FUNCTION_BLKINFO,
|
||||
FUNCTION_AGG,
|
||||
FUNCTION_BLKINFO,
|
||||
FUNCTION_BLKINFO,
|
||||
FUNCSTATE_SO | FUNCSTATE_STABLE,
|
||||
FUNCTION_AGG,
|
||||
function_setup,
|
||||
blockInfo_func,
|
||||
blockinfo_func_finalizer,
|
||||
|
|
|
@ -12,13 +12,16 @@ static void doInitFunctionHashTable() {
|
|||
functionHashTable = taosHashInit(numOfEntries, MurmurHash3_32, false, false);
|
||||
for (int32_t i = 0; i < numOfEntries; i++) {
|
||||
int32_t len = (uint32_t)strlen(aggFunc[i].name);
|
||||
taosHashPut(functionHashTable, aggFunc[i].name, len, (void*)&aggFunc[i], POINTER_BYTES);
|
||||
|
||||
SAggFunctionInfo* ptr = &aggFunc[i];
|
||||
taosHashPut(functionHashTable, aggFunc[i].name, len, (void*)&ptr, POINTER_BYTES);
|
||||
}
|
||||
|
||||
numOfEntries = tListLen(scalarFunc);
|
||||
for(int32_t i = 0; i < numOfEntries; ++i) {
|
||||
int32_t len = (int32_t) strlen(scalarFunc[i].name);
|
||||
taosHashPut(functionHashTable, scalarFunc[i].name, len, (void*)&scalarFunc[i], POINTER_BYTES);
|
||||
SScalarFunctionInfo* ptr = &scalarFunc[i];
|
||||
taosHashPut(functionHashTable, scalarFunc[i].name, len, (void*)&ptr, POINTER_BYTES);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,8 +48,6 @@ typedef struct SSqlExpr {
|
|||
SColIndex colInfo;
|
||||
uint64_t uid; // table uid, todo refactor use the pointer
|
||||
int32_t interBytes; // inter result buffer size
|
||||
// int16_t colType; // table column type
|
||||
// int16_t colBytes; // table column bytes
|
||||
int16_t numOfParams; // argument value of each function
|
||||
SVariant param[3]; // parameters are not more than 3
|
||||
} SSqlExpr;
|
||||
|
@ -101,6 +99,9 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ
|
|||
*/
|
||||
int32_t evaluateSqlNode(SSqlNode* pNode, int32_t tsPrecision, SMsgBuf* pMsgBuf);
|
||||
|
||||
int32_t validateSqlNode(SSqlNode* pSqlNode, SQueryStmtInfo* pQueryInfo, SMsgBuf* pMsgBuf);
|
||||
void initQueryInfo(SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
/**
|
||||
* Extract request meta info from the sql statement
|
||||
* @param pSqlInfo
|
||||
|
|
|
@ -37,7 +37,7 @@ extern "C" {
|
|||
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
|
||||
|
||||
TAOS_FIELD createField(const SSchema* pSchema);
|
||||
void setSchemaVal(SSchema* pSchema, uint8_t type, int16_t bytes, int16_t colId, const char* name);
|
||||
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name);
|
||||
|
||||
SInternalField* insertFieldInfo(SFieldInfo* pFieldInfo, int32_t index, SSchema* field);
|
||||
int32_t getNumOfFields(SFieldInfo* pFieldInfo);
|
||||
|
@ -45,7 +45,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index);
|
|||
|
||||
int32_t parserValidateIdToken(SToken* pToken);
|
||||
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
|
||||
int32_t parserSetSyntaxErrMsg(char* dst, int32_t dstBufLen, const char* additionalInfo, const char* sourceStr);
|
||||
int32_t buildSyntaxErrMsg(char* dst, int32_t dstBufLen, const char* additionalInfo, const char* sourceStr);
|
||||
|
||||
int32_t createProjectionExpr(SQueryStmtInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SExprInfo*** pExpr, int32_t* num);
|
||||
STableMetaInfo* addEmptyMetaInfo(SQueryStmtInfo* pQueryInfo);
|
||||
|
@ -60,6 +60,8 @@ SColumn* insertPrimaryTsColumn(SArray* pColumnList, uint64_t tableUid);
|
|||
void cleanupTagCond(STagCond* pTagCond);
|
||||
void cleanupColumnCond(SArray** pCond);
|
||||
|
||||
uint32_t convertRelationalOperator(SToken *pToken);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -30,8 +30,10 @@ SSchema *getTableTagSchema(const STableMeta* pTableMeta);
|
|||
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
||||
|
||||
size_t getNumOfExprs(SQueryStmtInfo* pQueryInfo);
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex,
|
||||
SSchema* pResSchema, int16_t interSize);
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex, struct tExprNode* pParamExpr, SSchema* pResSchema, int16_t interSize);
|
||||
|
||||
SExprInfo* createBinaryExprInfo(struct tExprNode* pNode, SSchema* pResSchema);
|
||||
|
||||
void addExprInfo(SQueryStmtInfo* pQueryInfo, int32_t index, SExprInfo* pExprInfo);
|
||||
void updateExprInfo(SExprInfo* pExprInfo, int16_t functionId, int32_t colId, int16_t srcColumnIndex, int16_t resType, int16_t resSize);
|
||||
void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,7 +23,7 @@ bool qIsInsertSql(const char* pStr, size_t length) {
|
|||
int32_t index = 0;
|
||||
|
||||
do {
|
||||
SToken t0 = tStrGetToken(pStr, &index, false);
|
||||
SToken t0 = tStrGetToken((char*) pStr, &index, false);
|
||||
if (t0.type != TK_LP) {
|
||||
return t0.type == TK_INSERT || t0.type == TK_IMPORT;
|
||||
}
|
||||
|
@ -120,17 +120,12 @@ int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList, SMsgB
|
|||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
// tscDequoteAndTrimToken(t);
|
||||
if (parserValidateIdToken(t) != TSDB_CODE_SUCCESS) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg1);
|
||||
}
|
||||
|
||||
SName name = {0};
|
||||
// int32_t code = tscSetTableFullName(&name, t, pSql);
|
||||
// if (code != TSDB_CODE_SUCCESS) {
|
||||
// return code;
|
||||
// }
|
||||
|
||||
strndequote(name.tname, t->z, t->n);
|
||||
taosArrayPush(tableNameList, &name);
|
||||
}
|
||||
|
||||
|
@ -183,7 +178,7 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
|
|||
assert(t != NULL);
|
||||
|
||||
if (t->n >= TSDB_FUNC_NAME_LEN) {
|
||||
return parserSetSyntaxErrMsg(msg, msgBufLen, "too long function name", t->z);
|
||||
return buildSyntaxErrMsg(msg, msgBufLen, "too long function name", t->z);
|
||||
}
|
||||
|
||||
// Let's assume that it is an UDF/UDAF, if it is not a built-in function.
|
||||
|
@ -193,4 +188,6 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
|
@ -26,6 +26,11 @@ int32_t parserValidateIdToken(SToken* pToken) {
|
|||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
// it is a token quoted with escape char '`'
|
||||
if (pToken->z[0] == TS_ESCAPE_CHAR && pToken->z[pToken->n - 1] == TS_ESCAPE_CHAR) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
|
||||
if (sep == NULL) { // It is a single part token, not a complex type
|
||||
if (isNumber(pToken)) {
|
||||
|
@ -83,7 +88,7 @@ int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
|
|||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||
}
|
||||
|
||||
int32_t parserSetSyntaxErrMsg(char* dst, int32_t dstBufLen, const char* additionalInfo, const char* sourceStr) {
|
||||
int32_t buildSyntaxErrMsg(char* dst, int32_t dstBufLen, const char* additionalInfo, const char* sourceStr) {
|
||||
const char* msgFormat1 = "syntax error near \'%s\'";
|
||||
const char* msgFormat2 = "syntax error near \'%s\' (%s)";
|
||||
const char* msgFormat3 = "%s";
|
||||
|
@ -499,13 +504,14 @@ TAOS_FIELD createField(const SSchema* pSchema) {
|
|||
return f;
|
||||
}
|
||||
|
||||
void setSchemaVal(SSchema* pSchema, uint8_t type, int16_t bytes, int16_t colId, const char* name){
|
||||
assert(pSchema != NULL);
|
||||
pSchema->type = type;
|
||||
pSchema->bytes = bytes;
|
||||
pSchema->colId = colId;
|
||||
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name) {
|
||||
SSchema s = {0};
|
||||
s.type = type;
|
||||
s.bytes = bytes;
|
||||
s.colId = colId;
|
||||
|
||||
tstrncpy(pSchema->name, name, tListLen(pSchema->name));
|
||||
tstrncpy(s.name, name, tListLen(s.name));
|
||||
return s;
|
||||
}
|
||||
|
||||
int32_t getNumOfFields(SFieldInfo* pFieldInfo) {
|
||||
|
@ -1598,6 +1604,52 @@ int32_t getTagFilterSerializeLen(SQueryStmtInfo* pQueryInfo) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
uint32_t convertRelationalOperator(SToken *pToken) {
|
||||
switch (pToken->type) {
|
||||
case TK_LT:
|
||||
return TSDB_RELATION_LESS;
|
||||
case TK_LE:
|
||||
return TSDB_RELATION_LESS_EQUAL;
|
||||
case TK_GT:
|
||||
return TSDB_RELATION_GREATER;
|
||||
case TK_GE:
|
||||
return TSDB_RELATION_GREATER_EQUAL;
|
||||
case TK_NE:
|
||||
return TSDB_RELATION_NOT_EQUAL;
|
||||
case TK_AND:
|
||||
return TSDB_RELATION_AND;
|
||||
case TK_OR:
|
||||
return TSDB_RELATION_OR;
|
||||
case TK_EQ:
|
||||
return TSDB_RELATION_EQUAL;
|
||||
case TK_PLUS:
|
||||
return TSDB_BINARY_OP_ADD;
|
||||
|
||||
case TK_MINUS:
|
||||
return TSDB_BINARY_OP_SUBTRACT;
|
||||
case TK_STAR:
|
||||
return TSDB_BINARY_OP_MULTIPLY;
|
||||
case TK_SLASH:
|
||||
case TK_DIVIDE:
|
||||
return TSDB_BINARY_OP_DIVIDE;
|
||||
case TK_REM:
|
||||
return TSDB_BINARY_OP_REMAINDER;
|
||||
case TK_LIKE:
|
||||
return TSDB_RELATION_LIKE;
|
||||
case TK_MATCH:
|
||||
return TSDB_RELATION_MATCH;
|
||||
case TK_NMATCH:
|
||||
return TSDB_RELATION_NMATCH;
|
||||
case TK_ISNULL:
|
||||
return TSDB_RELATION_ISNULL;
|
||||
case TK_NOTNULL:
|
||||
return TSDB_RELATION_NOTNULL;
|
||||
case TK_IN:
|
||||
return TSDB_RELATION_IN;
|
||||
default: { return 0; }
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tscCreateQueryFromQueryInfo(SQueryStmtInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr) {
|
||||
memset(pQueryAttr, 0, sizeof(SQueryAttr));
|
||||
|
|
|
@ -55,11 +55,16 @@ SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
|||
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
||||
}
|
||||
|
||||
static tExprNode* createUnaryFunctionExprNode(int32_t functionId, SSchema* pSchema) {
|
||||
tExprNode* pColumnNode = calloc(1, sizeof(tExprNode));
|
||||
pColumnNode->nodeType = TEXPR_COL_NODE;
|
||||
pColumnNode->pSchema = calloc(1, sizeof(SSchema));
|
||||
memcpy(pColumnNode->pSchema, pSchema, sizeof(SSchema));
|
||||
static tExprNode* createUnaryFunctionExprNode(int32_t functionId, SSchema* pSchema, tExprNode* pColumnNode) {
|
||||
|
||||
if (pColumnNode == NULL) {
|
||||
pColumnNode = calloc(1, sizeof(tExprNode));
|
||||
pColumnNode->nodeType = TEXPR_COL_NODE;
|
||||
pColumnNode->pSchema = calloc(1, sizeof(SSchema));
|
||||
memcpy(pColumnNode->pSchema, pSchema, sizeof(SSchema));
|
||||
} else {
|
||||
assert(pSchema == NULL);
|
||||
}
|
||||
|
||||
tExprNode* pNode = calloc(1, sizeof(tExprNode));
|
||||
pNode->nodeType = TEXPR_UNARYEXPR_NODE;
|
||||
|
@ -69,7 +74,20 @@ static tExprNode* createUnaryFunctionExprNode(int32_t functionId, SSchema* pSche
|
|||
return pNode;
|
||||
}
|
||||
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex, SSchema* pResSchema, int16_t interSize) {
|
||||
SExprInfo* createBinaryExprInfo(tExprNode* pNode, SSchema* pResSchema) {
|
||||
assert(pNode != NULL && pResSchema != NULL);
|
||||
|
||||
SExprInfo* pExpr = calloc(1, sizeof(SExprInfo));
|
||||
if (pExpr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pExpr->pExpr = pNode;
|
||||
memcpy(&pExpr->base.resSchema, pResSchema, sizeof(SSchema));
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SColumnIndex* pColIndex, tExprNode* pParamExpr, SSchema* pResSchema, int16_t interSize) {
|
||||
SExprInfo* pExpr = calloc(1, sizeof(SExprInfo));
|
||||
if (pExpr == NULL) {
|
||||
return NULL;
|
||||
|
@ -77,29 +95,26 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SC
|
|||
|
||||
SSqlExpr* p = &pExpr->base;
|
||||
|
||||
// set the correct columnIndex index
|
||||
if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
if (pParamExpr != NULL) {
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, NULL, pParamExpr);
|
||||
} else if (pColIndex->columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||
assert(pParamExpr == NULL);
|
||||
|
||||
SSchema* s = getTbnameColumnSchema();
|
||||
p->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX;
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, s);
|
||||
} else if (pColIndex->columnIndex <= TSDB_UD_COLUMN_INDEX) {
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, s, pParamExpr);
|
||||
} else if (pColIndex->columnIndex <= TSDB_UD_COLUMN_INDEX || functionId == FUNCTION_BLKINFO) {
|
||||
assert(pParamExpr == NULL);
|
||||
|
||||
p->colInfo.colId = pColIndex->columnIndex;
|
||||
SSchema s = {.colId = pColIndex->columnIndex, .bytes = pResSchema->bytes, .type = pResSchema->type};
|
||||
tstrncpy(s.name, pResSchema->name, TSDB_COL_NAME_LEN);
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, &s);
|
||||
} else if (functionId == FUNCTION_BLKINFO) {
|
||||
p->colInfo.colId = pColIndex->columnIndex;
|
||||
SSchema s = {.colId = pColIndex->columnIndex, .bytes = pResSchema->bytes, .type = pResSchema->type};
|
||||
tstrncpy(s.name, pResSchema->name, TSDB_COL_NAME_LEN);
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, &s);
|
||||
// p->colBytes = TSDB_MAX_BINARY_LEN;
|
||||
// p->colType = TSDB_DATA_TYPE_BINARY;
|
||||
SSchema s = createSchema(pResSchema->type, pResSchema->bytes, pColIndex->columnIndex, pResSchema->name);
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, &s, pParamExpr);
|
||||
} else {
|
||||
int32_t len = tListLen(p->colInfo.name);
|
||||
if (TSDB_COL_IS_TAG(pColIndex->type)) {
|
||||
SSchema* pSchema = getTableTagSchema(pTableMetaInfo->pTableMeta);
|
||||
p->colInfo.colId = pSchema[pColIndex->columnIndex].colId;
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, &pSchema[pColIndex->columnIndex]);
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, &pSchema[pColIndex->columnIndex], pParamExpr);
|
||||
snprintf(p->colInfo.name, len, "%s.%s", pTableMetaInfo->aliasName, pSchema[pColIndex->columnIndex].name);
|
||||
} else if (pTableMetaInfo->pTableMeta != NULL) {
|
||||
// in handling select database/version/server_status(), the pTableMeta is NULL
|
||||
|
@ -107,7 +122,7 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SC
|
|||
p->colInfo.colId = pSchema->colId;
|
||||
snprintf(p->colInfo.name, len, "%s.%s", pTableMetaInfo->aliasName, pSchema->name);
|
||||
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, pSchema);
|
||||
pExpr->pExpr = createUnaryFunctionExprNode(functionId, pSchema, pParamExpr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,3 +12,367 @@
|
|||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <iostream>
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#include "os.h"
|
||||
|
||||
#include "astGenerator.h"
|
||||
#include "parserInt.h"
|
||||
#include "taos.h"
|
||||
#include "tdef.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
namespace {
|
||||
void setSchema(SSchema* p, int32_t type, int32_t bytes, const char* name, int32_t colId) {
|
||||
p->colId = colId;
|
||||
p->bytes = bytes;
|
||||
p->type = type;
|
||||
strcpy(p->name, name);
|
||||
}
|
||||
|
||||
void setTableMetaInfo(SQueryStmtInfo* pQueryInfo, SMetaReq *req) {
|
||||
pQueryInfo->numOfTables = 1;
|
||||
|
||||
pQueryInfo->pTableMetaInfo = (STableMetaInfo**)calloc(1, POINTER_BYTES);
|
||||
STableMetaInfo* pTableMetaInfo = (STableMetaInfo*)calloc(1, sizeof(STableMetaInfo));
|
||||
pQueryInfo->pTableMetaInfo[0] = pTableMetaInfo;
|
||||
|
||||
SName* name = (SName*)taosArrayGet(req->pTableName, 0);
|
||||
|
||||
memcpy(&pTableMetaInfo->name, taosArrayGet(req->pTableName, 0), sizeof(SName));
|
||||
pTableMetaInfo->pTableMeta = (STableMeta*)calloc(1, sizeof(STableMeta) + 4 * sizeof(SSchema));
|
||||
strcpy(pTableMetaInfo->aliasName, name->tname);
|
||||
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
|
||||
pTableMeta->tableType = TSDB_NORMAL_TABLE;
|
||||
pTableMeta->tableInfo.numOfColumns = 4;
|
||||
pTableMeta->tableInfo.rowSize = 28;
|
||||
pTableMeta->uid = 110;
|
||||
|
||||
pTableMetaInfo->tagColList = (SArray*) taosArrayInit(4, POINTER_BYTES);
|
||||
|
||||
SSchema* pSchema = pTableMetaInfo->pTableMeta->schema;
|
||||
setSchema(&pSchema[0], TSDB_DATA_TYPE_TIMESTAMP, 8, "ts", 0);
|
||||
setSchema(&pSchema[1], TSDB_DATA_TYPE_INT, 4, "a", 1);
|
||||
setSchema(&pSchema[2], TSDB_DATA_TYPE_DOUBLE, 8, "b", 2);
|
||||
setSchema(&pSchema[3], TSDB_DATA_TYPE_DOUBLE, 8, "col", 3);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
TEST(testCase, validateAST_test) {
|
||||
SSqlInfo info1 = doGenerateAST("select a a1111, a+b + 22, tbname from `t.1abc` where ts<now+2h and `col` < 20 + 99");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 3);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 0);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_INT);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1111");
|
||||
ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.a");
|
||||
ASSERT_EQ(p1->base.colInfo.colId, 1);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "a");
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 3);
|
||||
|
||||
SExprInfo* p2 = (SExprInfo*) taosArrayGetP(pExprList, 1);
|
||||
ASSERT_EQ(p2->base.uid, 0);
|
||||
ASSERT_EQ(p2->base.numOfParams, 1); // it is the serialized binary string of expression.
|
||||
ASSERT_EQ(p2->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_STRCASEEQ(p2->base.resSchema.name, "a+b + 22");
|
||||
|
||||
// ASSERT_STRCASEEQ(p2->base.colInfo.name, "t.1abc.a");
|
||||
// ASSERT_EQ(p1->base.colInfo.colId, 1);
|
||||
// ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p2->base.token, "a+b + 22");
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 3);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test) {
|
||||
SSqlInfo info1 = doGenerateAST("select count(a) from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 1);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 0);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "count(a)");
|
||||
ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.a");
|
||||
ASSERT_EQ(p1->base.colInfo.colId, 1);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "count(a)");
|
||||
ASSERT_EQ(p1->base.interBytes, 8);
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 2);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test2) {
|
||||
SSqlInfo info1 = doGenerateAST("select count(a) abc from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 1);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 0);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "abc");
|
||||
ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.a");
|
||||
ASSERT_EQ(p1->base.colInfo.colId, 1);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "count(a)");
|
||||
ASSERT_EQ(p1->base.interBytes, 8);
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 2);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test3) {
|
||||
SSqlInfo info1 = doGenerateAST("select first(*) from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 4);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 0);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "first(ts)");
|
||||
ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
|
||||
ASSERT_EQ(p1->base.colInfo.colId, 0);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "first(ts)");
|
||||
ASSERT_EQ(p1->base.interBytes, 24);
|
||||
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 4);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test4) {
|
||||
SSqlInfo info1 = doGenerateAST("select _block_dist() as a1 from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 1);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 1);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BINARY);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
|
||||
// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
|
||||
// ASSERT_EQ(p1->base.colInfo.colId, 0);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "_block_dist()");
|
||||
ASSERT_EQ(p1->base.interBytes, 0);
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 1);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test5) {
|
||||
SSqlInfo info1 = doGenerateAST("select sum(a) + avg(b) as a1 from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 3);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 0);
|
||||
ASSERT_EQ(p1->base.numOfParams, 1);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
|
||||
// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
|
||||
// ASSERT_EQ(p1->base.colInfo.colId, 0);
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "sum(a) + avg(b)");
|
||||
ASSERT_EQ(p1->base.interBytes, 0);
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
|
||||
}
|
||||
|
||||
TEST(testCase, function_Test6) {
|
||||
SSqlInfo info1 = doGenerateAST("select sum(a+b) as a1 from `t.1abc`");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMsgBuf buf;
|
||||
buf.len = 128;
|
||||
buf.buf = msg;
|
||||
|
||||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
|
||||
SQueryStmtInfo* pQueryInfo = (SQueryStmtInfo*)calloc(1, sizeof(SQueryStmtInfo));
|
||||
initQueryInfo(pQueryInfo);
|
||||
setTableMetaInfo(pQueryInfo, &req);
|
||||
|
||||
SSqlNode* pSqlNode = (SSqlNode*)taosArrayGetP(info1.list, 0);
|
||||
ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
SArray* pExprList = pQueryInfo->exprList;
|
||||
ASSERT_EQ(taosArrayGetSize(pExprList), 1);
|
||||
|
||||
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
|
||||
ASSERT_EQ(p1->base.uid, 110);
|
||||
ASSERT_EQ(p1->base.numOfParams, 0);
|
||||
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
|
||||
ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
|
||||
ASSERT_STRCASEEQ(p1->base.token, "sum(a+b)");
|
||||
ASSERT_EQ(p1->base.interBytes, 16);
|
||||
|
||||
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
|
||||
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
#include "os.h"
|
||||
|
||||
|
@ -89,6 +88,9 @@ TEST(testCase, validateToken_test) {
|
|||
char t01[] = "abc";
|
||||
EXPECT_EQ(testValidateName(t01), TSDB_CODE_SUCCESS);
|
||||
|
||||
char t110[] = "`1233abc.911`";
|
||||
EXPECT_EQ(testValidateName(t110), TSDB_CODE_SUCCESS);
|
||||
|
||||
char t02[] = "'abc'";
|
||||
EXPECT_EQ(testValidateName(t02), TSDB_CODE_TSC_INVALID_OPERATION);
|
||||
|
||||
|
@ -689,7 +691,7 @@ TEST(testCase, generateAST_test) {
|
|||
}
|
||||
|
||||
TEST(testCase, evaluateAST_test) {
|
||||
SSqlInfo info1 = doGenerateAST("select a, b+22 from `t.1abc` where ts<now+2h and col < 20 + 99");
|
||||
SSqlInfo info1 = doGenerateAST("select a, b+22 from `t.1abc` where ts<now+2h and `col` < 20 + 99");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
|
@ -700,6 +702,16 @@ TEST(testCase, evaluateAST_test) {
|
|||
SSqlNode* pNode = (SSqlNode*) taosArrayGetP(((SArray*)info1.list), 0);
|
||||
int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &msgBuf);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(testCase, extractMeta_test) {
|
||||
SSqlInfo info1 = doGenerateAST("select a, b+22 from `t.1abc` where ts<now+2h and `col` < 20 + 99");
|
||||
ASSERT_EQ(info1.valid, true);
|
||||
|
||||
char msg[128] = {0};
|
||||
SMetaReq req = {0};
|
||||
int32_t ret = qParserExtractRequestedMetaInfo(&info1, &req, msg, 128);
|
||||
ASSERT_EQ(ret, 0);
|
||||
ASSERT_EQ(taosArrayGetSize(req.pTableName), 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ int32_t strdequote(char *z) {
|
|||
}
|
||||
|
||||
int32_t quote = z[0];
|
||||
if (quote != '\'' && quote != '"') {
|
||||
if (quote != '\'' && quote != '"' && quote != '`') {
|
||||
return (int32_t)strlen(z);
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,34 @@ int32_t strRmquote(char *z, int32_t len){
|
|||
return len - 2 - cnt;
|
||||
}
|
||||
|
||||
int32_t strndequote(char *dst, const char* z, int32_t len) {
|
||||
assert(dst != NULL);
|
||||
if (z == NULL || len == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t quote = z[0];
|
||||
int32_t i = 1, j = 0;
|
||||
|
||||
while (z[i] != 0) {
|
||||
if (z[i] == quote) {
|
||||
if (z[i + 1] == quote) {
|
||||
dst[j++] = (char) quote;
|
||||
i++;
|
||||
} else {
|
||||
dst[j++] = 0;
|
||||
return (j - 1);
|
||||
}
|
||||
} else {
|
||||
dst[j++] = z[i];
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return j + 1; // only one quote, do nothing
|
||||
}
|
||||
|
||||
size_t strtrim(char *z) {
|
||||
int32_t i = 0;
|
||||
int32_t j = 0;
|
||||
|
|
Loading…
Reference in New Issue