Merge branch '3.0' of https://github.com/taosdata/TDengine into vnode_refact_merge
This commit is contained in:
commit
2f02aef2fc
|
@ -25,8 +25,10 @@ extern "C" {
|
||||||
#include "tvariant.h"
|
#include "tvariant.h"
|
||||||
|
|
||||||
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
|
||||||
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
#define TABLE_META_SIZE(pMeta) \
|
||||||
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
(NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
|
||||||
|
#define VGROUPS_INFO_SIZE(pInfo) \
|
||||||
|
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||||
|
|
||||||
typedef struct SRawExprNode {
|
typedef struct SRawExprNode {
|
||||||
ENodeType nodeType;
|
ENodeType nodeType;
|
||||||
|
@ -49,10 +51,7 @@ typedef struct SExprNode {
|
||||||
SArray* pAssociation;
|
SArray* pAssociation;
|
||||||
} SExprNode;
|
} SExprNode;
|
||||||
|
|
||||||
typedef enum EColumnType {
|
typedef enum EColumnType { COLUMN_TYPE_COLUMN = 1, COLUMN_TYPE_TAG } EColumnType;
|
||||||
COLUMN_TYPE_COLUMN = 1,
|
|
||||||
COLUMN_TYPE_TAG
|
|
||||||
} EColumnType;
|
|
||||||
|
|
||||||
typedef struct SColumnNode {
|
typedef struct SColumnNode {
|
||||||
SExprNode node; // QUERY_NODE_COLUMN
|
SExprNode node; // QUERY_NODE_COLUMN
|
||||||
|
@ -99,7 +98,6 @@ typedef struct SOperatorNode {
|
||||||
SNode* pRight;
|
SNode* pRight;
|
||||||
} SOperatorNode;
|
} SOperatorNode;
|
||||||
|
|
||||||
|
|
||||||
typedef struct SLogicConditionNode {
|
typedef struct SLogicConditionNode {
|
||||||
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
SExprNode node; // QUERY_NODE_LOGIC_CONDITION
|
||||||
ELogicConditionType condType;
|
ELogicConditionType condType;
|
||||||
|
@ -144,9 +142,7 @@ typedef struct STempTableNode {
|
||||||
SNode* pSubquery;
|
SNode* pSubquery;
|
||||||
} STempTableNode;
|
} STempTableNode;
|
||||||
|
|
||||||
typedef enum EJoinType {
|
typedef enum EJoinType { JOIN_TYPE_INNER = 1 } EJoinType;
|
||||||
JOIN_TYPE_INNER = 1
|
|
||||||
} EJoinType;
|
|
||||||
|
|
||||||
typedef struct SJoinTableNode {
|
typedef struct SJoinTableNode {
|
||||||
STableNode table; // QUERY_NODE_JOIN_TABLE
|
STableNode table; // QUERY_NODE_JOIN_TABLE
|
||||||
|
@ -156,9 +152,7 @@ typedef struct SJoinTableNode {
|
||||||
SNode* pOnCond;
|
SNode* pOnCond;
|
||||||
} SJoinTableNode;
|
} SJoinTableNode;
|
||||||
|
|
||||||
typedef enum EGroupingSetType {
|
typedef enum EGroupingSetType { GP_TYPE_NORMAL = 1 } EGroupingSetType;
|
||||||
GP_TYPE_NORMAL = 1
|
|
||||||
} EGroupingSetType;
|
|
||||||
|
|
||||||
typedef struct SGroupingSetNode {
|
typedef struct SGroupingSetNode {
|
||||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||||
|
@ -166,16 +160,9 @@ typedef struct SGroupingSetNode {
|
||||||
SNodeList* pParameterList;
|
SNodeList* pParameterList;
|
||||||
} SGroupingSetNode;
|
} SGroupingSetNode;
|
||||||
|
|
||||||
typedef enum EOrder {
|
typedef enum EOrder { ORDER_ASC = 1, ORDER_DESC } EOrder;
|
||||||
ORDER_ASC = 1,
|
|
||||||
ORDER_DESC
|
|
||||||
} EOrder;
|
|
||||||
|
|
||||||
typedef enum ENullOrder {
|
typedef enum ENullOrder { NULL_ORDER_DEFAULT = 1, NULL_ORDER_FIRST, NULL_ORDER_LAST } ENullOrder;
|
||||||
NULL_ORDER_DEFAULT = 1,
|
|
||||||
NULL_ORDER_FIRST,
|
|
||||||
NULL_ORDER_LAST
|
|
||||||
} ENullOrder;
|
|
||||||
|
|
||||||
typedef struct SOrderByExprNode {
|
typedef struct SOrderByExprNode {
|
||||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||||
|
@ -242,12 +229,10 @@ typedef struct SSelectStmt {
|
||||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
bool isEmptyResult;
|
bool isEmptyResult;
|
||||||
|
bool hasAggFuncs;
|
||||||
} SSelectStmt;
|
} SSelectStmt;
|
||||||
|
|
||||||
typedef enum ESetOperatorType {
|
typedef enum ESetOperatorType { SET_OP_TYPE_UNION_ALL = 1, SET_OP_TYPE_UNION } ESetOperatorType;
|
||||||
SET_OP_TYPE_UNION_ALL = 1,
|
|
||||||
SET_OP_TYPE_UNION
|
|
||||||
} ESetOperatorType;
|
|
||||||
|
|
||||||
typedef struct SSetOperator {
|
typedef struct SSetOperator {
|
||||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||||
|
@ -271,7 +256,6 @@ typedef enum ESqlClause {
|
||||||
SQL_CLAUSE_ORDER_BY
|
SQL_CLAUSE_ORDER_BY
|
||||||
} ESqlClause;
|
} ESqlClause;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PAYLOAD_TYPE_KV = 0,
|
PAYLOAD_TYPE_KV = 0,
|
||||||
PAYLOAD_TYPE_RAW = 1,
|
PAYLOAD_TYPE_RAW = 1,
|
||||||
|
|
|
@ -143,9 +143,7 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
pFunc->node.resType = (SDataType){.bytes = pPara1->resType.bytes, .type = pPara1->resType.type};
|
|
||||||
//pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY};
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +166,8 @@ static bool validAperventileAlgo(const SValueNode* pVal) {
|
||||||
if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) {
|
if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest"));
|
return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") ||
|
||||||
|
0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
@ -185,7 +184,8 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
||||||
if (3 == paraNum) {
|
if (3 == paraNum) {
|
||||||
SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2);
|
SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2);
|
||||||
if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) {
|
if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) {
|
||||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'");
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
|
"Third parameter algorithm of apercentile must be 'default' or 't-digest'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,8 @@ static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
||||||
|
|
||||||
static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateTbnameColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
// pseudo column do not need to check parameters
|
// pseudo column do not need to check parameters
|
||||||
pFunc->node.resType = (SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR};
|
pFunc->node.resType =
|
||||||
|
(SDataType){.bytes = TSDB_TABLE_FNAME_LEN - 1 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +229,8 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
||||||
|
|
||||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns");
|
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||||
|
"The parameters of first/last can only be columns");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||||
|
@ -245,11 +247,13 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT };
|
pFunc->node.resType =
|
||||||
|
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, bool hasSep) {
|
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum,
|
||||||
|
int32_t maxParaNum, bool hasSep) {
|
||||||
int32_t paraNum = LIST_LENGTH(pFunc->pParameterList);
|
int32_t paraNum = LIST_LENGTH(pFunc->pParameterList);
|
||||||
if (paraNum < minParaNum || paraNum > maxParaNum) {
|
if (paraNum < minParaNum || paraNum > maxParaNum) {
|
||||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
@ -379,11 +383,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
|
||||||
|
|
||||||
uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
|
uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type;
|
||||||
if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) {
|
if ((!IS_VAR_DATA_TYPE(para1Type) && !IS_INTEGER_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) ||
|
||||||
|
!IS_INTEGER_TYPE(para2Type)) {
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
pFunc->node.resType =
|
||||||
|
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +431,7 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{.name = "count",
|
||||||
.name = "count",
|
|
||||||
.type = FUNCTION_TYPE_COUNT,
|
.type = FUNCTION_TYPE_COUNT,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||||
.translateFunc = translateCount,
|
.translateFunc = translateCount,
|
||||||
|
@ -434,10 +439,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.getEnvFunc = getCountFuncEnv,
|
.getEnvFunc = getCountFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
.processFunc = countFunction,
|
.processFunc = countFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "sum",
|
||||||
{
|
|
||||||
.name = "sum",
|
|
||||||
.type = FUNCTION_TYPE_SUM,
|
.type = FUNCTION_TYPE_SUM,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||||
.translateFunc = translateSum,
|
.translateFunc = translateSum,
|
||||||
|
@ -445,10 +448,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.getEnvFunc = getSumFuncEnv,
|
.getEnvFunc = getSumFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
.processFunc = sumFunction,
|
.processFunc = sumFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "min",
|
||||||
{
|
|
||||||
.name = "min",
|
|
||||||
.type = FUNCTION_TYPE_MIN,
|
.type = FUNCTION_TYPE_MIN,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
|
@ -456,10 +457,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = minFunctionSetup,
|
.initFunc = minFunctionSetup,
|
||||||
.processFunc = minFunction,
|
.processFunc = minFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "max",
|
||||||
{
|
|
||||||
.name = "max",
|
|
||||||
.type = FUNCTION_TYPE_MAX,
|
.type = FUNCTION_TYPE_MAX,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
|
@ -467,48 +466,39 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = maxFunctionSetup,
|
.initFunc = maxFunctionSetup,
|
||||||
.processFunc = maxFunction,
|
.processFunc = maxFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "stddev",
|
||||||
{
|
|
||||||
.name = "stddev",
|
|
||||||
.type = FUNCTION_TYPE_STDDEV,
|
.type = FUNCTION_TYPE_STDDEV,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = getStddevFuncEnv,
|
.getEnvFunc = getStddevFuncEnv,
|
||||||
.initFunc = stddevFunctionSetup,
|
.initFunc = stddevFunctionSetup,
|
||||||
.processFunc = stddevFunction,
|
.processFunc = stddevFunction,
|
||||||
.finalizeFunc = stddevFinalize
|
.finalizeFunc = stddevFinalize},
|
||||||
},
|
{.name = "avg",
|
||||||
{
|
|
||||||
.name = "avg",
|
|
||||||
.type = FUNCTION_TYPE_AVG,
|
.type = FUNCTION_TYPE_AVG,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = getAvgFuncEnv,
|
.getEnvFunc = getAvgFuncEnv,
|
||||||
.initFunc = avgFunctionSetup,
|
.initFunc = avgFunctionSetup,
|
||||||
.processFunc = avgFunction,
|
.processFunc = avgFunction,
|
||||||
.finalizeFunc = avgFinalize
|
.finalizeFunc = avgFinalize},
|
||||||
},
|
{.name = "percentile",
|
||||||
{
|
|
||||||
.name = "percentile",
|
|
||||||
.type = FUNCTION_TYPE_PERCENTILE,
|
.type = FUNCTION_TYPE_PERCENTILE,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translatePercentile,
|
.translateFunc = translatePercentile,
|
||||||
.getEnvFunc = getPercentileFuncEnv,
|
.getEnvFunc = getPercentileFuncEnv,
|
||||||
.initFunc = percentileFunctionSetup,
|
.initFunc = percentileFunctionSetup,
|
||||||
.processFunc = percentileFunction,
|
.processFunc = percentileFunction,
|
||||||
.finalizeFunc = percentileFinalize
|
.finalizeFunc = percentileFinalize},
|
||||||
},
|
{.name = "apercentile",
|
||||||
{
|
|
||||||
.name = "apercentile",
|
|
||||||
.type = FUNCTION_TYPE_APERCENTILE,
|
.type = FUNCTION_TYPE_APERCENTILE,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translateApercentile,
|
.translateFunc = translateApercentile,
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = maxFunctionSetup,
|
.initFunc = maxFunctionSetup,
|
||||||
.processFunc = maxFunction,
|
.processFunc = maxFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.name = "top",
|
.name = "top",
|
||||||
.type = FUNCTION_TYPE_TOP,
|
.type = FUNCTION_TYPE_TOP,
|
||||||
|
@ -519,446 +509,357 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.processFunc = topFunction,
|
.processFunc = topFunction,
|
||||||
.finalizeFunc = topBotFinalize,
|
.finalizeFunc = topBotFinalize,
|
||||||
},
|
},
|
||||||
{
|
{.name = "bottom",
|
||||||
.name = "bottom",
|
|
||||||
.type = FUNCTION_TYPE_BOTTOM,
|
.type = FUNCTION_TYPE_BOTTOM,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translateBottom,
|
.translateFunc = translateBottom,
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = maxFunctionSetup,
|
.initFunc = maxFunctionSetup,
|
||||||
.processFunc = maxFunction,
|
.processFunc = maxFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "spread",
|
||||||
{
|
|
||||||
.name = "spread",
|
|
||||||
.type = FUNCTION_TYPE_SPREAD,
|
.type = FUNCTION_TYPE_SPREAD,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
.translateFunc = translateSpread,
|
.translateFunc = translateSpread,
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = maxFunctionSetup,
|
.initFunc = maxFunctionSetup,
|
||||||
.processFunc = maxFunction,
|
.processFunc = maxFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "last_row",
|
||||||
{
|
|
||||||
.name = "last_row",
|
|
||||||
.type = FUNCTION_TYPE_LAST_ROW,
|
.type = FUNCTION_TYPE_LAST_ROW,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||||
.translateFunc = translateLastRow,
|
.translateFunc = translateLastRow,
|
||||||
.getEnvFunc = getMinmaxFuncEnv,
|
.getEnvFunc = getMinmaxFuncEnv,
|
||||||
.initFunc = maxFunctionSetup,
|
.initFunc = maxFunctionSetup,
|
||||||
.processFunc = maxFunction,
|
.processFunc = maxFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "first",
|
||||||
{
|
|
||||||
.name = "first",
|
|
||||||
.type = FUNCTION_TYPE_FIRST,
|
.type = FUNCTION_TYPE_FIRST,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||||
.translateFunc = translateFirstLast,
|
.translateFunc = translateFirstLast,
|
||||||
.getEnvFunc = getFirstLastFuncEnv,
|
.getEnvFunc = getFirstLastFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
.processFunc = firstFunction,
|
.processFunc = firstFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "last",
|
||||||
{
|
|
||||||
.name = "last",
|
|
||||||
.type = FUNCTION_TYPE_LAST,
|
.type = FUNCTION_TYPE_LAST,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||||
.translateFunc = translateFirstLast,
|
.translateFunc = translateFirstLast,
|
||||||
.getEnvFunc = getFirstLastFuncEnv,
|
.getEnvFunc = getFirstLastFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
.processFunc = lastFunction,
|
.processFunc = lastFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "diff",
|
||||||
{
|
|
||||||
.name = "diff",
|
|
||||||
.type = FUNCTION_TYPE_DIFF,
|
.type = FUNCTION_TYPE_DIFF,
|
||||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC,
|
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
.getEnvFunc = getDiffFuncEnv,
|
.getEnvFunc = getDiffFuncEnv,
|
||||||
.initFunc = diffFunctionSetup,
|
.initFunc = diffFunctionSetup,
|
||||||
.processFunc = diffFunction,
|
.processFunc = diffFunction,
|
||||||
.finalizeFunc = functionFinalize
|
.finalizeFunc = functionFinalize},
|
||||||
},
|
{.name = "abs",
|
||||||
{
|
|
||||||
.name = "abs",
|
|
||||||
.type = FUNCTION_TYPE_ABS,
|
.type = FUNCTION_TYPE_ABS,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = absFunction,
|
.sprocessFunc = absFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "log",
|
||||||
{
|
|
||||||
.name = "log",
|
|
||||||
.type = FUNCTION_TYPE_LOG,
|
.type = FUNCTION_TYPE_LOG,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateIn2NumOutDou,
|
.translateFunc = translateIn2NumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = logFunction,
|
.sprocessFunc = logFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "pow",
|
||||||
{
|
|
||||||
.name = "pow",
|
|
||||||
.type = FUNCTION_TYPE_POW,
|
.type = FUNCTION_TYPE_POW,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateIn2NumOutDou,
|
.translateFunc = translateIn2NumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = powFunction,
|
.sprocessFunc = powFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "sqrt",
|
||||||
{
|
|
||||||
.name = "sqrt",
|
|
||||||
.type = FUNCTION_TYPE_SQRT,
|
.type = FUNCTION_TYPE_SQRT,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = sqrtFunction,
|
.sprocessFunc = sqrtFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "ceil",
|
||||||
{
|
|
||||||
.name = "ceil",
|
|
||||||
.type = FUNCTION_TYPE_CEIL,
|
.type = FUNCTION_TYPE_CEIL,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = ceilFunction,
|
.sprocessFunc = ceilFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "floor",
|
||||||
{
|
|
||||||
.name = "floor",
|
|
||||||
.type = FUNCTION_TYPE_FLOOR,
|
.type = FUNCTION_TYPE_FLOOR,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = floorFunction,
|
.sprocessFunc = floorFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "round",
|
||||||
{
|
|
||||||
.name = "round",
|
|
||||||
.type = FUNCTION_TYPE_ROUND,
|
.type = FUNCTION_TYPE_ROUND,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInOutNum,
|
.translateFunc = translateInOutNum,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = roundFunction,
|
.sprocessFunc = roundFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "sin",
|
||||||
{
|
|
||||||
.name = "sin",
|
|
||||||
.type = FUNCTION_TYPE_SIN,
|
.type = FUNCTION_TYPE_SIN,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = sinFunction,
|
.sprocessFunc = sinFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "cos",
|
||||||
{
|
|
||||||
.name = "cos",
|
|
||||||
.type = FUNCTION_TYPE_COS,
|
.type = FUNCTION_TYPE_COS,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = cosFunction,
|
.sprocessFunc = cosFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "tan",
|
||||||
{
|
|
||||||
.name = "tan",
|
|
||||||
.type = FUNCTION_TYPE_TAN,
|
.type = FUNCTION_TYPE_TAN,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = tanFunction,
|
.sprocessFunc = tanFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "asin",
|
||||||
{
|
|
||||||
.name = "asin",
|
|
||||||
.type = FUNCTION_TYPE_ASIN,
|
.type = FUNCTION_TYPE_ASIN,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = asinFunction,
|
.sprocessFunc = asinFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "acos",
|
||||||
{
|
|
||||||
.name = "acos",
|
|
||||||
.type = FUNCTION_TYPE_ACOS,
|
.type = FUNCTION_TYPE_ACOS,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = acosFunction,
|
.sprocessFunc = acosFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "atan",
|
||||||
{
|
|
||||||
.name = "atan",
|
|
||||||
.type = FUNCTION_TYPE_ATAN,
|
.type = FUNCTION_TYPE_ATAN,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = atanFunction,
|
.sprocessFunc = atanFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "length",
|
||||||
{
|
|
||||||
.name = "length",
|
|
||||||
.type = FUNCTION_TYPE_LENGTH,
|
.type = FUNCTION_TYPE_LENGTH,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateLength,
|
.translateFunc = translateLength,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = lengthFunction,
|
.sprocessFunc = lengthFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "char_length",
|
||||||
{
|
|
||||||
.name = "char_length",
|
|
||||||
.type = FUNCTION_TYPE_CHAR_LENGTH,
|
.type = FUNCTION_TYPE_CHAR_LENGTH,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateLength,
|
.translateFunc = translateLength,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = charLengthFunction,
|
.sprocessFunc = charLengthFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "concat",
|
||||||
{
|
|
||||||
.name = "concat",
|
|
||||||
.type = FUNCTION_TYPE_CONCAT,
|
.type = FUNCTION_TYPE_CONCAT,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateConcat,
|
.translateFunc = translateConcat,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = concatFunction,
|
.sprocessFunc = concatFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "concat_ws",
|
||||||
{
|
|
||||||
.name = "concat_ws",
|
|
||||||
.type = FUNCTION_TYPE_CONCAT_WS,
|
.type = FUNCTION_TYPE_CONCAT_WS,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateConcatWs,
|
.translateFunc = translateConcatWs,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = concatWsFunction,
|
.sprocessFunc = concatWsFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "lower",
|
||||||
{
|
|
||||||
.name = "lower",
|
|
||||||
.type = FUNCTION_TYPE_LOWER,
|
.type = FUNCTION_TYPE_LOWER,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateInOutStr,
|
.translateFunc = translateInOutStr,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = lowerFunction,
|
.sprocessFunc = lowerFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "upper",
|
||||||
{
|
|
||||||
.name = "upper",
|
|
||||||
.type = FUNCTION_TYPE_UPPER,
|
.type = FUNCTION_TYPE_UPPER,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateInOutStr,
|
.translateFunc = translateInOutStr,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = upperFunction,
|
.sprocessFunc = upperFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "ltrim",
|
||||||
{
|
|
||||||
.name = "ltrim",
|
|
||||||
.type = FUNCTION_TYPE_LTRIM,
|
.type = FUNCTION_TYPE_LTRIM,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateInOutStr,
|
.translateFunc = translateInOutStr,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = ltrimFunction,
|
.sprocessFunc = ltrimFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "rtrim",
|
||||||
{
|
|
||||||
.name = "rtrim",
|
|
||||||
.type = FUNCTION_TYPE_RTRIM,
|
.type = FUNCTION_TYPE_RTRIM,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateInOutStr,
|
.translateFunc = translateInOutStr,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = rtrimFunction,
|
.sprocessFunc = rtrimFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "substr",
|
||||||
{
|
|
||||||
.name = "substr",
|
|
||||||
.type = FUNCTION_TYPE_SUBSTR,
|
.type = FUNCTION_TYPE_SUBSTR,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||||
.translateFunc = translateSubstr,
|
.translateFunc = translateSubstr,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = substrFunction,
|
.sprocessFunc = substrFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "cast",
|
||||||
{
|
|
||||||
.name = "cast",
|
|
||||||
.type = FUNCTION_TYPE_CAST,
|
.type = FUNCTION_TYPE_CAST,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateCast,
|
.translateFunc = translateCast,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = castFunction,
|
.sprocessFunc = castFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "to_iso8601",
|
||||||
{
|
|
||||||
.name = "to_iso8601",
|
|
||||||
.type = FUNCTION_TYPE_TO_ISO8601,
|
.type = FUNCTION_TYPE_TO_ISO8601,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateToIso8601,
|
.translateFunc = translateToIso8601,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = toISO8601Function,
|
.sprocessFunc = toISO8601Function,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "to_unixtimestamp",
|
||||||
{
|
|
||||||
.name = "to_unixtimestamp",
|
|
||||||
.type = FUNCTION_TYPE_TO_UNIXTIMESTAMP,
|
.type = FUNCTION_TYPE_TO_UNIXTIMESTAMP,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateToUnixtimestamp,
|
.translateFunc = translateToUnixtimestamp,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = toUnixtimestampFunction,
|
.sprocessFunc = toUnixtimestampFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "timetruncate",
|
||||||
{
|
|
||||||
.name = "timetruncate",
|
|
||||||
.type = FUNCTION_TYPE_TIMETRUNCATE,
|
.type = FUNCTION_TYPE_TIMETRUNCATE,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateTimeTruncate,
|
.translateFunc = translateTimeTruncate,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = timeTruncateFunction,
|
.sprocessFunc = timeTruncateFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "timediff",
|
||||||
{
|
|
||||||
.name = "timediff",
|
|
||||||
.type = FUNCTION_TYPE_TIMEDIFF,
|
.type = FUNCTION_TYPE_TIMEDIFF,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateTimeDiff,
|
.translateFunc = translateTimeDiff,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = timeDiffFunction,
|
.sprocessFunc = timeDiffFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "now",
|
||||||
{
|
|
||||||
.name = "now",
|
|
||||||
.type = FUNCTION_TYPE_NOW,
|
.type = FUNCTION_TYPE_NOW,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = nowFunction,
|
.sprocessFunc = nowFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "today",
|
||||||
{
|
|
||||||
.name = "today",
|
|
||||||
.type = FUNCTION_TYPE_TODAY,
|
.type = FUNCTION_TYPE_TODAY,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = todayFunction,
|
.sprocessFunc = todayFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "timezone",
|
||||||
{
|
|
||||||
.name = "timezone",
|
|
||||||
.type = FUNCTION_TYPE_TIMEZONE,
|
.type = FUNCTION_TYPE_TIMEZONE,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateTimezone,
|
.translateFunc = translateTimezone,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = timezoneFunction,
|
.sprocessFunc = timezoneFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_rowts",
|
||||||
{
|
|
||||||
.name = "_rowts",
|
|
||||||
.type = FUNCTION_TYPE_ROWTS,
|
.type = FUNCTION_TYPE_ROWTS,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = NULL,
|
.sprocessFunc = NULL,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "tbname",
|
||||||
{
|
|
||||||
.name = "tbname",
|
|
||||||
.type = FUNCTION_TYPE_TBNAME,
|
.type = FUNCTION_TYPE_TBNAME,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||||
.translateFunc = translateTbnameColumn,
|
.translateFunc = translateTbnameColumn,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = NULL,
|
.sprocessFunc = NULL,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_qstartts",
|
||||||
{
|
|
||||||
.name = "_qstartts",
|
|
||||||
.type = FUNCTION_TYPE_QSTARTTS,
|
.type = FUNCTION_TYPE_QSTARTTS,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = qStartTsFunction,
|
.sprocessFunc = qStartTsFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_qendts",
|
||||||
{
|
|
||||||
.name = "_qendts",
|
|
||||||
.type = FUNCTION_TYPE_QENDTS,
|
.type = FUNCTION_TYPE_QENDTS,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = qEndTsFunction,
|
.sprocessFunc = qEndTsFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_wstartts",
|
||||||
{
|
|
||||||
.name = "_wstartts",
|
|
||||||
.type = FUNCTION_TYPE_WSTARTTS,
|
.type = FUNCTION_TYPE_WSTARTTS,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = winStartTsFunction,
|
.sprocessFunc = winStartTsFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_wendts",
|
||||||
{
|
|
||||||
.name = "_wendts",
|
|
||||||
.type = FUNCTION_TYPE_WENDTS,
|
.type = FUNCTION_TYPE_WENDTS,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||||
.translateFunc = translateTimePseudoColumn,
|
.translateFunc = translateTimePseudoColumn,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = winEndTsFunction,
|
.sprocessFunc = winEndTsFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "_wduration",
|
||||||
{
|
|
||||||
.name = "_wduration",
|
|
||||||
.type = FUNCTION_TYPE_WDURATION,
|
.type = FUNCTION_TYPE_WDURATION,
|
||||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||||
.translateFunc = translateWduration,
|
.translateFunc = translateWduration,
|
||||||
.getEnvFunc = getTimePseudoFuncEnv,
|
.getEnvFunc = getTimePseudoFuncEnv,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = winDurFunction,
|
.sprocessFunc = winDurFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL},
|
||||||
},
|
{.name = "to_json",
|
||||||
{
|
|
||||||
.name = "to_json",
|
|
||||||
.type = FUNCTION_TYPE_TO_JSON,
|
.type = FUNCTION_TYPE_TO_JSON,
|
||||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||||
.translateFunc = translateToJson,
|
.translateFunc = translateToJson,
|
||||||
.getEnvFunc = NULL,
|
.getEnvFunc = NULL,
|
||||||
.initFunc = NULL,
|
.initFunc = NULL,
|
||||||
.sprocessFunc = toJsonFunction,
|
.sprocessFunc = toJsonFunction,
|
||||||
.finalizeFunc = NULL
|
.finalizeFunc = NULL}};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
||||||
|
|
|
@ -27,10 +27,32 @@ extern "C" {
|
||||||
#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__)
|
#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__)
|
||||||
#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__)
|
#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__)
|
||||||
|
|
||||||
#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
#define NODES_ERR_RET(c) \
|
||||||
#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
do { \
|
||||||
#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
int32_t _code = c; \
|
||||||
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = _code; \
|
||||||
|
return _code; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define NODES_RET(c) \
|
||||||
|
do { \
|
||||||
|
int32_t _code = c; \
|
||||||
|
if (_code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = _code; \
|
||||||
|
} \
|
||||||
|
return _code; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define NODES_ERR_JRET(c) \
|
||||||
|
do { \
|
||||||
|
code = c; \
|
||||||
|
if (code != TSDB_CODE_SUCCESS) { \
|
||||||
|
terrno = code; \
|
||||||
|
goto _return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
#include "cmdnodes.h"
|
#include "cmdnodes.h"
|
||||||
#include "nodesUtil.h"
|
#include "nodesUtil.h"
|
||||||
#include "plannodes.h"
|
#include "plannodes.h"
|
||||||
#include "querynodes.h"
|
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
|
#include "querynodes.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "tjson.h"
|
#include "tjson.h"
|
||||||
|
|
||||||
|
@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
|
||||||
code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo);
|
code = tjsonAddObject(pJson, jkTableMetaComInfo, tableComInfoToJson, &pNode->tableInfo);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema), TABLE_TOTAL_COL_NUM(pNode));
|
code = tjsonAddArray(pJson, jkTableMetaColSchemas, schemaToJson, pNode->schema, sizeof(SSchema),
|
||||||
|
TABLE_TOTAL_COL_NUM(pNode));
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiTagScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); }
|
||||||
return physiScanNodeToJson(pObj, pJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) {
|
static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); }
|
||||||
return jsonToPhysiScanNode(pJson, pObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* jkTableScanPhysiPlanScanCount = "ScanCount";
|
static const char* jkTableScanPhysiPlanScanCount = "ScanCount";
|
||||||
static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount";
|
static const char* jkTableScanPhysiPlanReverseScanCount = "ReverseScanCount";
|
||||||
|
@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) { return physiScanNodeToJson(pObj, pJson); }
|
||||||
return physiScanNodeToJson(pObj, pJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) {
|
static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) { return jsonToPhysiScanNode(pJson, pObj); }
|
||||||
return jsonToPhysiScanNode(pJson, pObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* jkEndPointFqdn = "Fqdn";
|
static const char* jkEndPointFqdn = "Fqdn";
|
||||||
static const char* jkEndPointPort = "Port";
|
static const char* jkEndPointPort = "Port";
|
||||||
|
@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
|
||||||
return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc);
|
return jsonToNodeObject(pJson, jkDataSinkInputDataBlockDesc, (SNode**)&pNode->pInputDataBlockDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiDispatchNodeToJson(const void* pObj, SJson* pJson) { return physicDataSinkNodeToJson(pObj, pJson); }
|
||||||
return physicDataSinkNodeToJson(pObj, pJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) {
|
static int32_t jsonToPhysiDispatchNode(const SJson* pJson, void* pObj) { return jsonToPhysicDataSinkNode(pJson, pObj); }
|
||||||
return jsonToPhysicDataSinkNode(pJson, pObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char* jkSubplanIdQueryId = "QueryId";
|
static const char* jkSubplanIdQueryId = "QueryId";
|
||||||
static const char* jkSubplanIdGroupId = "GroupId";
|
static const char* jkSubplanIdGroupId = "GroupId";
|
||||||
|
@ -2015,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
|
||||||
|
|
||||||
int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups);
|
int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), pNode->numOfVgroups);
|
code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo),
|
||||||
|
pNode->numOfVgroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -2381,6 +2371,7 @@ static const char* jkSelectStmtOrderBy = "OrderBy";
|
||||||
static const char* jkSelectStmtLimit = "Limit";
|
static const char* jkSelectStmtLimit = "Limit";
|
||||||
static const char* jkSelectStmtSlimit = "Slimit";
|
static const char* jkSelectStmtSlimit = "Slimit";
|
||||||
static const char* jkSelectStmtStmtName = "StmtName";
|
static const char* jkSelectStmtStmtName = "StmtName";
|
||||||
|
static const char* jkSelectStmtHasAggFuncs = "HasAggFuncs";
|
||||||
|
|
||||||
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||||
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
||||||
|
@ -2419,6 +2410,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonAddBoolToObject(pJson, jkSelectStmtHasAggFuncs, pNode->hasAggFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2460,6 +2454,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = tjsonGetBoolValue(pJson, jkSelectStmtHasAggFuncs, &pNode->hasAggFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,29 +17,24 @@
|
||||||
|
|
||||||
#define COMPARE_SCALAR_FIELD(fldname) \
|
#define COMPARE_SCALAR_FIELD(fldname) \
|
||||||
do { \
|
do { \
|
||||||
if (a->fldname != b->fldname) \
|
if (a->fldname != b->fldname) return false; \
|
||||||
return false; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define COMPARE_STRING(a, b) \
|
#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
|
||||||
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
|
|
||||||
|
|
||||||
#define COMPARE_STRING_FIELD(fldname) \
|
#define COMPARE_STRING_FIELD(fldname) \
|
||||||
do { \
|
do { \
|
||||||
if (!COMPARE_STRING(a->fldname, b->fldname)) \
|
if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \
|
||||||
return false; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define COMPARE_NODE_FIELD(fldname) \
|
#define COMPARE_NODE_FIELD(fldname) \
|
||||||
do { \
|
do { \
|
||||||
if (!nodesEqualNode(a->fldname, b->fldname)) \
|
if (!nodesEqualNode(a->fldname, b->fldname)) return false; \
|
||||||
return false; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define COMPARE_NODE_LIST_FIELD(fldname) \
|
#define COMPARE_NODE_LIST_FIELD(fldname) \
|
||||||
do { \
|
do { \
|
||||||
if (!nodeNodeListEqual(a->fldname, b->fldname)) \
|
if (!nodeNodeListEqual(a->fldname, b->fldname)) return false; \
|
||||||
return false; \
|
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
|
static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
|
||||||
|
|
|
@ -21,9 +21,35 @@
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
#include "thash.h"
|
#include "thash.h"
|
||||||
|
|
||||||
char *gOperatorStr[] = {NULL, "+", "-", "*", "/", "%", "-", "&", "|", ">", ">=", "<", "<=", "=", "<>",
|
char *gOperatorStr[] = {NULL,
|
||||||
"IN", "NOT IN", "LIKE", "NOT LIKE", "MATCH", "NMATCH", "IS NULL", "IS NOT NULL",
|
"+",
|
||||||
"IS TRUE", "IS FALSE", "IS UNKNOWN", "IS NOT TRUE", "IS NOT FALSE", "IS NOT UNKNOWN"};
|
"-",
|
||||||
|
"*",
|
||||||
|
"/",
|
||||||
|
"%",
|
||||||
|
"-",
|
||||||
|
"&",
|
||||||
|
"|",
|
||||||
|
">",
|
||||||
|
">=",
|
||||||
|
"<",
|
||||||
|
"<=",
|
||||||
|
"=",
|
||||||
|
"<>",
|
||||||
|
"IN",
|
||||||
|
"NOT IN",
|
||||||
|
"LIKE",
|
||||||
|
"NOT LIKE",
|
||||||
|
"MATCH",
|
||||||
|
"NMATCH",
|
||||||
|
"IS NULL",
|
||||||
|
"IS NOT NULL",
|
||||||
|
"IS TRUE",
|
||||||
|
"IS FALSE",
|
||||||
|
"IS UNKNOWN",
|
||||||
|
"IS NOT TRUE",
|
||||||
|
"IS NOT FALSE",
|
||||||
|
"IS NOT UNKNOWN"};
|
||||||
char *gLogicConditionStr[] = {"AND", "OR", "NOT"};
|
char *gLogicConditionStr[] = {"AND", "OR", "NOT"};
|
||||||
|
|
||||||
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
|
int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "querynodes.h"
|
|
||||||
#include "plannodes.h"
|
#include "plannodes.h"
|
||||||
|
#include "querynodes.h"
|
||||||
|
|
||||||
typedef enum ETraversalOrder {
|
typedef enum ETraversalOrder {
|
||||||
TRAVERSAL_PREORDER = 1,
|
TRAVERSAL_PREORDER = 1,
|
||||||
|
@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk
|
||||||
static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
||||||
static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext);
|
||||||
|
|
||||||
static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext, FNodeDispatcher dispatcher) {
|
static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext,
|
||||||
|
FNodeDispatcher dispatcher) {
|
||||||
if (NULL == pNode) {
|
if (NULL == pNode) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, void* pContext) {
|
static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker,
|
||||||
|
void* pContext) {
|
||||||
EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext);
|
EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext);
|
||||||
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||||
res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext);
|
res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext);
|
||||||
|
|
|
@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
||||||
nodesDestroyList(pNode->pScanCols);
|
nodesDestroyList(pNode->pScanCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroyDataSinkNode(SDataSinkNode* pNode) {
|
static void destroyDataSinkNode(SDataSinkNode* pNode) { nodesDestroyNode(pNode->pInputDataBlockDesc); }
|
||||||
nodesDestroyNode(pNode->pInputDataBlockDesc);
|
|
||||||
}
|
|
||||||
|
|
||||||
void nodesDestroyNode(SNodeptr pNode) {
|
void nodesDestroyNode(SNodeptr pNode) {
|
||||||
if (NULL == pNode) {
|
if (NULL == pNode) {
|
||||||
|
@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
|
||||||
|
|
||||||
bool nodesIsExprNode(const SNode* pNode) {
|
bool nodesIsExprNode(const SNode* pNode) {
|
||||||
ENodeType type = nodeType(pNode);
|
ENodeType type = nodeType(pNode);
|
||||||
return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type || QUERY_NODE_FUNCTION == type);
|
return (QUERY_NODE_COLUMN == type || QUERY_NODE_VALUE == type || QUERY_NODE_OPERATOR == type ||
|
||||||
|
QUERY_NODE_FUNCTION == type);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nodesIsUnaryOp(const SOperatorNode* pOp) {
|
bool nodesIsUnaryOp(const SOperatorNode* pOp) {
|
||||||
|
@ -1037,13 +1036,9 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nodesIsTimeorderQuery(const SNode* pQuery) {
|
bool nodesIsTimeorderQuery(const SNode* pQuery) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool nodesIsTimelineQuery(const SNode* pQuery) {
|
bool nodesIsTimelineQuery(const SNode* pQuery) { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct SCollectColumnsCxt {
|
typedef struct SCollectColumnsCxt {
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
|
@ -1089,8 +1084,7 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
|
||||||
.errCode = TSDB_CODE_SUCCESS,
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
.pTableAlias = pTableAlias,
|
.pTableAlias = pTableAlias,
|
||||||
.pCols = nodesMakeList(),
|
.pCols = nodesMakeList(),
|
||||||
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)
|
.pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK)};
|
||||||
};
|
|
||||||
if (NULL == cxt.pCols || NULL == cxt.pColHash) {
|
if (NULL == cxt.pCols || NULL == cxt.pColHash) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SCollectFuncsCxt cxt = {
|
SCollectFuncsCxt cxt = {.errCode = TSDB_CODE_SUCCESS, .classifier = classifier, .pFuncs = nodesMakeList()};
|
||||||
.errCode = TSDB_CODE_SUCCESS,
|
|
||||||
.classifier = classifier,
|
|
||||||
.pFuncs = nodesMakeList()
|
|
||||||
};
|
|
||||||
if (NULL == cxt.pFuncs) {
|
if (NULL == cxt.pFuncs) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -1152,7 +1142,6 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* getFillModeString(EFillMode mode) {
|
char* getFillModeString(EFillMode mode) {
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case FILL_MODE_NONE:
|
case FILL_MODE_NONE:
|
||||||
|
@ -1201,7 +1190,6 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
||||||
pVal->nType = pNode->node.resType.type;
|
pVal->nType = pNode->node.resType.type;
|
||||||
pVal->nLen = pNode->node.resType.bytes;
|
pVal->nLen = pNode->node.resType.bytes;
|
||||||
|
@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "cmdnodes.h"
|
#include "cmdnodes.h"
|
||||||
#include "parser.h"
|
|
||||||
#include "parToken.h"
|
#include "parToken.h"
|
||||||
#include "parUtil.h"
|
#include "parUtil.h"
|
||||||
|
#include "parser.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
|
|
||||||
typedef struct SAstCreateContext {
|
typedef struct SAstCreateContext {
|
||||||
|
@ -105,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
|
||||||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
|
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
|
||||||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap);
|
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap);
|
||||||
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr);
|
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr);
|
||||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill);
|
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
|
||||||
|
SNode* pFill);
|
||||||
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
|
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues);
|
||||||
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
|
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||||
|
|
||||||
|
@ -130,16 +131,20 @@ SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOptio
|
||||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment);
|
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment);
|
||||||
SDataType createDataType(uint8_t type);
|
SDataType createDataType(uint8_t type);
|
||||||
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
||||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions);
|
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
SNodeList* pTags, SNode* pOptions);
|
||||||
|
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
|
||||||
|
SNodeList* pSpecificTags, SNodeList* pValsOfTags);
|
||||||
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
|
||||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
||||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||||
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType);
|
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||||
|
const SToken* pColName, SDataType dataType);
|
||||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName);
|
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName);
|
||||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName);
|
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||||
|
const SToken* pOldColName, const SToken* pNewColName);
|
||||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal);
|
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal);
|
||||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern);
|
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern);
|
||||||
|
@ -151,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
|
||||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
|
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
|
||||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName,
|
||||||
|
SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
||||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding);
|
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding);
|
||||||
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName);
|
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName);
|
||||||
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
||||||
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId);
|
||||||
SNode* createTopicOptions(SAstCreateContext* pCxt);
|
SNode* createTopicOptions(SAstCreateContext* pCxt);
|
||||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions);
|
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||||
|
const SToken* pSubscribeDbName, SNode* pOptions);
|
||||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
|
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
|
||||||
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
|
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
|
||||||
|
@ -167,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
|
||||||
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable);
|
||||||
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
|
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
|
||||||
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups);
|
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups);
|
||||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize);
|
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||||
|
const SToken* pLibPath, SDataType dataType, int32_t bufSize);
|
||||||
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName);
|
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||||
SNode* createStreamOptions(SAstCreateContext* pCxt);
|
SNode* createStreamOptions(SAstCreateContext* pCxt);
|
||||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery);
|
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable,
|
||||||
|
SNode* pOptions, SNode* pQuery);
|
||||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName);
|
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName);
|
||||||
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId);
|
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId);
|
||||||
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2);
|
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2);
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "ttypes.h"
|
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
|
#include "ttypes.h"
|
||||||
|
|
||||||
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
|
||||||
|
|
||||||
|
@ -74,7 +74,8 @@ typedef struct STableDataBlocks {
|
||||||
uint32_t nAllocSize;
|
uint32_t nAllocSize;
|
||||||
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
uint32_t headerSize; // header for table info (uid, tid, submit metadata)
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
|
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to
|
||||||
|
// avoid to be removed from cache
|
||||||
char *pData;
|
char *pData;
|
||||||
bool cloned;
|
bool cloned;
|
||||||
int32_t createTbReqLen;
|
int32_t createTbReqLen;
|
||||||
|
@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
|
||||||
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
(int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx,
|
static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset,
|
||||||
int32_t *toffset, col_id_t *colIdx) {
|
col_id_t *colIdx) {
|
||||||
col_id_t schemaIdx = 0;
|
col_id_t schemaIdx = 0;
|
||||||
if (IS_DATA_COL_ORDERED(spd)) {
|
if (IS_DATA_COL_ORDERED(spd)) {
|
||||||
schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID;
|
schemaIdx = spd->boundColumns[idx] - PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||||
|
@ -115,7 +116,8 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) {
|
static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows) {
|
||||||
pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid);
|
pBlocks->suid =
|
||||||
|
(TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? dataBuf->pTableMeta->uid : dataBuf->pTableMeta->suid);
|
||||||
pBlocks->uid = dataBuf->pTableMeta->uid;
|
pBlocks->uid = dataBuf->pTableMeta->uid;
|
||||||
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
pBlocks->sversion = dataBuf->pTableMeta->sversion;
|
||||||
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
pBlocks->schemaLen = dataBuf->createTbReqLen;
|
||||||
|
@ -136,7 +138,8 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash);
|
||||||
int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo);
|
||||||
int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows);
|
int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t *numOfRows);
|
||||||
int32_t getDataBlockFromList(SHashObj *pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
int32_t getDataBlockFromList(SHashObj *pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
||||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq);
|
const STableMeta *pTableMeta, STableDataBlocks **dataBlocks, SArray *pBlockList,
|
||||||
|
SVCreateTbReq *pCreateTbReq);
|
||||||
int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks);
|
int32_t mergeTableDataBlocks(SHashObj *pHashObj, uint8_t payloadType, SArray **pVgDataBlocks);
|
||||||
int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
int32_t buildCreateTbMsg(STableDataBlocks *pBlocks, SVCreateTbReq *pCreateTbReq);
|
||||||
int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize);
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "parser.h"
|
|
||||||
#include "parToken.h"
|
#include "parToken.h"
|
||||||
#include "parUtil.h"
|
#include "parUtil.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
|
int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery);
|
||||||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);
|
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery);
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
|
|
||||||
// used to denote the minimum unite in sql parsing
|
// used to denote the minimum unite in sql parsing
|
||||||
|
|
|
@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
|
||||||
|
|
||||||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND,
|
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND,
|
||||||
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
|
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft),
|
||||||
|
createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR,
|
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft),
|
||||||
createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft), createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
|
createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
|
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
|
||||||
|
@ -483,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
|
||||||
return (SNode*)state;
|
return (SNode*)state;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) {
|
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
|
||||||
|
SNode* pFill) {
|
||||||
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||||
CHECK_OUT_OF_MEM(interval);
|
CHECK_OUT_OF_MEM(interval);
|
||||||
interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||||
|
@ -758,8 +760,8 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||||
bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNodeList* pTags, SNode* pOptions) {
|
SNodeList* pTags, SNode* pOptions) {
|
||||||
if (NULL == pRealTable) {
|
if (NULL == pRealTable) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -775,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt,
|
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
|
||||||
bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
|
SNodeList* pSpecificTags, SNodeList* pValsOfTags) {
|
||||||
if (NULL == pRealTable) {
|
if (NULL == pRealTable) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -842,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) {
|
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||||
|
const SToken* pColName, SDataType dataType) {
|
||||||
if (NULL == pRealTable) {
|
if (NULL == pRealTable) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -865,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) {
|
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
|
||||||
|
const SToken* pOldColName, const SToken* pNewColName) {
|
||||||
if (NULL == pRealTable) {
|
if (NULL == pRealTable) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -900,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needDbShowStmt(ENodeType type) {
|
static bool needDbShowStmt(ENodeType type) {
|
||||||
return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type || QUERY_NODE_SHOW_VGROUPS_STMT == type;
|
return QUERY_NODE_SHOW_TABLES_STMT == type || QUERY_NODE_SHOW_STABLES_STMT == type ||
|
||||||
|
QUERY_NODE_SHOW_VGROUPS_STMT == type;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
||||||
|
@ -909,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
|
||||||
pCxt->valid = false;
|
pCxt->valid = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SShowStmt* pStmt = nodesMakeNode(type);;
|
SShowStmt* pStmt = nodesMakeNode(type);
|
||||||
|
;
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->pDbName = pDbName;
|
pStmt->pDbName = pDbName;
|
||||||
pStmt->pTbNamePattern = pTbNamePattern;
|
pStmt->pTbNamePattern = pTbNamePattern;
|
||||||
|
@ -1004,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue) {
|
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig,
|
||||||
|
const SToken* pValue) {
|
||||||
SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT);
|
SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->dnodeId = strtol(pDnode->z, NULL, 10);
|
pStmt->dnodeId = strtol(pDnode->z, NULL, 10);
|
||||||
|
@ -1015,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName, SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName,
|
||||||
|
SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||||
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1030,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding) {
|
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset,
|
||||||
|
SNode* pSliding) {
|
||||||
SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS);
|
SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS);
|
||||||
CHECK_OUT_OF_MEM(pOptions);
|
CHECK_OUT_OF_MEM(pOptions);
|
||||||
pOptions->pFuncs = pFuncs;
|
pOptions->pFuncs = pFuncs;
|
||||||
|
@ -1055,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
|
||||||
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||||
SCreateComponentNodeStmt* pStmt = nodesMakeNode(type);
|
SCreateComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);
|
||||||
|
;
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||||
SDropComponentNodeStmt* pStmt = nodesMakeNode(type);
|
SDropComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);;
|
pStmt->dnodeId = strtol(pDnodeId->z, NULL, 10);
|
||||||
|
;
|
||||||
return (SNode*)pStmt;
|
return (SNode*)pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1075,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
|
||||||
return (SNode*)pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt,
|
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||||
bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName, SNode* pOptions) {
|
const SToken* pSubscribeDbName, SNode* pOptions) {
|
||||||
SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||||
|
@ -1158,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
|
||||||
return pStmt;
|
return pStmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt,
|
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||||
bool ignoreExists, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
||||||
if (pLibPath->n <= 2) {
|
if (pLibPath->n <= 2) {
|
||||||
pCxt->valid = false;
|
pCxt->valid = false;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1188,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
||||||
return (SNode*)pOptions;
|
return (SNode*)pOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery) {
|
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable,
|
||||||
|
SNode* pOptions, SNode* pQuery) {
|
||||||
SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
||||||
CHECK_OUT_OF_MEM(pStmt);
|
CHECK_OUT_OF_MEM(pStmt);
|
||||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||||
|
|
|
@ -281,12 +281,10 @@ static bool isEmptyResultQuery(SNode* pStmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||||
SCalcConstContext cxt = {
|
SCalcConstContext cxt = {.pParseCxt = pParseCxt,
|
||||||
.pParseCxt = pParseCxt,
|
|
||||||
.msgBuf.buf = pParseCxt->pMsg,
|
.msgBuf.buf = pParseCxt->pMsg,
|
||||||
.msgBuf.len = pParseCxt->msgLen,
|
.msgBuf.len = pParseCxt->msgLen,
|
||||||
.code = TSDB_CODE_SUCCESS
|
.code = TSDB_CODE_SUCCESS};
|
||||||
};
|
|
||||||
int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
|
int32_t code = calcConstQuery(&cxt, pQuery->pRoot, false);
|
||||||
if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) {
|
if (TSDB_CODE_SUCCESS == code && isEmptyResultQuery(pQuery->pRoot)) {
|
||||||
pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
pQuery->execMode = QUERY_EXEC_MODE_EMPTY_RESULT;
|
||||||
|
|
|
@ -77,7 +77,6 @@ typedef struct SMemParam {
|
||||||
col_id_t colIdx;
|
col_id_t colIdx;
|
||||||
} SMemParam;
|
} SMemParam;
|
||||||
|
|
||||||
|
|
||||||
#define CHECK_CODE(expr) \
|
#define CHECK_CODE(expr) \
|
||||||
do { \
|
do { \
|
||||||
int32_t code = expr; \
|
int32_t code = expr; \
|
||||||
|
@ -86,7 +85,6 @@ typedef struct SMemParam {
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
static int32_t skipInsertInto(SInsertParseContext* pCxt) {
|
static int32_t skipInsertInto(SInsertParseContext* pCxt) {
|
||||||
SToken sToken;
|
SToken sToken;
|
||||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||||
|
@ -180,7 +178,6 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) {
|
static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, const char* dbName, SMsgBuf* pMsgBuf) {
|
||||||
const char* msg1 = "name too long";
|
const char* msg1 = "name too long";
|
||||||
const char* msg2 = "invalid database name";
|
const char* msg2 = "invalid database name";
|
||||||
|
@ -740,7 +737,8 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value == NULL) { // it is a null data
|
if (value == NULL) { // it is a null data
|
||||||
// tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
// tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset,
|
||||||
|
// pa->colIdx);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,7 +885,8 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, char* tmpTokenBuf) {
|
static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow,
|
||||||
|
char* tmpTokenBuf) {
|
||||||
SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo;
|
SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo;
|
||||||
SRowBuilder* pBuilder = &pDataBlocks->rowBuilder;
|
SRowBuilder* pBuilder = &pDataBlocks->rowBuilder;
|
||||||
STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header
|
STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header
|
||||||
|
@ -1069,7 +1068,8 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) {
|
if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) {
|
||||||
return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");;
|
return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt");
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroyInsertParseContextForTable(pCxt);
|
destroyInsertParseContextForTable(pCxt);
|
||||||
|
@ -1171,18 +1171,18 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
|
||||||
.pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false),
|
.pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false),
|
||||||
.totalNum = 0,
|
.totalNum = 0,
|
||||||
.pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT),
|
.pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT),
|
||||||
.pStmtCb = pContext->pStmtCb
|
.pStmtCb = pContext->pStmtCb};
|
||||||
};
|
|
||||||
|
|
||||||
if (pContext->pStmtCb && *pQuery) {
|
if (pContext->pStmtCb && *pQuery) {
|
||||||
(*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, &context.pTableBlockHashObj);
|
(*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj,
|
||||||
|
&context.pTableBlockHashObj);
|
||||||
} else {
|
} else {
|
||||||
context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false);
|
||||||
context.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
context.pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj ||
|
if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj ||
|
||||||
NULL == context.pSubTableHashObj || NULL == context.pOutput) {
|
NULL == context.pOutput) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1211,8 +1211,8 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen) {
|
int32_t msgBufLen) {
|
||||||
SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf msg = {.buf = msgBuf, .len = msgBufLen};
|
||||||
SToken sToken;
|
SToken sToken;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -1238,7 +1238,6 @@ int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) {
|
||||||
SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot;
|
SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -1258,7 +1257,8 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen){
|
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_BIND_v2* bind, char* msgBuf,
|
||||||
|
int32_t msgBufLen) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||||
|
@ -1308,7 +1308,6 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen) {
|
int32_t qBindStmtColsValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||||
|
@ -1383,7 +1382,8 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum) {
|
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_BIND_v2* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||||
|
int32_t rowNum) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||||
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
||||||
|
@ -1463,7 +1463,6 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf,
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD** fields) {
|
int32_t buildBoundFields(SParsedDataColInfo* boundInfo, SSchema* pSchema, int32_t* fieldNum, TAOS_FIELD** fields) {
|
||||||
if (fields) {
|
if (fields) {
|
||||||
*fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD));
|
*fields = taosMemoryCalloc(boundInfo->numOfBound, sizeof(TAOS_FIELD));
|
||||||
|
@ -1484,7 +1483,6 @@ int32_t buildBoundFields(SParsedDataColInfo *boundInfo, SSchema *pSchema, int32_
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields) {
|
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields) {
|
||||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||||
|
@ -1521,6 +1519,3 @@ int32_t qBuildStmtColFields(void *pBlock, int32_t *fieldNum, TAOS_FIELD** fields
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#include "parInsertData.h"
|
#include "parInsertData.h"
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
|
#include "parInt.h"
|
||||||
#include "parUtil.h"
|
#include "parUtil.h"
|
||||||
#include "querynodes.h"
|
#include "querynodes.h"
|
||||||
#include "parInt.h"
|
|
||||||
|
|
||||||
#define IS_RAW_PAYLOAD(t) \
|
#define IS_RAW_PAYLOAD(t) \
|
||||||
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||||
|
@ -115,8 +115,8 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
|
||||||
taosMemoryFreeClear(pColList->colIdxInfo);
|
taosMemoryFreeClear(pColList->colIdxInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset,
|
static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOffset, const STableMeta* pTableMeta,
|
||||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks) {
|
STableDataBlocks** dataBlocks) {
|
||||||
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
STableDataBlocks* dataBuf = (STableDataBlocks*)taosMemoryCalloc(1, sizeof(STableDataBlocks));
|
||||||
if (dataBuf == NULL) {
|
if (dataBuf == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
@ -186,7 +186,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int32_t startOffset, int32_t rowSize,
|
||||||
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList, SVCreateTbReq* pCreateTbReq) {
|
const STableMeta* pTableMeta, STableDataBlocks** dataBlocks, SArray* pBlockList,
|
||||||
|
SVCreateTbReq* pCreateTbReq) {
|
||||||
*dataBlocks = NULL;
|
*dataBlocks = NULL;
|
||||||
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id));
|
STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pHashList, (const char*)&id, sizeof(id));
|
||||||
if (t1 != NULL) {
|
if (t1 != NULL) {
|
||||||
|
@ -383,7 +384,8 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erase the empty space reserved for binary data
|
// Erase the empty space reserved for binary data
|
||||||
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple, bool isRawPayload) {
|
static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SBlockKeyTuple* blkKeyTuple,
|
||||||
|
bool isRawPayload) {
|
||||||
// TODO: optimize this function, handle the case while binary is not presented
|
// TODO: optimize this function, handle the case while binary is not presented
|
||||||
STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
|
STableMeta* pTableMeta = pTableDataBlock->pTableMeta;
|
||||||
STableComInfo tinfo = getTableInfo(pTableMeta);
|
STableComInfo tinfo = getTableInfo(pTableMeta);
|
||||||
|
@ -453,8 +455,9 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
||||||
SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData;
|
SSubmitBlk* pBlocks = (SSubmitBlk*)pOneTableBlock->pData;
|
||||||
if (pBlocks->numOfRows > 0) {
|
if (pBlocks->numOfRows > 0) {
|
||||||
STableDataBlocks* dataBuf = NULL;
|
STableDataBlocks* dataBuf = NULL;
|
||||||
int32_t ret = getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE,
|
int32_t ret =
|
||||||
INSERT_HEAD_SIZE, 0, pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
getDataBlockFromList(pVnodeDataBlockHashList, pOneTableBlock->vgId, TSDB_PAYLOAD_SIZE, INSERT_HEAD_SIZE, 0,
|
||||||
|
pOneTableBlock->pTableMeta, &dataBuf, pVnodeDataBlockList, NULL);
|
||||||
if (ret != TSDB_CODE_SUCCESS) {
|
if (ret != TSDB_CODE_SUCCESS) {
|
||||||
taosHashCleanup(pVnodeDataBlockHashList);
|
taosHashCleanup(pVnodeDataBlockHashList);
|
||||||
destroyBlockArrayList(pVnodeDataBlockList);
|
destroyBlockArrayList(pVnodeDataBlockList);
|
||||||
|
@ -499,7 +502,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
||||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta);
|
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta);
|
||||||
|
|
||||||
// erase the empty space reserved for binary data
|
// erase the empty space reserved for binary data
|
||||||
int32_t finalLen = trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
int32_t finalLen =
|
||||||
|
trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
||||||
assert(finalLen <= len);
|
assert(finalLen <= len);
|
||||||
|
|
||||||
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
||||||
|
@ -580,7 +584,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
||||||
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
STableDataBlocks* pBlock = (STableDataBlocks*)block;
|
||||||
|
|
||||||
|
@ -608,7 +611,6 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) {
|
||||||
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
*pDst = taosMemoryMalloc(sizeof(STableDataBlocks));
|
||||||
if (NULL == *pDst) {
|
if (NULL == *pDst) {
|
||||||
|
@ -639,7 +641,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void qFreeStmtDataBlock(void* pDataBlock) {
|
void qFreeStmtDataBlock(void* pDataBlock) {
|
||||||
if (pDataBlock == NULL) {
|
if (pDataBlock == NULL) {
|
||||||
return;
|
return;
|
||||||
|
@ -659,4 +660,3 @@ void qDestroyStmtDataBlock(void* pBlock) {
|
||||||
pDataBlock->cloned = false;
|
pDataBlock->cloned = false;
|
||||||
destroyDataBlock(pDataBlock);
|
destroyDataBlock(pDataBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "parToken.h"
|
#include "parToken.h"
|
||||||
#include "thash.h"
|
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
#include "thash.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
|
|
||||||
// All the keywords of the SQL language are stored in a hash table
|
// All the keywords of the SQL language are stored in a hash table
|
||||||
|
@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here is the 1u/1a/2s/3m/9y */
|
/* here is the 1u/1a/2s/3m/9y */
|
||||||
if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' ||
|
if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' ||
|
||||||
z[i] == 'y' || z[i] == 'w' ||
|
z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' ||
|
||||||
z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' ||
|
z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') &&
|
||||||
z[i] == 'Y' || z[i] == 'W') &&
|
|
||||||
(isIdChar[(uint8_t)z[i + 1]] == 0)) {
|
(isIdChar[(uint8_t)z[i + 1]] == 0)) {
|
||||||
*tokenId = TK_NK_VARIABLE;
|
*tokenId = TK_NK_VARIABLE;
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -728,9 +727,7 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
|
||||||
return t0;
|
return t0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool taosIsKeyWordToken(const char* z, int32_t len) {
|
bool taosIsKeyWordToken(const char* z, int32_t len) { return (tKeywordCode((char*)z, len) != TK_NK_ID); }
|
||||||
return (tKeywordCode((char*)z, len) != TK_NK_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void taosCleanupKeywordsTable() {
|
void taosCleanupKeywordsTable() {
|
||||||
void* m = keywordHashTable;
|
void* m = keywordHashTable;
|
||||||
|
|
|
@ -600,7 +600,8 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
||||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||||
return DEAL_RES_ERROR;
|
return DEAL_RES_ERROR;
|
||||||
}
|
}
|
||||||
if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) {
|
if (fmIsAggFunc(pFunc->funcId)) {
|
||||||
|
if (beforeHaving(pCxt->currClause)) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||||
}
|
}
|
||||||
bool haveAggFunc = false;
|
bool haveAggFunc = false;
|
||||||
|
@ -608,6 +609,9 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
||||||
if (haveAggFunc) {
|
if (haveAggFunc) {
|
||||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||||
}
|
}
|
||||||
|
pCxt->pCurrStmt->hasAggFuncs = true;
|
||||||
|
}
|
||||||
|
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,14 +200,16 @@ SSchema *getTableColumnSchema(const STableMeta *pTableMeta) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
||||||
assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 && colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta)));
|
assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 &&
|
||||||
|
colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta)));
|
||||||
|
|
||||||
SSchema* pSchema = (SSchema*)pTableMeta->schema;
|
SSchema* pSchema = (SSchema*)pTableMeta->schema;
|
||||||
return &pSchema[colIndex];
|
return &pSchema[colIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
||||||
assert(pTableMeta != NULL && (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
assert(pTableMeta != NULL &&
|
||||||
|
(pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
||||||
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +342,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
||||||
uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON;
|
uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON;
|
||||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type
|
tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNotNULL, CHAR_BYTES); // add json type
|
||||||
}
|
}
|
||||||
taosHashPut(keyHash, jsonKey, keyLen, &keyLen, CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
|
taosHashPut(keyHash, jsonKey, keyLen, &keyLen,
|
||||||
|
CHAR_BYTES); // add key to hash to remove dumplicate, value is useless
|
||||||
|
|
||||||
if (item->type == cJSON_String) { // add json value format: type|data
|
if (item->type == cJSON_String) { // add json value format: type|data
|
||||||
char* jsonValue = item->valuestring;
|
char* jsonValue = item->valuestring;
|
||||||
|
@ -357,7 +360,8 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
||||||
*valueType = TSDB_DATA_TYPE_NCHAR;
|
*valueType = TSDB_DATA_TYPE_NCHAR;
|
||||||
if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)varDataVal(valueData),
|
if (valLen > 0 && !taosMbsToUcs4(jsonValue, valLen, (TdUcs4*)varDataVal(valueData),
|
||||||
(int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) {
|
(int32_t)(valLen * TSDB_NCHAR_SIZE), &valLen)) {
|
||||||
qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue, strerror(errno));
|
qError("charset:%s to %s. val:%s, errno:%s, convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, jsonValue,
|
||||||
|
strerror(errno));
|
||||||
retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
|
retCode = buildSyntaxErrMsg(pMsgBuf, "charset convert json error", jsonValue);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -372,9 +376,12 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
||||||
}
|
}
|
||||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||||
char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
char* valueData = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||||
*valueType = (item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE;
|
*valueType =
|
||||||
if(*valueType== TSDB_DATA_TYPE_DOUBLE) *((double *)valueData) = item->valuedouble;
|
(item->valuedouble - (int64_t)(item->valuedouble) == 0) ? TSDB_DATA_TYPE_BIGINT : TSDB_DATA_TYPE_DOUBLE;
|
||||||
else if(*valueType == TSDB_DATA_TYPE_BIGINT) *((int64_t *)valueData) = item->valueint;
|
if (*valueType == TSDB_DATA_TYPE_DOUBLE)
|
||||||
|
*((double*)valueData) = item->valuedouble;
|
||||||
|
else if (*valueType == TSDB_DATA_TYPE_BIGINT)
|
||||||
|
*((int64_t*)valueData) = item->valueint;
|
||||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES);
|
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES + LONG_BYTES);
|
||||||
} else if (item->type == cJSON_True || item->type == cJSON_False) {
|
} else if (item->type == cJSON_True || item->type == cJSON_False) {
|
||||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||||
|
@ -386,8 +393,7 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
|
||||||
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE);
|
||||||
*valueType = TSDB_DATA_TYPE_NULL;
|
*valueType = TSDB_DATA_TYPE_NULL;
|
||||||
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
tdAddColToKVRow(kvRowBuilder, jsonIndex++, tagKV, keyLen + VARSTR_HEADER_SIZE + CHAR_BYTES);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json);
|
retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "os.h"
|
||||||
|
|
||||||
#include "parInt.h"
|
#include "parInt.h"
|
||||||
#include "parToken.h"
|
#include "parToken.h"
|
||||||
|
|
|
@ -30,103 +30,128 @@ namespace {
|
||||||
|
|
||||||
void generateInformationSchema(MockCatalogService* mcs) {
|
void generateInformationSchema(MockCatalogService* mcs) {
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "dnodes", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "mnodes", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "modules", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1).addColumn("id", TSDB_DATA_TYPE_INT);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "qnodes", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("id", TSDB_DATA_TYPE_INT);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_databases", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1).addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_functions", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("name", TSDB_DATA_TYPE_BINARY, TSDB_FUNC_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2)
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_indexes", TSDB_SYSTEM_TABLE, 2)
|
||||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||||
|
.addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2)
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_stables", TSDB_SYSTEM_TABLE, 2)
|
||||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||||
|
.addColumn("stable_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1).addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_streams", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("stream_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2)
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_tables", TSDB_SYSTEM_TABLE, 2)
|
||||||
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN).addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN)
|
||||||
|
.addColumn("table_name", TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
ITableBuilder& builder =
|
||||||
|
mcs->createTableBuilder("information_schema", "user_table_distributed", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1).addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "user_users", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("user_name", TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1).addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
ITableBuilder& builder = mcs->createTableBuilder("information_schema", "vgroups", TSDB_SYSTEM_TABLE, 1)
|
||||||
|
.addColumn("db_name", TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateTestT1(MockCatalogService* mcs) {
|
void generateTestT1(MockCatalogService* mcs) {
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI).setVgid(1).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20).addColumn("c3", TSDB_DATA_TYPE_BIGINT)
|
.setVgid(1)
|
||||||
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE).addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
|
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||||
|
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||||
|
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
|
.addColumn("c3", TSDB_DATA_TYPE_BIGINT)
|
||||||
|
.addColumn("c4", TSDB_DATA_TYPE_DOUBLE)
|
||||||
|
.addColumn("c5", TSDB_DATA_TYPE_DOUBLE);
|
||||||
builder.done();
|
builder.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateTestST1(MockCatalogService* mcs) {
|
void generateTestST1(MockCatalogService* mcs) {
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI).addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
.addColumn("c1", TSDB_DATA_TYPE_INT).addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||||
.addTag("tag1", TSDB_DATA_TYPE_INT).addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
|
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||||
|
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
|
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
||||||
|
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
|
||||||
builder.done();
|
builder.done();
|
||||||
mcs->createSubTable("test", "st1", "st1s1", 1);
|
mcs->createSubTable("test", "st1", "st1s1", 1);
|
||||||
mcs->createSubTable("test", "st1", "st1s2", 2);
|
mcs->createSubTable("test", "st1", "st1s2", 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
int32_t __catalogGetHandle(const char *clusterId, struct SCatalog** catalogHandle) {
|
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||||
|
STableMeta** pTableMeta) {
|
||||||
return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
return mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo* vgInfo) {
|
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, void* pRpc, const SEpSet* pMgmtEps,
|
||||||
|
const SName* pTableName, SVgroupInfo* vgInfo) {
|
||||||
return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
return mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgList) {
|
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const SName* pTableName,
|
||||||
|
SArray** pVgList) {
|
||||||
return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
return mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId, int32_t *tableNum) {
|
int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* version, int64_t* dbId,
|
||||||
|
int32_t* tableNum) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SArray** vgroupList) {
|
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* dbFName,
|
||||||
|
SArray** vgroupList) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +214,4 @@ void generateMetaData() {
|
||||||
mockCatalogService->showTables();
|
mockCatalogService->showTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroyMetaDataEnv() {
|
void destroyMetaDataEnv() { mockCatalogService.reset(); }
|
||||||
mockCatalogService.reset();
|
|
||||||
}
|
|
||||||
|
|
|
@ -13,12 +13,13 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "mockCatalogService.h"
|
||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "mockCatalogService.h"
|
|
||||||
#include "tdatablock.h"
|
|
||||||
|
|
||||||
|
#include "tdatablock.h"
|
||||||
#include "tname.h"
|
#include "tname.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
|
||||||
|
@ -55,15 +56,14 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void done() {
|
virtual void done() { schema()->tableInfo.rowSize = rowsize_; }
|
||||||
schema()->tableInfo.rowSize = rowsize_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class MockCatalogServiceImpl;
|
friend class MockCatalogServiceImpl;
|
||||||
|
|
||||||
static std::unique_ptr<TableBuilder> createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
static std::unique_ptr<TableBuilder> createTableBuilder(int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||||
STableMeta* meta = (STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags));
|
STableMeta* meta =
|
||||||
|
(STableMeta*)taosMemoryCalloc(1, sizeof(STableMeta) + sizeof(SSchema) * (numOfColumns + numOfTags));
|
||||||
if (nullptr == meta) {
|
if (nullptr == meta) {
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
@ -77,13 +77,9 @@ private:
|
||||||
meta_->schema = schemaMeta;
|
meta_->schema = schemaMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMeta* schema() {
|
STableMeta* schema() { return meta_->schema; }
|
||||||
return meta_->schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MockTableMeta> table() {
|
std::shared_ptr<MockTableMeta> table() { return meta_; }
|
||||||
return meta_;
|
|
||||||
}
|
|
||||||
|
|
||||||
col_id_t colId_;
|
col_id_t colId_;
|
||||||
int32_t rowsize_;
|
int32_t rowsize_;
|
||||||
|
@ -94,12 +90,9 @@ class MockCatalogServiceImpl {
|
||||||
public:
|
public:
|
||||||
static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]);
|
static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]);
|
||||||
|
|
||||||
MockCatalogServiceImpl() : id_(1) {
|
MockCatalogServiceImpl() : id_(1) {}
|
||||||
}
|
|
||||||
|
|
||||||
int32_t catalogGetHandle() const {
|
int32_t catalogGetHandle() const { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
|
int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const {
|
||||||
std::unique_ptr<STableMeta> table;
|
std::unique_ptr<STableMeta> table;
|
||||||
|
@ -129,7 +122,8 @@ public:
|
||||||
return copyTableVgroup(db, tNameGetTableName(pTableName), vgList);
|
return copyTableVgroup(db, tNameGetTableName(pTableName), vgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
TableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType,
|
||||||
|
int32_t numOfColumns, int32_t numOfTags) {
|
||||||
builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags);
|
builder_ = TableBuilder::createTableBuilder(tableType, numOfColumns, numOfTags);
|
||||||
meta_[db][tbname] = builder_->table();
|
meta_[db][tbname] = builder_->table();
|
||||||
meta_[db][tbname]->schema->uid = id_++;
|
meta_[db][tbname]->schema->uid = id_++;
|
||||||
|
@ -163,7 +157,9 @@ public:
|
||||||
// number of backward fills
|
// number of backward fills
|
||||||
#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2)
|
#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2)
|
||||||
// center aligned
|
// center aligned
|
||||||
#define CA(n, s) std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" << "|"
|
#define CA(n, s) \
|
||||||
|
std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" \
|
||||||
|
<< "|"
|
||||||
// string field length
|
// string field length
|
||||||
#define SFL 20
|
#define SFL 20
|
||||||
// string field header
|
// string field header
|
||||||
|
@ -185,7 +181,8 @@ public:
|
||||||
std::cout << SL(3, 1) << std::endl;
|
std::cout << SL(3, 1) << std::endl;
|
||||||
for (const auto& table : db.second) {
|
for (const auto& table : db.second) {
|
||||||
const auto& schema = table.second->schema;
|
const auto& schema = table.second->schema;
|
||||||
std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision)) << IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl;
|
std::cout << SF(table.first) << SF(ttToString(schema->tableType)) << SF(pToString(schema->tableInfo.precision))
|
||||||
|
<< IF(schema->vgId) << IF(schema->tableInfo.rowSize) << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +197,8 @@ public:
|
||||||
int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags;
|
int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags;
|
||||||
for (int16_t i = 0; i < numOfFields; ++i) {
|
for (int16_t i = 0; i < numOfFields; ++i) {
|
||||||
const SSchema* col = schema->schema + i;
|
const SSchema* col = schema->schema + i;
|
||||||
std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl;
|
std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type))
|
||||||
|
<< IF(col->bytes) << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -257,9 +255,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string dtToString(int8_t type) const {
|
std::string dtToString(int8_t type) const { return tDataTypes[type].name; }
|
||||||
return tDataTypes[type].name;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ftToString(int16_t colid, int16_t numOfColumns) const {
|
std::string ftToString(int16_t colid, int16_t numOfColumns) const {
|
||||||
return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag"));
|
return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag"));
|
||||||
|
@ -270,7 +266,8 @@ private:
|
||||||
return table ? table->schema : nullptr;
|
return table ? table->schema : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname, std::unique_ptr<STableMeta>* dst) const {
|
int32_t copyTableSchemaMeta(const std::string& db, const std::string& tbname,
|
||||||
|
std::unique_ptr<STableMeta>* dst) const {
|
||||||
STableMeta* src = getTableSchemaMeta(db, tbname);
|
STableMeta* src = getTableSchemaMeta(db, tbname);
|
||||||
if (nullptr == src) {
|
if (nullptr == src) {
|
||||||
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
return TSDB_CODE_TSC_INVALID_TABLE_NAME;
|
||||||
|
@ -310,25 +307,24 @@ private:
|
||||||
DbMetaCache meta_;
|
DbMetaCache meta_;
|
||||||
};
|
};
|
||||||
|
|
||||||
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {
|
MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {}
|
||||||
}
|
|
||||||
|
|
||||||
MockCatalogService::~MockCatalogService() {
|
MockCatalogService::~MockCatalogService() {}
|
||||||
}
|
|
||||||
|
|
||||||
ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, const std::string& tbname,
|
||||||
|
int8_t tableType, int32_t numOfColumns, int32_t numOfTags) {
|
||||||
return impl_->createTableBuilder(db, tbname, tableType, numOfColumns, numOfTags);
|
return impl_->createTableBuilder(db, tbname, tableType, numOfColumns, numOfTags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid) {
|
void MockCatalogService::createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname,
|
||||||
|
int16_t vgid) {
|
||||||
impl_->createSubTable(db, stbname, tbname, vgid);
|
impl_->createSubTable(db, stbname, tbname, vgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MockCatalogService::showTables() const {
|
void MockCatalogService::showTables() const { impl_->showTables(); }
|
||||||
impl_->showTables();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MockTableMeta> MockCatalogService::getTableMeta(const std::string& db, const std::string& tbname) const {
|
std::shared_ptr<MockTableMeta> MockCatalogService::getTableMeta(const std::string& db,
|
||||||
|
const std::string& tbname) const {
|
||||||
return impl_->getTableMeta(db, tbname);
|
return impl_->getTableMeta(db, tbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,17 +20,15 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#define ALLOW_FORBID_FUNC
|
||||||
|
|
||||||
#include "catalog.h"
|
#include "catalog.h"
|
||||||
|
|
||||||
class ITableBuilder {
|
class ITableBuilder {
|
||||||
public:
|
public:
|
||||||
ITableBuilder& addTag(const std::string& name, int8_t type) {
|
ITableBuilder& addTag(const std::string& name, int8_t type) { return addColumn(name, type, tDataTypes[type].bytes); }
|
||||||
return addColumn(name, type, tDataTypes[type].bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) {
|
ITableBuilder& addTag(const std::string& name, int8_t type, int32_t bytes) { return addColumn(name, type, bytes); }
|
||||||
return addColumn(name, type, bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
ITableBuilder& addColumn(const std::string& name, int8_t type) {
|
ITableBuilder& addColumn(const std::string& name, int8_t type) {
|
||||||
return addColumn(name, type, tDataTypes[type].bytes);
|
return addColumn(name, type, tDataTypes[type].bytes);
|
||||||
|
@ -43,9 +41,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MockTableMeta {
|
struct MockTableMeta {
|
||||||
~MockTableMeta() {
|
~MockTableMeta() { taosMemoryFree(schema); }
|
||||||
taosMemoryFree(schema);
|
|
||||||
}
|
|
||||||
|
|
||||||
STableMeta* schema;
|
STableMeta* schema;
|
||||||
std::vector<SVgroupInfo> vgs;
|
std::vector<SVgroupInfo> vgs;
|
||||||
|
@ -56,7 +52,8 @@ class MockCatalogService {
|
||||||
public:
|
public:
|
||||||
MockCatalogService();
|
MockCatalogService();
|
||||||
~MockCatalogService();
|
~MockCatalogService();
|
||||||
ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType, int32_t numOfColumns, int32_t numOfTags = 0);
|
ITableBuilder& createTableBuilder(const std::string& db, const std::string& tbname, int8_t tableType,
|
||||||
|
int32_t numOfColumns, int32_t numOfTags = 0);
|
||||||
void createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid);
|
void createSubTable(const std::string& db, const std::string& stbname, const std::string& tbname, int16_t vgid);
|
||||||
void showTables() const;
|
void showTables() const;
|
||||||
std::shared_ptr<MockTableMeta> getTableMeta(const std::string& db, const std::string& tbname) const;
|
std::shared_ptr<MockTableMeta> getTableMeta(const std::string& db, const std::string& tbname) const;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "parserTestUtil.h"
|
|
||||||
#include "parInt.h"
|
#include "parInt.h"
|
||||||
|
#include "parserTestUtil.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) {
|
||||||
bind("SELECT 123, 20.4, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1");
|
bind("SELECT 123, 20.4, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1");
|
bind(
|
||||||
|
"SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc', \"wxy\", "
|
||||||
|
"TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("SELECT 123 + 45 FROM t1 where 2 - 1");
|
bind("SELECT 123 + 45 FROM t1 where 2 - 1");
|
||||||
|
@ -449,7 +451,8 @@ TEST_F(ParserTest, createDatabase) {
|
||||||
bind("create database wxy_db");
|
bind("create database wxy_db");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create database if not exists wxy_db "
|
bind(
|
||||||
|
"create database if not exists wxy_db "
|
||||||
"BLOCKS 100 "
|
"BLOCKS 100 "
|
||||||
"CACHE 100 "
|
"CACHE 100 "
|
||||||
"CACHELAST 2 "
|
"CACHELAST 2 "
|
||||||
|
@ -467,14 +470,13 @@ TEST_F(ParserTest, createDatabase) {
|
||||||
"VGROUPS 100 "
|
"VGROUPS 100 "
|
||||||
"SINGLE_STABLE 0 "
|
"SINGLE_STABLE 0 "
|
||||||
"STREAM_MODE 1 "
|
"STREAM_MODE 1 "
|
||||||
"RETENTIONS '15s:7d,1m:21d,15m:5y'"
|
"RETENTIONS '15s:7d,1m:21d,15m:5y'");
|
||||||
);
|
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create database if not exists wxy_db "
|
bind(
|
||||||
|
"create database if not exists wxy_db "
|
||||||
"DAYS 100m "
|
"DAYS 100m "
|
||||||
"KEEP 200m,300h,400d "
|
"KEEP 200m,300h,400d ");
|
||||||
);
|
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) {
|
||||||
bind("alter database wxy_db BLOCKS 200");
|
bind("alter database wxy_db BLOCKS 200");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("alter database wxy_db "
|
bind(
|
||||||
|
"alter database wxy_db "
|
||||||
"BLOCKS 200 "
|
"BLOCKS 200 "
|
||||||
"CACHELAST 1 "
|
"CACHELAST 1 "
|
||||||
"FSYNC 200 "
|
"FSYNC 200 "
|
||||||
"KEEP 200 "
|
"KEEP 200 "
|
||||||
"QUORUM 2 "
|
"QUORUM 2 "
|
||||||
"WAL 1 "
|
"WAL 1 ");
|
||||||
);
|
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) {
|
||||||
bind("create table t1(ts timestamp, c1 int)");
|
bind("create table t1(ts timestamp, c1 int)");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create table if not exists test.t1("
|
bind(
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
"create table if not exists test.t1("
|
||||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
|
"SMALLINT, "
|
||||||
);
|
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||||
|
"c14 JSON, c15 VARCHAR(50)) "
|
||||||
|
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create table if not exists test.t1("
|
bind(
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
"create table if not exists test.t1("
|
||||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
|
"SMALLINT, "
|
||||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
|
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
|
"c14 JSON, c15 VARCHAR(50)) "
|
||||||
);
|
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
|
||||||
|
"BINARY(20), a8 SMALLINT, "
|
||||||
|
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
|
||||||
|
"a14 JSON, a15 VARCHAR(50)) "
|
||||||
|
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create table if not exists t1 using st1 tags(1, 'wxy')");
|
bind("create table if not exists t1 using st1 tags(1, 'wxy')");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create table "
|
bind(
|
||||||
|
"create table "
|
||||||
"if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') "
|
"if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc') "
|
||||||
"if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') "
|
"if not exists test.t2 using test.st1 (tag1, tag2) tags(2, 'abc') "
|
||||||
"if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') "
|
"if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc') "
|
||||||
"if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null) "
|
"if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null) "
|
||||||
"if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc') "
|
"if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc') "
|
||||||
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)"
|
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)");
|
||||||
);
|
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create stable t1(ts timestamp, c1 int) TAGS(id int)");
|
bind("create stable t1(ts timestamp, c1 int) TAGS(id int)");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("create stable if not exists test.t1("
|
bind(
|
||||||
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
|
"create stable if not exists test.t1("
|
||||||
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
|
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
|
||||||
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
|
"SMALLINT, "
|
||||||
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
|
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
|
||||||
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
|
"c14 JSON, c15 VARCHAR(50)) "
|
||||||
);
|
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
|
||||||
|
"BINARY(20), a8 SMALLINT, "
|
||||||
|
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
|
||||||
|
"a14 JSON, a15 VARCHAR(50)) "
|
||||||
|
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,8 @@ using namespace std;
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
string toString(int32_t code) {
|
string toString(int32_t code) { return tstrerror(code); }
|
||||||
return tstrerror(code);
|
} // namespace
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// syntax:
|
// syntax:
|
||||||
// INSERT INTO
|
// INSERT INTO
|
||||||
|
@ -49,7 +47,6 @@ protected:
|
||||||
cxt_.sqlLen = strlen(sql);
|
cxt_.sqlLen = strlen(sql);
|
||||||
sqlBuf_[cxt_.sqlLen] = '\0';
|
sqlBuf_[cxt_.sqlLen] = '\0';
|
||||||
cxt_.pSql = sqlBuf_;
|
cxt_.pSql = sqlBuf_;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t run() {
|
int32_t run() {
|
||||||
|
@ -63,7 +60,8 @@ protected:
|
||||||
void dumpReslut() {
|
void dumpReslut() {
|
||||||
SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_);
|
SVnodeModifOpStmt* pStmt = getVnodeModifStmt(res_);
|
||||||
size_t num = taosArrayGetSize(pStmt->pDataBlocks);
|
size_t num = taosArrayGetSize(pStmt->pDataBlocks);
|
||||||
cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType << ", numOfVgs:" << num << endl;
|
cout << "payloadType:" << (int32_t)pStmt->payloadType << ", insertType:" << pStmt->insertType
|
||||||
|
<< ", numOfVgs:" << num << endl;
|
||||||
for (size_t i = 0; i < num; ++i) {
|
for (size_t i = 0; i < num; ++i) {
|
||||||
SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i);
|
SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(pStmt->pDataBlocks, i);
|
||||||
cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl;
|
cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl;
|
||||||
|
@ -73,8 +71,9 @@ protected:
|
||||||
SSubmitBlk* blk = (SSubmitBlk*)(submit + 1);
|
SSubmitBlk* blk = (SSubmitBlk*)(submit + 1);
|
||||||
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
for (int32_t i = 0; i < numOfBlocks; ++i) {
|
||||||
cout << "Block:" << i << endl;
|
cout << "Block:" << i << endl;
|
||||||
cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding) << ", sversion:" << ntohl(blk->sversion)
|
cout << "\tuid:" << be64toh(blk->uid) << ", tid:" << be64toh(blk->suid) << ", padding:" << ntohl(blk->padding)
|
||||||
<< ", dataLen:" << ntohl(blk->dataLen) << ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl;
|
<< ", sversion:" << ntohl(blk->sversion) << ", dataLen:" << ntohl(blk->dataLen)
|
||||||
|
<< ", schemaLen:" << ntohl(blk->schemaLen) << ", numOfRows:" << ntohs(blk->numOfRows) << endl;
|
||||||
blk = (SSubmitBlk*)(blk->data + ntohl(blk->dataLen));
|
blk = (SSubmitBlk*)(blk->data + ntohl(blk->dataLen));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,9 +113,7 @@ private:
|
||||||
code_ = TSDB_CODE_SUCCESS;
|
code_ = TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) {
|
SVnodeModifOpStmt* getVnodeModifStmt(SQuery* pQuery) { return (SVnodeModifOpStmt*)pQuery->pRoot; }
|
||||||
return (SVnodeModifOpStmt*)pQuery->pRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
string acctId_;
|
string acctId_;
|
||||||
string db_;
|
string db_;
|
||||||
|
@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) {
|
||||||
TEST_F(InsertTest, singleTableMultiRowTest) {
|
TEST_F(InsertTest, singleTableMultiRowTest) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)");
|
bind(
|
||||||
|
"insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, "
|
||||||
|
"10, 11)");
|
||||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||||
dumpReslut();
|
dumpReslut();
|
||||||
checkReslut(1, 3);
|
checkReslut(1, 3);
|
||||||
|
@ -161,7 +160,8 @@ TEST_F(InsertTest, multiTableSingleRowTest) {
|
||||||
TEST_F(InsertTest, multiTableMultiRowTest) {
|
TEST_F(InsertTest, multiTableMultiRowTest) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"
|
bind(
|
||||||
|
"insert into st1s1 values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")"
|
||||||
" st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")");
|
" st1s2 values (now, 10, \"131028\")(now+1s, 20, \"132028\")");
|
||||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||||
dumpReslut();
|
dumpReslut();
|
||||||
|
@ -174,7 +174,9 @@ TEST_F(InsertTest, multiTableMultiRowTest) {
|
||||||
TEST_F(InsertTest, autoCreateTableTest) {
|
TEST_F(InsertTest, autoCreateTableTest) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
|
bind(
|
||||||
|
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, "
|
||||||
|
"\"guangzhou\")");
|
||||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||||
dumpReslut();
|
dumpReslut();
|
||||||
checkReslut(1, 3);
|
checkReslut(1, 3);
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
@ -23,11 +23,11 @@
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
#define TD_USE_WINSOCK
|
#define TD_USE_WINSOCK
|
||||||
#endif
|
#endif
|
||||||
#include "os.h"
|
|
||||||
#include "parserTestUtil.h"
|
|
||||||
#include "parToken.h"
|
|
||||||
#include "functionMgt.h"
|
#include "functionMgt.h"
|
||||||
#include "mockCatalog.h"
|
#include "mockCatalog.h"
|
||||||
|
#include "os.h"
|
||||||
|
#include "parToken.h"
|
||||||
|
#include "parserTestUtil.h"
|
||||||
|
|
||||||
bool g_isDump = false;
|
bool g_isDump = false;
|
||||||
|
|
||||||
|
@ -51,10 +51,7 @@ public:
|
||||||
static void parseArg(int argc, char* argv[]) {
|
static void parseArg(int argc, char* argv[]) {
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
const char* optstring = "";
|
const char* optstring = "";
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||||
{"dump", no_argument, NULL, 'd'},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
|
|
|
@ -24,7 +24,8 @@ typedef struct SLogicPlanContext {
|
||||||
typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**);
|
typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**);
|
||||||
typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**);
|
typedef int32_t (*FCreateSetOpLogicNode)(SLogicPlanContext*, SSetOperator*, SLogicNode**);
|
||||||
|
|
||||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode);
|
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||||
|
SLogicNode** pLogicNode);
|
||||||
static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode);
|
static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode);
|
||||||
|
|
||||||
typedef struct SRewriteExprCxt {
|
typedef struct SRewriteExprCxt {
|
||||||
|
@ -115,7 +116,8 @@ static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLo
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, SLogicNode** pRoot) {
|
static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func,
|
||||||
|
SLogicNode** pRoot) {
|
||||||
SLogicNode* pNode = NULL;
|
SLogicNode* pNode = NULL;
|
||||||
int32_t code = func(pCxt, pSelect, &pNode);
|
int32_t code = func(pCxt, pSelect, &pNode);
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
||||||
|
@ -191,7 +193,8 @@ static int32_t addPrimaryKeyCol(uint64_t tableId, SNodeList** pCols) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) {
|
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
||||||
if (NULL == pScan) {
|
if (NULL == pScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -245,18 +248,18 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) {
|
static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode);
|
int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
FOREACH(pNode, (*pLogicNode)->pTargets) {
|
FOREACH(pNode, (*pLogicNode)->pTargets) { strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias); }
|
||||||
strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, SLogicNode** pLogicNode) {
|
static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN);
|
SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN);
|
||||||
if (NULL == pJoin) {
|
if (NULL == pJoin) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -316,7 +319,8 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
switch (nodeType(pTable)) {
|
switch (nodeType(pTable)) {
|
||||||
case QUERY_NODE_REAL_TABLE:
|
case QUERY_NODE_REAL_TABLE:
|
||||||
return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode);
|
return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode);
|
||||||
|
@ -330,7 +334,8 @@ static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pS
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SLogicNode* pNode = NULL;
|
SLogicNode* pNode = NULL;
|
||||||
int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode);
|
int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -409,12 +414,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||||
SNodeList* pAggFuncs = NULL;
|
if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) {
|
||||||
int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs);
|
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
if (NULL == pAggFuncs && NULL == pSelect->pGroupByList) {
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,6 +423,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
// set grouyp keys, agg funcs and having conditions
|
// set grouyp keys, agg funcs and having conditions
|
||||||
if (NULL != pSelect->pGroupByList) {
|
if (NULL != pSelect->pGroupByList) {
|
||||||
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
||||||
|
@ -431,17 +433,16 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) {
|
|
||||||
pAgg->pAggFuncs = nodesCloneList(pAggFuncs);
|
|
||||||
if (NULL == pAgg->pAggFuncs) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
||||||
|
code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAgg->pAggFuncs);
|
||||||
|
}
|
||||||
|
|
||||||
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
code = rewriteExprForSelect(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||||
}
|
}
|
||||||
|
@ -470,7 +471,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) {
|
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
||||||
|
|
||||||
if (pCxt->pPlanCxt->streamQuery) {
|
if (pCxt->pPlanCxt->streamQuery) {
|
||||||
|
@ -486,6 +488,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
|
||||||
code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets);
|
code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pSelect->hasAggFuncs = false;
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pLogicNode = (SLogicNode*)pWindow;
|
*pLogicNode = (SLogicNode*)pWindow;
|
||||||
} else {
|
} else {
|
||||||
|
@ -495,7 +499,8 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindowNode* pState, SSelectStmt* pSelect,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||||
if (NULL == pWindow) {
|
if (NULL == pWindow) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -513,7 +518,8 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo
|
||||||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionWindowNode* pSession,
|
||||||
|
SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||||
if (NULL == pWindow) {
|
if (NULL == pWindow) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -531,7 +537,8 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW
|
||||||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval,
|
||||||
|
SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||||
if (NULL == pWindow) {
|
if (NULL == pWindow) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -542,7 +549,8 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
|
||||||
pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit;
|
pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit;
|
||||||
pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0);
|
pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0);
|
||||||
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
||||||
pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
pWindow->slidingUnit =
|
||||||
|
(NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||||
|
|
||||||
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
|
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
|
||||||
if (NULL == pWindow->pTspk) {
|
if (NULL == pWindow->pTspk) {
|
||||||
|
@ -615,7 +623,8 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) {
|
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs,
|
||||||
|
SNodeList** pCols) {
|
||||||
SNodeList* pList = nodesMakeList();
|
SNodeList* pList = nodesMakeList();
|
||||||
if (NULL == pList) {
|
if (NULL == pList) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -778,7 +787,8 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) {
|
static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||||
|
FCreateSetOpLogicNode func, SLogicNode** pRoot) {
|
||||||
SLogicNode* pNode = NULL;
|
SLogicNode* pNode = NULL;
|
||||||
int32_t code = func(pCxt, pSetOperator, &pNode);
|
int32_t code = func(pCxt, pSetOperator, &pNode);
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
||||||
|
@ -823,7 +833,8 @@ static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* p
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) {
|
static int32_t createSetOpProjectLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT);
|
SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT);
|
||||||
if (NULL == pProject) {
|
if (NULL == pProject) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -927,7 +938,8 @@ static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetO
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) {
|
static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator,
|
||||||
|
SLogicNode** pLogicNode) {
|
||||||
SLogicNode* pRoot = NULL;
|
SLogicNode* pRoot = NULL;
|
||||||
int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot);
|
int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
@ -944,7 +956,9 @@ static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator*
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getMsgType(ENodeType sqlType) {
|
static int32_t getMsgType(ENodeType sqlType) {
|
||||||
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) ? TDMT_VND_CREATE_TABLE : TDMT_VND_SUBMIT;
|
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType)
|
||||||
|
? TDMT_VND_CREATE_TABLE
|
||||||
|
: TDMT_VND_SUBMIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) {
|
static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) {
|
||||||
|
|
|
@ -13,9 +13,9 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "planInt.h"
|
|
||||||
#include "functionMgt.h"
|
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
|
#include "functionMgt.h"
|
||||||
|
#include "planInt.h"
|
||||||
|
|
||||||
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
|
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
|
||||||
if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) {
|
if (TSDB_SUPER_TABLE == ((SScanLogicNode*)pNode)->pMeta->tableType) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (NULL == pNode->pParent ||
|
if (NULL == pNode->pParent || (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) &&
|
||||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) {
|
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) {
|
||||||
|
@ -399,13 +399,18 @@ static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) {
|
static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) {
|
||||||
SCpdIsMultiTableCondCxt cxt = { .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false };
|
SCpdIsMultiTableCondCxt cxt = {
|
||||||
|
.pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false};
|
||||||
nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt);
|
nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt);
|
||||||
return (JOIN_TYPE_INNER != joinType ? COND_ACTION_STAY :
|
return (JOIN_TYPE_INNER != joinType
|
||||||
(cxt.havaLeftCol && cxt.haveRightCol ? COND_ACTION_PUSH_JOIN : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD)));
|
? COND_ACTION_STAY
|
||||||
|
: (cxt.havaLeftCol && cxt.haveRightCol
|
||||||
|
? COND_ACTION_PUSH_JOIN
|
||||||
|
: (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||||
|
SNode** pRightChildCond) {
|
||||||
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions;
|
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions;
|
||||||
if (LOGIC_COND_TYPE_AND != pLogicCond->condType) {
|
if (LOGIC_COND_TYPE_AND != pLogicCond->condType) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -473,7 +478,8 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||||
|
SNode** pRightChildCond) {
|
||||||
SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets;
|
SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets;
|
||||||
SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets;
|
SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets;
|
||||||
ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions);
|
ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions);
|
||||||
|
@ -490,7 +496,8 @@ static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode*
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) {
|
static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond,
|
||||||
|
SNode** pRightChildCond) {
|
||||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) {
|
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) {
|
||||||
return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond);
|
return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond);
|
||||||
} else {
|
} else {
|
||||||
|
@ -762,11 +769,9 @@ static int32_t opkOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) {
|
||||||
return opkOptimizeImpl(pCxt, pSort);
|
return opkOptimizeImpl(pCxt, pSort);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const SOptimizeRule optimizeRuleSet[] = {
|
static const SOptimizeRule optimizeRuleSet[] = {{.pName = "OptimizeScanData", .optimizeFunc = osdOptimize},
|
||||||
{ .pName = "OptimizeScanData", .optimizeFunc = osdOptimize },
|
|
||||||
{.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize},
|
{.pName = "ConditionPushDown", .optimizeFunc = cpdOptimize},
|
||||||
{ .pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize }
|
{.pName = "OrderByPrimaryKey", .optimizeFunc = opkOptimize}};
|
||||||
};
|
|
||||||
|
|
||||||
static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule));
|
static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule));
|
||||||
|
|
||||||
|
@ -784,6 +789,4 @@ static int32_t applyOptimizeRule(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { return applyOptimizeRule(pCxt, pLogicNode); }
|
||||||
return applyOptimizeRule(pCxt, pLogicNode);
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
|
|
||||||
#include "planInt.h"
|
#include "planInt.h"
|
||||||
|
|
||||||
|
#include "catalog.h"
|
||||||
#include "functionMgt.h"
|
#include "functionMgt.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "catalog.h"
|
|
||||||
|
|
||||||
typedef struct SSlotIdInfo {
|
typedef struct SSlotIdInfo {
|
||||||
int16_t slotId;
|
int16_t slotId;
|
||||||
|
@ -104,7 +104,8 @@ static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode,
|
||||||
return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash);
|
return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) {
|
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId,
|
||||||
|
SHashObj** pDescHash) {
|
||||||
SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||||
if (NULL == pHash) {
|
if (NULL == pHash) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -118,7 +119,8 @@ static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) {
|
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc,
|
||||||
|
SHashObj* pHash) {
|
||||||
pDataBlockDesc->pSlots = nodesMakeList();
|
pDataBlockDesc->pSlots = nodesMakeList();
|
||||||
if (NULL == pDataBlockDesc->pSlots) {
|
if (NULL == pDataBlockDesc->pSlots) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -177,7 +179,8 @@ static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) {
|
||||||
return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId;
|
return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) {
|
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc,
|
||||||
|
const char* pStmtName, bool output) {
|
||||||
if (NULL == pList) {
|
if (NULL == pList) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +245,8 @@ static int32_t addDataBlockSlot(SPhysiPlanContext* pCxt, SNode** pNode, SDataBlo
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList,
|
||||||
|
SDataBlockDescNode* pDataBlockDesc) {
|
||||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true);
|
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +281,8 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode, SNode** pOutput) {
|
static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNode* pNode,
|
||||||
|
SNode** pOutput) {
|
||||||
SNode* pRes = nodesCloneNode(pNode);
|
SNode* pRes = nodesCloneNode(pNode);
|
||||||
if (NULL == pRes) {
|
if (NULL == pRes) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -286,8 +291,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
||||||
SSetSlotIdCxt cxt = {
|
SSetSlotIdCxt cxt = {
|
||||||
.errCode = TSDB_CODE_SUCCESS,
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
||||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))
|
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))};
|
||||||
};
|
|
||||||
nodesWalkExpr(pRes, doSetSlotId, &cxt);
|
nodesWalkExpr(pRes, doSetSlotId, &cxt);
|
||||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||||
nodesDestroyNode(pRes);
|
nodesDestroyNode(pRes);
|
||||||
|
@ -298,7 +302,8 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) {
|
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId,
|
||||||
|
const SNodeList* pList, SNodeList** pOutput) {
|
||||||
SNodeList* pRes = nodesCloneList(pList);
|
SNodeList* pRes = nodesCloneList(pList);
|
||||||
if (NULL == pRes) {
|
if (NULL == pRes) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -307,8 +312,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
||||||
SSetSlotIdCxt cxt = {
|
SSetSlotIdCxt cxt = {
|
||||||
.errCode = TSDB_CODE_SUCCESS,
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
.pLeftHash = taosArrayGetP(pCxt->pLocationHelper, leftDataBlockId),
|
||||||
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))
|
.pRightHash = (rightDataBlockId < 0 ? NULL : taosArrayGetP(pCxt->pLocationHelper, rightDataBlockId))};
|
||||||
};
|
|
||||||
nodesWalkExprs(pRes, doSetSlotId, &cxt);
|
nodesWalkExprs(pRes, doSetSlotId, &cxt);
|
||||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||||
nodesDestroyList(pRes);
|
nodesDestroyList(pRes);
|
||||||
|
@ -346,7 +350,8 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLo
|
||||||
|
|
||||||
static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) {
|
static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pLogicNode, SPhysiNode* pPhysiNode) {
|
||||||
if (NULL != pLogicNode->pConditions) {
|
if (NULL != pLogicNode->pConditions) {
|
||||||
return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions, &pPhysiNode->pConditions);
|
return setNodeSlotId(pCxt, pPhysiNode->pOutputDataBlockDesc->dataBlockId, -1, pLogicNode->pConditions,
|
||||||
|
&pPhysiNode->pConditions);
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -364,15 +369,11 @@ static int32_t sortScanCols(SNodeList* pScanCols) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* pCol = NULL;
|
SNode* pCol = NULL;
|
||||||
FOREACH(pCol, pScanCols) {
|
FOREACH(pCol, pScanCols) { taosArrayPush(pArray, &pCol); }
|
||||||
taosArrayPush(pArray, &pCol);
|
|
||||||
}
|
|
||||||
taosArraySort(pArray, colIdCompare);
|
taosArraySort(pArray, colIdCompare);
|
||||||
|
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
FOREACH(pCol, pScanCols) {
|
FOREACH(pCol, pScanCols) { REPLACE_NODE(taosArrayGetP(pArray, index++)); }
|
||||||
REPLACE_NODE(taosArrayGetP(pArray, index++));
|
|
||||||
}
|
|
||||||
taosArrayDestroy(pArray);
|
taosArrayDestroy(pArray);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -386,7 +387,8 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
||||||
return sortScanCols(pScanPhysiNode->pScanCols);
|
return sortScanCols(pScanPhysiNode->pScanCols);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode,
|
||||||
|
SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
||||||
int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols);
|
int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
// Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
|
// Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
|
||||||
|
@ -416,15 +418,19 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||||
if (NULL == pTagScan) {
|
if (NULL == pTagScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode);
|
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTagScan, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
SPhysiNode** pPhyNode) {
|
||||||
|
STableScanPhysiNode* pTableScan =
|
||||||
|
(STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode,
|
||||||
|
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||||
if (NULL == pTableScan) {
|
if (NULL == pTableScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -451,8 +457,11 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
||||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode);
|
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
|
||||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SSystemTableScanPhysiNode* pScan =
|
||||||
|
(SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision,
|
||||||
|
(SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||||
if (NULL == pScan) {
|
if (NULL == pScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -472,15 +481,19 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
||||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SStreamScanPhysiNode* pScan =
|
||||||
|
(SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision,
|
||||||
|
(SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||||
if (NULL == pScan) {
|
if (NULL == pScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pScan, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||||
|
SPhysiNode** pPhyNode) {
|
||||||
switch (pScanLogicNode->scanType) {
|
switch (pScanLogicNode->scanType) {
|
||||||
case SCAN_TYPE_TAG:
|
case SCAN_TYPE_TAG:
|
||||||
return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode);
|
return createTagScanPhysiNode(pCxt, pScanLogicNode, pPhyNode);
|
||||||
|
@ -496,8 +509,10 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode,
|
||||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode,
|
||||||
|
QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||||
if (NULL == pJoin) {
|
if (NULL == pJoin) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -508,10 +523,12 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
||||||
|
|
||||||
pJoin->joinType = pJoinLogicNode->joinType;
|
pJoin->joinType = pJoinLogicNode->joinType;
|
||||||
if (NULL != pJoinLogicNode->pOnConditions) {
|
if (NULL != pJoinLogicNode->pOnConditions) {
|
||||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions);
|
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions,
|
||||||
|
&pJoin->pOnConditions);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets);
|
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets,
|
||||||
|
&pJoin->pTargets);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||||
|
@ -555,7 +572,8 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
|
||||||
if ('\0' != pRewrittenExpr->aliasName[0]) {
|
if ('\0' != pRewrittenExpr->aliasName[0]) {
|
||||||
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
||||||
} else {
|
} else {
|
||||||
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId);
|
snprintf(pRewrittenExpr->aliasName, sizeof(pRewrittenExpr->aliasName), "#expr_%d_%d", pCxt->planNodeId,
|
||||||
|
pCxt->rewriteId);
|
||||||
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
strcpy(pCol->colName, pRewrittenExpr->aliasName);
|
||||||
}
|
}
|
||||||
nodesDestroyNode(*pNode);
|
nodesDestroyNode(*pNode);
|
||||||
|
@ -581,7 +599,8 @@ static EDealRes doRewritePrecalcExprs(SNode** pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs, SNodeList** pRewrittenList) {
|
static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SNodeList** pPrecalcExprs,
|
||||||
|
SNodeList** pRewrittenList) {
|
||||||
if (NULL == pList) {
|
if (NULL == pList) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -622,7 +641,8 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
||||||
return cxt.errCode;
|
return cxt.errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs, SNode** pRewritten) {
|
static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeList** pPrecalcExprs,
|
||||||
|
SNode** pRewritten) {
|
||||||
if (NULL == pNode) {
|
if (NULL == pNode) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -641,8 +661,10 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode,
|
||||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode,
|
||||||
|
QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||||
if (NULL == pAgg) {
|
if (NULL == pAgg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -695,8 +717,10 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||||
if (NULL == pProject) {
|
if (NULL == pProject) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -706,9 +730,11 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
||||||
pProject->slimit = pProjectLogicNode->slimit;
|
pProject->slimit = pProjectLogicNode->slimit;
|
||||||
pProject->soffset = pProjectLogicNode->soffset;
|
pProject->soffset = pProjectLogicNode->soffset;
|
||||||
|
|
||||||
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId,
|
||||||
|
-1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections,
|
||||||
|
pProject->node.pOutputDataBlockDesc);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject);
|
code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject);
|
||||||
|
@ -723,8 +749,10 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(
|
||||||
|
pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||||
if (NULL == pExchange) {
|
if (NULL == pExchange) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -734,8 +762,10 @@ static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogic
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||||
if (NULL == pScan) {
|
if (NULL == pScan) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -767,7 +797,8 @@ static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExc
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode,
|
||||||
|
SPhysiNode** pPhyNode) {
|
||||||
if (pCxt->pPlanCxt->streamQuery) {
|
if (pCxt->pPlanCxt->streamQuery) {
|
||||||
return createStreamScanPhysiNodeByExchange(pCxt, pExchangeLogicNode, pPhyNode);
|
return createStreamScanPhysiNodeByExchange(pCxt, pExchangeLogicNode, pPhyNode);
|
||||||
} else {
|
} else {
|
||||||
|
@ -775,7 +806,8 @@ static int32_t createExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWinodwPhysiNode* pWindow,
|
||||||
|
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||||
SNodeList* pPrecalcExprs = NULL;
|
SNodeList* pPrecalcExprs = NULL;
|
||||||
SNodeList* pFuncs = NULL;
|
SNodeList* pFuncs = NULL;
|
||||||
int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs);
|
int32_t code = rewritePrecalcExprs(pCxt, pWindowLogicNode->pFuncs, &pPrecalcExprs, &pFuncs);
|
||||||
|
@ -812,8 +844,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||||
if (NULL == pInterval) {
|
if (NULL == pInterval) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -833,8 +867,10 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
||||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||||
if (NULL == pSession) {
|
if (NULL == pSession) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -844,8 +880,10 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
||||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pSession->window, pWindowLogicNode, pPhyNode);
|
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pSession->window, pWindowLogicNode, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
||||||
if (NULL == pState) {
|
if (NULL == pState) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -878,7 +916,8 @@ static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC
|
||||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pState->window, pWindowLogicNode, pPhyNode);
|
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pState->window, pWindowLogicNode, pPhyNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode,
|
||||||
|
SPhysiNode** pPhyNode) {
|
||||||
switch (pWindowLogicNode->winType) {
|
switch (pWindowLogicNode->winType) {
|
||||||
case WINDOW_TYPE_INTERVAL:
|
case WINDOW_TYPE_INTERVAL:
|
||||||
return createIntervalPhysiNode(pCxt, pChildren, pWindowLogicNode, pPhyNode);
|
return createIntervalPhysiNode(pCxt, pChildren, pWindowLogicNode, pPhyNode);
|
||||||
|
@ -892,8 +931,10 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode,
|
||||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
SPhysiNode** pPhyNode) {
|
||||||
|
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode,
|
||||||
|
QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||||
if (NULL == pSort) {
|
if (NULL == pSort) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -931,8 +972,10 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) {
|
static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||||
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) {
|
||||||
|
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(
|
||||||
|
pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
||||||
if (NULL == pPart) {
|
if (NULL == pPart) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
@ -970,7 +1013,8 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan,
|
||||||
|
SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
||||||
switch (nodeType(pLogicNode)) {
|
switch (nodeType(pLogicNode)) {
|
||||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||||
return createScanPhysiNode(pCxt, pSubplan, (SScanLogicNode*)pLogicNode, pPhyNode);
|
return createScanPhysiNode(pCxt, pSubplan, (SScanLogicNode*)pLogicNode, pPhyNode);
|
||||||
|
@ -995,7 +1039,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SPhysiNode** pPhyNode) {
|
static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan,
|
||||||
|
SPhysiNode** pPhyNode) {
|
||||||
SNodeList* pChildren = nodesMakeList();
|
SNodeList* pChildren = nodesMakeList();
|
||||||
if (NULL == pChildren) {
|
if (NULL == pChildren) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -1019,9 +1064,7 @@ static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode,
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
(*pPhyNode)->pChildren = pChildren;
|
(*pPhyNode)->pChildren = pChildren;
|
||||||
SNode* pChild;
|
SNode* pChild;
|
||||||
FOREACH(pChild, (*pPhyNode)->pChildren) {
|
FOREACH(pChild, (*pPhyNode)->pChildren) { ((SPhysiNode*)pChild)->pParent = (*pPhyNode); }
|
||||||
((SPhysiNode*)pChild)->pParent = (*pPhyNode);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
nodesDestroyList(pChildren);
|
nodesDestroyList(pChildren);
|
||||||
}
|
}
|
||||||
|
@ -1137,7 +1180,8 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l
|
||||||
return nodesListStrictAppend(pGroup->pNodeList, pSubplan);
|
return nodesListStrictAppend(pGroup->pNodeList, pSubplan);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) {
|
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent,
|
||||||
|
SQueryPlan* pQueryPlan) {
|
||||||
SSubplan* pSubplan = NULL;
|
SSubplan* pSubplan = NULL;
|
||||||
int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan);
|
int32_t code = createPhysiSubplan(pCxt, pLogicSubplan, &pSubplan);
|
||||||
|
|
||||||
|
@ -1221,13 +1265,11 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) {
|
int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) {
|
||||||
SPhysiPlanContext cxt = {
|
SPhysiPlanContext cxt = {.pPlanCxt = pCxt,
|
||||||
.pPlanCxt = pCxt,
|
|
||||||
.errCode = TSDB_CODE_SUCCESS,
|
.errCode = TSDB_CODE_SUCCESS,
|
||||||
.nextDataBlockId = 0,
|
.nextDataBlockId = 0,
|
||||||
.pLocationHelper = taosArrayInit(32, POINTER_BYTES),
|
.pLocationHelper = taosArrayInit(32, POINTER_BYTES),
|
||||||
.pExecNodeList = pExecNodeList
|
.pExecNodeList = pExecNodeList};
|
||||||
};
|
|
||||||
if (NULL == cxt.pLocationHelper) {
|
if (NULL == cxt.pLocationHelper) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
|
||||||
return pSubplan;
|
return pSubplan;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, ESubplanType subplanType) {
|
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan,
|
||||||
|
ESubplanType subplanType) {
|
||||||
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
|
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
|
||||||
if (NULL == pExchange) {
|
if (NULL == pExchange) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag,
|
||||||
}
|
}
|
||||||
|
|
||||||
static SLogicNode* stsMatchByNode(SLogicNode* pNode) {
|
static SLogicNode* stsMatchByNode(SLogicNode* pNode) {
|
||||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) &&
|
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != ((SScanLogicNode*)pNode)->pVgroupList &&
|
||||||
NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) {
|
((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) {
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
SNode* pChild;
|
SNode* pChild;
|
||||||
|
@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) {
|
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS));
|
int32_t code =
|
||||||
|
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS));
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE);
|
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE);
|
||||||
}
|
}
|
||||||
|
@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
|
||||||
SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
||||||
SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1);
|
SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1);
|
||||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) &&
|
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) &&
|
||||||
QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) {
|
QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) &&
|
||||||
|
ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) {
|
||||||
return pRight;
|
return pRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) {
|
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ));
|
int32_t code =
|
||||||
|
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ));
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType);
|
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType);
|
||||||
}
|
}
|
||||||
|
@ -360,12 +364,10 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const SSplitRule splitRuleSet[] = {
|
static const SSplitRule splitRuleSet[] = {{.pName = "SuperTableScan", .splitFunc = stsSplit},
|
||||||
{ .pName = "SuperTableScan", .splitFunc = stsSplit },
|
|
||||||
{.pName = "ChildTableJoin", .splitFunc = ctjSplit},
|
{.pName = "ChildTableJoin", .splitFunc = ctjSplit},
|
||||||
{.pName = "UnionAll", .splitFunc = uaSplit},
|
{.pName = "UnionAll", .splitFunc = uaSplit},
|
||||||
{ .pName = "Union", .splitFunc = unSplit }
|
{.pName = "Union", .splitFunc = unSplit}};
|
||||||
};
|
|
||||||
|
|
||||||
static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule));
|
static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule));
|
||||||
|
|
||||||
|
@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) {
|
||||||
static void doSetLogicNodeParent(SLogicNode* pNode, SLogicNode* pParent) {
|
static void doSetLogicNodeParent(SLogicNode* pNode, SLogicNode* pParent) {
|
||||||
pNode->pParent = pParent;
|
pNode->pParent = pParent;
|
||||||
SNode* pChild;
|
SNode* pChild;
|
||||||
FOREACH(pChild, pNode->pChildren) {
|
FOREACH(pChild, pNode->pChildren) { doSetLogicNodeParent((SLogicNode*)pChild, pNode); }
|
||||||
doSetLogicNodeParent((SLogicNode*)pChild, pNode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setLogicNodeParent(SLogicNode* pNode) {
|
static void setLogicNodeParent(SLogicNode* pNode) { doSetLogicNodeParent(pNode, NULL); }
|
||||||
doSetLogicNodeParent(pNode, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan** pLogicSubplan) {
|
int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan** pLogicSubplan) {
|
||||||
SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
||||||
|
@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
|
||||||
}
|
}
|
||||||
if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) {
|
if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) {
|
||||||
pSubplan->subplanType = SUBPLAN_TYPE_MODIFY;
|
pSubplan->subplanType = SUBPLAN_TYPE_MODIFY;
|
||||||
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks, SArray*);
|
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)pSubplan->pNode)->pDataBlocks,
|
||||||
|
SArray*);
|
||||||
} else {
|
} else {
|
||||||
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
|
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,9 +171,7 @@ static int32_t setValueByBindParam(SValueNode* pVal, TAOS_BIND_v2* pParam) {
|
||||||
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams) {
|
int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams) {
|
||||||
int32_t index = 0;
|
int32_t index = 0;
|
||||||
SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
FOREACH(pNode, pPlan->pPlaceholderValues) {
|
FOREACH(pNode, pPlan->pPlaceholderValues) { setValueByBindParam((SValueNode*)pNode, pParams + index); }
|
||||||
setValueByBindParam((SValueNode*)pNode, pParams + index);
|
|
||||||
}
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +186,7 @@ int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
||||||
return nodesNodeToString((const SNode*)pSubplan, false, pStr, pLen);
|
return nodesNodeToString((const SNode*)pSubplan, false, pStr, pLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) {
|
int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan) { return nodesStringToNode(pStr, (SNode**)pSubplan); }
|
||||||
return nodesStringToNode(pStr, (SNode**)pSubplan);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* qQueryPlanToString(const SQueryPlan* pPlan) {
|
char* qQueryPlanToString(const SQueryPlan* pPlan) {
|
||||||
char* pStr = NULL;
|
char* pStr = NULL;
|
||||||
|
@ -209,6 +205,4 @@ SQueryPlan* qStringToQueryPlan(const char* pStr) {
|
||||||
return pPlan;
|
return pPlan;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qDestroyQueryPlan(SQueryPlan* pPlan) {
|
void qDestroyQueryPlan(SQueryPlan* pPlan) { nodesDestroyNode(pPlan); }
|
||||||
nodesDestroyNode(pPlan);
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class PlanOptimizeTest : public PlannerTestBase {
|
class PlanOptimizeTest : public PlannerTestBase {};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
|
TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* 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 "planTestUtil.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class PlanSuperTableTest : public PlannerTestBase {};
|
||||||
|
|
||||||
|
TEST_F(PlanSuperTableTest, unionAll) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("select tbname from st1");
|
||||||
|
}
|
|
@ -18,9 +18,7 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class PlanSetOpTest : public PlannerTestBase {
|
class PlanSetOpTest : public PlannerTestBase {};
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(PlanSetOpTest, unionAll) {
|
TEST_F(PlanSetOpTest, unionAll) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
|
@ -27,9 +27,7 @@ public:
|
||||||
generateMetaData();
|
generateMetaData();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void TearDown() {
|
virtual void TearDown() { destroyMetaDataEnv(); }
|
||||||
destroyMetaDataEnv();
|
|
||||||
}
|
|
||||||
|
|
||||||
PlannerEnv() {}
|
PlannerEnv() {}
|
||||||
virtual ~PlannerEnv() {}
|
virtual ~PlannerEnv() {}
|
||||||
|
@ -38,10 +36,7 @@ public:
|
||||||
static void parseArg(int argc, char* argv[]) {
|
static void parseArg(int argc, char* argv[]) {
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
const char* optstring = "";
|
const char* optstring = "";
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||||
{"dump", no_argument, NULL, 'd'},
|
|
||||||
{0, 0, 0, 0}
|
|
||||||
};
|
|
||||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include "planTestUtil.h"
|
#include "planTestUtil.h"
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ using namespace testing;
|
||||||
do { \
|
do { \
|
||||||
int32_t code__ = func(__VA_ARGS__); \
|
int32_t code__ = func(__VA_ARGS__); \
|
||||||
if (TSDB_CODE_SUCCESS != code__) { \
|
if (TSDB_CODE_SUCCESS != code__) { \
|
||||||
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + ", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
|
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + \
|
||||||
|
", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
|
@ -170,9 +171,7 @@ private:
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
FOREACH(pNode, (*pPlan)->pSubplans) {
|
FOREACH(pNode, (*pPlan)->pSubplans) {
|
||||||
SNode* pSubplan;
|
SNode* pSubplan;
|
||||||
FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) {
|
FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { res_.physiSubplans_.push_back(toString(pSubplan)); }
|
||||||
res_.physiSubplans_.push_back(toString(pSubplan));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,16 +209,10 @@ private:
|
||||||
stmtRes res_;
|
stmtRes res_;
|
||||||
};
|
};
|
||||||
|
|
||||||
PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {
|
PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {}
|
||||||
}
|
|
||||||
|
|
||||||
PlannerTestBase::~PlannerTestBase() {
|
PlannerTestBase::~PlannerTestBase() {}
|
||||||
}
|
|
||||||
|
|
||||||
void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) {
|
void PlannerTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); }
|
||||||
impl_->useDb(acctId, db);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlannerTestBase::run(const std::string& sql) {
|
void PlannerTestBase::run(const std::string& sql) { return impl_->run(sql); }
|
||||||
return impl_->run(sql);
|
|
||||||
}
|
|
||||||
|
|
|
@ -45,7 +45,8 @@ protected:
|
||||||
int32_t code = qParseQuerySql(&cxt_, &query_);
|
int32_t code = qParseQuerySql(&cxt_, &query_);
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
|
cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code)
|
||||||
|
<< ", msg:" << errMagBuf_ << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +91,8 @@ protected:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = createPhysiPlan(&cxt, pLogicPlan, &plan_, NULL);
|
SArray* pExecNodeList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SQueryNodeAddr));
|
||||||
|
code = createPhysiPlan(&cxt, pLogicPlan, &plan_, pExecNodeList);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl;
|
cout << "sql:[" << cxt_.pSql << "] createPhysiPlan code:" << code << ", strerror:" << tstrerror(code) << endl;
|
||||||
return false;
|
return false;
|
||||||
|
@ -192,7 +194,9 @@ TEST_F(PlannerTest, selectJoin) {
|
||||||
bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts");
|
bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
bind("SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and t2.c2 = 'qwe'");
|
bind(
|
||||||
|
"SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and "
|
||||||
|
"t2.c2 = 'qwe'");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,12 +214,17 @@ TEST_F(PlannerTest, selectGroupBy) {
|
||||||
|
|
||||||
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("SELECT sum(ceil(c1)) FROM t1 GROUP BY ceil(c1)");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlannerTest, selectSubquery) {
|
TEST_F(PlannerTest, selectSubquery) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b");
|
bind(
|
||||||
|
"SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 "
|
||||||
|
"group by b");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +371,9 @@ TEST_F(PlannerTest, createTopic) {
|
||||||
TEST_F(PlannerTest, createStream) {
|
TEST_F(PlannerTest, createStream) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 interval(10s)");
|
bind(
|
||||||
|
"create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 "
|
||||||
|
"interval(10s)");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue