Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f1f3d9aa
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f1f3d9aa
编写于
9月 01, 2020
作者:
H
haojun Liao
提交者:
GitHub
9月 01, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3311 from taosdata/feature/TD-1230
Feature/td 1230
上级
ac85a5f0
aac7fc67
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
238 addition
and
30 deletion
+238
-30
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+0
-1
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+6
-3
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+27
-11
src/inc/taosmsg.h
src/inc/taosmsg.h
+7
-0
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+1
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+16
-10
src/query/src/qFill.c
src/query/src/qFill.c
+4
-4
tests/script/fullGeneralSuite.sim
tests/script/fullGeneralSuite.sim
+1
-0
tests/script/general/compute/last_row.sim
tests/script/general/compute/last_row.sim
+175
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
f1f3d9aa
...
@@ -39,7 +39,6 @@ extern "C" {
...
@@ -39,7 +39,6 @@ extern "C" {
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo)\
#define UTIL_TABLE_IS_NORMAL_TABLE(metaInfo)\
(!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo)))
(!(UTIL_TABLE_IS_SUPER_TABLE(metaInfo) || UTIL_TABLE_IS_CHILD_TABLE(metaInfo)))
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
typedef
struct
SParsedColElem
{
typedef
struct
SParsedColElem
{
int16_t
colIndex
;
int16_t
colIndex
;
...
...
src/client/inc/tsclient.h
浏览文件 @
f1f3d9aa
...
@@ -471,7 +471,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
...
@@ -471,7 +471,7 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
char
*
pData
=
pRes
->
data
+
pInfo
->
pSqlExpr
->
offset
*
pRes
->
numOfRows
+
bytes
*
pRes
->
row
;
char
*
pData
=
pRes
->
data
+
pInfo
->
pSqlExpr
->
offset
*
pRes
->
numOfRows
+
bytes
*
pRes
->
row
;
// user defined constant value output columns
// user defined constant value output columns
if
(
pInfo
->
pSqlExpr
->
colInfo
.
flag
==
TSDB_COL_UDC
)
{
if
(
TSDB_COL_IS_UD_COL
(
pInfo
->
pSqlExpr
->
colInfo
.
flag
)
)
{
if
(
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
type
==
TSDB_DATA_TYPE_NCHAR
||
type
==
TSDB_DATA_TYPE_BINARY
)
{
pData
=
pInfo
->
pSqlExpr
->
param
[
1
].
pz
;
pData
=
pInfo
->
pSqlExpr
->
param
[
1
].
pz
;
pRes
->
length
[
columnIndex
]
=
pInfo
->
pSqlExpr
->
param
[
1
].
nLen
;
pRes
->
length
[
columnIndex
]
=
pInfo
->
pSqlExpr
->
param
[
1
].
nLen
;
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
f1f3d9aa
...
@@ -1648,9 +1648,10 @@ static void last_function(SQLFunctionCtx *pCtx) {
...
@@ -1648,9 +1648,10 @@ static void last_function(SQLFunctionCtx *pCtx) {
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
if
(
!
pCtx
->
requireNull
)
{
continue
;
continue
;
}
}
}
memcpy
(
pCtx
->
aOutputBuf
,
data
,
pCtx
->
inputBytes
);
memcpy
(
pCtx
->
aOutputBuf
,
data
,
pCtx
->
inputBytes
);
TSKEY
ts
=
pCtx
->
ptsList
[
i
];
TSKEY
ts
=
pCtx
->
ptsList
[
i
];
...
@@ -1721,8 +1722,10 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
...
@@ -1721,8 +1722,10 @@ static void last_dist_function(SQLFunctionCtx *pCtx) {
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
for
(
int32_t
i
=
pCtx
->
size
-
1
;
i
>=
0
;
--
i
)
{
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
char
*
data
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
i
);
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
if
(
pCtx
->
hasNull
&&
isNull
(
data
,
pCtx
->
inputType
))
{
if
(
!
pCtx
->
requireNull
)
{
continue
;
continue
;
}
}
}
last_data_assign_impl
(
pCtx
,
data
,
i
);
last_data_assign_impl
(
pCtx
,
data
,
i
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
f1f3d9aa
...
@@ -33,6 +33,8 @@
...
@@ -33,6 +33,8 @@
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
#define TSWINDOW_IS_EQUAL(t1, t2) (((t1).skey == (t2).skey) && ((t1).ekey == (t2).ekey))
// -1 is tbname column index, so here use the -3 as the initial value
// -1 is tbname column index, so here use the -3 as the initial value
#define COLUMN_INDEX_INITIAL_VAL (-3)
#define COLUMN_INDEX_INITIAL_VAL (-3)
#define COLUMN_INDEX_INITIALIZER \
#define COLUMN_INDEX_INITIALIZER \
...
@@ -45,6 +47,10 @@ typedef struct SColumnList { // todo refactor
...
@@ -45,6 +47,10 @@ typedef struct SColumnList { // todo refactor
SColumnIndex
ids
[
TSDB_MAX_COLUMNS
];
SColumnIndex
ids
[
TSDB_MAX_COLUMNS
];
}
SColumnList
;
}
SColumnList
;
typedef
struct
SConvertFunc
{
int32_t
originFuncId
;
int32_t
execFuncId
;
}
SConvertFunc
;
static
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colIndex
,
int32_t
tableIndex
);
static
SSqlExpr
*
doAddProjectCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
outputIndex
,
int32_t
colIndex
,
int32_t
tableIndex
);
static
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
static
int32_t
setShowInfo
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
...
@@ -1507,13 +1513,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
...
@@ -1507,13 +1513,13 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
setExprInfoForFunctions
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSchema
*
pSchema
,
int32_t
functionID
,
char
*
aliasName
,
static
int32_t
setExprInfoForFunctions
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSchema
*
pSchema
,
SConvertFunc
cvtFunc
,
char
*
aliasName
,
int32_t
resColIdx
,
SColumnIndex
*
pColIndex
)
{
int32_t
resColIdx
,
SColumnIndex
*
pColIndex
)
{
int16_t
type
=
0
;
int16_t
type
=
0
;
int16_t
bytes
=
0
;
int16_t
bytes
=
0
;
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
char
columnName
[
TSDB_COL_NAME_LEN
]
=
{
0
};
const
char
*
msg1
=
"not support column types"
;
const
char
*
msg1
=
"not support column types"
;
int32_t
functionID
=
cvtFunc
.
execFuncId
;
if
(
functionID
==
TSDB_FUNC_SPREAD
)
{
if
(
functionID
==
TSDB_FUNC_SPREAD
)
{
if
(
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
if
(
pSchema
[
pColIndex
->
columnIndex
].
type
==
TSDB_DATA_TYPE_BINARY
||
...
@@ -1533,12 +1539,17 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
...
@@ -1533,12 +1539,17 @@ static int32_t setExprInfoForFunctions(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SS
if
(
aliasName
!=
NULL
)
{
if
(
aliasName
!=
NULL
)
{
tstrncpy
(
columnName
,
aliasName
,
sizeof
(
columnName
));
tstrncpy
(
columnName
,
aliasName
,
sizeof
(
columnName
));
}
else
{
}
else
{
getRevisedName
(
columnName
,
functionID
,
sizeof
(
columnName
)
-
1
,
pSchema
[
pColIndex
->
columnIndex
].
name
);
getRevisedName
(
columnName
,
cvtFunc
.
originFuncId
,
sizeof
(
columnName
)
-
1
,
pSchema
[
pColIndex
->
columnIndex
].
name
);
}
}
SSqlExpr
*
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
pColIndex
,
type
,
bytes
,
bytes
,
false
);
SSqlExpr
*
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
functionID
,
pColIndex
,
type
,
bytes
,
bytes
,
false
);
tstrncpy
(
pExpr
->
aliasName
,
columnName
,
sizeof
(
pExpr
->
aliasName
));
tstrncpy
(
pExpr
->
aliasName
,
columnName
,
sizeof
(
pExpr
->
aliasName
));
if
(
cvtFunc
.
originFuncId
==
TSDB_FUNC_LAST_ROW
&&
cvtFunc
.
originFuncId
!=
functionID
)
{
pExpr
->
colInfo
.
flag
|=
TSDB_COL_NULL
;
}
// set reverse order scan data blocks for last query
// set reverse order scan data blocks for last query
if
(
functionID
==
TSDB_FUNC_LAST
)
{
if
(
functionID
==
TSDB_FUNC_LAST
)
{
pExpr
->
numOfParams
=
1
;
pExpr
->
numOfParams
=
1
;
...
@@ -1772,7 +1783,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
...
@@ -1772,7 +1783,10 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
(
changeFunctionID
(
optr
,
&
functionID
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
changeFunctionID
(
optr
,
&
functionID
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg9
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg9
);
}
}
SConvertFunc
cvtFunc
=
{.
originFuncId
=
functionID
,
.
execFuncId
=
functionID
};
if
(
functionID
==
TSDB_FUNC_LAST_ROW
&&
TSWINDOW_IS_EQUAL
(
pQueryInfo
->
window
,
TSWINDOW_INITIALIZER
))
{
cvtFunc
.
execFuncId
=
TSDB_FUNC_LAST
;
}
if
(
!
requireAllFields
)
{
if
(
!
requireAllFields
)
{
if
(
pItem
->
pNode
->
pParam
->
nExpr
<
1
)
{
if
(
pItem
->
pNode
->
pParam
->
nExpr
<
1
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
@@ -1804,7 +1818,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
...
@@ -1804,7 +1818,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
for
(
int32_t
j
=
0
;
j
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
j
)
{
index
.
columnIndex
=
j
;
index
.
columnIndex
=
j
;
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colIndex
++
,
&
index
)
!=
0
)
{
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
pItem
->
aliasName
,
colIndex
++
,
&
index
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
}
}
...
@@ -1821,8 +1835,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
...
@@ -1821,8 +1835,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
if
((
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
||
(
index
.
columnIndex
<
0
))
{
if
((
index
.
columnIndex
>=
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
))
||
(
index
.
columnIndex
<
0
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
}
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
pItem
->
aliasName
,
colIndex
+
i
,
&
index
)
!=
0
)
{
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colIndex
+
i
,
&
index
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
...
@@ -1859,7 +1872,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
...
@@ -1859,7 +1872,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
for
(
int32_t
i
=
0
;
i
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
tscGetNumOfColumns
(
pTableMetaInfo
->
pTableMeta
);
++
i
)
{
SColumnIndex
index
=
{.
tableIndex
=
j
,
.
columnIndex
=
i
};
SColumnIndex
index
=
{.
tableIndex
=
j
,
.
columnIndex
=
i
};
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
functionID
,
pItem
->
aliasName
,
colIndex
,
&
index
)
!=
0
)
{
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
pSchema
,
cvtFunc
,
pItem
->
aliasName
,
colIndex
,
&
index
)
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
...
@@ -5246,7 +5259,7 @@ static bool tagColumnInGroupby(SSqlGroupbyExpr* pGroupbyExpr, int16_t columnId)
...
@@ -5246,7 +5259,7 @@ static bool tagColumnInGroupby(SSqlGroupbyExpr* pGroupbyExpr, int16_t columnId)
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
j
);
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
j
);
if
(
columnId
==
pColIndex
->
colId
&&
pColIndex
->
flag
==
TSDB_COL_TAG
)
{
if
(
columnId
==
pColIndex
->
colId
&&
TSDB_COL_IS_TAG
(
pColIndex
->
flag
)
)
{
return
true
;
return
true
;
}
}
}
}
...
@@ -5545,7 +5558,6 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
...
@@ -5545,7 +5558,6 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
return
checkUpdateTagPrjFunctions
(
pQueryInfo
,
pCmd
);
return
checkUpdateTagPrjFunctions
(
pQueryInfo
,
pCmd
);
}
}
}
}
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
)
{
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
)
{
const
char
*
msg1
=
"only one expression allowed"
;
const
char
*
msg1
=
"only one expression allowed"
;
const
char
*
msg2
=
"invalid expression in select clause"
;
const
char
*
msg2
=
"invalid expression in select clause"
;
...
@@ -6086,6 +6098,10 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
...
@@ -6086,6 +6098,10 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
}
}
int32_t
joinQuery
=
(
pQuerySql
->
from
!=
NULL
&&
pQuerySql
->
from
->
nExpr
>
2
);
int32_t
joinQuery
=
(
pQuerySql
->
from
!=
NULL
&&
pQuerySql
->
from
->
nExpr
>
2
);
if
(
pQuerySql
->
pWhere
)
{
pQueryInfo
->
window
=
TSWINDOW_INITIALIZER
;
}
if
(
parseSelectClause
(
pCmd
,
index
,
pQuerySql
->
pSelection
,
isSTable
,
joinQuery
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
parseSelectClause
(
pCmd
,
index
,
pQuerySql
->
pSelection
,
isSTable
,
joinQuery
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
...
...
src/inc/taosmsg.h
浏览文件 @
f1f3d9aa
...
@@ -170,6 +170,13 @@ enum _mgmt_table {
...
@@ -170,6 +170,13 @@ enum _mgmt_table {
#define TSDB_COL_NORMAL 0x0u // the normal column of the table
#define TSDB_COL_NORMAL 0x0u // the normal column of the table
#define TSDB_COL_TAG 0x1u // the tag column type
#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
#define TSDB_COL_NULL 0x4u // the column filter NULL or not
#define TSDB_COL_IS_TAG(f) (((f&(~(TSDB_COL_NULL)))&TSDB_COL_TAG) != 0)
#define TSDB_COL_IS_NORMAL_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_NORMAL)
#define TSDB_COL_IS_UD_COL(f) ((f&(~(TSDB_COL_NULL))) == TSDB_COL_UDC)
#define TSDB_COL_REQ_NULL(f) (((f)&TSDB_COL_NULL) != 0)
extern
char
*
taosMsg
[];
extern
char
*
taosMsg
[];
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
f1f3d9aa
...
@@ -168,6 +168,7 @@ typedef struct SQLFunctionCtx {
...
@@ -168,6 +168,7 @@ typedef struct SQLFunctionCtx {
int16_t
outputType
;
int16_t
outputType
;
int16_t
outputBytes
;
// size of results, determined by function and input column data type
int16_t
outputBytes
;
// size of results, determined by function and input column data type
bool
hasNull
;
// null value exist in current block
bool
hasNull
;
// null value exist in current block
bool
requireNull
;
// require null in some function
int16_t
functionId
;
// function id
int16_t
functionId
;
// function id
void
*
aInputElemBuf
;
void
*
aInputElemBuf
;
char
*
aOutputBuf
;
// final result output buffer, point to sdata->data
char
*
aOutputBuf
;
// final result output buffer, point to sdata->data
...
...
src/query/src/qExecutor.c
浏览文件 @
f1f3d9aa
...
@@ -35,9 +35,7 @@
...
@@ -35,9 +35,7 @@
* forced to load primary column explicitly.
* forced to load primary column explicitly.
*/
*/
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0)
#define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0)
#define TSDB_COL_IS_NORMAL_COL(f) ((f) == TSDB_COL_NORMAL)
#define TSDB_COL_IS_UD_COL(f) ((f) == TSDB_COL_UDC)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
...
@@ -285,7 +283,7 @@ bool isGroupbyNormalCol(SSqlGroupbyExpr *pGroupbyExpr) {
...
@@ -285,7 +283,7 @@ bool isGroupbyNormalCol(SSqlGroupbyExpr *pGroupbyExpr) {
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
i
);
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
i
);
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
if
(
TSDB_COL_IS_NORMAL_COL
(
pColIndex
->
flag
)
)
{
//make sure the normal column locates at the second position if tbname exists in group by clause
//make sure the normal column locates at the second position if tbname exists in group by clause
if
(
pGroupbyExpr
->
numOfGroupCols
>
1
)
{
if
(
pGroupbyExpr
->
numOfGroupCols
>
1
)
{
assert
(
pColIndex
->
colIndex
>
0
);
assert
(
pColIndex
->
colIndex
>
0
);
...
@@ -306,7 +304,7 @@ int16_t getGroupbyColumnType(SQuery *pQuery, SSqlGroupbyExpr *pGroupbyExpr) {
...
@@ -306,7 +304,7 @@ int16_t getGroupbyColumnType(SQuery *pQuery, SSqlGroupbyExpr *pGroupbyExpr) {
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pGroupbyExpr
->
numOfGroupCols
;
++
i
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
i
);
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
i
);
if
(
pColIndex
->
flag
==
TSDB_COL_NORMAL
)
{
if
(
TSDB_COL_IS_NORMAL_COL
(
pColIndex
->
flag
)
)
{
colId
=
pColIndex
->
colId
;
colId
=
pColIndex
->
colId
;
break
;
break
;
}
}
...
@@ -1133,7 +1131,7 @@ static char *getGroupbyColumnData(SQuery *pQuery, int16_t *type, int16_t *bytes,
...
@@ -1133,7 +1131,7 @@ static char *getGroupbyColumnData(SQuery *pQuery, int16_t *type, int16_t *bytes,
for
(
int32_t
k
=
0
;
k
<
pGroupbyExpr
->
numOfGroupCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pGroupbyExpr
->
numOfGroupCols
;
++
k
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
k
);
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
k
);
if
(
pColIndex
->
flag
==
TSDB_COL_TAG
)
{
if
(
TSDB_COL_IS_TAG
(
pColIndex
->
flag
)
)
{
continue
;
continue
;
}
}
...
@@ -1603,6 +1601,13 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
...
@@ -1603,6 +1601,13 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
SQLFunctionCtx
*
pCtx
=
&
pRuntimeEnv
->
pCtx
[
i
];
SColIndex
*
pIndex
=
&
pSqlFuncMsg
->
colInfo
;
SColIndex
*
pIndex
=
&
pSqlFuncMsg
->
colInfo
;
if
(
TSDB_COL_REQ_NULL
(
pIndex
->
flag
))
{
pCtx
->
requireNull
=
true
;
pIndex
->
flag
&=
~
(
TSDB_COL_NULL
);
}
else
{
pCtx
->
requireNull
=
false
;
}
int32_t
index
=
pSqlFuncMsg
->
colInfo
.
colIndex
;
int32_t
index
=
pSqlFuncMsg
->
colInfo
.
colIndex
;
if
(
TSDB_COL_IS_TAG
(
pIndex
->
flag
))
{
if
(
TSDB_COL_IS_TAG
(
pIndex
->
flag
))
{
if
(
pIndex
->
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
// todo refactor
if
(
pIndex
->
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
// todo refactor
...
@@ -1622,6 +1627,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
...
@@ -1622,6 +1627,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
pCtx
->
inputType
=
pQuery
->
colList
[
index
].
type
;
pCtx
->
inputType
=
pQuery
->
colList
[
index
].
type
;
}
}
assert
(
isValidDataType
(
pCtx
->
inputType
));
assert
(
isValidDataType
(
pCtx
->
inputType
));
pCtx
->
ptsOutputBuf
=
NULL
;
pCtx
->
ptsOutputBuf
=
NULL
;
...
@@ -1831,7 +1837,7 @@ static bool onlyQueryTags(SQuery* pQuery) {
...
@@ -1831,7 +1837,7 @@ static bool onlyQueryTags(SQuery* pQuery) {
if
(
functionId
!=
TSDB_FUNC_TAGPRJ
&&
if
(
functionId
!=
TSDB_FUNC_TAGPRJ
&&
functionId
!=
TSDB_FUNC_TID_TAG
&&
functionId
!=
TSDB_FUNC_TID_TAG
&&
(
!
(
functionId
==
TSDB_FUNC_COUNT
&&
pExprInfo
->
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
))
&&
(
!
(
functionId
==
TSDB_FUNC_COUNT
&&
pExprInfo
->
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
))
&&
(
!
(
functionId
==
TSDB_FUNC_PRJ
&&
pExprInfo
->
base
.
colInfo
.
flag
==
TSDB_COL_UDC
)))
{
(
!
(
functionId
==
TSDB_FUNC_PRJ
&&
TSDB_COL_IS_UD_COL
(
pExprInfo
->
base
.
colInfo
.
flag
)
)))
{
return
false
;
return
false
;
}
}
}
}
...
@@ -5402,7 +5408,7 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pE
...
@@ -5402,7 +5408,7 @@ static int32_t getColumnIndexInSource(SQueryTableMsg *pQueryMsg, SSqlFuncMsg *pE
j
+=
1
;
j
+=
1
;
}
}
}
else
if
(
pExprMsg
->
colInfo
.
flag
==
TSDB_COL_UDC
)
{
// user specified column data
}
else
if
(
TSDB_COL_IS_UD_COL
(
pExprMsg
->
colInfo
.
flag
)
)
{
// user specified column data
return
TSDB_UD_COLUMN_INDEX
;
return
TSDB_UD_COLUMN_INDEX
;
}
else
{
}
else
{
while
(
j
<
pQueryMsg
->
numOfCols
)
{
while
(
j
<
pQueryMsg
->
numOfCols
)
{
...
@@ -5610,7 +5616,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
...
@@ -5610,7 +5616,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList,
int16_t
functionId
=
pExprMsg
->
functionId
;
int16_t
functionId
=
pExprMsg
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_TAG_DUMMY
)
{
if
(
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TAGPRJ
||
functionId
==
TSDB_FUNC_TAG_DUMMY
)
{
if
(
pExprMsg
->
colInfo
.
flag
!=
TSDB_COL_TAG
)
{
// ignore the column index check for arithmetic expression.
if
(
!
TSDB_COL_IS_TAG
(
pExprMsg
->
colInfo
.
flag
)
)
{
// ignore the column index check for arithmetic expression.
code
=
TSDB_CODE_QRY_INVALID_MSG
;
code
=
TSDB_CODE_QRY_INVALID_MSG
;
goto
_cleanup
;
goto
_cleanup
;
}
}
...
@@ -6893,7 +6899,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
...
@@ -6893,7 +6899,7 @@ static void buildTagQueryResult(SQInfo* pQInfo) {
int16_t
type
=
0
,
bytes
=
0
;
int16_t
type
=
0
,
bytes
=
0
;
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pQuery
->
numOfOutput
;
++
j
)
{
// not assign value in case of user defined constant output column
// not assign value in case of user defined constant output column
if
(
pExprInfo
[
j
].
base
.
colInfo
.
flag
==
TSDB_COL_UDC
)
{
if
(
TSDB_COL_IS_UD_COL
(
pExprInfo
[
j
].
base
.
colInfo
.
flag
)
)
{
continue
;
continue
;
}
}
...
...
src/query/src/qFill.c
浏览文件 @
f1f3d9aa
...
@@ -55,7 +55,7 @@ SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_
...
@@ -55,7 +55,7 @@ SFillInfo* taosInitFillInfo(int32_t order, TSKEY skey, int32_t numOfTags, int32_
SFillColInfo
*
pColInfo
=
&
pFillInfo
->
pFillCol
[
i
];
SFillColInfo
*
pColInfo
=
&
pFillInfo
->
pFillCol
[
i
];
pFillInfo
->
pData
[
i
]
=
calloc
(
1
,
pColInfo
->
col
.
bytes
*
capacity
);
pFillInfo
->
pData
[
i
]
=
calloc
(
1
,
pColInfo
->
col
.
bytes
*
capacity
);
if
(
pColInfo
->
flag
==
TSDB_COL_TAG
)
{
if
(
TSDB_COL_IS_TAG
(
pColInfo
->
flag
)
)
{
bool
exists
=
false
;
bool
exists
=
false
;
for
(
int32_t
j
=
0
;
j
<
k
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
k
;
++
j
)
{
if
(
pFillInfo
->
pTags
[
j
].
col
.
colId
==
pColInfo
->
col
.
colId
)
{
if
(
pFillInfo
->
pTags
[
j
].
col
.
colId
==
pColInfo
->
col
.
colId
)
{
...
@@ -155,7 +155,7 @@ void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, tFilePage* pInpu
...
@@ -155,7 +155,7 @@ void taosFillCopyInputDataFromOneFilePage(SFillInfo* pFillInfo, tFilePage* pInpu
char
*
data
=
pInput
->
data
+
pCol
->
col
.
offset
*
pInput
->
num
;
char
*
data
=
pInput
->
data
+
pCol
->
col
.
offset
*
pInput
->
num
;
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
(
size_t
)(
pInput
->
num
*
pCol
->
col
.
bytes
));
memcpy
(
pFillInfo
->
pData
[
i
],
data
,
(
size_t
)(
pInput
->
num
*
pCol
->
col
.
bytes
));
if
(
pCol
->
flag
==
TSDB_COL_TAG
)
{
// copy the tag value to tag value buffer
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
)
)
{
// copy the tag value to tag value buffer
for
(
int32_t
j
=
0
;
j
<
pFillInfo
->
numOfTags
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pFillInfo
->
numOfTags
;
++
j
)
{
SFillTagColInfo
*
pTag
=
&
pFillInfo
->
pTags
[
j
];
SFillTagColInfo
*
pTag
=
&
pFillInfo
->
pTags
[
j
];
if
(
pTag
->
col
.
colId
==
pCol
->
col
.
colId
)
{
if
(
pTag
->
col
.
colId
==
pCol
->
col
.
colId
)
{
...
@@ -259,7 +259,7 @@ int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoi
...
@@ -259,7 +259,7 @@ int taosDoLinearInterpolation(int32_t type, SPoint* point1, SPoint* point2, SPoi
static
void
setTagsValue
(
SFillInfo
*
pFillInfo
,
tFilePage
**
data
,
int32_t
num
)
{
static
void
setTagsValue
(
SFillInfo
*
pFillInfo
,
tFilePage
**
data
,
int32_t
num
)
{
for
(
int32_t
j
=
0
;
j
<
pFillInfo
->
numOfCols
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pFillInfo
->
numOfCols
;
++
j
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
j
];
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
j
];
if
(
pCol
->
flag
==
TSDB_COL_NORMAL
)
{
if
(
TSDB_COL_IS_NORMAL_COL
(
pCol
->
flag
)
)
{
continue
;
continue
;
}
}
...
@@ -459,7 +459,7 @@ int32_t generateDataBlockImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t nu
...
@@ -459,7 +459,7 @@ int32_t generateDataBlockImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t nu
// assign rows to dst buffer
// assign rows to dst buffer
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pFillInfo
->
numOfCols
;
++
i
)
{
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
SFillColInfo
*
pCol
=
&
pFillInfo
->
pFillCol
[
i
];
if
(
pCol
->
flag
==
TSDB_COL_TAG
)
{
if
(
TSDB_COL_IS_TAG
(
pCol
->
flag
)
)
{
continue
;
continue
;
}
}
...
...
tests/script/fullGeneralSuite.sim
浏览文件 @
f1f3d9aa
...
@@ -24,6 +24,7 @@ run general/compute/diff2.sim
...
@@ -24,6 +24,7 @@ run general/compute/diff2.sim
run general/compute/first.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/interval.sim
run general/compute/last.sim
run general/compute/last.sim
run general/compute/last_row.sim
run general/compute/leastsquare.sim
run general/compute/leastsquare.sim
run general/compute/max.sim
run general/compute/max.sim
run general/compute/min.sim
run general/compute/min.sim
...
...
tests/script/general/compute/last_row.sim
0 → 100644
浏览文件 @
f1f3d9aa
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect
$dbPrefix = m_la_db
$tbPrefix = m_la_tb
$mtPrefix = m_la_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$ms = $x . m
sql insert into $tb values (now + $ms , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select last_row(tbcol) from $tb
print ===> $data00
if $data00 != 19 then
return -1
endi
print =============== step3
sql select last_row(tbcol) from $tb where ts < now + 4m
print ===> $data00
if $data00 != 4 then
return -1
endi
print =============== step4
sql select last_row(tbcol) as b from $tb
print ===> $data00
if $data00 != 19 then
return -1
endi
print =============== step7
sql select last_row(tbcol) from $mt
print ===> $data00
if $data00 != 19 then
return -1
endi
print =============== step8
sql select last_row(tbcol) as c from $mt where ts < now + 4m
print ===> $data00
if $data00 != 4 then
return -1
endi
sql select last_row(tbcol) as c from $mt where tgcol < 5
print ===> $data00
if $data00 != 19 then
return -1
endi
sql select last_row(tbcol) as c from $mt where tgcol < 5 and ts < now + 4m
print ===> $data00
if $data00 != 4 then
return -1
endi
print =============== step10
sql select last_row(tbcol) as b from $mt group by tgcol
print ===> $data00
if $data00 != 19 then
return -1
endi
if $rows != $tbNum then
return -1
endi
print =============== step11
sql insert into $tb values(now + 1h, 10)
sql insert into $tb values(now + 3h, null)
sql insert into $tb values(now + 5h, -1)
sql insert into $tb values(now + 7h, null)
## for super table
sql select last_row(*) from $mt where ts < now + 6h
if $data01 != -1 then
return -1
endi
sql select last_row(*) from $mt where ts < now + 8h
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $mt
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $mt where ts < now + 4h
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $mt where ts > now + 1h and ts < now + 4h
if $data01 != NULL then
return -1
endi
## for table
sql select last_row(*) from $tb where ts < now + 6h
if $data01 != -1 then
return -1
endi
sql select last_row(*) from $tb where ts < now + 8h
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $tb
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $tb where ts < now + 4h
if $data01 != NULL then
return -1
endi
sql select last_row(*) from $tb where ts > now + 1h and ts < now + 4h
if $data01 != NULL then
return -1
endi
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录