Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
103418bf
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
103418bf
编写于
4月 25, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some problems of udf and 'create table'
上级
14e9fa35
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
166 addition
and
152 deletion
+166
-152
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-2
source/client/src/clientMain.c
source/client/src/clientMain.c
+1
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+6
-5
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+150
-143
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+4
-1
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+4
-0
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
103418bf
...
@@ -46,7 +46,7 @@ typedef struct SExprNode {
...
@@ -46,7 +46,7 @@ typedef struct SExprNode {
ENodeType
type
;
ENodeType
type
;
SDataType
resType
;
SDataType
resType
;
char
aliasName
[
TSDB_COL_NAME_LEN
];
char
aliasName
[
TSDB_COL_NAME_LEN
];
S
NodeList
*
pAssociationList
;
S
Array
*
pAssociation
;
}
SExprNode
;
}
SExprNode
;
typedef
enum
EColumnType
{
typedef
enum
EColumnType
{
...
@@ -81,7 +81,6 @@ typedef struct SValueNode {
...
@@ -81,7 +81,6 @@ typedef struct SValueNode {
char
*
literal
;
char
*
literal
;
bool
isDuration
;
bool
isDuration
;
bool
translate
;
bool
translate
;
bool
genByCalc
;
int16_t
placeholderNo
;
int16_t
placeholderNo
;
union
{
union
{
bool
b
;
bool
b
;
...
...
source/client/src/clientMain.c
浏览文件 @
103418bf
...
@@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
...
@@ -120,7 +120,7 @@ const char *taos_errstr(TAOS_RES *res) {
return
(
const
char
*
)
tstrerror
(
terrno
);
return
(
const
char
*
)
tstrerror
(
terrno
);
}
}
if
(
strlen
(
pRequest
->
msgBuf
)
>
0
||
pRequest
->
code
==
TSDB_CODE_RPC_FQDN_ERROR
)
{
if
(
NULL
!=
pRequest
->
msgBuf
&&
(
strlen
(
pRequest
->
msgBuf
)
>
0
||
pRequest
->
code
==
TSDB_CODE_RPC_FQDN_ERROR
)
)
{
return
pRequest
->
msgBuf
;
return
pRequest
->
msgBuf
;
}
else
{
}
else
{
return
(
const
char
*
)
tstrerror
(
pRequest
->
code
);
return
(
const
char
*
)
tstrerror
(
pRequest
->
code
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
103418bf
...
@@ -1663,7 +1663,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
...
@@ -1663,7 +1663,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
return
code
;
return
code
;
}
}
static
const
char
*
jkValue
GenByCalc
=
"GenByCalc
"
;
static
const
char
*
jkValue
LiteralSize
=
"LiteralSize
"
;
static
const
char
*
jkValueLiteral
=
"Literal"
;
static
const
char
*
jkValueLiteral
=
"Literal"
;
static
const
char
*
jkValueDuration
=
"Duration"
;
static
const
char
*
jkValueDuration
=
"Duration"
;
static
const
char
*
jkValueTranslate
=
"Translate"
;
static
const
char
*
jkValueTranslate
=
"Translate"
;
...
@@ -1717,9 +1717,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
...
@@ -1717,9 +1717,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
int32_t
code
=
exprNodeToJson
(
pObj
,
pJson
);
int32_t
code
=
exprNodeToJson
(
pObj
,
pJson
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAdd
BoolToObject
(
pJson
,
jkValueGenByCalc
,
pNode
->
genByCalc
);
code
=
tjsonAdd
IntegerToObject
(
pJson
,
jkValueLiteralSize
,
NULL
!=
pNode
->
literal
?
strlen
(
pNode
->
literal
)
:
0
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
!
pNode
->
genByCalc
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pNode
->
literal
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkValueLiteral
,
pNode
->
literal
);
code
=
tjsonAddStringToObject
(
pJson
,
jkValueLiteral
,
pNode
->
literal
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
@@ -1789,10 +1789,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
...
@@ -1789,10 +1789,11 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
SValueNode
*
pNode
=
(
SValueNode
*
)
pObj
;
SValueNode
*
pNode
=
(
SValueNode
*
)
pObj
;
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
int32_t
literalSize
=
0
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGet
BoolValue
(
pJson
,
jkValueGenByCalc
,
&
pNode
->
genByCalc
);
code
=
tjsonGet
IntValue
(
pJson
,
jkValueLiteralSize
,
&
literalSize
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
!
pNode
->
genByCalc
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
literalSize
>
0
)
{
code
=
tjsonDupStringValue
(
pJson
,
jkValueLiteral
,
&
pNode
->
literal
);
code
=
tjsonDupStringValue
(
pJson
,
jkValueLiteral
,
&
pNode
->
literal
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
103418bf
...
@@ -24,109 +24,37 @@ typedef struct SCalcConstContext {
...
@@ -24,109 +24,37 @@ typedef struct SCalcConstContext {
int32_t
code
;
int32_t
code
;
}
SCalcConstContext
;
}
SCalcConstContext
;
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
);
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
,
bool
subquery
);
static
EDealRes
doCalcConst
(
SNode
**
pNode
,
SCalcConstContext
*
pCxt
)
{
static
int32_t
calcConstSubquery
(
SCalcConstContext
*
pCxt
,
STempTableNode
*
pTempTable
)
{
SNode
*
pNew
=
NULL
;
return
calcConstQuery
(
pCxt
,
pTempTable
->
pSubquery
,
true
);
pCxt
->
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
code
)
{
return
DEAL_RES_ERROR
;
}
((
SValueNode
*
)
pNew
)
->
genByCalc
=
true
;
((
SValueNode
*
)
pNew
)
->
translate
=
true
;
*
pNode
=
pNew
;
return
DEAL_RES_CONTINUE
;
}
static
bool
isTimestampCol
(
SNode
*
pNode
)
{
if
(
NULL
==
pNode
)
{
return
false
;
}
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
&&
TSDB_DATA_TYPE_TIMESTAMP
==
((
SExprNode
*
)
pNode
)
->
resType
.
type
);
}
static
EDealRes
stringToTimestamp
(
SCalcConstContext
*
pCxt
,
uint8_t
precision
,
SValueNode
*
pVal
)
{
switch
(
pVal
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
int64_t
val
=
0
;
if
(
TSDB_CODE_SUCCESS
!=
convertStringToTimestamp
(
pVal
->
node
.
resType
.
type
,
pVal
->
datum
.
p
,
precision
,
&
val
))
{
pCxt
->
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INCORRECT_TIMESTAMP_VAL
,
varDataVal
(
pVal
->
datum
.
p
));
return
DEAL_RES_ERROR
;
}
pVal
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
pVal
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_TIMESTAMP
].
bytes
;
taosMemoryFreeClear
(
pVal
->
datum
.
p
);
pVal
->
datum
.
i
=
val
;
break
;
}
default:
break
;
}
return
DEAL_RES_CONTINUE
;
}
}
static
EDealRes
calcConstOperator
(
SOperatorNode
**
pNode
,
void
*
pContext
)
{
static
int32_t
calcConstNode
(
SNode
**
pNode
)
{
SCalcConstContext
*
pCxt
=
pContext
;
if
(
NULL
==
*
pNode
)
{
SOperatorNode
*
pOp
=
*
pNode
;
return
TSDB_CODE_SUCCESS
;
if
(
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pLeft
)
&&
(
NULL
==
pOp
->
pRight
||
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pRight
)))
{
return
doCalcConst
((
SNode
**
)
pNode
,
pCxt
);
}
if
(
isTimestampCol
(
pOp
->
pLeft
)
&&
(
NULL
==
pOp
->
pRight
||
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pRight
)))
{
return
stringToTimestamp
(
pCxt
,
((
SColumnNode
*
)
pOp
->
pLeft
)
->
node
.
resType
.
precision
,
(
SValueNode
*
)
pOp
->
pRight
);
}
else
if
(
isTimestampCol
(
pOp
->
pRight
)
&&
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pLeft
))
{
return
stringToTimestamp
(
pCxt
,
((
SColumnNode
*
)
pOp
->
pRight
)
->
node
.
resType
.
precision
,
(
SValueNode
*
)
pOp
->
pLeft
);
}
}
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
calcConstFunction
(
SFunctionNode
**
pNode
,
void
*
pContext
)
{
SNode
*
pNew
=
NULL
;
SFunctionNode
*
pFunc
=
*
pNode
;
int32_t
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
if
(
!
fmIsScalarFunc
(
pFunc
->
funcId
)
||
fmIsUserDefinedFunc
(
pFunc
->
funcId
))
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
return
DEAL_RES_CONTINUE
;
*
pNode
=
pNew
;
}
SNode
*
pParam
=
NULL
;
FOREACH
(
pParam
,
pFunc
->
pParameterList
)
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParam
))
{
return
DEAL_RES_CONTINUE
;
}
}
}
return
doCalcConst
((
SNode
**
)
pNode
,
(
SCalcConstContext
*
)
pContext
)
;
return
code
;
}
}
static
EDealRes
calcConstLogicCond
(
SLogicConditionNode
**
pNode
,
void
*
pContext
)
{
static
int32_t
calcConstList
(
SNodeList
*
pList
)
{
SLogicConditionNode
*
pCond
=
*
pNode
;
SNode
*
pNode
=
NULL
;
SNode
*
pParam
=
NULL
;
FOREACH
(
pNode
,
pList
)
{
FOREACH
(
pParam
,
pCond
->
pParameterList
)
{
SNode
*
pNew
=
NULL
;
// todo calc "true and c1 > 10"
int32_t
code
=
scalarCalculateConstants
(
pNode
,
&
pNew
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParam
))
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
return
DEAL_RES_CONTINUE
;
REPLACE_NODE
(
pNew
);
}
else
{
return
code
;
}
}
}
}
return
doCalcConst
((
SNode
**
)
pNode
,
(
SCalcConstContext
*
)
pContext
);
return
TSDB_CODE_SUCCESS
;
}
static
EDealRes
calcConstSubquery
(
STempTableNode
**
pNode
,
void
*
pContext
)
{
SCalcConstContext
*
pCxt
=
pContext
;
pCxt
->
code
=
calcConstQuery
(
pCxt
,
(
*
pNode
)
->
pSubquery
);
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
);
}
static
EDealRes
calcConst
(
SNode
**
pNode
,
void
*
pContext
)
{
switch
(
nodeType
(
*
pNode
))
{
case
QUERY_NODE_OPERATOR
:
return
calcConstOperator
((
SOperatorNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_FUNCTION
:
return
calcConstFunction
((
SFunctionNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_LOGIC_CONDITION
:
return
calcConstLogicCond
((
SLogicConditionNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_TEMP_TABLE
:
return
calcConstSubquery
((
STempTableNode
**
)
pNode
,
pContext
);
default:
break
;
}
return
DEAL_RES_CONTINUE
;
}
}
static
bool
isCondition
(
const
SNode
*
pNode
)
{
static
bool
isCondition
(
const
SNode
*
pNode
)
{
...
@@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) {
...
@@ -174,18 +102,41 @@ static int32_t rewriteCondition(SCalcConstContext* pCxt, SNode** pNode) {
return
pCxt
->
code
;
return
pCxt
->
code
;
}
}
static
int32_t
calcConstCondition
(
SCalcConstContext
*
pCxt
,
SNode
**
pNode
)
{
int32_t
code
=
rewriteCondition
(
pCxt
,
pNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstNode
(
pNode
);
}
return
code
;
}
static
int32_t
rewriteConditionForFromTable
(
SCalcConstContext
*
pCxt
,
SNode
*
pTable
)
{
static
int32_t
rewriteConditionForFromTable
(
SCalcConstContext
*
pCxt
,
SNode
*
pTable
)
{
if
(
QUERY_NODE_JOIN_TABLE
==
nodeType
(
pTable
))
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SJoinTableNode
*
pJoin
=
(
SJoinTableNode
*
)
pTable
;
switch
(
nodeType
(
pTable
))
{
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pJoin
->
pLeft
);
case
QUERY_NODE_TEMP_TABLE
:
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
code
=
calcConstSubquery
(
pCxt
,
(
STempTableNode
*
)
pTable
);
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pJoin
->
pRight
);
break
;
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
&&
NULL
!=
pJoin
->
pOnCond
)
{
pCxt
->
code
=
rewriteCondition
(
pCxt
,
&
pJoin
->
pOnCond
);
}
}
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoin
=
(
SJoinTableNode
*
)
pTable
;
code
=
rewriteConditionForFromTable
(
pCxt
,
pJoin
->
pLeft
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteConditionForFromTable
(
pCxt
,
pJoin
->
pRight
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pJoin
->
pOnCond
)
{
code
=
calcConstCondition
(
pCxt
,
&
pJoin
->
pOnCond
);
}
// todo empty table
break
;
}
default:
break
;
}
}
return
pCxt
->
code
;
return
code
;
}
static
int32_t
calcConstFromTable
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
return
rewriteConditionForFromTable
(
pCxt
,
pSelect
->
pFromTable
);
}
}
static
void
rewriteConstCondition
(
SSelectStmt
*
pSelect
,
SNode
**
pCond
)
{
static
void
rewriteConstCondition
(
SSelectStmt
*
pSelect
,
SNode
**
pCond
)
{
...
@@ -200,77 +151,133 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
...
@@ -200,77 +151,133 @@ static void rewriteConstCondition(SSelectStmt* pSelect, SNode** pCond) {
}
}
}
}
static
int32_t
calcConstFromTable
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
static
int32_t
calcConstSelectCondition
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
**
pCond
)
{
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pSelect
->
pFromTable
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pFromTable
,
calcConst
,
pCxt
);
}
return
pCxt
->
code
;
}
static
int32_t
calcConstCondition
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
**
pCond
)
{
if
(
NULL
==
*
pCond
)
{
if
(
NULL
==
*
pCond
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
pCxt
->
code
=
rewriteCondition
(
pCxt
,
pCond
);
int32_t
code
=
rewriteCondition
(
pCxt
,
pCond
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
nodesRewriteExprPostOrder
(
pCond
,
calcConst
,
pCxt
);
code
=
calcConstNode
(
pCond
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
rewriteConstCondition
(
pSelect
,
pCond
);
rewriteConstCondition
(
pSelect
,
pCond
);
}
}
return
pCxt
->
code
;
return
code
;
}
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
static
int32_t
calcConstProject
(
SNode
*
pProject
,
SNode
**
pNew
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pProjectionList
,
calcConst
,
pCxt
);
SArray
*
pAssociation
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
NULL
!=
((
SExprNode
*
)
pProject
)
->
pAssociation
)
{
pCxt
->
code
=
calcConstFromTable
(
pCxt
,
pSelect
);
pAssociation
==
taosArrayDup
(((
SExprNode
*
)
pProject
)
->
pAssociation
);
if
(
NULL
==
pAssociation
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
pCxt
->
code
=
calcConstCondition
(
pCxt
,
pSelect
,
&
pSelect
->
pWhere
);
int32_t
code
=
scalarCalculateConstants
(
pProject
,
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
QUERY_NODE_VALUE
==
nodeType
(
pNew
)
&&
NULL
!=
pAssociation
)
{
int32_t
size
=
taosArrayGetSize
(
pAssociation
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SNode
**
pCol
=
taosArrayGet
(
pAssociation
,
i
);
*
pCol
=
nodesCloneNode
(
pNew
);
if
(
NULL
==
*
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
return
code
;
nodesRewriteExprsPostOrder
(
pSelect
->
pPartitionByList
,
calcConst
,
pCxt
);
}
static
int32_t
calcConstProjections
(
SCalcConstContext
*
pCxt
,
SNodeList
*
pProjections
,
bool
subquery
)
{
SNode
*
pProj
=
NULL
;
WHERE_EACH
(
pProj
,
pProjections
)
{
if
(
subquery
&&
NULL
==
((
SExprNode
*
)
pProj
)
->
pAssociation
)
{
ERASE_NODE
(
pProjections
);
continue
;
}
SNode
*
pNew
=
NULL
;
int32_t
code
=
calcConstProject
(
pProj
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
REPLACE_NODE
(
pNew
);
}
else
{
return
code
;
}
WHERE_NEXT
;
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
return
TSDB_CODE_SUCCESS
;
nodesRewriteExprPostOrder
(
&
pSelect
->
pWindow
,
calcConst
,
pCxt
);
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
int32_t
code
=
calcConstProjections
(
pCxt
,
pSelect
->
pProjectionList
,
subquery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstFromTable
(
pCxt
,
pSelect
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pGroupByList
,
calcConst
,
pCxt
);
code
=
calcConstSelectCondition
(
pCxt
,
pSelect
,
&
pSelect
->
pWhere
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pCxt
->
code
=
calcConstCondition
(
pCxt
,
pSelect
,
&
pSelect
->
pHaving
);
code
=
calcConstList
(
pSelect
->
pPartitionByList
);
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pOrderByList
,
calcConst
,
pCxt
);
code
=
calcConstNode
(
&
pSelect
->
pWindow
);
}
}
return
pCxt
->
code
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstList
(
pSelect
->
pGroupByList
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstSelectCondition
(
pCxt
,
pSelect
,
&
pSelect
->
pHaving
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstList
(
pSelect
->
pOrderByList
);
}
return
code
;
}
}
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
)
{
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
,
bool
subquery
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pStmt
))
{
switch
(
nodeType
(
pStmt
))
{
case
QUERY_NODE_SELECT_STMT
:
case
QUERY_NODE_SELECT_STMT
:
return
calcConstSelect
(
pCxt
,
(
SSelectStmt
*
)
pStmt
);
code
=
calcConstSelect
(
pCxt
,
(
SSelectStmt
*
)
pStmt
,
subquery
);
break
;
case
QUERY_NODE_EXPLAIN_STMT
:
case
QUERY_NODE_EXPLAIN_STMT
:
return
calcConstQuery
(
pCxt
,
((
SExplainStmt
*
)
pStmt
)
->
pQuery
);
code
=
calcConstQuery
(
pCxt
,
((
SExplainStmt
*
)
pStmt
)
->
pQuery
,
subquery
);
break
;
case
QUERY_NODE_SET_OPERATOR
:
{
SSetOperator
*
pSetOp
=
(
SSetOperator
*
)
pStmt
;
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pLeft
,
subquery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstQuery
(
pCxt
,
pSetOp
->
pRight
,
subquery
);
}
break
;
}
default:
default:
break
;
break
;
}
}
return
TSDB_CODE_SUCCESS
;
return
code
;
}
}
static
bool
isEmptyResultQuery
(
SNode
*
pStmt
)
{
static
bool
isEmptyResultQuery
(
SNode
*
pStmt
)
{
bool
isEmptyResult
=
false
;
switch
(
nodeType
(
pStmt
))
{
switch
(
nodeType
(
pStmt
))
{
case
QUERY_NODE_SELECT_STMT
:
case
QUERY_NODE_SELECT_STMT
:
return
((
SSelectStmt
*
)
pStmt
)
->
isEmptyResult
;
isEmptyResult
=
((
SSelectStmt
*
)
pStmt
)
->
isEmptyResult
;
break
;
case
QUERY_NODE_EXPLAIN_STMT
:
case
QUERY_NODE_EXPLAIN_STMT
:
return
isEmptyResultQuery
(((
SExplainStmt
*
)
pStmt
)
->
pQuery
);
isEmptyResult
=
isEmptyResultQuery
(((
SExplainStmt
*
)
pStmt
)
->
pQuery
);
break
;
case
QUERY_NODE_SET_OPERATOR
:
{
SSetOperator
*
pSetOp
=
(
SSetOperator
*
)
pStmt
;
isEmptyResult
=
isEmptyResultQuery
(
pSetOp
->
pLeft
);
if
(
isEmptyResult
)
{
isEmptyResult
=
isEmptyResultQuery
(
pSetOp
->
pRight
);
}
break
;
}
default:
default:
break
;
break
;
}
}
return
false
;
return
isEmptyResult
;
}
}
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
...
@@ -280,9 +287,9 @@ int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
...
@@ -280,9 +287,9 @@ int32_t calculateConstant(SParseContext* pParseCxt, SQuery* pQuery) {
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
code
=
TSDB_CODE_SUCCESS
.
code
=
TSDB_CODE_SUCCESS
};
};
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
);
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
,
false
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
isEmptyResultQuery
(
pQuery
->
pRoot
)
)
{
pQuery
->
execMode
=
isEmptyResultQuery
(
pQuery
->
pRoot
)
?
QUERY_EXEC_MODE_EMPTY_RESULT
:
pQuery
->
execMode
;
pQuery
->
execMode
=
QUERY_EXEC_MODE_EMPTY_RESULT
;
}
}
return
code
;
return
code
;
}
}
source/libs/parser/src/parTranslater.c
浏览文件 @
103418bf
...
@@ -306,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
...
@@ -306,7 +306,10 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
static
void
setColumnInfoByExpr
(
const
STableNode
*
pTable
,
SExprNode
*
pExpr
,
SColumnNode
*
pCol
)
{
static
void
setColumnInfoByExpr
(
const
STableNode
*
pTable
,
SExprNode
*
pExpr
,
SColumnNode
*
pCol
)
{
pCol
->
pProjectRef
=
(
SNode
*
)
pExpr
;
pCol
->
pProjectRef
=
(
SNode
*
)
pExpr
;
nodesListAppend
(
pExpr
->
pAssociationList
,
(
SNode
*
)
pCol
);
if
(
NULL
==
pExpr
->
pAssociation
)
{
pExpr
->
pAssociation
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
);
}
taosArrayPush
(
pExpr
->
pAssociation
,
&
pCol
);
if
(
NULL
!=
pTable
)
{
if
(
NULL
!=
pTable
)
{
strcpy
(
pCol
->
tableAlias
,
pTable
->
tableAlias
);
strcpy
(
pCol
->
tableAlias
,
pTable
->
tableAlias
);
}
else
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
}
else
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
103418bf
...
@@ -511,6 +511,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
...
@@ -511,6 +511,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) {
return
DEAL_RES_ERROR
;
return
DEAL_RES_ERROR
;
}
}
res
->
translate
=
true
;
if
(
colDataIsNull_s
(
output
.
columnData
,
0
))
{
if
(
colDataIsNull_s
(
output
.
columnData
,
0
))
{
res
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
res
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
}
else
{
}
else
{
...
@@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
...
@@ -553,6 +555,7 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) {
}
}
res
->
node
.
resType
=
node
->
node
.
resType
;
res
->
node
.
resType
=
node
->
node
.
resType
;
res
->
translate
=
true
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
if
(
IS_VAR_DATA_TYPE
(
type
))
{
...
@@ -595,6 +598,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
...
@@ -595,6 +598,7 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
}
}
res
->
node
.
resType
=
node
->
node
.
resType
;
res
->
node
.
resType
=
node
->
node
.
resType
;
res
->
translate
=
true
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
// todo refactor
if
(
IS_VAR_DATA_TYPE
(
type
))
{
// todo refactor
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录