Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f0df0da9
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看板
提交
f0df0da9
编写于
5月 14, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some problems of parser and planner
上级
e0a51d43
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
54 addition
and
17 deletion
+54
-17
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+48
-15
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+5
-1
source/libs/planner/test/planSubqueryTest.cpp
source/libs/planner/test/planSubqueryTest.cpp
+1
-1
未找到文件。
source/libs/parser/src/parTranslater.c
浏览文件 @
f0df0da9
...
...
@@ -480,8 +480,8 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
return
res
;
}
static
EDealRes
translateValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
uint8_t
precision
=
(
NULL
!=
pCxt
->
pCurrStmt
?
pCxt
->
pCurrStmt
->
precision
:
pVal
->
node
.
resType
.
precision
);
static
EDealRes
translateValue
Impl
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
SDataType
targetDt
)
{
uint8_t
precision
=
(
NULL
!=
pCxt
->
pCurrStmt
?
pCxt
->
pCurrStmt
->
precision
:
targetDt
.
precision
);
pVal
->
node
.
resType
.
precision
=
precision
;
if
(
pVal
->
placeholderNo
>
0
)
{
return
DEAL_RES_CONTINUE
;
...
...
@@ -493,7 +493,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
}
else
{
switch
(
pVal
->
node
.
resType
.
type
)
{
switch
(
targetDt
.
type
)
{
case
TSDB_DATA_TYPE_NULL
:
break
;
case
TSDB_DATA_TYPE_BOOL
:
...
...
@@ -562,27 +562,41 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
}
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
pVal
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
}
varDataSetLen
(
pVal
->
datum
.
p
,
pVal
->
node
.
resType
.
bytes
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
pVal
->
literal
,
pVal
->
node
.
resType
.
bytes
);
varDataSetLen
(
pVal
->
datum
.
p
,
targetDt
.
bytes
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
pVal
->
literal
,
targetDt
.
bytes
);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
taosParseTime
(
pVal
->
literal
,
&
pVal
->
datum
.
i
,
pVal
->
node
.
resType
.
bytes
,
precision
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
taosParseTime
(
pVal
->
literal
,
&
pVal
->
datum
.
i
,
targetDt
.
bytes
,
precision
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_NCHAR
:
{
targetDt
.
bytes
*=
TSDB_NCHAR_SIZE
;
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
;
}
int32_t
output
=
0
;
if
(
!
taosMbsToUcs4
(
pVal
->
literal
,
pVal
->
node
.
resType
.
bytes
,
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
targetDt
.
bytes
,
&
output
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
varDataSetLen
(
pVal
->
datum
.
p
,
output
);
break
;
}
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
// todo
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
default:
break
;
}
...
...
@@ -591,6 +605,10 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
translateValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
return
translateValueImpl
(
pCxt
,
pVal
,
pVal
->
node
.
resType
);
}
static
EDealRes
translateOperator
(
STranslateContext
*
pCxt
,
SOperatorNode
*
pOp
)
{
if
(
nodesIsUnaryOp
(
pOp
))
{
if
(
OP_TYPE_MINUS
==
pOp
->
opType
)
{
...
...
@@ -636,6 +654,9 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
((
SExprNode
*
)
pOp
->
pRight
)
->
resType
=
((
SExprNode
*
)
pOp
->
pLeft
)
->
resType
;
}
if
(
nodesIsRegularOp
(
pOp
))
{
if
(
!
IS_STR_DATA_TYPE
(((
SExprNode
*
)(
pOp
->
pLeft
))
->
resType
.
type
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pLeft
))
->
aliasName
);
}
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
)
||
!
IS_STR_DATA_TYPE
(((
SExprNode
*
)(
pOp
->
pRight
))
->
resType
.
type
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pRight
))
->
aliasName
);
}
...
...
@@ -3847,7 +3868,7 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
if
(
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_NULL
)
{
// todo
}
else
{
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
nodesGetValueFromNode
(
pVal
->
datum
.
p
),
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
nodesGetValueFromNode
(
pVal
),
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
?
varDataTLen
(
pVal
->
datum
.
p
)
:
TYPE_BYTES
[
pSchema
->
type
]);
}
...
...
@@ -3861,11 +3882,23 @@ static int32_t createValueFromFunction(STranslateContext* pCxt, SFunctionNode* p
return
scalarCalculateConstants
((
SNode
*
)
pFunc
,
(
SNode
**
)
pVal
);
}
static
int32_t
translateTagVal
(
STranslateContext
*
pCxt
,
SNode
*
pNode
,
SValueNode
**
pVal
)
{
static
SDataType
schemaToDataType
(
SSchema
*
pSchema
)
{
SDataType
dt
=
{.
type
=
pSchema
->
type
,
.
bytes
=
pSchema
->
bytes
,
.
precision
=
0
,
.
scale
=
0
};
if
(
TSDB_DATA_TYPE_VARCHAR
==
dt
.
type
||
TSDB_DATA_TYPE_BINARY
==
dt
.
type
||
TSDB_DATA_TYPE_VARBINARY
==
dt
.
type
)
{
dt
.
bytes
-=
VARSTR_HEADER_SIZE
;
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
dt
.
type
)
{
dt
.
bytes
=
(
dt
.
bytes
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
;
}
return
dt
;
}
static
int32_t
translateTagVal
(
STranslateContext
*
pCxt
,
SSchema
*
pSchema
,
SNode
*
pNode
,
SValueNode
**
pVal
)
{
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
))
{
return
createValueFromFunction
(
pCxt
,
(
SFunctionNode
*
)
pNode
,
pVal
);
}
else
if
(
QUERY_NODE_VALUE
==
nodeType
(
pNode
))
{
return
(
DEAL_RES_ERROR
==
translateValue
(
pCxt
,
(
SValueNode
*
)
pNode
)
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
);
return
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
(
SValueNode
*
)
pNode
,
schemaToDataType
(
pSchema
))
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
);
}
else
{
return
TSDB_CODE_FAILED
;
}
...
...
@@ -3894,7 +3927,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
}
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
p
Schema
,
p
Node
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
...
...
@@ -3924,7 +3957,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
int32_t
index
=
0
;
FOREACH
(
pNode
,
pStmt
->
pValsOfTags
)
{
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
p
TagSchema
+
index
,
p
Node
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
f0df0da9
...
...
@@ -723,7 +723,10 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
if
(
TSDB_SUPER_TABLE
!=
((
SScanLogicNode
*
)
pNode
)
->
pMeta
->
tableType
)
{
return
nodesListMakeAppend
(
pScanNodes
,
pNode
);
}
break
;
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
code
=
opkGetScanNodesImpl
(
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -739,6 +742,7 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL
if
(
1
!=
LIST_LENGTH
(
pNode
->
pChildren
))
{
*
pNotOptimize
=
true
;
return
TSDB_CODE_SUCCESS
;
}
return
opkGetScanNodesImpl
(
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
...
...
source/libs/planner/test/planSubqueryTest.cpp
浏览文件 @
f0df0da9
...
...
@@ -25,7 +25,7 @@ TEST_F(PlanSubqeuryTest, basic) {
run
(
"SELECT * FROM (SELECT * FROM t1)"
);
run
(
"SELECT LAST(c1) FROM ( SELECT * FROM t1)"
);
//
run("SELECT LAST(c1) FROM ( SELECT * FROM t1)");
}
TEST_F
(
PlanSubqeuryTest
,
doubleGroupBy
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录