Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
659e0d21
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
659e0d21
编写于
12月 03, 2020
作者:
H
haojun Liao
提交者:
GitHub
12月 03, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4425 from taosdata/feature/query
Feature/query
上级
f09b69a0
d79d3058
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
1052 addition
and
444 deletion
+1052
-444
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+4
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+172
-46
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+9
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+7
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+9
-7
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+14
-13
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+9
-9
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+488
-291
src/query/src/qUtil.c
src/query/src/qUtil.c
+64
-67
src/util/src/hash.c
src/util/src/hash.c
+3
-2
tests/script/general/parser/first_last.sim
tests/script/general/parser/first_last.sim
+41
-1
tests/script/general/parser/first_last_query.sim
tests/script/general/parser/first_last_query.sim
+3
-1
tests/script/general/parser/function.sim
tests/script/general/parser/function.sim
+228
-0
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
659e0d21
...
...
@@ -246,11 +246,14 @@ typedef struct SQueryInfo {
int16_t
fillType
;
// final result fill type
int16_t
numOfTables
;
STableMetaInfo
**
pTableMetaInfo
;
struct
STSBuf
*
tsBuf
;
struct
STSBuf
*
tsBuf
;
int64_t
*
fillVal
;
// default value for fill
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
int64_t
tableLimit
;
// table limit in case of super table projection query + global order + limit
int32_t
udColumnId
;
// current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
int16_t
resColumnId
;
// result column id
}
SQueryInfo
;
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
659e0d21
...
...
@@ -426,8 +426,7 @@ static void count_function_f(SQLFunctionCtx *pCtx, int32_t index) {
}
SET_VAL
(
pCtx
,
1
,
1
);
*
((
int64_t
*
)
pCtx
->
aOutputBuf
)
+=
1
;
*
((
int64_t
*
)
pCtx
->
aOutputBuf
)
+=
pCtx
->
size
;
// do not need it actually
SResultRowCellInfo
*
pInfo
=
GET_RES_INFO
(
pCtx
);
...
...
@@ -3632,114 +3631,119 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
return
true
;
}
static
int32_t
twa_function_impl
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
,
int32_t
size
)
{
static
int32_t
twa_function_impl
(
SQLFunctionCtx
*
pCtx
,
int32_t
tsIndex
,
int32_t
index
,
int32_t
size
)
{
int32_t
notNullElems
=
0
;
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
index
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
assert
(
pCtx
->
start
.
key
<
primaryKey
[
index
]
&&
pInfo
->
lastKey
==
INT64_MIN
);
assert
((
pCtx
->
start
.
key
<
primaryKey
[
tsIndex
+
i
]
&&
pCtx
->
order
==
TSDB_ORDER_ASC
)
||
(
pCtx
->
start
.
key
>
primaryKey
[
tsIndex
+
i
]
&&
pCtx
->
order
==
TSDB_ORDER_DESC
));
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
assert
(
pInfo
->
lastKey
==
INT64_MIN
);
pInfo
->
lastKey
=
primaryKey
[
tsIndex
+
i
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
pInfo
->
lastKey
-
pCtx
->
start
.
key
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
notNullElems
++
;
i
+=
1
;
i
+=
step
;
}
else
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
pInfo
->
lastKey
=
primaryKey
[
tsIndex
+
i
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
i
+=
1
;
i
+=
step
;
}
// calculate the value of
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
(
double
)
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
);
for
(;
i
<
size
&&
i
>=
0
;
i
+=
step
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
tsIndex
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
tsIndex
];
}
break
;
}
...
...
@@ -3764,16 +3768,13 @@ static void twa_function(SQLFunctionCtx *pCtx) {
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
// skip null value
int32_t
i
=
0
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
int32_t
i
=
(
pCtx
->
order
==
TSDB_ORDER_ASC
)
?
0
:
(
pCtx
->
size
-
1
);
while
(
pCtx
->
hasNull
&&
i
<
pCtx
->
size
&&
isNull
((
char
*
)
data
+
pCtx
->
inputBytes
*
i
,
pCtx
->
inputType
))
{
i
++
;
i
+=
step
;
}
if
(
i
>=
pCtx
->
size
)
{
return
;
}
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
pCtx
->
size
);
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
i
,
pCtx
->
size
);
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
...
...
@@ -3791,11 +3792,136 @@ static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
return
;
}
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
index
,
1
);
int32_t
notNullElems
=
0
;
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
pCtx
->
startOffset
;
int32_t
size
=
pCtx
->
size
;
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
assert
(
pInfo
->
lastKey
==
INT64_MIN
);
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
pInfo
->
lastKey
-
pCtx
->
start
.
key
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pCtx
->
start
.
key
;
notNullElems
++
;
i
+=
1
;
}
else
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
));
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
i
+=
1
;
}
// calculate the value of
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
val
=
(
int8_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
val
=
(
int16_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
val
=
(
int32_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
val
=
(
int64_t
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
(
double
)
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
val
=
(
float
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
val
=
(
double
*
)
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
for
(;
i
<
size
;
i
++
)
{
if
(
pCtx
->
hasNull
&&
isNull
((
const
char
*
)
&
val
[
i
],
pCtx
->
inputType
))
{
continue
;
}
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
+
index
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
+
index
];
}
break
;
}
default:
assert
(
0
);
}
// the last interpolated time window value
if
(
pCtx
->
end
.
key
!=
INT64_MIN
)
{
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
end
.
val
)
/
2
)
*
(
pCtx
->
end
.
key
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
pCtx
->
end
.
val
;
pInfo
->
lastKey
=
pCtx
->
end
.
key
;
}
pInfo
->
win
.
ekey
=
pInfo
->
lastKey
;
SET_VAL
(
pCtx
,
notNullElems
,
1
);
if
(
notNullElems
>
0
)
{
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
}
if
(
pCtx
->
stableQuery
)
{
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
memcpy
(
pCtx
->
aOutputBuf
,
GET_ROWCELL_INTERBUF
(
pResInfo
),
sizeof
(
STwaInfo
));
}
}
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
659e0d21
...
...
@@ -721,10 +721,16 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
// final result depends on the fields number
memset
(
pSchema
,
0
,
sizeof
(
SSchema
)
*
size
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
SSchema
*
p1
=
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colIndex
);
SSchema
p1
=
{
0
};
if
(
pExpr
->
colInfo
.
colIndex
!=
TSDB_TBNAME_COLUMN_INDEX
)
{
p1
=
*
tscGetTableColumnSchema
(
pTableMetaInfo
->
pTableMeta
,
pExpr
->
colInfo
.
colIndex
);
}
else
{
p1
=
tGetTableNameColumnSchema
();
}
int32_t
inter
=
0
;
int16_t
type
=
-
1
;
...
...
@@ -743,7 +749,8 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr
functionId
=
TSDB_FUNC_LAST
;
}
getResultDataInfo
(
p1
->
type
,
p1
->
bytes
,
functionId
,
0
,
&
type
,
&
bytes
,
&
inter
,
0
,
false
);
int32_t
ret
=
getResultDataInfo
(
p1
.
type
,
p1
.
bytes
,
functionId
,
0
,
&
type
,
&
bytes
,
&
inter
,
0
,
false
);
assert
(
ret
==
TSDB_CODE_SUCCESS
);
}
pSchema
[
i
].
type
=
(
uint8_t
)
type
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
659e0d21
...
...
@@ -5307,15 +5307,18 @@ int32_t parseLimitClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t clauseIn
// keep original limitation value in globalLimit
pQueryInfo
->
clauseLimit
=
pQueryInfo
->
limit
.
limit
;
pQueryInfo
->
prjOffset
=
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
prjOffset
=
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
tableLimit
=
-
1
;
if
(
tscOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
))
{
/*
* the limitation/offset value should be removed during retrieve data from virtual node,
* since the global order are done in client side, so the limitation should also
* be done at the client side.
* the offset value should be removed during retrieve data from virtual node, since the
* global order are done in client side, so the offset is applied at the client side
* However, note that the maximum allowed number of result for each table should be less
* than or equal to the value of limit.
*/
if
(
pQueryInfo
->
limit
.
limit
>
0
)
{
pQueryInfo
->
tableLimit
=
pQueryInfo
->
limit
.
limit
+
pQueryInfo
->
limit
.
offset
;
pQueryInfo
->
limit
.
limit
=
-
1
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
659e0d21
...
...
@@ -684,6 +684,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pQueryMsg
->
tagNameRelType
=
htons
(
pQueryInfo
->
tagCond
.
relType
);
pQueryMsg
->
numOfTags
=
htonl
(
numOfTags
);
pQueryMsg
->
queryType
=
htonl
(
pQueryInfo
->
type
);
pQueryMsg
->
tableLimit
=
htobe64
(
pQueryInfo
->
tableLimit
);
size_t
numOfOutput
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
pQueryMsg
->
numOfOutput
=
htons
((
int16_t
)
numOfOutput
);
// this is the stage one output column number
...
...
src/inc/taosmsg.h
浏览文件 @
659e0d21
...
...
@@ -476,19 +476,21 @@ typedef struct {
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
orderByIdx
;
int16_t
orderType
;
// used in group by xx order by xxx
int64_t
tableLimit
;
// limit the number of rows for each table, used in order by + limit in stable projection query.
int16_t
prjOrder
;
// global order in super table projection query.
int64_t
limit
;
int64_t
offset
;
uint32_t
queryType
;
// denote another query process
int16_t
numOfOutput
;
// final output columns numbers
int16_t
tagNameRelType
;
// relation of tag criteria and tbname criteria
int16_t
fillType
;
// interpolate type
uint64_t
fillVal
;
// default value array list
int16_t
fillType
;
// interpolate type
uint64_t
fillVal
;
// default value array list
int32_t
secondStageOutput
;
int32_t
tsOffset
;
// offset value in current msg body, NOTE: ts list is compressed
int32_t
tsLen
;
// total length of ts comp block
int32_t
tsNumOfBlocks
;
// ts comp block numbers
int32_t
tsOrder
;
// ts comp block order
int32_t
numOfTags
;
// number of tags columns involved
int32_t
tsOffset
;
// offset value in current msg body, NOTE: ts list is compressed
int32_t
tsLen
;
// total length of ts comp block
int32_t
tsNumOfBlocks
;
// ts comp block numbers
int32_t
tsOrder
;
// ts comp block order
int32_t
numOfTags
;
// number of tags columns involved
SColumnInfo
colList
[];
}
SQueryTableMsg
;
...
...
src/query/inc/qExecutor.h
浏览文件 @
659e0d21
...
...
@@ -83,16 +83,15 @@ typedef struct SResultRec {
int32_t
threshold
;
// result size threshold in rows.
}
SResultRec
;
typedef
struct
SWindowResInfo
{
SResultRow
**
pResult
;
// result list
int16_t
type
:
8
;
// data type for hash key
int32_t
size
:
24
;
// number of result set
int32_t
threshold
;
// threshold to halt query and return the generated results.
int32_t
capacity
;
// max capacity
int32_t
curIndex
;
// current start active index
int64_t
startTime
;
// start time of the first time window for sliding query
int64_t
prevSKey
;
// previous (not completed) sliding window start key
}
SWindowResInfo
;
typedef
struct
SResultRowInfo
{
SResultRow
**
pResult
;
// result list
int16_t
type
:
8
;
// data type for hash key
int32_t
size
:
24
;
// number of result set
int32_t
capacity
;
// max capacity
int32_t
curIndex
;
// current start active index
int64_t
startTime
;
// start time of the first time window for sliding query
int64_t
prevSKey
;
// previous (not completed) sliding window start key
}
SResultRowInfo
;
typedef
struct
SColumnFilterElem
{
int16_t
bytes
;
// column length
...
...
@@ -115,7 +114,7 @@ typedef struct STableQueryInfo {
STimeWindow
win
;
STSCursor
cur
;
void
*
pTable
;
// for retrieve the page id list
S
WindowRes
Info
windowResInfo
;
S
ResultRow
Info
windowResInfo
;
}
STableQueryInfo
;
typedef
struct
SQueryCostInfo
{
...
...
@@ -179,7 +178,7 @@ typedef struct SQueryRuntimeEnv {
uint16_t
*
offset
;
uint16_t
scanFlag
;
// denotes reversed scan of data or not
SFillInfo
*
pFillInfo
;
S
WindowRes
Info
windowResInfo
;
S
ResultRow
Info
windowResInfo
;
STSBuf
*
pTSBuf
;
STSCursor
cur
;
SQueryCostInfo
summary
;
...
...
@@ -190,6 +189,7 @@ typedef struct SQueryRuntimeEnv {
bool
groupbyNormalCol
;
// denote if this is a groupby normal column query
bool
hasTagResults
;
// if there are tag values in final result or not
bool
timeWindowInterpo
;
// if the time window start/end required interpolation
bool
queryWindowIdentical
;
// all query time windows are identical for all tables in one group
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
prevGroupId
;
// previous executed group id
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
...
...
@@ -217,7 +217,8 @@ typedef struct SQInfo {
STableGroupInfo
tableGroupInfo
;
// table <tid, last_key> list SArray<STableKeyInfo>
STableGroupInfo
tableqinfoGroupInfo
;
// this is a group array list, including SArray<STableQueryInfo*> structure
SQueryRuntimeEnv
runtimeEnv
;
SArray
*
arrTableIdInfo
;
// SArray* arrTableIdInfo;
SHashObj
*
arrTableIdInfo
;
int32_t
groupIndex
;
/*
...
...
src/query/inc/qUtil.h
浏览文件 @
659e0d21
...
...
@@ -30,19 +30,19 @@ void clearResultRow(SQueryRuntimeEnv* pRuntimeEnv, SResultRow* pRow, int16_t typ
void
copyResultRow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
dst
,
const
SResultRow
*
src
,
int16_t
type
);
SResultRowCellInfo
*
getResultCell
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
const
SResultRow
*
pRow
,
int32_t
index
);
int32_t
initWindowResInfo
(
S
WindowResInfo
*
pWindowResInfo
,
int32_t
size
,
int32_t
threshold
,
int16_t
type
);
int32_t
initWindowResInfo
(
S
ResultRowInfo
*
pWindowResInfo
,
int32_t
size
,
int16_t
type
);
void
cleanupTimeWindowInfo
(
S
WindowRes
Info
*
pWindowResInfo
);
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
S
WindowRes
Info
*
pWindowResInfo
);
void
cleanupTimeWindowInfo
(
S
ResultRow
Info
*
pWindowResInfo
);
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
S
ResultRow
Info
*
pWindowResInfo
);
void
clearFirstNWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
num
);
void
clearClosedTimeWindow
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
int32_t
numOfClosedTimeWindow
(
S
WindowRes
Info
*
pWindowResInfo
);
void
closeTimeWindow
(
S
WindowRes
Info
*
pWindowResInfo
,
int32_t
slot
);
void
closeAllTimeWindow
(
S
WindowRes
Info
*
pWindowResInfo
);
void
removeRedundantWindow
(
S
WindowRes
Info
*
pWindowResInfo
,
TSKEY
lastKey
,
int32_t
order
);
int32_t
numOfClosedTimeWindow
(
S
ResultRow
Info
*
pWindowResInfo
);
void
closeTimeWindow
(
S
ResultRow
Info
*
pWindowResInfo
,
int32_t
slot
);
void
closeAllTimeWindow
(
S
ResultRow
Info
*
pWindowResInfo
);
void
removeRedundantWindow
(
S
ResultRow
Info
*
pWindowResInfo
,
TSKEY
lastKey
,
int32_t
order
);
static
FORCE_INLINE
SResultRow
*
getResultRow
(
S
WindowRes
Info
*
pWindowResInfo
,
int32_t
slot
)
{
static
FORCE_INLINE
SResultRow
*
getResultRow
(
S
ResultRow
Info
*
pWindowResInfo
,
int32_t
slot
)
{
assert
(
pWindowResInfo
!=
NULL
&&
slot
>=
0
&&
slot
<
pWindowResInfo
->
size
);
return
pWindowResInfo
->
pResult
[
slot
];
}
...
...
@@ -50,7 +50,7 @@ static FORCE_INLINE SResultRow *getResultRow(SWindowResInfo *pWindowResInfo, int
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pExpr1[1].base.arg->argValue.i64:1)
bool
isWindowResClosed
(
S
WindowRes
Info
*
pWindowResInfo
,
int32_t
slot
);
bool
isWindowResClosed
(
S
ResultRow
Info
*
pWindowResInfo
,
int32_t
slot
);
int32_t
initResultRow
(
SResultRow
*
pResultRow
);
...
...
src/query/src/qExecutor.c
浏览文件 @
659e0d21
此差异已折叠。
点击以展开。
src/query/src/qUtil.c
浏览文件 @
659e0d21
...
...
@@ -43,51 +43,48 @@ int32_t getOutputInterResultBufSize(SQuery* pQuery) {
return
size
;
}
int32_t
initWindowResInfo
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
size
,
int32_t
threshold
,
int16_t
type
)
{
pWindowResInfo
->
capacity
=
size
;
pWindowResInfo
->
threshold
=
threshold
;
pWindowResInfo
->
type
=
type
;
pWindowResInfo
->
curIndex
=
-
1
;
pWindowResInfo
->
size
=
0
;
pWindowResInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
int32_t
initWindowResInfo
(
SResultRowInfo
*
pResultRowInfo
,
int32_t
size
,
int16_t
type
)
{
pResultRowInfo
->
capacity
=
size
;
pResultRowInfo
->
type
=
type
;
pResultRowInfo
->
curIndex
=
-
1
;
pResultRowInfo
->
size
=
0
;
pResultRowInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
p
WindowResInfo
->
pResult
=
calloc
(
pWindowRes
Info
->
capacity
,
POINTER_BYTES
);
if
(
p
WindowRes
Info
->
pResult
==
NULL
)
{
p
ResultRowInfo
->
pResult
=
calloc
(
pResultRow
Info
->
capacity
,
POINTER_BYTES
);
if
(
p
ResultRow
Info
->
pResult
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
void
cleanupTimeWindowInfo
(
S
WindowResInfo
*
pWindowRes
Info
)
{
if
(
p
WindowRes
Info
==
NULL
)
{
void
cleanupTimeWindowInfo
(
S
ResultRowInfo
*
pResultRow
Info
)
{
if
(
p
ResultRow
Info
==
NULL
)
{
return
;
}
if
(
p
WindowRes
Info
->
capacity
==
0
)
{
assert
(
p
WindowRes
Info
->
pResult
==
NULL
);
if
(
p
ResultRow
Info
->
capacity
==
0
)
{
assert
(
p
ResultRow
Info
->
pResult
==
NULL
);
return
;
}
if
(
p
WindowResInfo
->
type
==
TSDB_DATA_TYPE_BINARY
||
pWindowRes
Info
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
for
(
int32_t
i
=
0
;
i
<
p
WindowRes
Info
->
size
;
++
i
)
{
tfree
(
p
WindowRes
Info
->
pResult
[
i
]
->
key
);
if
(
p
ResultRowInfo
->
type
==
TSDB_DATA_TYPE_BINARY
||
pResultRow
Info
->
type
==
TSDB_DATA_TYPE_NCHAR
)
{
for
(
int32_t
i
=
0
;
i
<
p
ResultRow
Info
->
size
;
++
i
)
{
tfree
(
p
ResultRow
Info
->
pResult
[
i
]
->
key
);
}
}
tfree
(
p
WindowRes
Info
->
pResult
);
tfree
(
p
ResultRow
Info
->
pResult
);
}
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
S
WindowResInfo
*
pWindowRes
Info
)
{
if
(
p
WindowResInfo
==
NULL
||
pWindowRes
Info
->
capacity
==
0
)
{
void
resetTimeWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
S
ResultRowInfo
*
pResultRow
Info
)
{
if
(
p
ResultRowInfo
==
NULL
||
pResultRow
Info
->
capacity
==
0
)
{
return
;
}
// assert(pWindowResInfo->size == 1);
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
SResultRow
*
pWindowRes
=
pWindowResInfo
->
pResult
[
i
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
pWindowResInfo
->
type
);
for
(
int32_t
i
=
0
;
i
<
pResultRowInfo
->
size
;
++
i
)
{
SResultRow
*
pWindowRes
=
pResultRowInfo
->
pResult
[
i
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
pResultRowInfo
->
type
);
int32_t
groupIndex
=
0
;
int64_t
uid
=
0
;
...
...
@@ -96,30 +93,30 @@ void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowR
taosHashRemove
(
pRuntimeEnv
->
pResultRowHashTable
,
(
const
char
*
)
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
sizeof
(
groupIndex
)));
}
p
WindowRes
Info
->
curIndex
=
-
1
;
p
WindowRes
Info
->
size
=
0
;
p
ResultRow
Info
->
curIndex
=
-
1
;
p
ResultRow
Info
->
size
=
0
;
p
WindowRes
Info
->
startTime
=
TSKEY_INITIAL_VAL
;
p
WindowRes
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
p
ResultRow
Info
->
startTime
=
TSKEY_INITIAL_VAL
;
p
ResultRow
Info
->
prevSKey
=
TSKEY_INITIAL_VAL
;
}
void
clearFirstNWindowRes
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
num
)
{
S
WindowResInfo
*
pWindowRes
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
WindowResInfo
==
NULL
||
pWindowResInfo
->
capacity
==
0
||
pWindowRes
Info
->
size
==
0
||
num
==
0
)
{
S
ResultRowInfo
*
pResultRow
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
ResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
||
pResultRow
Info
->
size
==
0
||
num
==
0
)
{
return
;
}
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
WindowRes
Info
);
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
ResultRow
Info
);
assert
(
num
>=
0
&&
num
<=
numOfClosed
);
int16_t
type
=
p
WindowRes
Info
->
type
;
int16_t
type
=
p
ResultRow
Info
->
type
;
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
char
*
key
=
NULL
;
int16_t
bytes
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SResultRow
*
pResult
=
p
WindowRes
Info
->
pResult
[
i
];
SResultRow
*
pResult
=
p
ResultRow
Info
->
pResult
[
i
];
if
(
pResult
->
closed
)
{
// remove the window slot from hash table
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
...
...
@@ -129,23 +126,23 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
}
}
int32_t
remain
=
p
WindowRes
Info
->
size
-
num
;
int32_t
remain
=
p
ResultRow
Info
->
size
-
num
;
// clear all the closed windows from the window list
for
(
int32_t
k
=
0
;
k
<
remain
;
++
k
)
{
copyResultRow
(
pRuntimeEnv
,
p
WindowResInfo
->
pResult
[
k
],
pWindowRes
Info
->
pResult
[
num
+
k
],
type
);
copyResultRow
(
pRuntimeEnv
,
p
ResultRowInfo
->
pResult
[
k
],
pResultRow
Info
->
pResult
[
num
+
k
],
type
);
}
// move the unclosed window in the front of the window list
for
(
int32_t
k
=
remain
;
k
<
p
WindowRes
Info
->
size
;
++
k
)
{
SResultRow
*
pWindowRes
=
p
WindowRes
Info
->
pResult
[
k
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
WindowRes
Info
->
type
);
for
(
int32_t
k
=
remain
;
k
<
p
ResultRow
Info
->
size
;
++
k
)
{
SResultRow
*
pWindowRes
=
p
ResultRow
Info
->
pResult
[
k
];
clearResultRow
(
pRuntimeEnv
,
pWindowRes
,
p
ResultRow
Info
->
type
);
}
p
WindowRes
Info
->
size
=
remain
;
p
ResultRow
Info
->
size
=
remain
;
for
(
int32_t
k
=
0
;
k
<
p
WindowRes
Info
->
size
;
++
k
)
{
SResultRow
*
pResult
=
p
WindowRes
Info
->
pResult
[
k
];
for
(
int32_t
k
=
0
;
k
<
p
ResultRow
Info
->
size
;
++
k
)
{
SResultRow
*
pResult
=
p
ResultRow
Info
->
pResult
[
k
];
getResultRowKeyInfo
(
pResult
,
type
,
&
key
,
&
bytes
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
...
...
@@ -153,43 +150,43 @@ void clearFirstNWindowRes(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
assert
(
p
!=
NULL
);
int32_t
v
=
(
*
p
-
num
);
assert
(
v
>=
0
&&
v
<=
p
WindowRes
Info
->
size
);
assert
(
v
>=
0
&&
v
<=
p
ResultRow
Info
->
size
);
SET_RES_WINDOW_KEY
(
pRuntimeEnv
->
keyBuf
,
key
,
bytes
,
uid
);
taosHashPut
(
pRuntimeEnv
->
pResultRowHashTable
,
pRuntimeEnv
->
keyBuf
,
GET_RES_WINDOW_KEY_LEN
(
bytes
),
(
char
*
)
&
v
,
sizeof
(
int32_t
));
}
p
WindowRes
Info
->
curIndex
=
-
1
;
p
ResultRow
Info
->
curIndex
=
-
1
;
}
void
clearClosedTimeWindow
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
S
WindowResInfo
*
pWindowRes
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
WindowResInfo
==
NULL
||
pWindowResInfo
->
capacity
==
0
||
pWindowRes
Info
->
size
==
0
)
{
S
ResultRowInfo
*
pResultRow
Info
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
p
ResultRowInfo
==
NULL
||
pResultRowInfo
->
capacity
==
0
||
pResultRow
Info
->
size
==
0
)
{
return
;
}
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
WindowRes
Info
);
int32_t
numOfClosed
=
numOfClosedTimeWindow
(
p
ResultRow
Info
);
clearFirstNWindowRes
(
pRuntimeEnv
,
numOfClosed
);
}
int32_t
numOfClosedTimeWindow
(
S
WindowResInfo
*
pWindowRes
Info
)
{
int32_t
numOfClosedTimeWindow
(
S
ResultRowInfo
*
pResultRow
Info
)
{
int32_t
i
=
0
;
while
(
i
<
p
WindowResInfo
->
size
&&
pWindowRes
Info
->
pResult
[
i
]
->
closed
)
{
while
(
i
<
p
ResultRowInfo
->
size
&&
pResultRow
Info
->
pResult
[
i
]
->
closed
)
{
++
i
;
}
return
i
;
}
void
closeAllTimeWindow
(
S
WindowResInfo
*
pWindowRes
Info
)
{
assert
(
p
WindowResInfo
->
size
>=
0
&&
pWindowResInfo
->
capacity
>=
pWindowRes
Info
->
size
);
void
closeAllTimeWindow
(
S
ResultRowInfo
*
pResultRow
Info
)
{
assert
(
p
ResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRow
Info
->
size
);
for
(
int32_t
i
=
0
;
i
<
p
WindowRes
Info
->
size
;
++
i
)
{
if
(
p
WindowRes
Info
->
pResult
[
i
]
->
closed
)
{
for
(
int32_t
i
=
0
;
i
<
p
ResultRow
Info
->
size
;
++
i
)
{
if
(
p
ResultRow
Info
->
pResult
[
i
]
->
closed
)
{
continue
;
}
p
WindowRes
Info
->
pResult
[
i
]
->
closed
=
true
;
p
ResultRow
Info
->
pResult
[
i
]
->
closed
=
true
;
}
}
...
...
@@ -198,41 +195,41 @@ void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
* the last qualified time stamp in case of sliding query, which the sliding time is not equalled to the interval time.
* NOTE: remove redundant, only when the result set order equals to traverse order
*/
void
removeRedundantWindow
(
S
WindowResInfo
*
pWindowRes
Info
,
TSKEY
lastKey
,
int32_t
order
)
{
assert
(
p
WindowResInfo
->
size
>=
0
&&
pWindowResInfo
->
capacity
>=
pWindowRes
Info
->
size
);
if
(
p
WindowRes
Info
->
size
<=
1
)
{
void
removeRedundantWindow
(
S
ResultRowInfo
*
pResultRow
Info
,
TSKEY
lastKey
,
int32_t
order
)
{
assert
(
p
ResultRowInfo
->
size
>=
0
&&
pResultRowInfo
->
capacity
>=
pResultRow
Info
->
size
);
if
(
p
ResultRow
Info
->
size
<=
1
)
{
return
;
}
// get the result order
int32_t
resultOrder
=
(
p
WindowResInfo
->
pResult
[
0
]
->
win
.
skey
<
pWindowRes
Info
->
pResult
[
1
]
->
win
.
skey
)
?
1
:-
1
;
int32_t
resultOrder
=
(
p
ResultRowInfo
->
pResult
[
0
]
->
win
.
skey
<
pResultRow
Info
->
pResult
[
1
]
->
win
.
skey
)
?
1
:-
1
;
if
(
order
!=
resultOrder
)
{
return
;
}
int32_t
i
=
0
;
if
(
order
==
QUERY_ASC_FORWARD_STEP
)
{
TSKEY
ekey
=
p
WindowRes
Info
->
pResult
[
i
]
->
win
.
ekey
;
while
(
i
<
p
WindowRes
Info
->
size
&&
(
ekey
<
lastKey
))
{
TSKEY
ekey
=
p
ResultRow
Info
->
pResult
[
i
]
->
win
.
ekey
;
while
(
i
<
p
ResultRow
Info
->
size
&&
(
ekey
<
lastKey
))
{
++
i
;
}
}
else
if
(
order
==
QUERY_DESC_FORWARD_STEP
)
{
while
(
i
<
p
WindowResInfo
->
size
&&
(
pWindowRes
Info
->
pResult
[
i
]
->
win
.
skey
>
lastKey
))
{
while
(
i
<
p
ResultRowInfo
->
size
&&
(
pResultRow
Info
->
pResult
[
i
]
->
win
.
skey
>
lastKey
))
{
++
i
;
}
}
if
(
i
<
p
WindowRes
Info
->
size
)
{
p
WindowRes
Info
->
size
=
(
i
+
1
);
if
(
i
<
p
ResultRow
Info
->
size
)
{
p
ResultRow
Info
->
size
=
(
i
+
1
);
}
}
bool
isWindowResClosed
(
S
WindowResInfo
*
pWindowRes
Info
,
int32_t
slot
)
{
return
(
getResultRow
(
p
WindowRes
Info
,
slot
)
->
closed
==
true
);
bool
isWindowResClosed
(
S
ResultRowInfo
*
pResultRow
Info
,
int32_t
slot
)
{
return
(
getResultRow
(
p
ResultRow
Info
,
slot
)
->
closed
==
true
);
}
void
closeTimeWindow
(
S
WindowResInfo
*
pWindowRes
Info
,
int32_t
slot
)
{
getResultRow
(
p
WindowRes
Info
,
slot
)
->
closed
=
true
;
void
closeTimeWindow
(
S
ResultRowInfo
*
pResultRow
Info
,
int32_t
slot
)
{
getResultRow
(
p
ResultRow
Info
,
slot
)
->
closed
=
true
;
}
void
clearResultRow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SResultRow
*
pWindowRes
,
int16_t
type
)
{
...
...
src/util/src/hash.c
浏览文件 @
659e0d21
...
...
@@ -151,8 +151,9 @@ static void pushfrontNodeInEntryList(SHashEntry *pEntry, SHashNode *pNode);
*/
SHashObj
*
taosHashInit
(
size_t
capacity
,
_hash_fn_t
fn
,
bool
update
,
SHashLockTypeE
type
)
{
if
(
capacity
==
0
||
fn
==
NULL
)
{
return
NULL
;
assert
(
fn
!=
NULL
);
if
(
capacity
==
0
)
{
capacity
=
4
;
}
SHashObj
*
pHashObj
=
(
SHashObj
*
)
calloc
(
1
,
sizeof
(
SHashObj
));
...
...
tests/script/general/parser/first_last.sim
浏览文件 @
659e0d21
...
...
@@ -46,7 +46,8 @@ while $i < $tbNum
endw
$i = $i + 1
endw
endw
$ts = $ts + 60000
$tb = $tbPrefix . 0
sql insert into $tb (ts) values ( $ts )
...
...
@@ -84,4 +85,43 @@ sleep 500
run general/parser/first_last_query.sim
print =================> insert data regression test
sql create database test keep 36500
sql use test
sql create table tm0 (ts timestamp, k int)
print =========================> td-2298
$ts0 = 1537146000000
$xs = 6000
$x = 0
while $x < 5000
$ts = $ts0 + $xs
$ts1 = $ts + $xs
$x1 = $x + 1
sql insert into tm0 values ( $ts , $x ) ( $ts1 , $x1 )
$x = $x1
$ts0 = $ts1
endw
system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 3000
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
sql connect
sleep 500
sql use test
sql select count(*), last(ts) from tm0 interval(1s)
if $rows != 10000 then
print expect 10000, actual: $rows
return -1
endi
sql select last(ts) from tm0 interval(1s)
if $rows != 10000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
tests/script/general/parser/first_last_query.sim
浏览文件 @
659e0d21
...
...
@@ -266,4 +266,6 @@ endi
if $data14 != @test2@ then
print expect test2 , actual: $data14
return -1
endi
\ No newline at end of file
endi
sql drop table stest
\ No newline at end of file
tests/script/general/parser/function.sim
0 → 100644
浏览文件 @
659e0d21
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/cfg.sh -n dnode1 -c tableMetaKeepTimer -v 3
system sh/exec.sh -n dnode1 -s start
sleep 500
sql connect
$dbPrefix = m_func_db
$tbPrefix = m_func_tb
$mtPrefix = m_func_mt
$tbNum = 10
$rowNum = 5
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== alter.sim
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database if exists $db
sql create database $db
sql use $db
print =====================================> test case for twa in single block
sql create table t1 (ts timestamp, k float);
sql insert into t1 values('2015-08-18 00:00:00', 2.064);
sql insert into t1 values('2015-08-18 00:06:00', 2.116);
sql insert into t1 values('2015-08-18 00:12:00', 2.028);
sql insert into t1 values('2015-08-18 00:18:00', 2.126);
sql insert into t1 values('2015-08-18 00:24:00', 2.041);
sql insert into t1 values('2015-08-18 00:30:00', 2.051);
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:05:00'
if $rows != 1 then
return -1
endi
if $data00 != 2.063999891 then
return -1
endi
if $data01 != 2.063999891 then
return -1
endi
if $data02 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00'
if $rows != 1 then
return -1
endi
if $data00 != 2.089999914 then
return -1
endi
if $data01 != 2.089999914 then
return -1
endi
if $data02 != 2 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts asc
if $rows != 2 then
return -1
endi
if $data00 != @15-08-18 00:00:00.000@ then
return -1
endi
if $data01 != 2.068333156 then
return -1
endi
if $data02 != 2.063999891 then
return -1
endi
if $data03 != 1 then
return -1
endi
if $data10 != @15-08-18 00:06:00.000@ then
return -1
endi
if $data11 != 2.115999937 then
return -1
endi
if $data12 != 2.115999937 then
return -1
endi
if $data13 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:07:00' interval(1m) order by ts desc;
if $rows != 2 then
return -1
endi
if $data00 != @15-08-18 00:06:00.00@ then
return -1
endi
if $data01 != 2.115999937 then
return -1
endi
if $data02 != 2.115999937 then
return -1
endi
if $data03 != 1 then
return -1
endi
if $data11 != 2.068333156 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts asc
if $rows != 3 then
return -1
endi
if $data01 != 2.088666666 then
return -1
endi
if $data02 != 2.089999914 then
return -1
endi
if $data03 != 2 then
return -1
endi
if $data11 != 2.077099980 then
return -1
endi
if $data12 != 2.077000022 then
return -1
endi
if $data13 != 2 then
return -1
endi
if $data21 != 2.069333235 then
return -1
endi
if $data22 != 2.040999889 then
return -1
endi
if $data23 != 1 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:27:00' interval(10m) order by ts desc
if $rows != 3 then
return -1
endi
if $data01 != 2.069333235 then
return -1
endi
if $data11 != 2.077099980 then
return -1
endi
if $data21 != 2.088666666 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' order by ts asc
if $data00 != 2.073699975 then
return -1
endi
if $data01 != 2.070999980 then
return -1
endi
if $data02 != 6 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' order by ts desc
if $rows != 1 then
return -1
endi
if $data00 != 2.073699975 then
return -1
endi
if $data01 != 2.070999980 then
return -1
endi
if $data02 != 6 then
return -1
endi
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts asc
sql select twa(k),avg(k),count(1) from t1 where ts>='2015-8-18 00:00:00' and ts<='2015-8-18 00:30:00' interval(10m) order by ts desc
#todo add test case while column filte exists.
select count(*),TWA(k) from tm0 where ts>='1970-1-1 13:43:00' and ts<='1970-1-1 13:44:10' interval(9s)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录