Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
ba9ef137
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看板
提交
ba9ef137
编写于
8月 24, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-1151] add test cases and fix the found bugs.
上级
e4e4c7fc
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
372 addition
and
85 deletion
+372
-85
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+3
-2
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+13
-8
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+41
-47
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-4
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+2
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+5
-4
src/common/inc/tname.h
src/common/inc/tname.h
+2
-1
src/common/src/tname.c
src/common/src/tname.c
+11
-6
src/inc/taosdef.h
src/inc/taosdef.h
+1
-1
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-1
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+9
-8
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+1
-1
tests/script/general/parser/bug.sim
tests/script/general/parser/bug.sim
+274
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
ba9ef137
...
...
@@ -198,7 +198,7 @@ int32_t tscValidateName(SSQLToken* pToken);
void
tscIncStreamExecutionCount
(
void
*
pStream
);
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
);
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
,
int32_t
numOfParams
);
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pCond
,
uint64_t
uid
);
...
...
src/client/inc/tsclient.h
浏览文件 @
ba9ef137
...
...
@@ -195,9 +195,9 @@ typedef struct STableDataBlocks {
typedef
struct
SQueryInfo
{
int16_t
command
;
// the command may be different for each subclause, so keep it seperately.
uint32_t
type
;
// query/insert
/import
type
uint32_t
type
;
// query/insert type
char
slidingTimeUnit
;
STimeWindow
window
;
STimeWindow
window
;
// query time window
int64_t
intervalTime
;
// aggregation time interval
int64_t
slidingTime
;
// sliding window in mseconds
SSqlGroupbyExpr
groupbyExpr
;
// group by tags info
...
...
@@ -216,6 +216,7 @@ typedef struct SQueryInfo {
char
*
msg
;
// pointer to the pCmd->payload to keep error message temporarily
int64_t
clauseLimit
;
// limit for current sub clause
int64_t
prjOffset
;
// offset value in the original sql expression, only applied at client side
int32_t
udColumnId
;
// current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
}
SQueryInfo
;
typedef
struct
{
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
ba9ef137
...
...
@@ -2902,12 +2902,12 @@ static FORCE_INLINE void date_col_output_function_f(SQLFunctionCtx *pCtx, int32_
}
static
void
col_project_function
(
SQLFunctionCtx
*
pCtx
)
{
if
(
pCtx
->
numOfParams
==
1
)
{
// the number of output rows should not affect the final number of rows, so set it to be 1
INC_INIT_VAL
(
pCtx
,
1
);
if
(
pCtx
->
numOfParams
==
2
)
{
// the number of output rows should not affect the final number of rows, so set it to be 0
SET_VAL
(
pCtx
,
pCtx
->
size
,
1
);
char
*
output
=
pCtx
->
aOutputBuf
;
for
(
int32_t
i
=
0
;
i
<
pCtx
->
size
;
++
i
)
{
tVariantDump
(
&
pCtx
->
param
[
0
],
output
,
pCtx
->
outputType
,
true
);
tVariantDump
(
&
pCtx
->
param
[
1
],
output
,
pCtx
->
outputType
,
true
);
output
+=
pCtx
->
outputBytes
;
}
...
...
@@ -2936,11 +2936,16 @@ static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
if
(
pCtx
->
param
[
0
].
i64Key
==
1
&&
pResInfo
->
numOfRes
>=
1
)
{
return
;
}
INC_INIT_VAL
(
pCtx
,
1
);
char
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
if
(
pCtx
->
numOfParams
==
2
)
{
// the number of output rows should not affect the final number of rows, so set it to be 0
SET_VAL
(
pCtx
,
pCtx
->
size
,
1
);
tVariantDump
(
&
pCtx
->
param
[
1
],
pCtx
->
aOutputBuf
,
pCtx
->
outputType
,
true
);
}
else
{
INC_INIT_VAL
(
pCtx
,
1
);
char
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
memcpy
(
pCtx
->
aOutputBuf
,
pData
,
pCtx
->
inputBytes
);
}
pCtx
->
aOutputBuf
+=
pCtx
->
inputBytes
;
}
...
...
src/client/src/tscSQLParser.c
浏览文件 @
ba9ef137
...
...
@@ -1094,18 +1094,6 @@ int32_t setObjFullName(char* fullName, const char* account, SSQLToken* pDB, SSQL
return
(
totalLen
<
TSDB_TABLE_FNAME_LEN
)
?
TSDB_CODE_SUCCESS
:
TSDB_CODE_TSC_INVALID_SQL
;
}
static
void
extractColumnNameFromString
(
tSQLExprItem
*
pItem
)
{
if
(
pItem
->
pNode
->
nSQLOptr
==
TK_STRING
)
{
pItem
->
pNode
->
val
.
nLen
=
strdequote
(
pItem
->
pNode
->
val
.
pz
);
pItem
->
pNode
->
nSQLOptr
=
TK_ID
;
SSQLToken
*
pIdToken
=
&
pItem
->
pNode
->
colInfo
;
pIdToken
->
type
=
TK_ID
;
pIdToken
->
z
=
pItem
->
pNode
->
val
.
pz
;
pIdToken
->
n
=
pItem
->
pNode
->
val
.
nLen
;
}
}
static
int32_t
handleArithmeticExpr
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
int32_t
exprIndex
,
tSQLExprItem
*
pItem
)
{
const
char
*
msg1
=
"invalid column name, or illegal column type"
;
const
char
*
msg2
=
"invalid arithmetic expression in select clause"
;
...
...
@@ -1234,6 +1222,11 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
return
TSDB_CODE_SUCCESS
;
}
static
void
tscInsertPrimaryTSSourceColumn
(
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
)
{
SColumnIndex
tsCol
=
{.
tableIndex
=
pIndex
->
tableIndex
,
.
columnIndex
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
tscColumnListInsert
(
pQueryInfo
->
colList
,
&
tsCol
);
}
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
tSQLExprList
*
pSelection
,
bool
isSTable
)
{
assert
(
pSelection
!=
NULL
&&
pCmd
!=
NULL
);
...
...
@@ -1254,15 +1247,12 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
// project on all fields
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
if
(
optr
==
TK_ALL
||
optr
==
TK_ID
||
optr
==
TK_STRING
||
(
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
)
{
if
(
optr
==
TK_ALL
||
optr
==
TK_ID
||
optr
==
TK_STRING
||
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
{
// it is actually a function, but the function name is invalid
if
(
pItem
->
pNode
->
nSQLOptr
==
TK_ID
&&
(
pItem
->
pNode
->
colInfo
.
z
==
NULL
&&
pItem
->
pNode
->
colInfo
.
n
==
0
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
// if the name of column is quoted, remove it and set the right information for later process
extractColumnNameFromString
(
pItem
);
// select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2
if
(
addProjectionExprAndResultField
(
pCmd
,
pQueryInfo
,
pItem
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
@@ -1292,6 +1282,13 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
}
}
// there is only one user-defined column in the final result field, add the timestamp column.
size_t
numOfSrcCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
if
(
numOfSrcCols
<=
0
&&
!
tscQueryTags
(
pQueryInfo
))
{
SColumnIndex
index
=
{
0
};
tscInsertPrimaryTSSourceColumn
(
pQueryInfo
,
&
index
);
}
if
(
!
functionCompatibleCheck
(
pQueryInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -1431,17 +1428,11 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
return
numOfTotalColumns
;
}
static
void
tscInsertPrimaryTSSourceColumn
(
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
)
{
SColumnIndex
tsCol
=
{.
tableIndex
=
pIndex
->
tableIndex
,
.
columnIndex
=
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
tscColumnListInsert
(
pQueryInfo
->
colList
,
&
tsCol
);
}
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSQLExprItem
*
pItem
)
{
const
char
*
msg0
=
"invalid column name"
;
const
char
*
msg1
=
"tag for normal table query is not allowed"
;
int32_t
startPos
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
int32_t
startPos
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
if
(
optr
==
TK_ALL
)
{
// project on all fields
...
...
@@ -1465,40 +1456,43 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
// add the primary timestamp column even though it is not required by user
tscInsertPrimaryTSSourceColumn
(
pQueryInfo
,
&
index
);
}
else
if
(
optr
==
TK_
ID
||
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
{
// simple column projection query
}
else
if
(
optr
==
TK_
STRING
||
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
{
// simple column projection query
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
// user-specified constant value as a new result column
if
((
optr
==
TK_INTEGER
||
optr
==
TK_FLOAT
)
||
(
getColumnIndexByName
(
pCmd
,
&
pItem
->
pNode
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
))
{
index
.
columnIndex
=
TSDB_UD_COLUMN_INDEX
;
index
.
tableIndex
=
0
;
index
.
columnIndex
=
(
pQueryInfo
->
udColumnId
--
);
index
.
tableIndex
=
0
;
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
pItem
->
pNode
->
val
.
pz
,
pItem
->
pNode
->
val
.
nType
,
pItem
->
aliasName
);
SSqlExpr
*
pExpr
=
tscAddSpecialColumnForSelect
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
);
pExpr
->
numOfParams
=
1
;
tVariantAssign
(
&
pExpr
->
param
[
0
],
&
pItem
->
pNode
->
val
);
SSchema
colSchema
=
tGetUserSpecifiedColumnSchema
(
&
pItem
->
pNode
->
val
,
pItem
->
aliasName
);
SSqlExpr
*
pExpr
=
tscAddSpecialColumnForSelect
(
pQueryInfo
,
startPos
,
TSDB_FUNC_PRJ
,
&
index
,
&
colSchema
,
TSDB_COL_UDC
);
}
else
{
// columns from the queried table
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
);
// NOTE: the first parameter is reserved for the tag column id during join query process.
pExpr
->
numOfParams
=
2
;
tVariantAssign
(
&
pExpr
->
param
[
1
],
&
pItem
->
pNode
->
val
);
}
else
if
(
optr
==
TK_ID
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
SSchema
colSchema
=
tGetTableNameColumnSchema
();
tscAddSpecialColumnForSelect
(
pQueryInfo
,
startPos
,
TSDB_FUNC_TAGPRJ
,
&
index
,
&
colSchema
,
TSDB_COL_TAG
);
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
getColumnIndexByName
(
pCmd
,
&
pItem
->
pNode
->
colInfo
,
pQueryInfo
,
&
index
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg0
);
}
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMeta
)
&&
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
SSchema
colSchema
=
tGetTableNameColumnSchema
();
tscAddSpecialColumnForSelect
(
pQueryInfo
,
startPos
,
TSDB_FUNC_TAGPRJ
,
&
index
,
&
colSchema
,
TSDB_COL_TAG
);
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
index
.
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
addProjectQueryCol
(
pQueryInfo
,
startPos
,
&
index
,
pItem
);
if
(
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMeta
)
&&
UTIL_TABLE_IS_NORMAL_TABLE
(
pTableMetaInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
// add the primary timestamp column even though it is not required by user
tscInsertPrimaryTSSourceColumn
(
pQueryInfo
,
&
index
);
addProjectQueryCol
(
pQueryInfo
,
startPos
,
&
index
,
pItem
);
}
// add the primary timestamp column even though it is not required by user
tscInsertPrimaryTSSourceColumn
(
pQueryInfo
,
&
index
);
}
else
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -2069,7 +2063,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
// todo refactor
static
SColumnList
getColumnList
(
int32_t
num
,
int16_t
tableIndex
,
int32_t
columnIndex
)
{
assert
(
num
==
1
&&
columnIndex
>=
-
2
&&
tableIndex
>=
0
);
assert
(
num
==
1
&&
tableIndex
>=
0
);
SColumnList
columnList
=
{
0
};
columnList
.
num
=
num
;
...
...
@@ -4706,7 +4700,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
}
}
if
(
pExpr
->
functionId
==
TSDB_FUNC_PRJ
||
pExpr
->
functionId
==
TSDB_FUNC_DIFF
||
if
(
(
pExpr
->
functionId
==
TSDB_FUNC_PRJ
&&
pExpr
->
numOfParams
==
0
)
||
pExpr
->
functionId
==
TSDB_FUNC_DIFF
||
pExpr
->
functionId
==
TSDB_FUNC_ARITHM
)
{
isProjectionFunction
=
true
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
ba9ef137
...
...
@@ -628,9 +628,12 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
taosArrayGetSize
(
pQueryInfo
->
colList
)
<=
0
&&
!
tscQueryTags
(
pQueryInfo
))
{
tscError
(
"%p illegal value of numOfCols in query msg: %d"
,
pSql
,
tscGetNumOfColumns
(
pTableMeta
));
size_t
numOfSrcCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
if
(
numOfSrcCols
<=
0
&&
!
tscQueryTags
(
pQueryInfo
))
{
tscError
(
"%p illegal value of numOfCols in query msg: %"
PRIu64
", table cols:%d"
,
pSql
,
numOfSrcCols
,
tscGetNumOfColumns
(
pTableMeta
));
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -728,7 +731,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
for
(
int32_t
i
=
0
;
i
<
tscSqlExprNumOfExprs
(
pQueryInfo
);
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
!
tscValidateColumnId
(
pTableMetaInfo
,
pExpr
->
colInfo
.
colId
))
{
if
(
!
tscValidateColumnId
(
pTableMetaInfo
,
pExpr
->
colInfo
.
colId
,
pExpr
->
numOfParams
))
{
/* column id is not valid according to the cached table meta, the table meta is expired */
tscError
(
"%p table schema is not matched with parsed sql"
,
pSql
);
return
TSDB_CODE_TSC_INVALID_SQL
;
...
...
src/client/src/tscSubquery.c
浏览文件 @
ba9ef137
...
...
@@ -353,11 +353,12 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
}
// set the join condition tag column info, to
do extract method
// set the join condition tag column info, todo extract method
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
assert
(
pQueryInfo
->
tagCond
.
joinInfo
.
hasJoin
);
int16_t
colId
=
tscGetJoinTagColIdByUid
(
&
pQueryInfo
->
tagCond
,
pTableMetaInfo
->
pTableMeta
->
id
.
uid
);
// set the tag column id for executor to extract correct tag value
pExpr
->
param
[
0
].
i64Key
=
colId
;
pExpr
->
numOfParams
=
1
;
}
...
...
src/client/src/tscUtil.c
浏览文件 @
ba9ef137
...
...
@@ -937,8 +937,8 @@ static SSqlExpr* doBuildSqlExpr(SQueryInfo* pQueryInfo, int16_t functionId, SCol
// set the correct columnIndex index
if
(
pColIndex
->
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
pExpr
->
colInfo
.
colId
=
TSDB_TBNAME_COLUMN_INDEX
;
}
else
if
(
pColIndex
->
columnIndex
=
=
TSDB_UD_COLUMN_INDEX
)
{
pExpr
->
colInfo
.
colId
=
TSDB_UD_COLUMN_INDEX
;
}
else
if
(
pColIndex
->
columnIndex
<
=
TSDB_UD_COLUMN_INDEX
)
{
pExpr
->
colInfo
.
colId
=
pColIndex
->
columnIndex
;
}
else
{
if
(
TSDB_COL_IS_TAG
(
colType
))
{
SSchema
*
pSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
...
...
@@ -1290,12 +1290,12 @@ void tscIncStreamExecutionCount(void* pStream) {
ps
->
num
+=
1
;
}
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
)
{
bool
tscValidateColumnId
(
STableMetaInfo
*
pTableMetaInfo
,
int32_t
colId
,
int32_t
numOfParams
)
{
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
)
{
return
false
;
}
if
(
colId
==
TSDB_TBNAME_COLUMN_INDEX
||
colId
==
TSDB_UD_COLUMN_INDEX
)
{
if
(
colId
==
TSDB_TBNAME_COLUMN_INDEX
||
(
colId
<=
TSDB_UD_COLUMN_INDEX
&&
numOfParams
==
2
)
)
{
return
true
;
}
...
...
@@ -1511,6 +1511,7 @@ void tscInitQueryInfo(SQueryInfo* pQueryInfo) {
assert
(
pQueryInfo
->
exprList
==
NULL
);
pQueryInfo
->
exprList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pQueryInfo
->
colList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
pQueryInfo
->
udColumnId
=
TSDB_UD_COLUMN_INDEX
;
}
int32_t
tscAddSubqueryInfo
(
SSqlCmd
*
pCmd
)
{
...
...
src/common/inc/tname.h
浏览文件 @
ba9ef137
...
...
@@ -4,6 +4,7 @@
#include "os.h"
#include "taosmsg.h"
#include "tstoken.h"
#include "tvariant.h"
typedef
struct
SDataStatis
{
int16_t
colId
;
...
...
@@ -28,7 +29,7 @@ void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
SSchema
tGetTableNameColumnSchema
();
SSchema
tGetUserSpecifiedColumnSchema
(
const
char
*
v
,
int16_t
type
,
const
char
*
name
);
SSchema
tGetUserSpecifiedColumnSchema
(
tVariant
*
pVal
,
const
char
*
name
);
bool
tscValidateTableNameLength
(
size_t
len
);
...
...
src/common/src/tname.c
浏览文件 @
ba9ef137
...
...
@@ -4,6 +4,7 @@
#include "tname.h"
#include "tstoken.h"
#include "ttokendef.h"
#include "tvariant.h"
// todo refactor
UNUSED_FUNC
static
FORCE_INLINE
const
char
*
skipSegments
(
const
char
*
input
,
char
delim
,
int32_t
num
)
{
...
...
@@ -47,19 +48,23 @@ SSchema tGetTableNameColumnSchema() {
return
s
;
}
SSchema
tGetUserSpecifiedColumnSchema
(
const
char
*
v
,
int16_t
type
,
const
char
*
name
)
{
SSchema
tGetUserSpecifiedColumnSchema
(
tVariant
*
pVal
,
const
char
*
name
)
{
SSchema
s
=
{
0
};
s
.
type
=
t
ype
;
s
.
type
=
pVal
->
nT
ype
;
if
(
s
.
type
==
TSDB_DATA_TYPE_BINARY
||
s
.
type
==
TSDB_DATA_TYPE_NCHAR
)
{
size_t
len
=
strlen
(
v
);
s
.
bytes
=
len
+
VARSTR_HEADER_SIZE
;
s
.
bytes
=
pVal
->
nLen
+
VARSTR_HEADER_SIZE
;
}
else
{
s
.
bytes
=
tDataTypeDesc
[
t
ype
].
nSize
;
s
.
bytes
=
tDataTypeDesc
[
pVal
->
nT
ype
].
nSize
;
}
s
.
colId
=
TSDB_UD_COLUMN_INDEX
;
tstrncpy
(
s
.
name
,
name
,
sizeof
(
s
.
name
));
if
(
name
!=
NULL
)
{
tstrncpy
(
s
.
name
,
name
,
sizeof
(
s
.
name
));
}
else
{
tVariantToString
(
pVal
,
s
.
name
);
strdequote
(
s
.
name
);
}
return
s
;
}
...
...
src/inc/taosdef.h
浏览文件 @
ba9ef137
...
...
@@ -287,7 +287,7 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_MAX_REPLICA 5
#define TSDB_TBNAME_COLUMN_INDEX (-1)
#define TSDB_UD_COLUMN_INDEX
(-2
)
#define TSDB_UD_COLUMN_INDEX
(-100
)
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
#define TSDB_MIN_CACHE_BLOCK_SIZE 1
...
...
src/inc/taosmsg.h
浏览文件 @
ba9ef137
...
...
@@ -169,7 +169,7 @@ enum _mgmt_table {
#define TSDB_COL_NORMAL 0x0u // the normal column of the table
#define TSDB_COL_TAG 0x1u // the tag column type
#define TSDB_COL_UDC 0x2u // the user specified normal string column, it is a dummy column
#define TSDB_COL_UDC
0x2u // the user specified normal string column, it is a dummy column
extern
char
*
taosMsg
[];
...
...
src/query/inc/qSqlparser.h
浏览文件 @
ba9ef137
...
...
@@ -210,6 +210,7 @@ typedef struct tSQLExprItem {
char
*
aliasName
;
// alias name, null-terminated string
}
tSQLExprItem
;
// todo refactor by using SArray
typedef
struct
tSQLExprList
{
int32_t
nExpr
;
/* Number of expressions on the list */
int32_t
nAlloc
;
/* Number of entries allocated below */
...
...
src/query/src/qExecutor.c
浏览文件 @
ba9ef137
...
...
@@ -168,7 +168,7 @@ static void buildTagQueryResult(SQInfo *pQInfo);
static
int32_t
setAdditionalInfo
(
SQInfo
*
pQInfo
,
void
*
pTable
,
STableQueryInfo
*
pTableQueryInfo
);
static
int32_t
flushFromResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
);
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfFilterCols
;
++
k
)
{
SSingleColumnFilterInfo
*
pFilterInfo
=
&
pQuery
->
pFilterInfo
[
k
];
...
...
@@ -899,7 +899,7 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
}
assert
(
dataBlock
!=
NULL
);
sas
->
data
[
i
]
=
dataBlock
/* + pQuery->colList[i].bytes*/
;
// start from the offset
sas
->
data
[
i
]
=
dataBlock
;
// start from the offset
}
}
else
{
// other type of query function
...
...
@@ -1583,7 +1583,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
int16_t
type
=
pSqlFuncMsg
->
arg
[
j
].
argType
;
int16_t
bytes
=
pSqlFuncMsg
->
arg
[
j
].
argBytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
tVariantCreateFromBinary
(
&
pCtx
->
param
[
j
],
pSqlFuncMsg
->
arg
->
argValue
.
pz
,
bytes
,
type
);
tVariantCreateFromBinary
(
&
pCtx
->
param
[
j
],
pSqlFuncMsg
->
arg
[
j
].
argValue
.
pz
,
bytes
,
type
);
}
else
{
tVariantCreateFromBinary
(
&
pCtx
->
param
[
j
],
(
char
*
)
&
pSqlFuncMsg
->
arg
[
j
].
argValue
.
i64
,
bytes
,
type
);
}
...
...
@@ -5728,11 +5728,12 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo *
SSchema
s
=
tGetTableNameColumnSchema
();
type
=
s
.
type
;
bytes
=
s
.
bytes
;
}
else
if
(
pExprs
[
i
].
base
.
colInfo
.
colId
==
TSDB_UD_COLUMN_INDEX
)
{
}
else
if
(
pExprs
[
i
].
base
.
colInfo
.
colId
<=
TSDB_UD_COLUMN_INDEX
)
{
// it is a user-defined constant value column
assert
(
pExprs
[
i
].
base
.
functionId
==
TSDB_FUNC_PRJ
);
type
=
pExprs
[
i
].
base
.
arg
[
0
].
argType
;
bytes
=
pExprs
[
i
].
base
.
arg
[
0
].
argBytes
;
type
=
pExprs
[
i
].
base
.
arg
[
1
].
argType
;
bytes
=
pExprs
[
i
].
base
.
arg
[
1
].
argBytes
;
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
bytes
+=
VARSTR_HEADER_SIZE
;
...
...
@@ -5927,8 +5928,8 @@ static void doUpdateExprColumnIndex(SQuery *pQuery) {
}
assert
(
f
<
pQuery
->
numOfCols
);
}
else
if
(
pColIndex
->
colId
=
=
TSDB_UD_COLUMN_INDEX
)
{
// do nothing
}
else
if
(
pColIndex
->
colId
<
=
TSDB_UD_COLUMN_INDEX
)
{
// do nothing
for user-defined constant value result columns
}
else
{
int32_t
f
=
0
;
for
(
f
=
0
;
f
<
pQuery
->
numOfTags
;
++
f
)
{
...
...
src/query/src/qParserImpl.c
浏览文件 @
ba9ef137
...
...
@@ -78,7 +78,7 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken
pList
=
calloc
(
1
,
sizeof
(
tSQLExprList
));
}
if
(
pList
->
nAlloc
<=
pList
->
nExpr
)
{
//
if
(
pList
->
nAlloc
<=
pList
->
nExpr
)
{
pList
->
nAlloc
=
(
pList
->
nAlloc
<<
1
)
+
4
;
pList
->
a
=
realloc
(
pList
->
a
,
pList
->
nAlloc
*
sizeof
(
pList
->
a
[
0
]));
if
(
pList
->
a
==
0
)
{
...
...
tests/script/general/parser/bug.sim
浏览文件 @
ba9ef137
...
...
@@ -40,4 +40,278 @@ sql select st1.ts, st1.f1, st2.f2 from db.st1, db.st2 where st1.t1=st2.t2 and st
system_content curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select st1.ts, st1.f1, st2.f2 from db.st1, db.st2 where st1.t1=st2.t2 and st1.ts=st2.ts' 127.0.0.1:7111/restful/sql
print ==============select with user-defined columns
sql select 'abc' as f, ts,f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != @abc@ then
return -1
endi
if $data01 != @19-12-09 16:27:35.000@ then
return -1
endi
if $data02 != 1 then
return -1
endi
sql select 'abc', ts, f1 from t1
if $rows != 1 then
return -1
endi
if $data01 != @19-12-09 16:27:35.000@ then
return -1
endi
if $data02 != 1 then
return -1
endi
sql select 'abc' from t1
if $rows != 1 then
return -1
endi
if $data00 != @abc@ then
return -1
endi
sql select 'abc' as f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != @abc@ then
return -1
endi
sql select 1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
sql select 1 as f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
sql select 1 as f, f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
sql select 1.123 as f, f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1.123000000 then
print expect 1.123000000 , actual:$data00
return -1
endi
sql select 1, f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
sql select 1.2391, f1 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1.239100000 then
print expect 1.239100000 actual: $data00
return -1
endi
if $data01 != 1 then
return -1
endi
print ===================== user-defined columns with agg functions
sql select 1 as t, count(*) from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
sql select 1, sum(f1) from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 1 then
return -1
endi
sql select 1,2,3, sum(f1)*99, 4,5,6,7,8,9,10 from t1
if $rows != 1 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data02 != 3 then
return -1
endi
if $data03 != 99.000000000 then
print expect 99.000000000, actual:$data03
return -1
endi
sql select sum(f1)*avg(f1)+12, 1,2,3,4,5,6,7,8,9,10 from t1
if $rows != 1 then
return -1
endi
if $data00 != 13.000000000 then
print expect 13.000000000 actual:$data00
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != 2 then
return -1
endi
sql select 1.2987, f1, 'k' from t1 where f1=1
if $rows != 1 then
return -1
endi
if $data00 != 1.298700000 then
print expect 1.298700000 actual:$data00
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != @k@ then
return -1
endi
print ====================user-defined columns with union
sql select f1, 'f1' from t1 union all select f1, 'f1' from t1;
if $rows != 2 then
return -1
endi
if $data00 != 1 then
return -1
endi
if $data01 != @f1@ then
return -1
endi
if $data10 != 1 then
return -1
endi
if $data11 != @f1@ then
return -1
endi
print =====================udc with join
sql select st1.ts, st1.f1, st2.f2, 'abc', 1.9827 from db.st1, db.st2 where st1.t1=st2.t2 and st1.ts=st2.ts
if $rows != 1 then
return -1
endi
if $data00 != @19-12-09 16:27:35.000@ then
print expect @19-12-09 16:27:35.000@ actual:$data00
return -1
endi
if $data01 != 1 then
return -1
endi
if $data02 != 2 then
return -1
endi
if $data03 != @abc@ then
return -1
endi
if $data04 != 1.982700000 then
print expect 1.982700000 actual:$data04
return -1
endi
print ======================udc with interval
sql select count(*), 'uuu' from t1 interval(1s) order by ts desc;
if $rows != 1 then
return -1
endi
print ======================udc with tags
sql select t1,'abc',tbname from st1
if $rows != 1 then
return -1
endi
print ======================udc with arithmetic
sql select 1+1 from t1
if $rows != 1 then
return -1
endi
sql_error select from t1
sql_error select abc from t1
sql_error select abc as tu from t1
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录