feature/qnode
This commit is contained in:
parent
ae8e556ba5
commit
ef0d9262c9
|
@ -337,6 +337,7 @@ SNodeList* nodesListAppend(SNodeList* pList, SNode* pNode);
|
||||||
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
||||||
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
SNode* nodesListGetNode(SNodeList* pList, int32_t index);
|
||||||
void nodesDestroyList(SNodeList* pList);
|
void nodesDestroyList(SNodeList* pList);
|
||||||
|
void *nodesGetValueFromNode(SValueNode *pNode);
|
||||||
|
|
||||||
typedef enum EDealRes {
|
typedef enum EDealRes {
|
||||||
DEAL_RES_CONTINUE = 1,
|
DEAL_RES_CONTINUE = 1,
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
#ifndef TDENGINE_SCALAR_H
|
||||||
|
#define TDENGINE_SCALAR_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define sclFatal(...) qFatal(__VA_ARGS__)
|
||||||
|
#define sclError(...) qError(__VA_ARGS__)
|
||||||
|
#define sclWarn(...) qWarn(__VA_ARGS__)
|
||||||
|
#define sclInfo(...) qInfo(__VA_ARGS__)
|
||||||
|
#define sclDebug(...) qDebug(__VA_ARGS__)
|
||||||
|
#define sclTrace(...) qTrace(__VA_ARGS__)
|
||||||
|
|
||||||
|
#define SCL_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||||
|
#define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||||
|
#define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TDENGINE_SCALAR_H
|
|
@ -3243,7 +3243,7 @@ static void arithmetic_function(SqlFunctionCtx *pCtx) {
|
||||||
SScalarFuncParam output = {0};
|
SScalarFuncParam output = {0};
|
||||||
output.data = pCtx->pOutput;
|
output.data = pCtx->pOutput;
|
||||||
|
|
||||||
evaluateExprNodeTree(pSup->pExprInfo->pExpr, pCtx->size, &output, pSup, getArithColumnData);
|
//evaluateExprNodeTree(pSup->pExprInfo->pExpr, pCtx->size, &output, pSup, getArithColumnData);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
|
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
|
||||||
|
|
|
@ -465,18 +465,16 @@ void vectorConcat(SScalarFuncParam* pLeft, SScalarFuncParam* pRight, void *out,
|
||||||
|
|
||||||
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
|
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
|
||||||
switch (binFunctionId) {
|
switch (binFunctionId) {
|
||||||
case TSDB_BINARY_OP_ADD:
|
case OP_TYPE_ADD:
|
||||||
return vectorAdd;
|
return vectorAdd;
|
||||||
case TSDB_BINARY_OP_SUBTRACT:
|
case OP_TYPE_SUB:
|
||||||
return vectorSub;
|
return vectorSub;
|
||||||
case TSDB_BINARY_OP_MULTIPLY:
|
case OP_TYPE_MULTI:
|
||||||
return vectorMultiply;
|
return vectorMultiply;
|
||||||
case TSDB_BINARY_OP_DIVIDE:
|
case OP_TYPE_DIV:
|
||||||
return vectorDivide;
|
return vectorDivide;
|
||||||
case TSDB_BINARY_OP_REMAINDER:
|
case OP_TYPE_MOD:
|
||||||
return vectorRemainder;
|
return vectorRemainder;
|
||||||
case TSDB_BINARY_OP_CONCAT:
|
|
||||||
return vectorConcat;
|
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
#include "nodes.h"
|
||||||
|
#include "tscalar.h"
|
||||||
|
|
||||||
|
EDealRes sclCalculateConstants(SNode** pNode, void* pContext) {
|
||||||
|
if (QUERY_NODE_VALUE == nodeType(*pNode)) {
|
||||||
|
return DEAL_RES_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QUERY_NODE_OPERATOR != nodeType(*pNode)) {
|
||||||
|
sclError("invalid node type for calculating constants, type:%d", );
|
||||||
|
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorNode *oper = (SOperatorNode *)*pNode;
|
||||||
|
if (NULL == oper->pLeft || NULL == oper->pRight) {
|
||||||
|
sclError("invalid operation node, left:%p, right:%p", oper->pLeft, oper->pRight);
|
||||||
|
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (QUERY_NODE_VALUE != nodeType(oper->pLeft) || QUERY_NODE_VALUE != nodeType(oper->pRight)) {
|
||||||
|
sclError("invalid operation node, leftType:%d, rightType:%d", nodeType(oper->pLeft), nodeType(oper->pRight));
|
||||||
|
*(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SValueNode *res = nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
if (NULL == res) {
|
||||||
|
sclError("make value node failed");
|
||||||
|
*(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
|
return DEAL_RES_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
res->node.resType = oper->node.resType;
|
||||||
|
|
||||||
|
SValueNode *leftValue = (SValueNode *)oper->pLeft;
|
||||||
|
SValueNode *rightValue = (SValueNode *)oper->pRight;
|
||||||
|
|
||||||
|
SScalarFuncParam leftParam = {0}, rightParam = {0};
|
||||||
|
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(oper->opType);
|
||||||
|
setScalarFuncParam(&leftParam, leftValue->node.resType, 0, nodesGetValueFromNode(leftValue), 1);
|
||||||
|
setScalarFuncParam(&rightParam, rightValue->node.resType, 0, nodesGetValueFromNode(rightValue), 1);
|
||||||
|
|
||||||
|
OperatorFn(&leftParam, &rightParam, nodesGetValueFromNode(res), TSDB_ORDER_ASC);
|
||||||
|
|
||||||
|
nodesDestroyNode(*pNode);
|
||||||
|
*pNode = (SNode*)res;
|
||||||
|
|
||||||
|
return DEAL_RES_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
|
||||||
|
if (NULL == pNode) {
|
||||||
|
SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
nodesRewriteNodePostOrder(&pNode, sclCalculateConstants, (void *)&code);
|
||||||
|
|
||||||
|
if (code) {
|
||||||
|
nodesDestroyNode(pNode);
|
||||||
|
SCL_ERR_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
*pRes = pNode;
|
||||||
|
|
||||||
|
SCL_RET(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -273,6 +273,7 @@ bool isStringOp(int32_t op) {
|
||||||
return op == TSDB_BINARY_OP_CONCAT;
|
return op == TSDB_BINARY_OP_CONCAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,
|
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,
|
||||||
char* (*getSourceDataBlock)(void*, const char*, int32_t)) {
|
char* (*getSourceDataBlock)(void*, const char*, int32_t)) {
|
||||||
if (pExprs == NULL) {
|
if (pExprs == NULL) {
|
||||||
|
@ -361,6 +362,8 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
SScalarFunctionInfo scalarFunc[8] = {
|
SScalarFunctionInfo scalarFunc[8] = {
|
||||||
{"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil},
|
{"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil},
|
||||||
|
|
|
@ -152,6 +152,36 @@ void nodesDestroyList(SNodeList* pList) {
|
||||||
tfree(pList);
|
tfree(pList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *nodesGetValueFromNode(SValueNode *pNode) {
|
||||||
|
switch (pNode->node.resType.type) {
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
return (void *)&pNode->datum.b;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
return (void *)&pNode->datum.i;
|
||||||
|
case TSDB_DATA_TYPE_UTINYINT:
|
||||||
|
case TSDB_DATA_TYPE_USMALLINT:
|
||||||
|
case TSDB_DATA_TYPE_UINT:
|
||||||
|
case TSDB_DATA_TYPE_UBIGINT:
|
||||||
|
return (void *)&pNode->datum.u;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
return (void *)&pNode->datum.d;
|
||||||
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
|
return (void *)pNode->datum.p;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -209,4 +239,4 @@ bool nodesIsTimeorderQuery(const SNode* pQuery) {
|
||||||
|
|
||||||
bool nodesIsTimelineQuery(const SNode* pQuery) {
|
bool nodesIsTimelineQuery(const SNode* pQuery) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue