Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
57dae9fc
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
57dae9fc
编写于
7月 04, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: increase the tag value overflow check when creating table
上级
ac34cde0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
143 addition
and
106 deletion
+143
-106
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+143
-106
未找到文件。
source/libs/parser/src/parTranslater.c
浏览文件 @
57dae9fc
...
...
@@ -784,127 +784,163 @@ static int32_t parseBoolFromValueNode(STranslateContext* pCxt, SValueNode* pVal)
}
}
static
EDealRes
translateValueImpl
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
SDataType
targetDt
)
{
uint8_t
precision
=
getPrecisionFromCurrStmt
(
pCxt
->
pCurrStmt
,
targetDt
.
precision
);
pVal
->
node
.
resType
.
precision
=
precision
;
if
(
pVal
->
placeholderNo
>
0
||
pVal
->
isNull
)
{
return
DEAL_RES_CONTINUE
;
static
EDealRes
translateDurationValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
if
(
parseNatualDuration
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
&
pVal
->
datum
.
i
,
&
pVal
->
unit
,
pVal
->
node
.
resType
.
precision
)
!=
TSDB_CODE_SUCCESS
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
if
(
TSDB_DATA_TYPE_NULL
==
pVal
->
node
.
resType
.
type
)
{
// TODO
// pVal->node.resType = targetDt;
pVal
->
translate
=
true
;
pVal
->
isNull
=
true
;
return
DEAL_RES_CONTINUE
;
}
if
(
pVal
->
isDuration
)
{
if
(
parseNatualDuration
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
&
pVal
->
datum
.
i
,
&
pVal
->
unit
,
precision
)
!=
TSDB_CODE_SUCCESS
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
}
else
{
switch
(
targetDt
.
type
)
{
case
TSDB_DATA_TYPE_NULL
:
break
;
case
TSDB_DATA_TYPE_BOOL
:
if
(
TSDB_CODE_SUCCESS
!=
parseBoolFromValueNode
(
pCxt
,
pVal
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
bool
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
b
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
{
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
translateNormalValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
SDataType
targetDt
,
bool
strict
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
targetDt
.
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
if
(
TSDB_CODE_SUCCESS
!=
parseBoolFromValueNode
(
pCxt
,
pVal
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
*
(
bool
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
b
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
{
code
=
toInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
i
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_TINYINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_INT
:
{
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
*
(
int8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
code
=
toInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
i
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_SMALLINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_BIGINT
:
{
pVal
->
datum
.
i
=
taosStr2Int64
(
pVal
->
literal
,
NULL
,
10
);
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
*
(
int16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
code
=
toInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
i
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_INT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
*
(
int32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
code
=
toInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
i
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_BIGINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
code
=
toUInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
u
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_UTINYINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_UINT
:
{
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
*
(
uint8_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
code
=
toUInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
u
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_USMALLINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
pVal
->
datum
.
u
=
taosStr2UInt64
(
pVal
->
literal
,
NULL
,
10
);
*
(
uint64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
*
(
uint16_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
code
=
toUInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
u
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_UINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_FLOAT
:
{
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
float
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
*
(
uint32_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
code
=
toUInteger
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
10
,
&
pVal
->
datum
.
u
);
if
(
strict
&&
(
TSDB_CODE_SUCCESS
!=
code
||
!
IS_VALID_UBIGINT
(
pVal
->
datum
.
i
)))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
double
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
*
(
uint64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
u
;
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
float
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
pVal
->
datum
.
d
=
taosStr2Double
(
pVal
->
literal
,
NULL
);
*
(
double
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
d
;
break
;
}
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
}
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
}
int32_t
len
=
TMIN
(
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
pVal
->
node
.
resType
.
bytes
);
varDataSetLen
(
pVal
->
datum
.
p
,
len
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
pVal
->
literal
,
len
);
break
;
int32_t
len
=
TMIN
(
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
pVal
->
node
.
resType
.
bytes
);
varDataSetLen
(
pVal
->
datum
.
p
,
len
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
pVal
->
literal
,
len
);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
TSDB_CODE_SUCCESS
!=
parseTimeFromValueNode
(
pCxt
,
pVal
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
TSDB_CODE_SUCCESS
!=
parseTimeFromValueNode
(
pCxt
,
pVal
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
*
(
int64_t
*
)
&
pVal
->
typeData
=
pVal
->
datum
.
i
;
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
}
case
TSDB_DATA_TYPE_NCHAR
:
{
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
}
int32_t
len
=
0
;
if
(
!
taosMbsToUcs4
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
&
len
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
varDataSetLen
(
pVal
->
datum
.
p
,
len
);
break
;
}
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
int32_t
len
=
0
;
if
(
!
taosMbsToUcs4
(
pVal
->
literal
,
strlen
(
pVal
->
literal
),
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
,
&
len
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
default:
break
;
}
varDataSetLen
(
pVal
->
datum
.
p
,
len
);
break
;
}
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
default:
break
;
}
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
translateValueImpl
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
,
SDataType
targetDt
,
bool
strict
)
{
if
(
pVal
->
placeholderNo
>
0
||
pVal
->
isNull
)
{
return
DEAL_RES_CONTINUE
;
}
if
(
TSDB_DATA_TYPE_NULL
==
pVal
->
node
.
resType
.
type
)
{
// TODO
// pVal->node.resType = targetDt;
pVal
->
translate
=
true
;
pVal
->
isNull
=
true
;
return
DEAL_RES_CONTINUE
;
}
pVal
->
node
.
resType
.
precision
=
getPrecisionFromCurrStmt
(
pCxt
->
pCurrStmt
,
targetDt
.
precision
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
if
(
pVal
->
isDuration
)
{
res
=
translateDurationValue
(
pCxt
,
pVal
);
}
else
{
res
=
translateNormalValue
(
pCxt
,
pVal
,
targetDt
,
strict
);
}
pVal
->
node
.
resType
=
targetDt
;
pVal
->
translate
=
true
;
return
DEAL_RES_CONTINUE
;
return
res
;
}
static
int32_t
calcTypeBytes
(
SDataType
dt
)
{
...
...
@@ -920,7 +956,7 @@ static int32_t calcTypeBytes(SDataType dt) {
static
EDealRes
translateValue
(
STranslateContext
*
pCxt
,
SValueNode
*
pVal
)
{
SDataType
dt
=
pVal
->
node
.
resType
;
dt
.
bytes
=
calcTypeBytes
(
dt
);
return
translateValueImpl
(
pCxt
,
pVal
,
dt
);
return
translateValueImpl
(
pCxt
,
pVal
,
dt
,
false
);
}
static
bool
isMultiResFunc
(
SNode
*
pNode
)
{
...
...
@@ -4305,7 +4341,8 @@ static void getSourceDatabase(SNode* pStmt, int32_t acctId, char* pDbFName) {
static
int32_t
addWstartTsToCreateStreamQuery
(
SNode
*
pStmt
)
{
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pStmt
;
SNode
*
pProj
=
nodesListGetNode
(
pSelect
->
pProjectionList
,
0
);
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pProj
)
&&
0
==
strcmp
(
"_wstartts"
,
((
SFunctionNode
*
)
pProj
)
->
functionName
))
{
if
(
NULL
==
pSelect
->
pWindow
||
(
QUERY_NODE_FUNCTION
==
nodeType
(
pProj
)
&&
0
==
strcmp
(
"_wstartts"
,
((
SFunctionNode
*
)
pProj
)
->
functionName
)))
{
return
TSDB_CODE_SUCCESS
;
}
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
...
...
@@ -5400,7 +5437,7 @@ static int32_t createTagValFromVal(STranslateContext* pCxt, SDataType targetDt,
if
(
NULL
==
*
pVal
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
return
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
*
pVal
,
targetDt
)
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
;
return
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
*
pVal
,
targetDt
,
true
)
?
pCxt
->
errCode
:
TSDB_CODE_SUCCESS
;
}
static
int32_t
createTagVal
(
STranslateContext
*
pCxt
,
uint8_t
precision
,
SSchema
*
pSchema
,
SNode
*
pNode
,
...
...
@@ -5784,7 +5821,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
}
SDataType
targetDt
=
schemaToDataType
(
pTableMeta
->
tableInfo
.
precision
,
pSchema
);
if
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
pStmt
->
pVal
,
targetDt
))
{
if
(
DEAL_RES_ERROR
==
translateValueImpl
(
pCxt
,
pStmt
->
pVal
,
targetDt
,
true
))
{
return
pCxt
->
errCode
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录