Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ceb2aa72
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ceb2aa72
编写于
6月 21, 2021
作者:
H
Haojun Liao
提交者:
GitHub
6月 21, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6510 from taosdata/origin/feature/TD-3086
[TD-3085] tags support timestamp
上级
1ecdcf8e
d3702a7d
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
913 addition
and
718 deletion
+913
-718
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+108
-49
src/common/src/texpr.c
src/common/src/texpr.c
+8
-1
src/common/src/tvariant.c
src/common/src/tvariant.c
+4
-0
src/inc/ttokendef.h
src/inc/ttokendef.h
+23
-23
src/query/inc/sql.y
src/query/inc/sql.y
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+3
-1
src/query/src/qFilterfunc.c
src/query/src/qFilterfunc.c
+11
-3
src/query/src/sql.c
src/query/src/sql.c
+640
-634
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+7
-2
tests/pytest/fulltest.sh
tests/pytest/fulltest.sh
+1
-0
tests/pytest/functions/function_operations.py
tests/pytest/functions/function_operations.py
+1
-1
tests/pytest/tag_lite/timestamp.py
tests/pytest/tag_lite/timestamp.py
+102
-0
tests/script/general/parser/create_mt.sim
tests/script/general/parser/create_mt.sim
+2
-2
tests/script/general/parser/where.sim
tests/script/general/parser/where.sim
+2
-2
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
ceb2aa72
...
...
@@ -63,7 +63,8 @@ static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int3
static
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
char
*
getAccountId
(
SSqlObj
*
pSql
);
static
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dest
,
int16_t
colType
);
static
int
convertTimestampStrToInt64
(
tVariant
*
pVar
,
int32_t
precision
);
static
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dest
,
int16_t
colType
,
uint8_t
precision
);
static
int32_t
validateParamOfRelationIn
(
tVariant
*
pVar
,
int32_t
colType
);
static
bool
has
(
SArray
*
pFieldList
,
int32_t
startIdx
,
const
char
*
name
);
...
...
@@ -149,7 +150,7 @@ int16_t getNewResColId(SSqlCmd* pCmd) {
// serialize expr in exprlist to binary
// formate "type | size | value"
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dst
,
int16_t
colType
)
{
bool
serializeExprListToVariant
(
SArray
*
pList
,
tVariant
**
dst
,
int16_t
colType
,
uint8_t
precision
)
{
bool
ret
=
false
;
if
(
!
pList
||
pList
->
size
<=
0
||
colType
<
0
)
{
return
ret
;
...
...
@@ -159,14 +160,17 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType)
int32_t
firstTokenType
=
item
->
pNode
->
token
.
type
;
int32_t
type
=
firstTokenType
;
//nchar to binary and
toTSDBType
(
type
);
if
(
type
!=
colType
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
||
colType
!=
TSDB_DATA_TYPE_NCHAR
))
{
return
false
;
}
type
=
colType
;
//nchar to binary and other xxint to bigint
toTSDBType
(
type
);
if
(
colType
!=
TSDB_DATA_TYPE_TIMESTAMP
&&
!
IS_UNSIGNED_NUMERIC_TYPE
(
colType
))
{
if
(
type
!=
colType
&&
(
type
!=
TSDB_DATA_TYPE_BINARY
||
colType
!=
TSDB_DATA_TYPE_NCHAR
))
{
return
false
;
}
}
type
=
colType
;
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
tbufEnsureCapacity
(
&
bw
,
512
);
int32_t
size
=
(
int32_t
)(
pList
->
size
);
...
...
@@ -179,16 +183,23 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType)
// check all the token type in expr list same or not
if
(
firstTokenType
!=
pSub
->
token
.
type
)
{
break
;
}
toTSDBType
(
pSub
->
token
.
type
);
tVariant
var
;
tVariantCreate
(
&
var
,
&
pSub
->
token
);
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
// ugly code, refactor later
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pSub
->
token
.
type
)
||
IS_SIGNED_NUMERIC_TYPE
(
pSub
->
token
.
type
))
{
tbufWriteUint64
(
&
bw
,
var
.
i64
);
}
else
{
tVariantDestroy
(
&
var
);
break
;
}
}
toTSDBType
(
pSub
->
token
.
type
);
tVariant
var
;
tVariantCreate
(
&
var
,
&
pSub
->
token
);
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_SMALLINT
||
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_INT
)
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
tbufWriteDouble
(
&
bw
,
var
.
dKey
);
}
else
if
(
type
==
TSDB_DATA_TYPE_BINARY
){
tbufWriteBinary
(
&
bw
,
var
.
pz
,
var
.
nLen
);
...
...
@@ -201,6 +212,16 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType)
}
tbufWriteBinary
(
&
bw
,
buf
,
twcslen
((
wchar_t
*
)
buf
)
*
TSDB_NCHAR_SIZE
);
free
(
buf
);
}
else
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
var
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
convertTimestampStrToInt64
(
&
var
,
precision
)
<
0
)
{
tVariantDestroy
(
&
var
);
break
;
}
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
else
if
(
var
.
nType
==
TSDB_DATA_TYPE_BIGINT
)
{
tbufWriteInt64
(
&
bw
,
var
.
i64
);
}
}
tVariantDestroy
(
&
var
);
...
...
@@ -286,29 +307,33 @@ static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) {
return
tscInvalidOperationMsg
(
dstBuffer
,
errMsg
,
NULL
);
}
static
int
setColumnFilterInfoForTimestamp
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tVariant
*
pVar
)
{
static
int
convertTimestampStrToInt64
(
tVariant
*
pVar
,
int32_t
precision
)
{
int64_t
time
=
0
;
const
char
*
msg
=
"invalid timestamp"
;
strdequote
(
pVar
->
pz
);
char
*
seg
=
strnchr
(
pVar
->
pz
,
'-'
,
pVar
->
nLen
,
false
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
char
*
seg
=
strnchr
(
pVar
->
pz
,
'-'
,
pVar
->
nLen
,
false
);
if
(
seg
!=
NULL
)
{
if
(
taosParseTime
(
pVar
->
pz
,
&
time
,
pVar
->
nLen
,
tinfo
.
precision
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
)
;
if
(
taosParseTime
(
pVar
->
pz
,
&
time
,
pVar
->
nLen
,
precision
,
tsDaylight
)
!=
TSDB_CODE_SUCCESS
)
{
return
-
1
;
}
}
else
{
if
(
tVariantDump
(
pVar
,
(
char
*
)
&
time
,
TSDB_DATA_TYPE_BIGINT
,
true
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
)
;
return
-
1
;
}
}
tVariantDestroy
(
pVar
);
tVariantCreateFromBinary
(
pVar
,
(
char
*
)
&
time
,
0
,
TSDB_DATA_TYPE_BIGINT
);
return
0
;
}
static
int
setColumnFilterInfoForTimestamp
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tVariant
*
pVar
)
{
const
char
*
msg
=
"invalid timestamp"
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
convertTimestampStrToInt64
(
pVar
,
tinfo
.
precision
)
<
-
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1282,7 +1307,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
const
char
*
msg1
=
"invalid number of tag columns"
;
const
char
*
msg2
=
"tag length too long"
;
const
char
*
msg3
=
"duplicated column names"
;
const
char
*
msg4
=
"timestamp not allowed in tags"
;
//
const char* msg4 = "timestamp not allowed in tags";
const
char
*
msg5
=
"invalid data type in tags"
;
const
char
*
msg6
=
"invalid tag name"
;
const
char
*
msg7
=
"invalid binary/nchar tag length"
;
...
...
@@ -1298,10 +1323,10 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
for
(
int32_t
i
=
0
;
i
<
numOfTags
;
++
i
)
{
TAOS_FIELD
*
p
=
taosArrayGet
(
pTagsList
,
i
);
if
(
p
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
return
false
;
}
//
if (p->type == TSDB_DATA_TYPE_TIMESTAMP) {
//
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
//
return false;
//
}
if
(
!
isValidDataType
(
p
->
type
))
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
...
...
@@ -1359,7 +1384,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
* tags name /column name is truncated in sql.y
*/
bool
validateOneTags
(
SSqlCmd
*
pCmd
,
TAOS_FIELD
*
pTagField
)
{
const
char
*
msg1
=
"timestamp not allowed in tags"
;
//
const char* msg1 = "timestamp not allowed in tags";
const
char
*
msg2
=
"duplicated column names"
;
const
char
*
msg3
=
"tag length too long"
;
const
char
*
msg4
=
"invalid tag name"
;
...
...
@@ -1382,10 +1407,10 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
}
// no timestamp allowable
if
(
pTagField
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
return
false
;
}
//
if (pTagField->type == TSDB_DATA_TYPE_TIMESTAMP) {
//
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
//
return false;
//
}
if
((
pTagField
->
type
<
TSDB_DATA_TYPE_BOOL
)
||
(
pTagField
->
type
>
TSDB_DATA_TYPE_UBIGINT
))
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
...
...
@@ -3337,8 +3362,8 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
// TK_GT,TK_GE,TK_EQ,TK_NE are based on the pColumn->lowerBndd
}
else
if
(
pExpr
->
tokenId
==
TK_IN
)
{
tVariant
*
pVal
;
if
(
pRight
->
tokenId
!=
TK_SET
||
!
serializeExprListToVariant
(
pRight
->
pParam
,
&
pVal
,
colType
)
||
colType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
tVariant
*
pVal
;
if
(
pRight
->
tokenId
!=
TK_SET
||
!
serializeExprListToVariant
(
pRight
->
pParam
,
&
pVal
,
colType
,
timePrecision
)
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg
);
}
if
(
validateParamOfRelationIn
(
pVal
,
colType
)
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -3349,8 +3374,7 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
pColumnFilter
->
pz
=
(
int64_t
)
calloc
(
1
,
pVal
->
nLen
+
1
);
pColumnFilter
->
len
=
pVal
->
nLen
;
pColumnFilter
->
filterstr
=
1
;
memcpy
((
char
*
)(
pColumnFilter
->
pz
),
(
char
*
)(
pVal
->
pz
),
pVal
->
nLen
);
//retVal = tVariantDump(pVal, (char *)(pColumnFilter->pz), TSDB_DATA_TYPE_BINARY, false);
memcpy
((
char
*
)(
pColumnFilter
->
pz
),
(
char
*
)(
pVal
->
pz
),
pVal
->
nLen
);
tVariantDestroy
(
pVal
);
free
(
pVal
);
...
...
@@ -3483,6 +3507,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
const
char
*
msg1
=
"non binary column not support like operator"
;
const
char
*
msg2
=
"binary column not support this operator"
;
const
char
*
msg3
=
"bool column not support this operator"
;
const
char
*
msg4
=
"primary key not support this operator"
;
SColumn
*
pColumn
=
tscColumnListInsert
(
pQueryInfo
->
colList
,
pIndex
->
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
SColumnFilterInfo
*
pColFilter
=
NULL
;
...
...
@@ -3539,6 +3564,9 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
pColumn
->
columnIndex
=
pIndex
->
columnIndex
;
pColumn
->
tableUid
=
pTableMeta
->
id
.
uid
;
if
(
pColumn
->
columnIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
&&
pExpr
->
tokenId
==
TK_IN
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
tinfo
.
precision
,
pColFilter
,
pSchema
->
type
,
pExpr
);
...
...
@@ -6808,7 +6836,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
const
int32_t
STABLE_INDEX
=
1
;
STableMetaInfo
*
pStableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
STABLE_INDEX
);
// super table name, create table by using dst
int32_t
numOfTables
=
(
int32_t
)
taosArrayGetSize
(
pCreateTable
->
childTableInfo
);
for
(
int32_t
j
=
0
;
j
<
numOfTables
;
++
j
)
{
...
...
@@ -6837,6 +6865,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
// too long tag values will return invalid sql, not be truncated automatically
SSchema
*
pTagSchema
=
tscGetTableTagSchema
(
pStableMetaInfo
->
pTableMeta
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pStableMetaInfo
->
pTableMeta
);
STagData
*
pTag
=
&
pCreateTableInfo
->
tagdata
;
SKVRowBuilder
kvRowBuilder
=
{
0
};
...
...
@@ -6886,6 +6915,15 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
else
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
ret
=
convertTimestampStrToInt64
(
&
(
pItem
->
pVar
),
tinfo
.
precision
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
}
else
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
pItem
->
pVar
.
i64
=
convertTimePrecision
(
pItem
->
pVar
.
i64
,
TSDB_TIME_PRECISION_NANO
,
tinfo
.
precision
);
}
}
ret
=
tVariantDump
(
&
(
pItem
->
pVar
),
tagVal
,
pSchema
->
type
,
true
);
...
...
@@ -6932,7 +6970,17 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
else
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_BINARY
)
{
ret
=
convertTimestampStrToInt64
(
&
(
pItem
->
pVar
),
tinfo
.
precision
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
}
else
if
(
pItem
->
pVar
.
nType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
pItem
->
pVar
.
i64
=
convertTimePrecision
(
pItem
->
pVar
.
i64
,
TSDB_TIME_PRECISION_NANO
,
tinfo
.
precision
);
}
}
ret
=
tVariantDump
(
&
(
pItem
->
pVar
),
tagVal
,
pSchema
->
type
,
true
);
...
...
@@ -8030,12 +8078,22 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
assert
(
pSqlExpr
->
pRight
==
NULL
);
if
(
pSqlExpr
->
type
==
SQL_NODE_VALUE
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
(
*
pExpr
)
->
nodeType
=
TSQL_NODE_VALUE
;
(
*
pExpr
)
->
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariantAssign
((
*
pExpr
)
->
pVal
,
&
pSqlExpr
->
value
);
return
TSDB_CODE_SUCCESS
;
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
if
(
pCols
!=
NULL
&&
taosArrayGetSize
(
pCols
)
>
0
)
{
SColIndex
*
idx
=
taosArrayGet
(
pCols
,
0
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
idx
->
colIndex
);
// convert time by precision
if
(
pSchema
!=
NULL
&&
TSDB_DATA_TYPE_TIMESTAMP
==
pSchema
->
type
&&
TSDB_DATA_TYPE_BINARY
==
(
*
pExpr
)
->
pVal
->
nType
)
{
ret
=
setColumnFilterInfoForTimestamp
(
pCmd
,
pQueryInfo
,
(
*
pExpr
)
->
pVal
);
}
}
return
ret
;
}
else
if
(
pSqlExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
// arithmetic expression on the results of aggregation functions
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
...
...
@@ -8092,21 +8150,22 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS
}
else
if
(
pSqlExpr
->
tokenId
==
TK_SET
)
{
int32_t
colType
=
-
1
;
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
if
(
pCols
!=
NULL
)
{
if
(
pCols
!=
NULL
&&
taosArrayGetSize
(
pCols
)
>
0
)
{
SColIndex
*
idx
=
taosArrayGet
(
pCols
,
0
);
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
idx
->
colIndex
);
if
(
pSchema
!=
NULL
)
{
colType
=
pSchema
->
type
;
}
}
tVariant
*
pVal
;
if
(
colType
>=
TSDB_DATA_TYPE_TINYINT
&&
colType
<=
TSDB_DATA_TYPE_BIGINT
)
{
colType
=
TSDB_DATA_TYPE_BIGINT
;
}
else
if
(
colType
==
TSDB_DATA_TYPE_FLOAT
||
colType
==
TSDB_DATA_TYPE_DOUBLE
)
{
colType
=
TSDB_DATA_TYPE_DOUBLE
;
}
if
(
serializeExprListToVariant
(
pSqlExpr
->
pParam
,
&
pVal
,
colType
)
==
false
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
if
(
serializeExprListToVariant
(
pSqlExpr
->
pParam
,
&
pVal
,
colType
,
tinfo
.
precision
)
==
false
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"not support filter expression"
);
}
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
...
...
src/common/src/texpr.c
浏览文件 @
ceb2aa72
...
...
@@ -476,7 +476,14 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) {
int
dummy
=
-
1
;
int32_t
sz
=
tbufReadInt32
(
&
br
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_SMALLINT
||
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_INT
)
{
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
int64_t
val
=
tbufReadInt64
(
&
br
);
taosHashPut
(
pObj
,
(
char
*
)
&
val
,
sizeof
(
val
),
&
dummy
,
sizeof
(
dummy
));
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
uint64_t
val
=
tbufReadUint64
(
&
br
);
taosHashPut
(
pObj
,
(
char
*
)
&
val
,
sizeof
(
val
),
&
dummy
,
sizeof
(
dummy
));
}
else
if
(
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
int64_t
val
=
tbufReadInt64
(
&
br
);
taosHashPut
(
pObj
,
(
char
*
)
&
val
,
sizeof
(
val
),
&
dummy
,
sizeof
(
dummy
));
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
...
...
src/common/src/tvariant.c
浏览文件 @
ceb2aa72
...
...
@@ -77,6 +77,10 @@ void tVariantCreate(tVariant *pVar, SStrToken *token) {
pVar
->
nLen
=
strRmquote
(
pVar
->
pz
,
token
->
n
);
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
pVar
->
i64
=
taosGetTimestamp
(
TSDB_TIME_PRECISION_NANO
);
break
;
}
default:
{
// nType == 0 means the null value
type
=
TSDB_DATA_TYPE_NULL
;
...
...
src/inc/ttokendef.h
浏览文件 @
ceb2aa72
...
...
@@ -128,29 +128,29 @@
#define TK_USING 110
#define TK_AS 111
#define TK_NULL 112
#define TK_
SELECT
113
#define TK_
UNION
114
#define TK_
ALL
115
#define TK_
DISTINCT
116
#define TK_
FROM
117
#define TK_
VARIABLE
118
#define TK_
INTERVAL
119
#define TK_
SESSION
120
#define TK_S
TATE_WINDOW
121
#define TK_
FILL
122
#define TK_
SLIDING
123
#define TK_
ORDER
124
#define TK_
BY
125
#define TK_
ASC
126
#define TK_
DESC
127
#define TK_
GROUP
128
#define TK_
HAVING
129
#define TK_
LIMIT
130
#define TK_
OFFSET
131
#define TK_
SLIMI
T 132
#define TK_S
OFFSET
133
#define TK_
WHERE
134
#define TK_
NOW
135
#define TK_
NOW
113
#define TK_
SELECT
114
#define TK_
UNION
115
#define TK_
ALL
116
#define TK_
DISTINCT
117
#define TK_
FROM
118
#define TK_
VARIABLE
119
#define TK_
INTERVAL
120
#define TK_S
ESSION
121
#define TK_
STATE_WINDOW
122
#define TK_
FILL
123
#define TK_
SLIDING
124
#define TK_
ORDER
125
#define TK_
BY
126
#define TK_
ASC
127
#define TK_
DESC
128
#define TK_
GROUP
129
#define TK_
HAVING
130
#define TK_
LIMIT
131
#define TK_
OFFSE
T 132
#define TK_S
LIMIT
133
#define TK_
SOFFSET
134
#define TK_
WHERE
135
#define TK_RESET 136
#define TK_QUERY 137
#define TK_SYNCDB 138
...
...
src/query/inc/sql.y
浏览文件 @
ceb2aa72
...
...
@@ -437,6 +437,7 @@ tagitem(A) ::= FLOAT(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= STRING(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= BOOL(X). { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= NULL(X). { X.type = 0; tVariantCreate(&A, &X); }
tagitem(A) ::= NOW(X). { X.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&A, &X);}
tagitem(A) ::= MINUS(X) INTEGER(Y).{
X.n += Y.n;
...
...
src/query/src/qExecutor.c
浏览文件 @
ceb2aa72
...
...
@@ -2891,7 +2891,9 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
doSetTagValueInParam
(
pTable
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
base
.
resType
,
pLocalExprInfo
->
base
.
resBytes
);
if
(
IS_NUMERIC_TYPE
(
pLocalExprInfo
->
base
.
resType
)
||
pLocalExprInfo
->
base
.
resType
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
IS_NUMERIC_TYPE
(
pLocalExprInfo
->
base
.
resType
)
||
pLocalExprInfo
->
base
.
resType
==
TSDB_DATA_TYPE_BOOL
||
pLocalExprInfo
->
base
.
resType
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
memcpy
(
pRuntimeEnv
->
tagVal
+
offset
,
&
pCtx
[
idx
].
tag
.
i64
,
pLocalExprInfo
->
base
.
resBytes
);
}
else
{
memcpy
(
pRuntimeEnv
->
tagVal
+
offset
,
pCtx
[
idx
].
tag
.
pz
,
pCtx
[
idx
].
tag
.
nLen
);
...
...
src/query/src/qFilterfunc.c
浏览文件 @
ceb2aa72
...
...
@@ -254,15 +254,23 @@ bool notNullOperator(SColumnFilterElem *pFilter, const char* minval, const char*
return
true
;
}
bool
inOperator
(
SColumnFilterElem
*
pFilter
,
const
char
*
minval
,
const
char
*
maxval
,
int16_t
type
)
{
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_SMALLINT
||
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_INT
)
{
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
int64_t
minv
=
-
1
,
maxv
=
-
1
;
GET_TYPED_DATA
(
minv
,
int64_t
,
type
,
minval
);
GET_TYPED_DATA
(
maxv
,
int64_t
,
type
,
maxval
);
if
(
minv
==
maxv
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pFilter
->
q
,
(
char
*
)
&
minv
,
sizeof
(
minv
));
}
return
true
;
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
return
false
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
uint64_t
minv
=
0
,
maxv
=
0
;
GET_TYPED_DATA
(
minv
,
uint64_t
,
type
,
minval
);
GET_TYPED_DATA
(
maxv
,
uint64_t
,
type
,
maxval
);
if
(
minv
==
maxv
)
{
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pFilter
->
q
,
(
char
*
)
&
minv
,
sizeof
(
minv
));
}
return
false
;
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_FLOAT
)
{
double
v
;
GET_TYPED_DATA
(
v
,
double
,
type
,
minval
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pFilter
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
...
...
src/query/src/sql.c
浏览文件 @
ceb2aa72
此差异已折叠。
点击以展开。
src/tsdb/src/tsdbRead.c
浏览文件 @
ceb2aa72
...
...
@@ -3355,11 +3355,16 @@ static bool tableFilterFp(const void* pNode, void* param) {
}
}
else
if
(
pInfo
->
optr
==
TSDB_RELATION_IN
)
{
int
type
=
pInfo
->
sch
.
type
;
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_SMALLINT
||
type
==
TSDB_DATA_TYPE_BIGINT
||
type
==
TSDB_DATA_TYPE_INT
)
{
if
(
type
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_TIMESTAMP
)
{
int64_t
v
;
GET_TYPED_DATA
(
v
,
int64_t
,
pInfo
->
sch
.
type
,
val
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pInfo
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
uint64_t
v
;
GET_TYPED_DATA
(
v
,
uint64_t
,
pInfo
->
sch
.
type
,
val
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pInfo
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
||
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
double
v
;
GET_TYPED_DATA
(
v
,
double
,
pInfo
->
sch
.
type
,
val
);
return
NULL
!=
taosHashGet
((
SHashObj
*
)
pInfo
->
q
,
(
char
*
)
&
v
,
sizeof
(
v
));
...
...
tests/pytest/fulltest.sh
浏览文件 @
ceb2aa72
...
...
@@ -73,6 +73,7 @@ python3 ./test.py -f tag_lite/int.py
python3 ./test.py
-f
tag_lite/set.py
python3 ./test.py
-f
tag_lite/smallint.py
python3 ./test.py
-f
tag_lite/tinyint.py
python3 ./test.py
-f
tag_lite/timestamp.py
#python3 ./test.py -f dbmgmt/database-name-boundary.py
python3 test.py
-f
dbmgmt/nanoSecondCheck.py
...
...
tests/pytest/functions/function_operations.py
浏览文件 @
ceb2aa72
...
...
@@ -16,7 +16,7 @@ import taos
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
import
numpy
as
np
#
import numpy as np
class
TDTestCase
:
...
...
tests/pytest/tag_lite/timestamp.py
0 → 100644
浏览文件 @
ceb2aa72
# -*- coding: utf-8 -*-
import
sys
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
run
(
self
):
tdSql
.
prepare
()
tdLog
.
info
(
'======================== dnode1 start'
)
tbPrefix
=
"ta_fl_tb"
mtPrefix
=
"ta_fl_mt"
tbNum
=
10
rowNum
=
20
totalNum
=
200
tdLog
.
info
(
'=============== step1'
)
i
=
0
mt
=
"%s%d"
%
(
mtPrefix
,
i
)
tdSql
.
execute
(
'create table %s (ts timestamp, tbcol int) TAGS(tgcol float, tgTs timestamp, tgcol2 int)'
%
(
mt
))
i
=
0
ts
=
1605045600000
tsStr
=
"2020-11-11 06:00:00"
while
(
i
<
5
):
tb
=
"%s%d"
%
(
tbPrefix
,
i
)
tdLog
.
info
(
'create table %s using %s tags(%d, %d, %d)'
%
(
tb
,
mt
,
i
,
ts
+
i
,
i
))
tdSql
.
execute
(
'create table %s using %s tags(%d, %d, %d)'
%
(
tb
,
mt
,
i
,
ts
+
i
,
i
))
x
=
0
while
(
x
<
rowNum
):
ms
=
x
*
60000
#tdLog.info(
# "insert into %s values (%d, %d)" %
# (tb, 1605045600000 + ms, x))
tdSql
.
execute
(
"insert into %s values (%d, %d)"
%
(
tb
,
1605045600000
+
ms
,
x
))
x
=
x
+
1
i
=
i
+
1
tdLog
.
info
(
'=============== step2'
)
tdSql
.
query
(
'select * from %s'
%
(
mt
))
tdSql
.
checkRows
(
5
*
rowNum
)
tdSql
.
query
(
'select * from %s where tgTs = %ld and tgcol2 = 0'
%
(
mt
,
ts
))
tdSql
.
checkRows
(
rowNum
)
tdSql
.
query
(
'select * from %s where tgTs =
\"
%s
\"
and tgcol2 = 0'
%
(
mt
,
tsStr
))
tdSql
.
checkRows
(
rowNum
)
tdLog
.
info
(
'=============== step3'
)
i
=
0
while
(
i
<
5
):
tb
=
"%s%d"
%
(
tbPrefix
,
i
+
100
)
tdLog
.
info
(
'create table %s using %s tags(%d,
\"
%s
\"
, %d)'
%
(
tb
,
mt
,
i
+
100
,
tsStr
,
i
+
100
))
tdSql
.
execute
(
'create table %s using %s tags(%d,
\"
%s
\"
, %d)'
%
(
tb
,
mt
,
i
+
100
,
tsStr
,
i
+
100
))
x
=
0
while
(
x
<
rowNum
):
ms
=
x
*
60000
#tdLog.info(
# "insert into %s values (%d, %d)" %
# (tb, 1605045600000 + ms, x))
tdSql
.
execute
(
"insert into %s values (%d, %d)"
%
(
tb
,
1605045600000
+
ms
,
x
))
x
=
x
+
1
i
=
i
+
1
tdSql
.
query
(
'select * from %s where tgTs = %ld and tgcol2 = 100'
%
(
mt
,
ts
))
tdSql
.
checkRows
(
rowNum
)
tdSql
.
query
(
'select * from %s where tgTs =
\"
%s
\"
and tgcol2 = 100'
%
(
mt
,
tsStr
))
tdSql
.
checkRows
(
rowNum
)
tdLog
.
info
(
'=============== step4'
)
i
=
0
tb
=
"%s%d"
%
(
tbPrefix
,
i
+
1000
)
tdSql
.
execute
(
'insert into %s using %s tags(%d,
\"
%s
\"
, %d) values(now, 10)'
%
(
tb
,
mt
,
i
+
100
,
tsStr
,
i
+
1000
))
tdSql
.
execute
(
'insert into %s using %s tags(%d,
\"
%s
\"
, %d) values(now+2s, 10)'
%
(
tb
,
mt
,
i
+
100
,
tsStr
,
i
+
1000
))
tdSql
.
execute
(
'insert into %s using %s tags(%d,
\"
%s
\"
, %d) values(now+3s, 10)'
%
(
tb
,
mt
,
i
+
100
,
tsStr
,
i
+
1000
))
tdSql
.
query
(
'select * from %s where tgTs =
\"
%s
\"
and tgcol2 = 1000'
%
(
mt
,
tsStr
))
tdSql
.
checkRows
(
3
)
i
=
0
tb
=
"%s%d"
%
(
tbPrefix
,
i
+
10000
)
tdSql
.
execute
(
'create table %s using %s tags(%d, now, %d)'
%
(
tb
,
mt
,
i
+
10000
,
i
+
10000
))
tdSql
.
checkRows
(
3
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/script/general/parser/create_mt.sim
浏览文件 @
ceb2aa72
...
...
@@ -99,7 +99,7 @@ $i_binary2 = varchar(20) # illegal string
$i_bool = boolean
$nchar = nchar # nchar with unspecified length
print ========== create_mt.sim case4: illegal data types in tags test
sql_error create table $mt (ts timestamp, col int) tags (tag1 timestamp )
##
sql_error create table $mt (ts timestamp, col int) tags (tag1 timestamp )
sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_ts )
sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_binary )
sql_error create table $mt (ts timestamp, col int) tags (tag1 $i_bigint )
...
...
@@ -253,4 +253,4 @@ if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/general/parser/where.sim
浏览文件 @
ceb2aa72
...
...
@@ -155,8 +155,8 @@ sql_error select last(*) from wh_mt1_tb1 where c6 in ('1')
#sql_error select last(*) from wh_mt1_tb1 where c7 in ('binary')
#sql_error select last(*) from wh_mt1 where c8 in ('nchar')
#sql_error select last(*) from wh_mt1_tb1 where c9 in (true, false)
sql_error select last(*) from wh_mt1 where c10 in ('2019-01-01 00:00:00.000')
sql_error select last(*) from wh_mt1_tb1 where c10 in ('2019-01-01 00:00:00.000')
#
sql_error select last(*) from wh_mt1 where c10 in ('2019-01-01 00:00:00.000')
#
sql_error select last(*) from wh_mt1_tb1 where c10 in ('2019-01-01 00:00:00.000')
sql select last(*) from wh_mt1 where c1 = 1
if $rows != 1 then
return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录