Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
00ce6543
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看板
提交
00ce6543
编写于
11月 28, 2020
作者:
P
Ping Xiao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into xiaoping/add_test_case2
上级
213cba6e
a9f53e2f
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
821 addition
and
282 deletion
+821
-282
src/client/inc/tscLocalMerge.h
src/client/inc/tscLocalMerge.h
+0
-1
src/client/src/tscFunctionImpl.c
src/client/src/tscFunctionImpl.c
+143
-116
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+9
-11
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+3
-2
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+8
-3
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+12
-17
src/query/src/qAst.c
src/query/src/qAst.c
+96
-11
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+290
-40
src/query/src/qUtil.c
src/query/src/qUtil.c
+2
-3
tests/script/general/parser/col_arithmetic_operation.sim
tests/script/general/parser/col_arithmetic_operation.sim
+11
-10
tests/script/general/parser/col_arithmetic_query.sim
tests/script/general/parser/col_arithmetic_query.sim
+231
-53
tests/script/general/parser/limit1_tb.sim
tests/script/general/parser/limit1_tb.sim
+5
-4
tests/script/general/parser/limit_tb.sim
tests/script/general/parser/limit_tb.sim
+9
-9
tests/script/general/parser/where.sim
tests/script/general/parser/where.sim
+2
-2
未找到文件。
src/client/inc/tscLocalMerge.h
浏览文件 @
00ce6543
...
@@ -56,7 +56,6 @@ typedef struct SLocalReducer {
...
@@ -56,7 +56,6 @@ typedef struct SLocalReducer {
tFilePage
*
pTempBuffer
;
tFilePage
*
pTempBuffer
;
struct
SQLFunctionCtx
*
pCtx
;
struct
SQLFunctionCtx
*
pCtx
;
int32_t
rowSize
;
// size of each intermediate result.
int32_t
rowSize
;
// size of each intermediate result.
int32_t
finalRowSize
;
// final result row size
int32_t
status
;
// denote it is in reduce process, in reduce process, it
int32_t
status
;
// denote it is in reduce process, in reduce process, it
bool
hasPrevRow
;
// cannot be released
bool
hasPrevRow
;
// cannot be released
bool
hasUnprocessedRow
;
bool
hasUnprocessedRow
;
...
...
src/client/src/tscFunctionImpl.c
浏览文件 @
00ce6543
...
@@ -65,12 +65,12 @@
...
@@ -65,12 +65,12 @@
} while (0);
} while (0);
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
do {
\
do {
\
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) {
\
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) {
\
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
} \
} \
} while
(0);
} while
(0);
void
noop1
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
))
{}
void
noop1
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
))
{}
void
noop2
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
),
int32_t
UNUSED_PARAM
(
index
))
{}
void
noop2
(
SQLFunctionCtx
*
UNUSED_PARAM
(
pCtx
),
int32_t
UNUSED_PARAM
(
index
))
{}
...
@@ -3624,141 +3624,178 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
...
@@ -3624,141 +3624,178 @@ static bool twa_function_setup(SQLFunctionCtx *pCtx) {
return
false
;
return
false
;
}
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
//->aOutputBuf + pCtx->outputBytes;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pInfo
->
lastKey
=
INT64_MIN
;
pInfo
->
lastKey
=
INT64_MIN
;
pInfo
->
type
=
pCtx
->
inputType
;
pInfo
->
win
=
TSWINDOW_INITIALIZER
;
return
true
;
return
true
;
}
}
static
FORCE_INLINE
void
setTWALastVal
(
SQLFunctionCtx
*
pCtx
,
const
char
*
data
,
int32_t
i
,
STwaInfo
*
pInfo
)
{
static
int32_t
twa_function_impl
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
,
int32_t
size
)
{
switch
(
pCtx
->
inputType
)
{
case
TSDB_DATA_TYPE_INT
:
pInfo
->
iLastValue
=
GET_INT32_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
pInfo
->
iLastValue
=
GET_INT8_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pInfo
->
iLastValue
=
GET_INT16_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pInfo
->
iLastValue
=
GET_INT64_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
pInfo
->
dLastValue
=
GET_FLOAT_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pInfo
->
dLastValue
=
GET_DOUBLE_VAL
(
data
+
pCtx
->
inputBytes
*
i
);
break
;
default:
assert
(
0
);
}
}
static
void
twa_function
(
SQLFunctionCtx
*
pCtx
)
{
void
*
data
=
GET_INPUT_CHAR
(
pCtx
);
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
int32_t
notNullElems
=
0
;
int32_t
notNullElems
=
0
;
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
0
;
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
int32_t
i
=
index
;
// skip null value
if
(
pCtx
->
start
.
key
!=
INT64_MIN
)
{
while
(
pCtx
->
hasNull
&&
i
<
pCtx
->
size
&&
isNull
((
char
*
)
data
+
pCtx
->
inputBytes
*
i
,
pCtx
->
inputType
))
{
assert
(
pCtx
->
start
.
key
<
primaryKey
[
index
]
&&
pInfo
->
lastKey
==
INT64_MIN
);
i
++
;
}
if
(
i
>=
pCtx
->
size
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
return
;
GET_TYPED_DATA
(
pInfo
->
lastValue
,
double
,
pCtx
->
inputType
,
GET_INPUT_CHAR_INDEX
(
pCtx
,
0
));
}
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
pInfo
->
dOutput
+=
((
pInfo
->
lastValue
+
pCtx
->
start
.
val
)
/
2
)
*
(
pInfo
->
lastKey
-
pCtx
->
start
.
key
);
pInfo
->
lastKey
=
pCtx
->
nStartQueryTimestamp
;
setTWALastVal
(
pCtx
,
data
,
i
,
pInfo
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
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
,
0
));
pInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
win
.
skey
=
pInfo
->
lastKey
;
notNullElems
++
;
notNullElems
++
;
i
+=
1
;
}
if
(
pCtx
->
inputType
==
TSDB_DATA_TYPE_FLOAT
||
pCtx
->
inputType
==
TSDB_DATA_TYPE_DOUBLE
)
{
// calculate the value of
pInfo
->
dOutput
+=
pInfo
->
dLastValue
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
switch
(
pCtx
->
inputType
)
{
}
else
{
case
TSDB_DATA_TYPE_TINYINT
:
{
pInfo
->
iOutput
+=
pInfo
->
iLastValue
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
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
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
setTWALastVal
(
pCtx
,
data
,
i
,
pInfo
);
}
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
;
}
for
(
++
i
;
i
<
pCtx
->
size
;
i
++
)
{
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
if
(
pCtx
->
hasNull
&&
isNull
((
char
*
)
data
+
pCtx
->
inputBytes
*
i
,
pCtx
->
inputType
))
{
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
}
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
;
continue
;
}
}
notNullElems
++
;
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
if
(
pCtx
->
inputType
==
TSDB_DATA_TYPE_FLOAT
||
pCtx
->
inputType
==
TSDB_DATA_TYPE_DOUBLE
)
{
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
dOutput
+=
pInfo
->
dLastValue
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
lastKey
=
primaryKey
[
i
];
}
else
{
}
pInfo
->
iOutput
+=
pInfo
->
iLastValue
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
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
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
(
double
)
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
setTWALastVal
(
pCtx
,
data
,
i
,
pInfo
);
}
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
;
}
}
SET_VAL
(
pCtx
,
notNullElems
,
1
);
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
}
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
;
}
if
(
notNullElems
>
0
)
{
pInfo
->
dOutput
+=
((
val
[
i
]
+
pInfo
->
lastValue
)
/
2
)
*
(
primaryKey
[
i
]
-
pInfo
->
lastKey
);
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
pInfo
->
lastValue
=
val
[
i
];
pInfo
->
lastKey
=
primaryKey
[
i
];
}
break
;
}
default:
assert
(
0
);
}
}
if
(
pCtx
->
stableQuery
)
{
// the last interpolated time window value
memcpy
(
pCtx
->
aOutputBuf
,
pInfo
,
sizeof
(
STwaInfo
));
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
;
}
}
// pCtx->numOfIteratedElems += notNullElems;
pInfo
->
win
.
ekey
=
pInfo
->
lastKey
;
return
notNullElems
;
}
}
static
void
twa_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
static
void
twa_function
(
SQLFunctionCtx
*
pCtx
)
{
void
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
void
*
data
=
GET_INPUT_CHAR
(
pCtx
);
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
return
;
}
SET_VAL
(
pCtx
,
1
,
1
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
TSKEY
*
primaryKey
=
pCtx
->
ptsList
;
// skip null value
int32_t
i
=
0
;
while
(
pCtx
->
hasNull
&&
i
<
pCtx
->
size
&&
isNull
((
char
*
)
data
+
pCtx
->
inputBytes
*
i
,
pCtx
->
inputType
))
{
i
++
;
}
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
if
(
i
>=
pCtx
->
size
)
{
STwaInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
return
;
}
if
(
pInfo
->
lastKey
==
INT64_MIN
)
{
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
pCtx
->
startOffset
,
pCtx
->
size
);
pInfo
->
lastKey
=
pCtx
->
nStartQueryTimestamp
;
SET_VAL
(
pCtx
,
notNullElems
,
1
);
setTWALastVal
(
pCtx
,
pData
,
0
,
pInfo
);
pInfo
->
hasResult
=
DATA_SET_FLAG
;
if
(
notNullElems
>
0
)
{
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
}
}
if
(
pCtx
->
inputType
==
TSDB_DATA_TYPE_FLOAT
||
pCtx
->
inputType
==
TSDB_DATA_TYPE_DOUBLE
)
{
if
(
pCtx
->
stableQuery
)
{
pInfo
->
dOutput
+=
pInfo
->
dLastValue
*
(
primaryKey
[
index
]
-
pInfo
->
lastKey
);
memcpy
(
pCtx
->
aOutputBuf
,
pInfo
,
sizeof
(
STwaInfo
));
}
else
{
pInfo
->
iOutput
+=
pInfo
->
iLastValue
*
(
primaryKey
[
index
]
-
pInfo
->
lastKey
);
}
}
}
// record the last key/value
static
void
twa_function_f
(
SQLFunctionCtx
*
pCtx
,
int32_t
index
)
{
pInfo
->
lastKey
=
primaryKey
[
index
];
void
*
pData
=
GET_INPUT_CHAR_INDEX
(
pCtx
,
index
);
setTWALastVal
(
pCtx
,
pData
,
0
,
pInfo
);
if
(
pCtx
->
hasNull
&&
isNull
(
pData
,
pCtx
->
inputType
))
{
return
;
}
// pCtx->numOfIteratedElems += 1
;
int32_t
notNullElems
=
twa_function_impl
(
pCtx
,
index
,
1
)
;
pResInfo
->
hasResult
=
DATA_SET_FLAG
;
SET_VAL
(
pCtx
,
notNullElems
,
1
)
;
if
(
pCtx
->
stableQuery
)
{
if
(
pCtx
->
stableQuery
)
{
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
memcpy
(
pCtx
->
aOutputBuf
,
GET_ROWCELL_INTERBUF
(
pResInfo
),
sizeof
(
STwaInfo
));
memcpy
(
pCtx
->
aOutputBuf
,
GET_ROWCELL_INTERBUF
(
pResInfo
),
sizeof
(
STwaInfo
));
}
}
}
}
...
@@ -3778,16 +3815,10 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
...
@@ -3778,16 +3815,10 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
}
}
numOfNotNull
++
;
numOfNotNull
++
;
if
(
pCtx
->
inputType
>=
TSDB_DATA_TYPE_TINYINT
&&
pCtx
->
inputType
<=
TSDB_DATA_TYPE_BIGINT
)
{
pBuf
->
iOutput
+=
pInput
->
iOutput
;
}
else
{
pBuf
->
dOutput
+=
pInput
->
dOutput
;
pBuf
->
dOutput
+=
pInput
->
dOutput
;
}
pBuf
->
SKey
=
pInput
->
SKey
;
pBuf
->
win
=
pInput
->
win
;
pBuf
->
EKey
=
pInput
->
EKey
;
pBuf
->
lastKey
=
pInput
->
lastKey
;
pBuf
->
lastKey
=
pInput
->
lastKey
;
pBuf
->
iLastValue
=
pInput
->
iLastValue
;
}
}
SET_VAL
(
pCtx
,
numOfNotNull
,
1
);
SET_VAL
(
pCtx
,
numOfNotNull
,
1
);
...
@@ -3814,21 +3845,17 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
...
@@ -3814,21 +3845,17 @@ void twa_function_finalizer(SQLFunctionCtx *pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
STwaInfo
*
pInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
STwaInfo
*
pInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pResInfo
);
assert
(
pInfo
->
EKey
>
=
pInfo
->
lastKey
&&
pInfo
->
hasResult
==
pResInfo
->
hasResult
);
assert
(
pInfo
->
win
.
ekey
=
=
pInfo
->
lastKey
&&
pInfo
->
hasResult
==
pResInfo
->
hasResult
);
if
(
pInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
if
(
pInfo
->
hasResult
!=
DATA_SET_FLAG
)
{
setNull
(
pCtx
->
aOutputBuf
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
setNull
(
pCtx
->
aOutputBuf
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
));
return
;
return
;
}
}
if
(
pInfo
->
SKey
==
pInfo
->
EKey
)
{
if
(
pInfo
->
win
.
ekey
==
pInfo
->
win
.
skey
)
{
*
(
double
*
)
pCtx
->
aOutputBuf
=
0
;
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
lastValue
;
}
else
if
(
pInfo
->
type
>=
TSDB_DATA_TYPE_TINYINT
&&
pInfo
->
type
<=
TSDB_DATA_TYPE_BIGINT
)
{
pInfo
->
iOutput
+=
pInfo
->
iLastValue
*
(
pInfo
->
EKey
-
pInfo
->
lastKey
);
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
iOutput
/
(
double
)(
pInfo
->
EKey
-
pInfo
->
SKey
);
}
else
{
}
else
{
pInfo
->
dOutput
+=
pInfo
->
dLastValue
*
(
pInfo
->
EKey
-
pInfo
->
lastKey
);
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
dOutput
/
(
pInfo
->
win
.
ekey
-
pInfo
->
win
.
skey
);
*
(
double
*
)
pCtx
->
aOutputBuf
=
pInfo
->
dOutput
/
(
pInfo
->
EKey
-
pInfo
->
SKey
);
}
}
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
1
;
GET_RES_INFO
(
pCtx
)
->
numOfRes
=
1
;
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
00ce6543
...
@@ -198,6 +198,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -198,6 +198,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
if
(
numOfFlush
==
0
||
numOfBuffer
==
0
)
{
if
(
numOfFlush
==
0
||
numOfBuffer
==
0
)
{
tscLocalReducerEnvDestroy
(
pMemBuffer
,
pDesc
,
finalmodel
,
pFFModel
,
numOfBuffer
);
tscLocalReducerEnvDestroy
(
pMemBuffer
,
pDesc
,
finalmodel
,
pFFModel
,
numOfBuffer
);
pCmd
->
command
=
TSDB_SQL_RETRIEVE_EMPTY_RESULT
;
// no result, set the result empty
tscDebug
(
"%p retrieved no data"
,
pSql
);
tscDebug
(
"%p retrieved no data"
,
pSql
);
return
;
return
;
}
}
...
@@ -330,22 +331,19 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
...
@@ -330,22 +331,19 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd
pReducer
->
nResultBufSize
=
pMemBuffer
[
0
]
->
pageSize
*
16
;
pReducer
->
nResultBufSize
=
pMemBuffer
[
0
]
->
pageSize
*
16
;
pReducer
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
pReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
pReducer
->
pResultBuf
=
(
tFilePage
*
)
calloc
(
1
,
pReducer
->
nResultBufSize
+
sizeof
(
tFilePage
));
pReducer
->
finalRowSize
=
tscGetResRowLength
(
pQueryInfo
->
exprList
);
pReducer
->
resColModel
=
finalmodel
;
pReducer
->
resColModel
=
finalmodel
;
pReducer
->
resColModel
->
capacity
=
pReducer
->
nResultBufSize
;
pReducer
->
resColModel
->
capacity
=
pReducer
->
nResultBufSize
;
pReducer
->
finalModel
=
pFFModel
;
pReducer
->
finalModel
=
pFFModel
;
assert
(
pReducer
->
finalRowSize
>
0
);
if
(
finalmodel
->
rowSize
>
0
)
{
if
(
pReducer
->
finalRowSize
>
0
)
{
pReducer
->
resColModel
->
capacity
/=
finalmodel
->
rowSize
;
pReducer
->
resColModel
->
capacity
/=
pReducer
->
finalRowSize
;
}
}
assert
(
pReducer
->
finalRowSize
<=
pReducer
->
rowSize
);
assert
(
finalmodel
->
rowSize
>
0
&&
finalmodel
->
rowSize
<=
pReducer
->
rowSize
);
pReducer
->
pFinalRes
=
calloc
(
1
,
pReducer
->
rowSize
*
pReducer
->
resColModel
->
capacity
);
pReducer
->
pFinalRes
=
calloc
(
1
,
pReducer
->
rowSize
*
pReducer
->
resColModel
->
capacity
);
if
(
pReducer
->
pTempBuffer
==
NULL
||
pReducer
->
discardData
==
NULL
||
pReducer
->
pResultBuf
==
NULL
||
if
(
pReducer
->
pTempBuffer
==
NULL
||
pReducer
->
discardData
==
NULL
||
pReducer
->
pResultBuf
==
NULL
||
/*pReducer->pBufForInterpo == NULL || */
pReducer
->
pFinalRes
==
NULL
||
pReducer
->
prevRowOfInput
==
NULL
)
{
pReducer
->
pFinalRes
==
NULL
||
pReducer
->
prevRowOfInput
==
NULL
)
{
tfree
(
pReducer
->
pTempBuffer
);
tfree
(
pReducer
->
pTempBuffer
);
tfree
(
pReducer
->
discardData
);
tfree
(
pReducer
->
discardData
);
tfree
(
pReducer
->
pResultBuf
);
tfree
(
pReducer
->
pResultBuf
);
...
@@ -920,7 +918,7 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
...
@@ -920,7 +918,7 @@ static void genFinalResWithoutFill(SSqlRes* pRes, SLocalReducer *pLocalReducer,
savePrevRecordAndSetupFillInfo
(
pLocalReducer
,
pQueryInfo
,
pLocalReducer
->
pFillInfo
);
savePrevRecordAndSetupFillInfo
(
pLocalReducer
,
pQueryInfo
,
pLocalReducer
->
pFillInfo
);
}
}
memcpy
(
pRes
->
data
,
pBeforeFillData
->
data
,
(
size_t
)(
pRes
->
numOfRows
*
pLocalReducer
->
final
R
owSize
));
memcpy
(
pRes
->
data
,
pBeforeFillData
->
data
,
(
size_t
)(
pRes
->
numOfRows
*
pLocalReducer
->
final
Model
->
r
owSize
));
pRes
->
numOfClauseTotal
+=
pRes
->
numOfRows
;
pRes
->
numOfClauseTotal
+=
pRes
->
numOfRows
;
pBeforeFillData
->
num
=
0
;
pBeforeFillData
->
num
=
0
;
...
@@ -1256,7 +1254,7 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
...
@@ -1256,7 +1254,7 @@ bool genFinalResults(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool noMoreCur
tColModelCompact
(
pModel
,
pResBuf
,
pModel
->
capacity
);
tColModelCompact
(
pModel
,
pResBuf
,
pModel
->
capacity
);
if
(
tscIsSecondStageQuery
(
pQueryInfo
))
{
if
(
tscIsSecondStageQuery
(
pQueryInfo
))
{
pLocalReducer
->
finalRowSize
=
doArithmeticCalculate
(
pQueryInfo
,
pResBuf
,
pModel
->
rowSize
,
pLocalReducer
->
finalR
owSize
);
doArithmeticCalculate
(
pQueryInfo
,
pResBuf
,
pModel
->
rowSize
,
pLocalReducer
->
finalModel
->
r
owSize
);
}
}
#ifdef _DEBUG_VIEW
#ifdef _DEBUG_VIEW
...
@@ -1627,7 +1625,8 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen)
...
@@ -1627,7 +1625,8 @@ void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen)
}
}
int32_t
doArithmeticCalculate
(
SQueryInfo
*
pQueryInfo
,
tFilePage
*
pOutput
,
int32_t
rowSize
,
int32_t
finalRowSize
)
{
int32_t
doArithmeticCalculate
(
SQueryInfo
*
pQueryInfo
,
tFilePage
*
pOutput
,
int32_t
rowSize
,
int32_t
finalRowSize
)
{
char
*
pbuf
=
calloc
(
1
,
pOutput
->
num
*
rowSize
);
int32_t
maxRowSize
=
MAX
(
rowSize
,
finalRowSize
);
char
*
pbuf
=
calloc
(
1
,
pOutput
->
num
*
maxRowSize
);
size_t
size
=
tscNumOfFields
(
pQueryInfo
);
size_t
size
=
tscNumOfFields
(
pQueryInfo
);
SArithmeticSupport
arithSup
=
{
0
};
SArithmeticSupport
arithSup
=
{
0
};
...
@@ -1660,7 +1659,6 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
...
@@ -1660,7 +1659,6 @@ int32_t doArithmeticCalculate(SQueryInfo* pQueryInfo, tFilePage* pOutput, int32_
offset
+=
pSup
->
field
.
bytes
;
offset
+=
pSup
->
field
.
bytes
;
}
}
assert
(
finalRowSize
<=
rowSize
);
memcpy
(
pOutput
->
data
,
pbuf
,
pOutput
->
num
*
offset
);
memcpy
(
pOutput
->
data
,
pbuf
,
pOutput
->
num
*
offset
);
tfree
(
pbuf
);
tfree
(
pbuf
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
00ce6543
...
@@ -4248,7 +4248,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
...
@@ -4248,7 +4248,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
tExprTreeDestroy
(
&
p
,
NULL
);
tExprTreeDestroy
(
&
p
,
NULL
);
taosArrayDestroy
(
colList
);
taosArrayDestroy
(
colList
);
if
(
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
)
>
0
&&
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
if
(
pQueryInfo
->
tagCond
.
pCond
!=
NULL
&&
taosArrayGetSize
(
pQueryInfo
->
tagCond
.
pCond
)
>
0
&&
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"filter on tag not supported for normal table"
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"filter on tag not supported for normal table"
);
}
}
}
}
...
@@ -4256,6 +4256,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
...
@@ -4256,6 +4256,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE
pCondExpr
->
pTagCond
=
NULL
;
pCondExpr
->
pTagCond
=
NULL
;
return
ret
;
return
ret
;
}
}
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tSQLExpr
**
pExpr
,
SSqlObj
*
pSql
)
{
int32_t
parseWhereClause
(
SQueryInfo
*
pQueryInfo
,
tSQLExpr
**
pExpr
,
SSqlObj
*
pSql
)
{
if
(
pExpr
==
NULL
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -6648,7 +6649,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
...
@@ -6648,7 +6649,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSQLExpr* pS
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
{
}
else
{
return
TSDB_CODE_TSC_INVALID_SQL
;
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"not support filter expression"
)
;
}
}
}
else
{
}
else
{
...
...
src/query/inc/qExecutor.h
浏览文件 @
00ce6543
...
@@ -63,9 +63,11 @@ typedef struct SSqlGroupbyExpr {
...
@@ -63,9 +63,11 @@ typedef struct SSqlGroupbyExpr {
typedef
struct
SResultRow
{
typedef
struct
SResultRow
{
int32_t
pageId
;
// pageId & rowId is the position of current result in disk-based output buffer
int32_t
pageId
;
// pageId & rowId is the position of current result in disk-based output buffer
int32_t
rowId
:
15
;
int32_t
rowId
:
29
;
// row index in buffer page
bool
closed
:
1
;
// this result status: closed or opened
bool
startInterp
;
// the time window start timestamp has done the interpolation already.
uint16_t
numOfRows
;
// number of rows of current time window
bool
endInterp
;
// the time window end timestamp has done the interpolation already.
bool
closed
;
// this result status: closed or opened
uint32_t
numOfRows
;
// number of rows of current time window
SResultRowCellInfo
*
pCellInfo
;
// For each result column, there is a resultInfo
SResultRowCellInfo
*
pCellInfo
;
// For each result column, there is a resultInfo
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current time window
union
{
STimeWindow
win
;
char
*
key
;};
// start key of current time window
}
SResultRow
;
}
SResultRow
;
...
@@ -187,6 +189,7 @@ typedef struct SQueryRuntimeEnv {
...
@@ -187,6 +189,7 @@ typedef struct SQueryRuntimeEnv {
bool
topBotQuery
;
// false
bool
topBotQuery
;
// false
bool
groupbyNormalCol
;
// denote if this is a groupby normal column query
bool
groupbyNormalCol
;
// denote if this is a groupby normal column query
bool
hasTagResults
;
// if there are tag values in final result or not
bool
hasTagResults
;
// if there are tag values in final result or not
bool
timeWindowInterpo
;
// if the time window start/end required interpolation
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
prevGroupId
;
// previous executed group id
int32_t
prevGroupId
;
// previous executed group id
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
SDiskbasedResultBuf
*
pResultBuf
;
// query result buffer based on blocked-wised disk file
...
@@ -195,6 +198,8 @@ typedef struct SQueryRuntimeEnv {
...
@@ -195,6 +198,8 @@ typedef struct SQueryRuntimeEnv {
SResultRowPool
*
pool
;
// window result object pool
SResultRowPool
*
pool
;
// window result object pool
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
int32_t
*
rowCellInfoOffset
;
// offset value for each row result cell info
char
**
prevRow
;
char
**
nextRow
;
}
SQueryRuntimeEnv
;
}
SQueryRuntimeEnv
;
enum
{
enum
{
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
00ce6543
...
@@ -152,6 +152,11 @@ typedef struct SResultRowCellInfo {
...
@@ -152,6 +152,11 @@ typedef struct SResultRowCellInfo {
uint32_t
numOfRes
;
// num of output result in current buffer
uint32_t
numOfRes
;
// num of output result in current buffer
}
SResultRowCellInfo
;
}
SResultRowCellInfo
;
typedef
struct
SPoint1
{
int64_t
key
;
double
val
;
}
SPoint1
;
#define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo)))
#define GET_ROWCELL_INTERBUF(_c) ((void*) ((char*)(_c) + sizeof(SResultRowCellInfo)))
struct
SQLFunctionCtx
;
struct
SQLFunctionCtx
;
...
@@ -194,6 +199,8 @@ typedef struct SQLFunctionCtx {
...
@@ -194,6 +199,8 @@ typedef struct SQLFunctionCtx {
SResultRowCellInfo
*
resultInfo
;
SResultRowCellInfo
*
resultInfo
;
SExtTagsInfo
tagInfo
;
SExtTagsInfo
tagInfo
;
SPoint1
start
;
SPoint1
end
;
}
SQLFunctionCtx
;
}
SQLFunctionCtx
;
typedef
struct
SQLAggFuncElem
{
typedef
struct
SQLAggFuncElem
{
...
@@ -245,19 +252,9 @@ enum {
...
@@ -245,19 +252,9 @@ enum {
typedef
struct
STwaInfo
{
typedef
struct
STwaInfo
{
TSKEY
lastKey
;
TSKEY
lastKey
;
int8_t
hasResult
;
// flag to denote has value
int8_t
hasResult
;
// flag to denote has value
int16_t
type
;
// source data type
TSKEY
SKey
;
TSKEY
EKey
;
union
{
double
dOutput
;
double
dOutput
;
int64_t
iOutput
;
double
lastValue
;
};
STimeWindow
win
;
union
{
double
dLastValue
;
int64_t
iLastValue
;
};
}
STwaInfo
;
}
STwaInfo
;
/* global sql function array */
/* global sql function array */
...
@@ -276,8 +273,6 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
...
@@ -276,8 +273,6 @@ bool topbot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, const cha
(_r)->initialized = false; \
(_r)->initialized = false; \
} while (0)
} while (0)
//void setResultInfoBuf(SResultRowCellInfo *pResInfo, char* buf);
static
FORCE_INLINE
void
initResultInfo
(
SResultRowCellInfo
*
pResInfo
,
uint32_t
bufLen
)
{
static
FORCE_INLINE
void
initResultInfo
(
SResultRowCellInfo
*
pResInfo
,
uint32_t
bufLen
)
{
pResInfo
->
initialized
=
true
;
// the this struct has been initialized flag
pResInfo
->
initialized
=
true
;
// the this struct has been initialized flag
...
...
src/query/src/qAst.c
浏览文件 @
00ce6543
...
@@ -370,6 +370,66 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
...
@@ -370,6 +370,66 @@ void tExprTreeTraverse(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, S
#endif
#endif
}
}
static
void
reverseCopy
(
char
*
dest
,
const
char
*
src
,
int16_t
type
,
int32_t
numOfRows
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_TINYINT
:
{
int8_t
*
p
=
(
int8_t
*
)
dest
;
int8_t
*
pSrc
=
(
int8_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
int16_t
*
p
=
(
int16_t
*
)
dest
;
int16_t
*
pSrc
=
(
int16_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
int32_t
*
p
=
(
int32_t
*
)
dest
;
int32_t
*
pSrc
=
(
int32_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
int64_t
*
p
=
(
int64_t
*
)
dest
;
int64_t
*
pSrc
=
(
int64_t
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
p
=
(
float
*
)
dest
;
float
*
pSrc
=
(
float
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
double
*
p
=
(
double
*
)
dest
;
double
*
pSrc
=
(
double
*
)
src
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
p
[
i
]
=
pSrc
[
numOfRows
-
i
-
1
];
}
break
;
}
default:
assert
(
0
);
}
}
void
tExprTreeCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
void
tExprTreeCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
))
{
char
*
(
*
getSourceDataBlock
)(
void
*
,
const
char
*
,
int32_t
))
{
if
(
pExprs
==
NULL
)
{
if
(
pExprs
==
NULL
)
{
...
@@ -387,6 +447,8 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
...
@@ -387,6 +447,8 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
/* the right output has result from the right child syntax tree */
/* the right output has result from the right child syntax tree */
char
*
pRightOutput
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
char
*
pRightOutput
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
char
*
pdata
=
malloc
(
sizeof
(
int64_t
)
*
numOfRows
);
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
tExprTreeCalcTraverse
(
pRight
,
numOfRows
,
pRightOutput
,
param
,
order
,
getSourceDataBlock
);
tExprTreeCalcTraverse
(
pRight
,
numOfRows
,
pRightOutput
,
param
,
order
,
getSourceDataBlock
);
}
}
...
@@ -398,52 +460,75 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
...
@@ -398,52 +460,75 @@ void tExprTreeCalcTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput,
* the type of returned value of one expression is always double float precious
* the type of returned value of one expression is always double float precious
*/
*/
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
pLeftOutput
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
fp
(
pLeftOutput
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// exprLeft + columnRight
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// exprLeft + columnRight
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
// set input buffer
// set input buffer
char
*
pInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
char
*
pInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
fp
(
pLeftOutput
,
pInputData
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pInputData
,
pRight
->
pSchema
->
type
,
numOfRows
);
fp
(
pLeftOutput
,
pdata
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftOutput
,
pInputData
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// exprLeft + 12
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// exprLeft + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
TSDB_DATA_TYPE_DOUBLE
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
pLeftOutput
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
order
);
fp
(
pLeftOutput
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
}
else
if
(
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
}
else
if
(
pLeft
->
nodeType
==
TSQL_NODE_COL
)
{
// column data specified on left-hand-side
// column data specified on left-hand-side
char
*
pLeftInputData
=
getSourceDataBlock
(
param
,
pLeft
->
pSchema
->
name
,
pLeft
->
pSchema
->
colId
);
char
*
pLeftInputData
=
getSourceDataBlock
(
param
,
pLeft
->
pSchema
->
name
,
pLeft
->
pSchema
->
colId
);
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// columnLeft + expr2
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// columnLeft + expr2
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pLeftInputData
,
pLeft
->
pSchema
->
type
,
numOfRows
);
fp
(
pdata
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftInputData
,
pRightOutput
,
numOfRows
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// columnLeft + columnRight
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// columnLeft + columnRight
// column data specified on right-hand-side
// column data specified on right-hand-side
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
pRightInputData
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
// both columns are descending order, do not reverse the source data
fp
(
pLeftInputData
,
pRightInputData
,
numOfRows
,
numOfRows
,
pOutput
,
order
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// columnLeft + 12
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// columnLeft + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pSchema
->
type
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
pLeftInputData
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pLeftInputData
,
pLeft
->
pSchema
->
type
,
numOfRows
);
fp
(
pdata
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
pLeftInputData
,
&
pRight
->
pVal
->
i64Key
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
}
}
else
{
}
else
{
// column data specified on left-hand-side
// column data specified on left-hand-side
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// 12 + expr2
if
(
pRight
->
nodeType
==
TSQL_NODE_EXPR
)
{
// 12 + expr2
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
TSDB_DATA_TYPE_DOUBLE
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightOutput
,
1
,
numOfRows
,
pOutput
,
order
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightOutput
,
1
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// 12 + columnRight
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_COL
)
{
// 12 + columnRight
// column data specified on right-hand-side
// column data specified on right-hand-side
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
char
*
pRightInputData
=
getSourceDataBlock
(
param
,
pRight
->
pSchema
->
name
,
pRight
->
pSchema
->
colId
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pSchema
->
type
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightInputData
,
1
,
numOfRows
,
pOutput
,
order
);
if
(
order
==
TSDB_ORDER_DESC
)
{
reverseCopy
(
pdata
,
pRightInputData
,
pRight
->
pSchema
->
type
,
numOfRows
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
pdata
,
numOfRows
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
else
{
fp
(
&
pLeft
->
pVal
->
i64Key
,
pRightInputData
,
1
,
numOfRows
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// 12 + 12
}
else
if
(
pRight
->
nodeType
==
TSQL_NODE_VALUE
)
{
// 12 + 12
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
_bi_consumer_fn_t
fp
=
tGetBiConsumerFn
(
pLeft
->
pVal
->
nType
,
pRight
->
pVal
->
nType
,
pExprs
->
_node
.
optr
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
&
pRight
->
pVal
->
i64Key
,
1
,
1
,
pOutput
,
order
);
fp
(
&
pLeft
->
pVal
->
i64Key
,
&
pRight
->
pVal
->
i64Key
,
1
,
1
,
pOutput
,
TSDB_ORDER_ASC
);
}
}
}
}
...
...
src/query/src/qExecutor.c
浏览文件 @
00ce6543
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include "query.h"
#include "query.h"
#include "queryLog.h"
#include "queryLog.h"
#include "tlosertree.h"
#include "tlosertree.h"
#include "ttype.h"
#define MAX_ROWS_PER_RESBUF_PAGE ((1u<<12) - 1)
#define MAX_ROWS_PER_RESBUF_PAGE ((1u<<12) - 1)
...
@@ -194,6 +195,7 @@ static int32_t setAdditionalInfo(SQInfo *pQInfo, void *pTable, STableQueryInfo *
...
@@ -194,6 +195,7 @@ static int32_t setAdditionalInfo(SQInfo *pQInfo, void *pTable, STableQueryInfo *
static
int32_t
flushFromResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
);
static
int32_t
flushFromResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SGroupResInfo
*
pGroupResInfo
);
static
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
static
int32_t
checkForQueryBuf
(
size_t
numOfTables
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
void
releaseQueryBuf
(
size_t
numOfTables
);
static
int32_t
binarySearchForKey
(
char
*
pValue
,
int
num
,
TSKEY
key
,
int
order
);
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
bool
doFilterData
(
SQuery
*
pQuery
,
int32_t
elemPos
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfFilterCols
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfFilterCols
;
++
k
)
{
...
@@ -400,6 +402,17 @@ static bool isTopBottomQuery(SQuery *pQuery) {
...
@@ -400,6 +402,17 @@ static bool isTopBottomQuery(SQuery *pQuery) {
return
false
;
return
false
;
}
}
static
bool
timeWindowInterpoRequired
(
SQuery
*
pQuery
)
{
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
pQuery
->
pExpr1
[
i
].
base
.
functionId
;
if
(
functionId
==
TSDB_FUNC_TWA
)
{
return
true
;
}
}
return
false
;
}
static
bool
hasTagValOutput
(
SQuery
*
pQuery
)
{
static
bool
hasTagValOutput
(
SQuery
*
pQuery
)
{
SExprInfo
*
pExprInfo
=
&
pQuery
->
pExpr1
[
0
];
SExprInfo
*
pExprInfo
=
&
pQuery
->
pExpr1
[
0
];
if
(
pQuery
->
numOfOutput
==
1
&&
pExprInfo
->
base
.
functionId
==
TSDB_FUNC_TS_COMP
)
{
if
(
pQuery
->
numOfOutput
==
1
&&
pExprInfo
->
base
.
functionId
==
TSDB_FUNC_TS_COMP
)
{
...
@@ -457,6 +470,7 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin
...
@@ -457,6 +470,7 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SWin
return
NULL
;
return
NULL
;
}
}
// TODO refactor
// more than the capacity, reallocate the resources
// more than the capacity, reallocate the resources
if
(
pWindowResInfo
->
size
>=
pWindowResInfo
->
capacity
)
{
if
(
pWindowResInfo
->
size
>=
pWindowResInfo
->
capacity
)
{
int64_t
newCapacity
=
0
;
int64_t
newCapacity
=
0
;
...
@@ -595,14 +609,17 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
...
@@ -595,14 +609,17 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf
}
}
static
int32_t
setWindowOutputBufByKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResInfo
*
pWindowResInfo
,
SDataBlockInfo
*
pBockInfo
,
static
int32_t
setWindowOutputBufByKey
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResInfo
*
pWindowResInfo
,
SDataBlockInfo
*
pBockInfo
,
STimeWindow
*
win
,
bool
masterscan
,
bool
*
newWind
)
{
STimeWindow
*
win
,
bool
masterscan
,
bool
*
newWind
,
SResultRow
**
pResult
)
{
assert
(
win
->
skey
<=
win
->
ekey
);
assert
(
win
->
skey
<=
win
->
ekey
);
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SDiskbasedResultBuf
*
pResultBuf
=
pRuntimeEnv
->
pResultBuf
;
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pWindowResInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
pBockInfo
->
uid
);
// todo refactor
int64_t
uid
=
getResultInfoUId
(
pRuntimeEnv
);
SResultRow
*
pResultRow
=
doPrepareResultRowFromKey
(
pRuntimeEnv
,
pWindowResInfo
,
(
char
*
)
&
win
->
skey
,
TSDB_KEYSIZE
,
masterscan
,
uid
);
if
(
pResultRow
==
NULL
)
{
if
(
pResultRow
==
NULL
)
{
*
newWind
=
false
;
*
newWind
=
false
;
// no master scan, no result generated means error occurs
return
masterscan
?
-
1
:
0
;
return
masterscan
?
-
1
:
0
;
}
}
...
@@ -618,15 +635,40 @@ static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowRes
...
@@ -618,15 +635,40 @@ static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowRes
// set time window for current result
// set time window for current result
pResultRow
->
win
=
(
*
win
);
pResultRow
->
win
=
(
*
win
);
*
pResult
=
pResultRow
;
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
);
setResultRowOutputBufInitCtx
(
pRuntimeEnv
,
pResultRow
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
get
TimeWindowRes
Status
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
)
{
static
bool
get
ResultRow
Status
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
)
{
assert
(
slot
>=
0
&&
slot
<
pWindowResInfo
->
size
);
assert
(
slot
>=
0
&&
slot
<
pWindowResInfo
->
size
);
return
pWindowResInfo
->
pResult
[
slot
]
->
closed
;
return
pWindowResInfo
->
pResult
[
slot
]
->
closed
;
}
}
typedef
enum
SResultTsInterpType
{
RESULT_ROW_START_INTERP
=
1
,
RESULT_ROW_END_INTERP
=
2
,
}
SResultTsInterpType
;
static
void
setResultRowInterpo
(
SResultRow
*
pResult
,
SResultTsInterpType
type
)
{
assert
(
pResult
!=
NULL
&&
(
type
==
RESULT_ROW_START_INTERP
||
type
==
RESULT_ROW_END_INTERP
));
if
(
type
==
RESULT_ROW_START_INTERP
)
{
pResult
->
startInterp
=
true
;
}
else
{
pResult
->
endInterp
=
true
;
}
}
static
bool
isResultRowInterpo
(
SResultRow
*
pResult
,
SResultTsInterpType
type
)
{
assert
(
pResult
!=
NULL
&&
(
type
==
RESULT_ROW_START_INTERP
||
type
==
RESULT_ROW_END_INTERP
));
if
(
type
==
RESULT_ROW_START_INTERP
)
{
return
pResult
->
startInterp
==
true
;
}
else
{
return
pResult
->
endInterp
==
true
;
}
}
static
FORCE_INLINE
int32_t
getForwardStepsInBlock
(
int32_t
numOfRows
,
__block_search_fn_t
searchFn
,
TSKEY
ekey
,
int16_t
pos
,
static
FORCE_INLINE
int32_t
getForwardStepsInBlock
(
int32_t
numOfRows
,
__block_search_fn_t
searchFn
,
TSKEY
ekey
,
int16_t
pos
,
int16_t
order
,
int64_t
*
pData
)
{
int16_t
order
,
int64_t
*
pData
)
{
int32_t
forwardStep
=
0
;
int32_t
forwardStep
=
0
;
...
@@ -990,6 +1032,113 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
...
@@ -990,6 +1032,113 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
return
dataBlock
;
return
dataBlock
;
}
}
// window start key interpolation
static
bool
setTimeWindowInterpolationStartTs
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
pos
,
SArray
*
pDataBlock
,
TSKEY
*
tsCols
,
STimeWindow
*
win
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
TSKEY
start
=
tsCols
[
pos
];
TSKEY
lastTs
=
*
(
TSKEY
*
)
pRuntimeEnv
->
prevRow
[
0
];
TSKEY
prevTs
=
(
pos
==
0
)
?
lastTs
:
tsCols
[
pos
-
1
];
// if lastTs == INT64_MIN, it is the first block, no need to do the start time interpolation
if
(((
lastTs
!=
INT64_MIN
&&
pos
>=
0
)
||
(
lastTs
==
INT64_MIN
&&
pos
>
0
))
&&
win
->
skey
>
lastTs
&&
win
->
skey
<
start
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
k
);
if
(
k
==
0
&&
pColInfo
->
info
.
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
assert
(
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
continue
;
}
double
v1
=
0
,
v2
=
0
,
v
=
0
;
char
*
prevVal
=
pos
==
0
?
pRuntimeEnv
->
prevRow
[
k
]
:
((
char
*
)
pColInfo
->
pData
)
+
(
pos
-
1
)
*
pColInfo
->
info
.
bytes
;
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
prevVal
);
GET_TYPED_DATA
(
v2
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pColInfo
->
pData
+
pos
*
pColInfo
->
info
.
bytes
);
SPoint
point1
=
(
SPoint
){.
key
=
prevTs
,
.
val
=
&
v1
};
SPoint
point2
=
(
SPoint
){.
key
=
start
,
.
val
=
&
v2
};
SPoint
point
=
(
SPoint
){.
key
=
win
->
skey
,
.
val
=
&
v
};
taosGetLinearInterpolationVal
(
TSDB_DATA_TYPE_DOUBLE
,
&
point1
,
&
point2
,
&
point
);
pRuntimeEnv
->
pCtx
[
k
].
start
.
key
=
point
.
key
;
pRuntimeEnv
->
pCtx
[
k
].
start
.
val
=
v
;
}
return
true
;
}
else
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
pRuntimeEnv
->
pCtx
[
k
].
start
.
key
=
INT64_MIN
;
}
return
false
;
}
}
static
bool
setTimeWindowInterpolationEndTs
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
int32_t
pos
,
SArray
*
pDataBlock
,
TSKEY
*
tsCols
,
TSKEY
ekey
,
STimeWindow
*
win
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
TSKEY
trueEndKey
=
tsCols
[
pos
];
if
(
win
->
ekey
<
ekey
&&
win
->
ekey
!=
trueEndKey
)
{
int32_t
nextIndex
=
pos
+
1
;
TSKEY
next
=
tsCols
[
nextIndex
];
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
k
);
if
(
k
==
0
&&
pColInfo
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
&&
pColInfo
->
info
.
colId
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
continue
;
}
double
v1
=
0
,
v2
=
0
,
v
=
0
;
GET_TYPED_DATA
(
v1
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pColInfo
->
pData
+
pos
*
pColInfo
->
info
.
bytes
);
GET_TYPED_DATA
(
v2
,
double
,
pColInfo
->
info
.
type
,
(
char
*
)
pColInfo
->
pData
+
nextIndex
*
pColInfo
->
info
.
bytes
);
SPoint
point1
=
(
SPoint
){.
key
=
trueEndKey
,
.
val
=
&
v1
};
SPoint
point2
=
(
SPoint
){.
key
=
next
,
.
val
=
&
v2
};
SPoint
point
=
(
SPoint
){.
key
=
win
->
ekey
,
.
val
=
&
v
};
taosGetLinearInterpolationVal
(
TSDB_DATA_TYPE_DOUBLE
,
&
point1
,
&
point2
,
&
point
);
pRuntimeEnv
->
pCtx
[
k
].
end
.
key
=
point
.
key
;
pRuntimeEnv
->
pCtx
[
k
].
end
.
val
=
v
;
}
return
true
;
}
else
{
// current time window does not ended in current data block, do nothing
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
pRuntimeEnv
->
pCtx
[
k
].
end
.
key
=
INT64_MIN
;
}
return
false
;
}
}
static
void
saveDataBlockLastRow
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataBlockInfo
*
pDataBlockInfo
,
SArray
*
pDataBlock
)
{
if
(
pDataBlock
==
NULL
)
{
return
;
}
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfCols
;
++
k
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
k
);
memcpy
(
pRuntimeEnv
->
prevRow
[
k
],
((
char
*
)
pColInfo
->
pData
)
+
(
pColInfo
->
info
.
bytes
*
(
pDataBlockInfo
->
rows
-
1
)),
pColInfo
->
info
.
bytes
);
}
}
static
TSKEY
getStartTsKey
(
SQuery
*
pQuery
,
SDataBlockInfo
*
pDataBlockInfo
,
TSKEY
*
tsCols
,
int32_t
step
)
{
TSKEY
ts
=
TSKEY_INITIAL_VAL
;
if
(
tsCols
==
NULL
)
{
ts
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
skey
:
pDataBlockInfo
->
window
.
ekey
;
}
else
{
int32_t
offset
=
GET_COL_DATA_POS
(
pQuery
,
0
,
step
);
ts
=
tsCols
[
offset
];
}
return
ts
;
}
/**
/**
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
* @param pRuntimeEnv
* @param pRuntimeEnv
...
@@ -1000,16 +1149,15 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
...
@@ -1000,16 +1149,15 @@ static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas
* @return the incremental number of output value, so it maybe 0 for fixed number of query,
* @return the incremental number of output value, so it maybe 0 for fixed number of query,
* such as count/min/max etc.
* such as count/min/max etc.
*/
*/
static
void
blockwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
static
void
blockwiseApplyFunctions
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SDataStatis
*
pStatis
,
SDataBlockInfo
*
pDataBlockInfo
,
SDataBlockInfo
*
pDataBlockInfo
,
SWindowResInfo
*
pWindowResInfo
,
SWindowResInfo
*
pWindowResInfo
,
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
__block_search_fn_t
searchFn
,
SArray
*
pDataBlock
)
{
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
SQLFunctionCtx
*
pCtx
=
pRuntimeEnv
->
pCtx
;
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
TSKEY
*
tsCols
=
NULL
;
TSKEY
*
tsCols
=
NULL
;
if
(
pDataBlock
!=
NULL
)
{
if
(
pDataBlock
!=
NULL
)
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pDataBlock
,
0
);
tsCols
=
(
TSKEY
*
)(
pColInfo
->
pData
);
tsCols
=
(
TSKEY
*
)(
pColInfo
->
pData
);
}
}
...
@@ -1018,7 +1166,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1018,7 +1166,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
SQInfo
*
pQInfo
=
GET_QINFO_ADDR
(
pRuntimeEnv
);
SQInfo
*
pQInfo
=
GET_QINFO_ADDR
(
pRuntimeEnv
);
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
char
*
dataBlock
=
getDataBlock
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
rows
,
pDataBlock
);
char
*
dataBlock
=
getDataBlock
(
pRuntimeEnv
,
&
sasArray
[
k
],
k
,
pDataBlockInfo
->
rows
,
pDataBlock
);
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
tsCols
,
pDataBlockInfo
,
pStatis
,
&
sasArray
[
k
],
k
,
pQInfo
->
vgId
);
setExecParams
(
pQuery
,
&
pCtx
[
k
],
dataBlock
,
tsCols
,
pDataBlockInfo
,
pStatis
,
&
sasArray
[
k
],
k
,
pQInfo
->
vgId
);
...
@@ -1026,18 +1174,13 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1026,18 +1174,13 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
TSKEY
ts
=
TSKEY_INITIAL_VAL
;
TSKEY
ts
=
getStartTsKey
(
pQuery
,
pDataBlockInfo
,
tsCols
,
step
);
if
(
tsCols
==
NULL
)
{
ts
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pDataBlockInfo
->
window
.
skey
:
pDataBlockInfo
->
window
.
ekey
;
}
else
{
int32_t
offset
=
GET_COL_DATA_POS
(
pQuery
,
0
,
step
);
ts
=
tsCols
[
offset
];
}
bool
hasTimeWindow
=
false
;
bool
hasTimeWindow
=
false
;
SResultRow
*
pResult
=
NULL
;
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
)
!=
TSDB_CODE_SUCCESS
)
{
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
sasArray
);
tfree
(
sasArray
);
return
;
return
;
}
}
...
@@ -1045,11 +1188,32 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1045,11 +1188,32 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
int32_t
forwardStep
=
0
;
int32_t
forwardStep
=
0
;
int32_t
startPos
=
pQuery
->
pos
;
int32_t
startPos
=
pQuery
->
pos
;
// in case of repeat scan/reverse scan, no new time window added.
if
(
hasTimeWindow
)
{
if
(
hasTimeWindow
)
{
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
win
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
pQuery
->
pos
,
ekey
,
searchFn
,
true
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
pQuery
->
pos
,
ekey
,
searchFn
,
true
);
bool
pStatus
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
// window start key interpolation
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
bool
alreadyInterp
=
isResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
alreadyInterp
)
{
bool
interp
=
setTimeWindowInterpolationStartTs
(
pRuntimeEnv
,
pQuery
->
pos
,
pDataBlock
,
tsCols
,
&
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
}
alreadyInterp
=
isResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
if
(
!
alreadyInterp
)
{
bool
interp
=
setTimeWindowInterpolationEndTs
(
pRuntimeEnv
,
pQuery
->
pos
+
forwardStep
-
1
,
pDataBlock
,
tsCols
,
pDataBlockInfo
->
window
.
ekey
,
&
win
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
}
}
}
bool
pStatus
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
pStatus
,
&
win
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
pStatus
,
&
win
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
}
}
...
@@ -1065,7 +1229,8 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1065,7 +1229,8 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
// null data, failed to allocate more memory buffer
// null data, failed to allocate more memory buffer
hasTimeWindow
=
false
;
hasTimeWindow
=
false
;
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
break
;
}
}
...
@@ -1076,7 +1241,26 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1076,7 +1241,26 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
nextWin
);
TSKEY
ekey
=
reviseWindowEkey
(
pQuery
,
&
nextWin
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
startPos
,
ekey
,
searchFn
,
true
);
forwardStep
=
getNumOfRowsInTimeWindow
(
pQuery
,
pDataBlockInfo
,
tsCols
,
startPos
,
ekey
,
searchFn
,
true
);
bool
closed
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
// window start(end) key interpolation
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
bool
alreadyInterp
=
isResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
if
(
!
alreadyInterp
)
{
bool
interp
=
setTimeWindowInterpolationStartTs
(
pRuntimeEnv
,
startPos
,
pDataBlock
,
tsCols
,
&
nextWin
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_START_INTERP
);
}
}
alreadyInterp
=
isResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
if
(
!
alreadyInterp
)
{
bool
interp
=
setTimeWindowInterpolationEndTs
(
pRuntimeEnv
,
startPos
+
forwardStep
-
1
,
pDataBlock
,
tsCols
,
pDataBlockInfo
->
window
.
ekey
,
&
nextWin
);
if
(
interp
)
{
setResultRowInterpo
(
pResult
,
RESULT_ROW_END_INTERP
);
}
}
}
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
doBlockwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
startPos
,
forwardStep
,
tsCols
,
pDataBlockInfo
->
rows
);
}
}
...
@@ -1090,12 +1274,17 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
...
@@ -1090,12 +1274,17 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutput
;
++
k
)
{
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
int32_t
functionId
=
pQuery
->
pExpr1
[
k
].
base
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
pCtx
[
k
].
nStartQueryTimestamp
=
pDataBlockInfo
->
window
.
skey
;
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
}
}
}
}
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
if
(
pRuntimeEnv
->
timeWindowInterpo
)
{
saveDataBlockLastRow
(
pRuntimeEnv
,
pDataBlockInfo
,
pDataBlock
);
}
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
if
(
pQuery
->
pExpr1
[
i
].
base
.
functionId
!=
TSDB_FUNC_ARITHM
)
{
if
(
pQuery
->
pExpr1
[
i
].
base
.
functionId
!=
TSDB_FUNC_ARITHM
)
{
continue
;
continue
;
}
}
...
@@ -1318,20 +1507,20 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1318,20 +1507,20 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
pQuery
->
order
.
order
,
pRuntimeEnv
->
pTSBuf
->
cur
.
order
);
pQuery
->
order
.
order
,
pRuntimeEnv
->
pTSBuf
->
cur
.
order
);
}
}
int32_t
j
=
0
;
int32_t
offset
=
-
1
;
int32_t
offset
=
-
1
;
// TSKEY prev = -1;
for
(
j
=
0
;
j
<
pDataBlockInfo
->
rows
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pDataBlockInfo
->
rows
;
++
j
)
{
offset
=
GET_COL_DATA_POS
(
pQuery
,
j
,
step
);
offset
=
GET_COL_DATA_POS
(
pQuery
,
j
,
step
);
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
int32_t
r
=
doTSJoinFilter
(
pRuntimeEnv
,
offset
);
int32_t
r
et
=
doTSJoinFilter
(
pRuntimeEnv
,
offset
);
if
(
r
==
TS_JOIN_TAG_NOT_EQUALS
)
{
if
(
r
et
==
TS_JOIN_TAG_NOT_EQUALS
)
{
break
;
break
;
}
else
if
(
r
==
TS_JOIN_TS_NOT_EQUALS
)
{
}
else
if
(
r
et
==
TS_JOIN_TS_NOT_EQUALS
)
{
continue
;
continue
;
}
else
{
}
else
{
assert
(
r
==
TS_JOIN_TS_EQUAL
);
assert
(
r
et
==
TS_JOIN_TS_EQUAL
);
}
}
}
}
...
@@ -1345,7 +1534,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1345,7 +1534,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
ts
,
pQuery
);
bool
hasTimeWindow
=
false
;
bool
hasTimeWindow
=
false
;
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
);
SResultRow
*
pResult
=
NULL
;
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
continue
;
continue
;
}
}
...
@@ -1353,8 +1543,28 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1353,8 +1543,28 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
if
(
!
hasTimeWindow
)
{
if
(
!
hasTimeWindow
)
{
continue
;
continue
;
}
}
/*
// window start key interpolation
if (pRuntimeEnv->timeWindowInterpo) {
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
if (!alreadyInterp) {
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, pos, pDataBlock, tsCols, &win);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
}
}
bool
closed
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
if (!alreadyInterp) {
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, pQuery->pos + forwardStep - 1, pDataBlock, tsCols,
pDataBlockInfo->window.ekey, &win);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
}
}
}
*/
bool
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
win
,
offset
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
win
,
offset
);
STimeWindow
nextWin
=
win
;
STimeWindow
nextWin
=
win
;
...
@@ -1373,12 +1583,32 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1373,12 +1583,32 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
// null data, failed to allocate more memory buffer
// null data, failed to allocate more memory buffer
hasTimeWindow
=
false
;
hasTimeWindow
=
false
;
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pDataBlockInfo
,
&
nextWin
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
TSDB_CODE_SUCCESS
)
{
break
;
break
;
}
}
if
(
hasTimeWindow
)
{
if
(
hasTimeWindow
)
{
closed
=
getTimeWindowResStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
/*
// window start(end) key interpolation
if (pRuntimeEnv->timeWindowInterpo) {
bool alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
if (!alreadyInterp) {
bool interp = setTimeWindowInterpolationStartTs(pRuntimeEnv, startPos, pDataBlock, tsCols, &nextWin);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
}
}
alreadyInterp = isResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
if (!alreadyInterp) {
bool interp = setTimeWindowInterpolationEndTs(pRuntimeEnv, startPos + forwardStep - 1, pDataBlock, tsCols, pDataBlockInfo->window.ekey, &nextWin);
if (interp) {
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
}
}
}
*/
closed
=
getResultRowStatus
(
pWindowResInfo
,
curTimeWindowIndex
(
pWindowResInfo
));
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
offset
);
doRowwiseApplyFunctions
(
pRuntimeEnv
,
closed
,
&
nextWin
,
offset
);
}
}
}
}
...
@@ -1403,6 +1633,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
...
@@ -1403,6 +1633,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS
}
}
}
}
// prev = tsCols[offset];
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
if
(
pRuntimeEnv
->
pTSBuf
!=
NULL
)
{
// if timestamp filter list is empty, quit current query
// if timestamp filter list is empty, quit current query
if
(
!
tsBufNextPos
(
pRuntimeEnv
->
pTSBuf
))
{
if
(
!
tsBufNextPos
(
pRuntimeEnv
->
pTSBuf
))
{
...
@@ -1528,10 +1760,10 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData, TSKEY
...
@@ -1528,10 +1760,10 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void* inputData, TSKEY
* top/bottom values emerge, so does diff function
* top/bottom values emerge, so does diff function
*/
*/
if
(
functionId
==
TSDB_FUNC_TWA
)
{
if
(
functionId
==
TSDB_FUNC_TWA
)
{
SResultRowCellInfo
*
pInfo
=
GET_RES_INFO
(
pCtx
)
;
pCtx
->
param
[
1
].
i64Key
=
pQuery
->
window
.
skey
;
STwaInfo
*
pTWAInfo
=
(
STwaInfo
*
)
GET_ROWCELL_INTERBUF
(
pInfo
)
;
pCtx
->
param
[
1
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
pTWAInfo
->
SKey
=
pQuery
->
window
.
s
key
;
pCtx
->
param
[
2
].
i64Key
=
pQuery
->
window
.
e
key
;
pTWAInfo
->
EKey
=
pQuery
->
window
.
ekey
;
pCtx
->
param
[
2
].
nType
=
TSDB_DATA_TYPE_BIGINT
;
}
}
}
else
if
(
functionId
==
TSDB_FUNC_ARITHM
)
{
}
else
if
(
functionId
==
TSDB_FUNC_ARITHM
)
{
...
@@ -1677,6 +1909,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
...
@@ -1677,6 +1909,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
pCtx
->
functionId
=
pSqlFuncMsg
->
functionId
;
pCtx
->
functionId
=
pSqlFuncMsg
->
functionId
;
pCtx
->
stableQuery
=
pRuntimeEnv
->
stableQuery
;
pCtx
->
stableQuery
=
pRuntimeEnv
->
stableQuery
;
pCtx
->
interBufBytes
=
pQuery
->
pExpr1
[
i
].
interBytes
;
pCtx
->
interBufBytes
=
pQuery
->
pExpr1
[
i
].
interBytes
;
pCtx
->
start
.
key
=
INT64_MIN
;
pCtx
->
end
.
key
=
INT64_MIN
;
pCtx
->
numOfParams
=
pSqlFuncMsg
->
numOfParams
;
pCtx
->
numOfParams
=
pSqlFuncMsg
->
numOfParams
;
for
(
int32_t
j
=
0
;
j
<
pCtx
->
numOfParams
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pCtx
->
numOfParams
;
++
j
)
{
...
@@ -1711,6 +1945,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
...
@@ -1711,6 +1945,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order
}
}
*
(
int64_t
*
)
pRuntimeEnv
->
prevRow
[
0
]
=
INT64_MIN
;
// if it is group by normal column, do not set output buffer, the output buffer is pResult
// if it is group by normal column, do not set output buffer, the output buffer is pResult
// fixed output query/multi-output query for normal table
// fixed output query/multi-output query for normal table
if
(
!
pRuntimeEnv
->
groupbyNormalCol
&&
!
pRuntimeEnv
->
stableQuery
&&
!
QUERY_IS_INTERVAL_QUERY
(
pRuntimeEnv
->
pQuery
))
{
if
(
!
pRuntimeEnv
->
groupbyNormalCol
&&
!
pRuntimeEnv
->
stableQuery
&&
!
QUERY_IS_INTERVAL_QUERY
(
pRuntimeEnv
->
pQuery
))
{
...
@@ -1781,6 +2017,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
...
@@ -1781,6 +2017,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
tfree
(
pRuntimeEnv
->
offset
);
tfree
(
pRuntimeEnv
->
offset
);
tfree
(
pRuntimeEnv
->
keyBuf
);
tfree
(
pRuntimeEnv
->
keyBuf
);
tfree
(
pRuntimeEnv
->
rowCellInfoOffset
);
tfree
(
pRuntimeEnv
->
rowCellInfoOffset
);
tfree
(
pRuntimeEnv
->
prevRow
);
taosHashCleanup
(
pRuntimeEnv
->
pResultRowHashTable
);
taosHashCleanup
(
pRuntimeEnv
->
pResultRowHashTable
);
pRuntimeEnv
->
pResultRowHashTable
=
NULL
;
pRuntimeEnv
->
pResultRowHashTable
=
NULL
;
...
@@ -2279,12 +2516,14 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo * pW
...
@@ -2279,12 +2516,14 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo * pW
// the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer
// the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
bool
hasTimeWindow
=
false
;
bool
hasTimeWindow
=
false
;
SResultRow
*
pResult
=
NULL
;
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
TSKEY
k
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlockInfo
->
window
.
skey
:
pBlockInfo
->
window
.
ekey
;
TSKEY
k
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
pBlockInfo
->
window
.
skey
:
pBlockInfo
->
window
.
ekey
;
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
k
,
pQuery
);
STimeWindow
win
=
getActiveTimeWindow
(
pWindowResInfo
,
k
,
pQuery
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
)
!=
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pBlockInfo
,
&
win
,
masterScan
,
&
hasTimeWindow
,
&
pResult
)
!=
TSDB_CODE_SUCCESS
)
{
TSDB_CODE_SUCCESS
)
{
// todo handle error in set result for timewindow
// todo handle error in set result for timewindow
}
}
...
@@ -3266,7 +3505,7 @@ static void disableFuncInReverseScanImpl(SQueryRuntimeEnv* pRuntimeEnv, SWindowR
...
@@ -3266,7 +3505,7 @@ static void disableFuncInReverseScanImpl(SQueryRuntimeEnv* pRuntimeEnv, SWindowR
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
bool
closed
=
get
TimeWindowRes
Status
(
pWindowResInfo
,
i
);
bool
closed
=
get
ResultRow
Status
(
pWindowResInfo
,
i
);
if
(
!
closed
)
{
if
(
!
closed
)
{
continue
;
continue
;
}
}
...
@@ -4617,6 +4856,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
...
@@ -4617,6 +4856,7 @@ int32_t doInitQInfo(SQInfo *pQInfo, STSBuf *pTsBuf, void *tsdb, int32_t vgId, bo
pRuntimeEnv
->
topBotQuery
=
isTopBottomQuery
(
pQuery
);
pRuntimeEnv
->
topBotQuery
=
isTopBottomQuery
(
pQuery
);
pRuntimeEnv
->
hasTagResults
=
hasTagValOutput
(
pQuery
);
pRuntimeEnv
->
hasTagResults
=
hasTagValOutput
(
pQuery
);
pRuntimeEnv
->
timeWindowInterpo
=
timeWindowInterpoRequired
(
pQuery
);
setScanLimitationByResultBuffer
(
pQuery
);
setScanLimitationByResultBuffer
(
pQuery
);
...
@@ -6447,9 +6687,11 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
...
@@ -6447,9 +6687,11 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
goto
_cleanup
;
goto
_cleanup
;
}
}
int32_t
srcSize
=
0
;
for
(
int16_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int16_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
pQuery
->
colList
[
i
]
=
pQueryMsg
->
colList
[
i
];
pQuery
->
colList
[
i
]
=
pQueryMsg
->
colList
[
i
];
pQuery
->
colList
[
i
].
filters
=
tscFilterInfoClone
(
pQueryMsg
->
colList
[
i
].
filters
,
pQuery
->
colList
[
i
].
numOfFilters
);
pQuery
->
colList
[
i
].
filters
=
tscFilterInfoClone
(
pQueryMsg
->
colList
[
i
].
filters
,
pQuery
->
colList
[
i
].
numOfFilters
);
srcSize
+=
pQuery
->
colList
[
i
].
bytes
;
}
}
// calculate the result row size
// calculate the result row size
...
@@ -6518,6 +6760,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
...
@@ -6518,6 +6760,14 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou
pQInfo
->
runtimeEnv
.
pResultRowHashTable
=
taosHashInit
(
pTableGroupInfo
->
numOfTables
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pQInfo
->
runtimeEnv
.
pResultRowHashTable
=
taosHashInit
(
pTableGroupInfo
->
numOfTables
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
pQInfo
->
runtimeEnv
.
keyBuf
=
malloc
(
TSDB_MAX_BYTES_PER_ROW
);
pQInfo
->
runtimeEnv
.
keyBuf
=
malloc
(
TSDB_MAX_BYTES_PER_ROW
);
pQInfo
->
runtimeEnv
.
pool
=
initResultRowPool
(
getWindowResultSize
(
&
pQInfo
->
runtimeEnv
));
pQInfo
->
runtimeEnv
.
pool
=
initResultRowPool
(
getWindowResultSize
(
&
pQInfo
->
runtimeEnv
));
pQInfo
->
runtimeEnv
.
prevRow
=
malloc
(
POINTER_BYTES
*
pQuery
->
numOfCols
+
srcSize
);
char
*
start
=
POINTER_BYTES
*
pQuery
->
numOfCols
+
(
char
*
)
pQInfo
->
runtimeEnv
.
prevRow
;
pQInfo
->
runtimeEnv
.
prevRow
[
0
]
=
start
;
for
(
int32_t
i
=
1
;
i
<
pQuery
->
numOfCols
;
++
i
)
{
pQInfo
->
runtimeEnv
.
prevRow
[
i
]
=
pQInfo
->
runtimeEnv
.
prevRow
[
i
-
1
]
+
pQuery
->
colList
[
i
-
1
].
bytes
;
}
pQInfo
->
pBuf
=
calloc
(
pTableGroupInfo
->
numOfTables
,
sizeof
(
STableQueryInfo
));
pQInfo
->
pBuf
=
calloc
(
pTableGroupInfo
->
numOfTables
,
sizeof
(
STableQueryInfo
));
if
(
pQInfo
->
pBuf
==
NULL
)
{
if
(
pQInfo
->
pBuf
==
NULL
)
{
...
...
src/query/src/qUtil.c
浏览文件 @
00ce6543
...
@@ -395,11 +395,10 @@ uint64_t getResultInfoUId(SQueryRuntimeEnv* pRuntimeEnv) {
...
@@ -395,11 +395,10 @@ uint64_t getResultInfoUId(SQueryRuntimeEnv* pRuntimeEnv) {
}
}
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
if
((
pQuery
->
checkBuffer
==
1
&&
pQuery
->
interval
.
interval
==
0
)
||
isPointInterpoQuery
(
pQuery
)
||
if
(
pQuery
->
interval
.
interval
==
0
||
isPointInterpoQuery
(
pQuery
)
||
pRuntimeEnv
->
groupbyNormalCol
)
{
pRuntimeEnv
->
groupbyNormalCol
)
{
return
0
;
return
0
;
}
}
STableId
*
id
=
TSDB_TABLEID
(
pRuntimeEnv
->
pQuery
->
current
);
STableId
*
id
=
TSDB_TABLEID
(
pRuntimeEnv
->
pQuery
->
current
->
pTable
);
return
id
->
uid
;
return
id
->
uid
;
}
}
\ No newline at end of file
tests/script/general/parser/col_arithmetic_operation.sim
浏览文件 @
00ce6543
...
@@ -117,16 +117,17 @@ run general/parser/col_arithmetic_query.sim
...
@@ -117,16 +117,17 @@ run general/parser/col_arithmetic_query.sim
# ================================================================================================
# ================================================================================================
print ====================> crash
print ====================> crash
# sql select spread(ts )/(1000*3600*24) from ca_stb0 interval(1y)
sql use $db
sql select spread(ts )/(1000*3600*24) from $stb interval(1y)
sql_error select first(c1, c2) - last(c1, c2) from stb interval(1y)
sql_error select first(ts) - last(ts) from stb interval(1y)
sql_error select first(c1, c2) - last(c1, c2) from $stb interval(1y)
sql_error select top(c1, 2) - last(c1) from stb;
sql_error select first(ts) - last(ts) from $stb interval(1y)
sql_error select stddev(c1) - last(c1) from stb;
sql_error select top(c1, 2) - last(c1) from $stb;
sql_error select diff(c1) - last(c1) from stb;
sql_error select stddev(c1) - last(c1) from $stb;
sql_error select first(c7) - last(c7) from stb;
sql_error select diff(c1) - last(c1) from $stb;
sql_error select first(c8) - last(c8) from stb;
sql_error select first(c7) - last(c7) from $stb;
sql_error select first(c9) - last(c9) from stb;
sql_error select first(c8) - last(c8) from $stb;
sql_error select first(c9) - last(c9) from $stb;
sql_error select max(c2*2) from $tb
sql_error select max(c2*2) from $tb
sql_error select max(c1-c2) from $tb
sql_error select max(c1-c2) from $tb
...
...
tests/script/general/parser/col_arithmetic_query.sim
浏览文件 @
00ce6543
...
@@ -62,21 +62,70 @@ if $data91 != 1.000000000 then
...
@@ -62,21 +62,70 @@ if $data91 != 1.000000000 then
return -1
return -1
endi
endi
sql select (c1 * 2) % 7.9 from $tb order by ts desc;
sql select (c1 * 2) % 7.9
, c1*1, c1*1*1, c1*c1, c1*c1*c1
from $tb order by ts desc;
if $rows != 10000 then
if $rows != 10000 then
return -1
return -1
endi
endi
if $data00 !=
0.1
00000000 then
if $data00 !=
2.2
00000000 then
print expect
0.100000000, acut
al:$data00
print expect
2.200000000, actu
al:$data00
return -1
return -1
endi
endi
if $data
10 != 2.1
00000000 then
if $data
01 != 9.0
00000000 then
return -1
return -1
endi
endi
if $data90 != 6.000000000 then
if $data02 != 9.000000000 then
return -1
endi
if $data03 != 81.000000000 then
return -1
endi
if $data04 != 729.000000000 then
return -1
endi
if $data10 != 0.200000000 then
return -1
endi
if $data11 != 8.000000000 then
return -1
endi
if $data12 != 8.000000000 then
return -1
endi
if $data13 != 64.000000000 then
return -1
endi
if $data14 != 512.000000000 then
return -1
endi
if $data90 != 0.000000000 then
return -1
endi
if $data91 != 0.000000000 then
return -1
endi
if $data92 != 0.000000000 then
return -1
endi
if $data93 != 0.000000000 then
return -1
endi
if $data94 != 0.000000000 then
return -1
return -1
endi
endi
...
@@ -95,7 +144,7 @@ if $data10 != 16.000000000 then
...
@@ -95,7 +144,7 @@ if $data10 != 16.000000000 then
endi
endi
if $data20 != 20.250000000 then
if $data20 != 20.250000000 then
print expect 20.250000000, ac
ut
al:$data21
print expect 20.250000000, ac
tu
al:$data21
return -1
return -1
endi
endi
...
@@ -320,7 +369,9 @@ sql_error select c7-c9 from $tb interval(2y)
...
@@ -320,7 +369,9 @@ sql_error select c7-c9 from $tb interval(2y)
# multiple retrieve [d.20]===============================================================
# multiple retrieve [d.20]===============================================================
sql select c2-c2, 911 from $tb
sql select c2-c2, 911 from $tb
#======================================= aggregation function arithmetic query cases ================
#======================================= aggregation function arithmetic query cases ===================================
# on $tb percentile() spread(ts) bug
# asc/desc order [d.2]
# asc/desc order [d.2]
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
sql select first(c1) * ( 2 / 3 ) from $stb order by ts asc;
if $rows != 1 then
if $rows != 1 then
...
@@ -349,11 +400,11 @@ if $data00 != 1.800000000 then
...
@@ -349,11 +400,11 @@ if $data00 != 1.800000000 then
return -1
return -1
endi
endi
if $data01 != 100000 then
if $data01 != 100000
.000000000
then
return -1
return -1
endi
endi
if $data02 != 200000 then
if $data02 != 200000
.000000000
then
return -1
return -1
endi
endi
...
@@ -374,77 +425,192 @@ if $data02 != 9.000000020 then
...
@@ -374,77 +425,192 @@ if $data02 != 9.000000020 then
return -1
return -1
endi
endi
# all possible function in the arithmetic expressioin
# all possible function in the arithmetic expression, add more
sql select min(c1) * max(c2) /4, sum(c1) * percentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2) from $stb where ts < and ts >
sql select min(c1) * max(c2) /4, sum(c1) * apercentile(c2, 20), apercentile(c4, 33) + 52/9, spread(c5)/min(c2), count(1)/sum(c1), avg(c2)*count(c2) from $stb where ts >= '2018-09-17 09:00:00.000' and ts <= '2018-11-25 19:30:00.000';
if $rows != 1 then
return -1
endi
# no result return [d.3]
if $data00 != 0.000000000 then
return -1
endi
if $data01 != 225000.000000000 then
return -1
endi
if $data02 != 8.077777778 then
return -1
endi
if $data03 != inf then
return -1
endi
if $data04 != 0.444444444 then
return -1
endi
if $data05 != 450000.000000000 then
return -1
endi
# no result return [d.3]===============================================================
sql select first(c1) * 91 - 7, last(c3) from $stb where ts < 1537146000000
sql select first(c1) * 91 - 7, last(c3) from $stb where ts < 1537146000000
if $rows != 0 then
if $rows != 0 then
return -1
return -1
endi
endi
# no result return [d.3]
# no result return [d.3]
sql select sum(c2) - avg(c2) from $
tb where ts>xxx
sql select sum(c2) - avg(c2) from $
stb where ts > '2018-11-25 19:30:00.000'
if $rows != 0 then
if $rows != 0 then
return -1
return -1
endi
endi
# single row result aggregation [d.4]
# single row result aggregation [d.4]
===================================================
sql select
# all those cases are aggregation test cases.
# error cases
# error cases
sql_error select first(c1, c2) - last(c1, c2) from $tb
sql_error select first(c1, c2) - last(c1, c2) from $stb
sql_error select top(c1, 5) - bottom(c1, 5) from $stb
sql_error select first(*) - 99 from $stb
# multi row result aggregation [d.4]
# multi row result aggregation [d.4]
sql select top(c1, 1) - bottom(c1, 1) from $tb
sql_error select top(c1, 1) - bottom(c1, 1) from $stb
sql select top(c1, 99) - bottom(c1, 99) from $tb
sql_error select top(c1, 99) - bottom(c1, 99) from $stb
# query on super table [d.5]=============================================================
# all cases in this part are query on super table
# all data types [d.6]
# all data types [d.6]
===================================================================
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $tb
sql select c2-c1, c3/c2, c4*c3, c5%c4, c6+99%22 from $
s
tb
# error case, ts/bool/binary/nchar not support arithmetic expression
# error case, ts/bool/binary/nchar not support arithmetic expression
sql_error select ts+ts from $tb
sql_error select first(c7)*12 from $stb
sql_error select ts+22 from $tb
sql_error select last(c8)/55 from $stb
sql_error select c7*12 from $tb
sql_error select last_row(c9) + last_row(c8) from $stb
sql_error select c8/55 from $tb
sql_error select c9+c8 from $tb
# arithmetic expression in join [d.7]
# arithmetic expression in join [d.7]
===============================================================
# arithmetic expression in union [d.8]
# arithmetic expression in union [d.8]
===============================================================
# arithmetic expression in group by [d.9]
# arithmetic expression in group by [d.9]
===============================================================
# in group by tag
# in group by tag
# not support for normal table
sql select avg(c4)*99 from $stb group by t1
sql_error select c5*99 from $tb group by t1
if $rows != 10 then
return -1
endi
if $data00 != 445.500000000 then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data90 != 445.500000000 then
return -1
endi
if $data91 != 9 then
return -1
endi
# in group by column
# in group by column
sql_error select c6-c6+c3*12 from $tb group by c3;
sql select apercentile(c6, 50)-first(c6)+last(c5)*12, last(c5)*12 from ca_stb0 group by c2;
if $rows != 10 then
return -1
endi
if $data00 != 0.000000000 then
return -1
endi
sql select first(c6) - last(c6) *12 / count(*) from $tb group by c3;
if $data01 != 0.000000000 then
return -1
endi
# limit offset [d.10]
if $data10 != 12.000000000 then
sql select c6-c6+12 from $tb limit 12 offset 99;
return -1
sql select c4/99.123 from $tb limit 1 offset 9999;
endi
# slimit/soffset not suport for normal table query. [d.11]
if $data11 != 12.000000000 then
sql_error select sum(c1) from $tb slimit 1 soffset 19;
return -1
endi
if $data20 != 24.000000000 then
return -1
endi
if $data21 != 24.000000000 then
return -1
endi
sql_error select first(c6) - last(c6) *12 / count(*) from $stb group by c3;
sql select first(c6) - last(c6) *12 / count(*) from $stb group by c5;
if $rows != 10 then
return -1
endi
if $data00 != 0.000000000 then
return -1
endi
if $data10 != 0.997600000 then
return -1
endi
if $data90 != 8.978400000 then
return -1
endi
# limit offset [d.10]===============================================================
sql select first(c6) - sum(c6) + 12 from $stb limit 12 offset 0;
if $rows != 1 then
return -1
endi
if $data00 != -449988.000000000 then
return -1
endi
sql select apercentile(c4, 21) / 99.123 from $stb limit 1 offset 1;
if $rows != 0 then
return -1
endi
sql select apercentile(c4, 21) / sum(c4) from $stb interval(1s) limit 1 offset 1;
if $rows != 1 then
return -1
endi
# slimit/soffset not support for normal table query. [d.11]===============================================================
sql select sum(c1) from $stb slimit 1 soffset 19;
if $rows != 0 then
return -1
endi
# fill [d.12]
sql select sum(c1) from $stb interval(1s) group by tbname slimit 1 soffset 1
sql
_error select c2-c2, c3-c4, c5%c6 from $tb fill(value, 12);
sql
select sum(c1) from ca_stb0 interval(1s) group by tbname slimit 2 soffset 4 limit 10 offset 1
# constant column. [d.13]
# fill [d.12]===============================================================
sql_error select first(c1)-last(c1), sum(c3)*count(c3), spread(c5 ) % count(*) from $stb interval(1s) fill(prev);
sql_error select first(c1) from $stb fill(value, 20);
# constant column. [d.13]===============================================================
# column value filter [d.14]
# column value filter [d.14]===============================================================
# tag filter(not support for normal table). [d.15]
sql_error select sum(c2)+99 from $tb where t1=12;
# multi-field output [d.16]
# tag filter. [d.15]===============================================================
sql select sum(c2)+99 from $stb where t1=12;
# multi-field output [d.16]===============================================================
sql select count(*), sum(c1)*avg(c2), avg(c3)*count(c3), sum(c3), sum(c4), first(c7), last(c8), first(c9), first(c7), last(c8) from $tb
sql select count(*), sum(c1)*avg(c2), avg(c3)*count(c3), sum(c3), sum(c4), first(c7), last(c8), first(c9), first(c7), last(c8) from $tb
sql select c4*1+1/2 from $tb
sql select c4*1+1/2 from $tb
...
@@ -461,18 +627,30 @@ if $data90 != 9.500000000 then
...
@@ -461,18 +627,30 @@ if $data90 != 9.500000000 then
return -1
return -1
endi
endi
# interval query [d.17]
# interval query [d.17]===============================================================
sql_error select c2*c2, c3-c3, c4+9 from $tb interval(1s)
sql select avg(c2)*count(c2), sum(c3)-first(c3), last(c4)+9 from $stb interval(1s)
sql_error select c7-c9 from $tb interval(2y)
if $rows != 10000 then
return -1
endi
# aggregation query [d.18]
if $data00 != @18-09-17 09:00:00.000@ then
# see test cases below
return -1
endi
# first/last query [d.19]
sql_error select first(c7)- last(c1) from $tb interval(2y)
# see test cases below
# multiple retrieve [d.20]
# aggregation query [d.18]===============================================================
sql select c2-c2 from $tb;
# all cases in this part are aggregation query test.
# first/last query [d.19]===============================================================
# multiple retrieve [d.20]===============================================================
sql select c2-c2 from $tb
sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb
sql select first(c1)-last(c1), spread(c2), max(c3) - min(c3), avg(c4)*count(c4) from $tb
#====================================================super table query==================================================
tests/script/general/parser/limit1_tb.sim
浏览文件 @
00ce6543
...
@@ -703,13 +703,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
...
@@ -703,13 +703,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
if $rows != 1 then
if $rows != 1 then
return -1
return -1
endi
endi
if $data00 != 4.
499549955
then
if $data00 != 4.
500000000
then
return -1
return -1
endi
endi
if $data02 != 4.
499549955
then
if $data02 != 4.
500000000
then
return -1
return -1
endi
endi
if $data05 != 4.
499549955
then
if $data05 != 4.
500000000
then
return -1
return -1
endi
endi
...
@@ -717,10 +717,12 @@ sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from
...
@@ -717,10 +717,12 @@ sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from
if $rows != 0 then
if $rows != 0 then
return -1
return -1
endi
endi
sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
if $rows != 3 then
if $rows != 3 then
return -1
return -1
endi
endi
if $data01 != 3 then
if $data01 != 3 then
return -1
return -1
endi
endi
...
@@ -731,7 +733,6 @@ if $data23 != 9.00000 then
...
@@ -731,7 +733,6 @@ if $data23 != 9.00000 then
return -1
return -1
endi
endi
sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
if $rows != 0 then
return -1
return -1
...
...
tests/script/general/parser/limit_tb.sim
浏览文件 @
00ce6543
...
@@ -327,22 +327,22 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
...
@@ -327,22 +327,22 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
if $rows != 1 then
if $rows != 1 then
return -1
return -1
endi
endi
if $data00 != 4.
0
00000000 then
if $data00 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data01 != 4.
0
00000000 then
if $data01 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data02 != 4.
0
00000000 then
if $data02 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data03 != 4.
0
00000000 then
if $data03 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data04 != 4.
0
00000000 then
if $data04 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data05 != 4.
0
00000000 then
if $data05 != 4.
5
00000000 then
return -1
return -1
endi
endi
...
@@ -690,13 +690,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
...
@@ -690,13 +690,13 @@ sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where t
if $rows != 1 then
if $rows != 1 then
return -1
return -1
endi
endi
if $data00 != 4.
0
00000000 then
if $data00 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data02 != 4.
0
00000000 then
if $data02 != 4.
5
00000000 then
return -1
return -1
endi
endi
if $data05 != 4.
0
00000000 then
if $data05 != 4.
5
00000000 then
return -1
return -1
endi
endi
...
...
tests/script/general/parser/where.sim
浏览文件 @
00ce6543
...
@@ -131,7 +131,6 @@ if $data00 != $rowNum then
...
@@ -131,7 +131,6 @@ if $data00 != $rowNum then
return -1
return -1
endi
endi
## like
## like
sql_error select * from $mt where c1 like 1
sql_error select * from $mt where c1 like 1
#sql_error select * from $mt where t1 like 1
#sql_error select * from $mt where t1 like 1
...
@@ -179,6 +178,7 @@ sql create table wh_mt2_tb1 using wh_mt2 tags ('wh_mt2_tb1')
...
@@ -179,6 +178,7 @@ sql create table wh_mt2_tb1 using wh_mt2 tags ('wh_mt2_tb1')
# 2019-01-01 09:10:00.000 1546305000000
# 2019-01-01 09:10:00.000 1546305000000
sql insert into wh_mt2_tb1 values ('2019-01-01 00:00:00.000', '2019-01-01 09:00:00.000', 'binary10', 'nchar10')
sql insert into wh_mt2_tb1 values ('2019-01-01 00:00:00.000', '2019-01-01 09:00:00.000', 'binary10', 'nchar10')
sql insert into wh_mt2_tb1 values ('2019-01-01 00:10:00.000', '2019-01-01 09:10:00.000', 'binary10', 'nchar10')
sql insert into wh_mt2_tb1 values ('2019-01-01 00:10:00.000', '2019-01-01 09:10:00.000', 'binary10', 'nchar10')
sql select * from wh_mt2_tb1 where c1 > 1546304400000
sql select * from wh_mt2_tb1 where c1 > 1546304400000
if $rows != 1 then
if $rows != 1 then
return -1
return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录