Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
a838ce83
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看板
未验证
提交
a838ce83
编写于
3月 15, 2021
作者:
H
haojun Liao
提交者:
GitHub
3月 15, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5440 from taosdata/feature/qrefactor
[td-3294]fix bug found by regression test.
上级
ea053a2b
8ac63bb2
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
688 addition
and
786 deletion
+688
-786
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+1
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+176
-363
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-7
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+173
-170
src/query/inc/sql.y
src/query/inc/sql.y
+65
-65
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+31
-12
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+135
-87
src/query/src/sql.c
src/query/src/sql.c
+75
-78
tests/script/general/parser/sliding.sim
tests/script/general/parser/sliding.sim
+25
-3
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
a838ce83
...
...
@@ -1360,7 +1360,7 @@ int tsParseSql(SSqlObj *pSql, bool initial) {
}
}
}
else
{
SSqlInfo
SQLInfo
=
qS
QL
Parse
(
pSql
->
sqlstr
);
SSqlInfo
SQLInfo
=
qS
ql
Parse
(
pSql
->
sqlstr
);
ret
=
tscToSQLCmd
(
pSql
,
&
SQLInfo
);
if
(
ret
==
TSDB_CODE_TSC_INVALID_SQL
&&
pSql
->
parseRetry
==
0
&&
SQLInfo
.
type
==
TSDB_SQL_NULL
)
{
tscResetSqlCmd
(
pCmd
,
true
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
a838ce83
此差异已折叠。
点击以展开。
src/client/src/tscServer.c
浏览文件 @
a838ce83
...
...
@@ -1350,7 +1350,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
SSqlCmd
*
pCmd
=
&
(
pSql
->
cmd
);
int32_t
size
=
minMsgSize
()
+
sizeof
(
SCMCreateTableMsg
)
+
sizeof
(
SCreateTableMsg
);
SCreateTableS
QL
*
pCreateTableInfo
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTableInfo
=
pInfo
->
pCreateTableInfo
;
if
(
pCreateTableInfo
->
type
==
TSQL_CREATE_TABLE_FROM_STABLE
)
{
int32_t
numOfTables
=
(
int32_t
)
taosArrayGetSize
(
pInfo
->
pCreateTableInfo
->
childTableInfo
);
size
+=
numOfTables
*
(
sizeof
(
SCreateTableMsg
)
+
TSDB_MAX_TAGS_LEN
);
...
...
@@ -1359,7 +1359,7 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
}
if
(
pCreateTableInfo
->
pSelect
!=
NULL
)
{
size
+=
(
pCreateTableInfo
->
pSelect
->
s
electToken
.
n
+
1
);
size
+=
(
pCreateTableInfo
->
pSelect
->
s
qlstr
.
n
+
1
);
}
return
size
+
TSDB_EXTRA_PAYLOAD_SIZE
;
...
...
@@ -1417,7 +1417,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int32_t
code
=
tNameExtractFullName
(
&
pTableMetaInfo
->
name
,
pCreateMsg
->
tableName
);
assert
(
code
==
0
);
SCreateTableS
QL
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
SCreateTableS
ql
*
pCreateTable
=
pInfo
->
pCreateTableInfo
;
pCreateMsg
->
igExists
=
pCreateTable
->
existCheck
?
1
:
0
;
pCreateMsg
->
numOfColumns
=
htons
(
pCmd
->
numOfCols
);
...
...
@@ -1440,11 +1440,11 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pMsg
=
(
char
*
)
pSchema
;
if
(
type
==
TSQL_CREATE_STREAM
)
{
// check if it is a stream sql
SQueryS
QL
*
pQuerySql
=
pInfo
->
pCreateTableInfo
->
pSelect
;
SQueryS
qlNode
*
pQuerySql
=
pInfo
->
pCreateTableInfo
->
pSelect
;
strncpy
(
pMsg
,
pQuerySql
->
s
electToken
.
z
,
pQuerySql
->
selectToken
.
n
+
1
);
pCreateMsg
->
sqlLen
=
htons
(
pQuerySql
->
s
electToken
.
n
+
1
);
pMsg
+=
pQuerySql
->
s
electToken
.
n
+
1
;
strncpy
(
pMsg
,
pQuerySql
->
s
qlstr
.
z
,
pQuerySql
->
sqlstr
.
n
+
1
);
pCreateMsg
->
sqlLen
=
htons
(
pQuerySql
->
s
qlstr
.
n
+
1
);
pMsg
+=
pQuerySql
->
s
qlstr
.
n
+
1
;
}
}
...
...
src/query/inc/qSqlparser.h
浏览文件 @
a838ce83
...
...
@@ -27,6 +27,18 @@ extern "C" {
#include "tvariant.h"
#define ParseTOKENTYPE SStrToken
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
enum
SQL_NODE_TYPE
{
SQL_NODE_TABLE_COLUMN
=
1
,
SQL_NODE_SQLFUNCTION
=
2
,
SQL_NODE_VALUE
=
3
,
SQL_NODE_EXPR
=
4
,
};
extern
char
tTokenTypeSwitcher
[
13
];
#define toTSDBType(x) \
...
...
@@ -38,144 +50,147 @@ extern char tTokenTypeSwitcher[13];
} \
} while (0)
#define TPARSER_HAS_TOKEN(_t) ((_t).n > 0)
#define TPARSER_SET_NONE_TOKEN(_t) ((_t).n = 0)
typedef
struct
SLimitVal
{
int64_t
limit
;
int64_t
offset
;
int64_t
limit
;
int64_t
offset
;
}
SLimitVal
;
typedef
struct
SOrderVal
{
uint32_t
order
;
int32_t
orderColId
;
uint32_t
order
;
int32_t
orderColId
;
}
SOrderVal
;
typedef
struct
tVariantListItem
{
tVariant
pVar
;
uint8_t
sortOrder
;
tVariant
pVar
;
uint8_t
sortOrder
;
}
tVariantListItem
;
typedef
struct
SIntervalVal
{
SStrToken
interval
;
SStrToken
offset
;
SStrToken
interval
;
SStrToken
offset
;
}
SIntervalVal
;
typedef
struct
SSessionWindowVal
{
SStrToken
col
;
SStrToken
gap
;
SStrToken
col
;
SStrToken
gap
;
}
SSessionWindowVal
;
typedef
struct
SQueryS
QL
{
struct
tSQLExprList
*
pSelection
;
// select clause
SArray
*
from
;
// from clause SArray<tVariantListItem
>
struct
tS
QLExpr
*
pWhere
;
// where clause [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
S
IntervalVal
interval
;
// (interval, interval_offset) [optional]
S
SessionWindowVal
sessionVal
;
// session window
[optional]
SS
trToken
sliding
;
// sliding
window [optional]
S
LimitVal
limit
;
// limit offset
[optional]
SLimitVal
slimit
;
// group
limit offset [optional]
S
Array
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
SStrToken
selectToken
;
// sql string
}
SQueryS
QL
;
typedef
struct
SQueryS
qlNode
{
struct
SArray
*
pSelectList
;
// select clause
SArray
*
from
;
// from clause SArray<SQuerySqlNode
>
struct
tS
qlExpr
*
pWhere
;
// where clause [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
S
Array
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
S
IntervalVal
interval
;
// (interval, interval_offset)
[optional]
SS
essionWindowVal
sessionVal
;
// session
window [optional]
S
StrToken
sliding
;
// sliding window
[optional]
SLimitVal
limit
;
//
limit offset [optional]
S
LimitVal
slimit
;
// group limit offset [optional]
SStrToken
sqlstr
;
// sql string in select clause
}
SQueryS
qlNode
;
typedef
struct
SCreatedTableInfo
{
SStrToken
name
;
// table name token
SStrToken
stableName
;
// super table name token , for using clause
SArray
*
pTagNames
;
// create by using super table, tag name
SArray
*
pTagVals
;
// create by using super table, tag value
char
*
fullname
;
// table full name
STagData
tagdata
;
// true tag data, super table full name is in STagData
int8_t
igExist
;
// ignore if exists
SStrToken
name
;
// table name token
SStrToken
stableName
;
// super table name token , for using clause
SArray
*
pTagNames
;
// create by using super table, tag name
SArray
*
pTagVals
;
// create by using super table, tag value
char
*
fullname
;
// table full name
STagData
tagdata
;
// true tag data, super table full name is in STagData
int8_t
igExist
;
// ignore if exists
}
SCreatedTableInfo
;
typedef
struct
SCreateTableS
QL
{
SStrToken
name
;
// table name, create table [name] xxx
int8_t
type
;
// create normal table/from super table/ stream
bool
existCheck
;
typedef
struct
SCreateTableS
ql
{
SStrToken
name
;
// table name, create table [name] xxx
int8_t
type
;
// create normal table/from super table/ stream
bool
existCheck
;
struct
{
SArray
*
pTagColumns
;
// SArray<TAOS_FIELD>
SArray
*
pColumns
;
// SArray<TAOS_FIELD>
SArray
*
pTagColumns
;
// SArray<TAOS_FIELD>
SArray
*
pColumns
;
// SArray<TAOS_FIELD>
}
colInfo
;
SArray
*
childTableInfo
;
// SArray<SCreatedTableInfo>
SQueryS
QL
*
pSelect
;
}
SCreateTableS
QL
;
SArray
*
childTableInfo
;
// SArray<SCreatedTableInfo>
SQueryS
qlNode
*
pSelect
;
}
SCreateTableS
ql
;
typedef
struct
SAlterTableInfo
{
SStrToken
name
;
int16_t
tableType
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
SStrToken
name
;
int16_t
tableType
;
int16_t
type
;
STagData
tagData
;
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
}
SAlterTableInfo
;
typedef
struct
SCreateDbInfo
{
SStrToken
dbname
;
int32_t
replica
;
int32_t
cacheBlockSize
;
int32_t
maxTablesPerVnode
;
int32_t
numOfBlocks
;
int32_t
daysPerFile
;
int32_t
minRowsPerBlock
;
int32_t
maxRowsPerBlock
;
int32_t
fsyncPeriod
;
int64_t
commitTime
;
int32_t
walLevel
;
int32_t
quorum
;
int32_t
compressionLevel
;
SStrToken
precision
;
bool
ignoreExists
;
int8_t
update
;
int8_t
cachelast
;
SArray
*
keep
;
int8_t
dbType
;
int16_t
partitions
;
SStrToken
dbname
;
int32_t
replica
;
int32_t
cacheBlockSize
;
int32_t
maxTablesPerVnode
;
int32_t
numOfBlocks
;
int32_t
daysPerFile
;
int32_t
minRowsPerBlock
;
int32_t
maxRowsPerBlock
;
int32_t
fsyncPeriod
;
int64_t
commitTime
;
int32_t
walLevel
;
int32_t
quorum
;
int32_t
compressionLevel
;
SStrToken
precision
;
bool
ignoreExists
;
int8_t
update
;
int8_t
cachelast
;
SArray
*
keep
;
int8_t
dbType
;
int16_t
partitions
;
}
SCreateDbInfo
;
typedef
struct
SCreateAcctInfo
{
int32_t
maxUsers
;
int32_t
maxDbs
;
int32_t
maxTimeSeries
;
int32_t
maxStreams
;
int32_t
maxPointsPerSecond
;
int64_t
maxStorage
;
int64_t
maxQueryTime
;
int32_t
maxConnections
;
SStrToken
stat
;
int32_t
maxUsers
;
int32_t
maxDbs
;
int32_t
maxTimeSeries
;
int32_t
maxStreams
;
int32_t
maxPointsPerSecond
;
int64_t
maxStorage
;
int64_t
maxQueryTime
;
int32_t
maxConnections
;
SStrToken
stat
;
}
SCreateAcctInfo
;
typedef
struct
SShowInfo
{
uint8_t
showType
;
SStrToken
prefix
;
SStrToken
pattern
;
uint8_t
showType
;
SStrToken
prefix
;
SStrToken
pattern
;
}
SShowInfo
;
typedef
struct
SUserInfo
{
SStrToken
user
;
SStrToken
passwd
;
SStrToken
privilege
;
int16_t
type
;
SStrToken
user
;
SStrToken
passwd
;
SStrToken
privilege
;
int16_t
type
;
}
SUserInfo
;
typedef
struct
SMiscInfo
{
SArray
*
a
;
// SArray<SStrToken>
bool
existsCheck
;
int16_t
dbType
;
int16_t
tableType
;
SUserInfo
user
;
SArray
*
a
;
// SArray<SStrToken>
bool
existsCheck
;
int16_t
dbType
;
int16_t
tableType
;
SUserInfo
user
;
union
{
SCreateDbInfo
dbOpt
;
SCreateAcctInfo
acctOpt
;
SShowInfo
showOpt
;
SStrToken
id
;
SCreateDbInfo
dbOpt
;
SCreateAcctInfo
acctOpt
;
SShowInfo
showOpt
;
SStrToken
id
;
};
}
SMiscInfo
;
typedef
struct
SSubclauseInfo
{
// "UNION" multiple select sub-clause
SQueryS
QL
**
pClause
;
int32_t
numOfClause
;
SQueryS
qlNode
**
pClause
;
int32_t
numOfClause
;
}
SSubclauseInfo
;
typedef
struct
SSqlInfo
{
...
...
@@ -184,99 +199,67 @@ typedef struct SSqlInfo {
SSubclauseInfo
subclauseInfo
;
char
msg
[
256
];
union
{
SCreateTableS
QL
*
pCreateTableInfo
;
SAlterTableInfo
*
pAlterInfo
;
SMiscInfo
*
pMiscInfo
;
SCreateTableS
ql
*
pCreateTableInfo
;
SAlterTableInfo
*
pAlterInfo
;
SMiscInfo
*
pMiscInfo
;
};
}
SSqlInfo
;
#define NON_ARITHMEIC_EXPR 0
#define NORMAL_ARITHMETIC 1
#define AGG_ARIGHTMEIC 2
enum
SQL_NODE_TYPE
{
SQL_NODE_TABLE_COLUMN
=
1
,
SQL_NODE_SQLFUNCTION
=
2
,
SQL_NODE_VALUE
=
3
,
SQL_NODE_EXPR
=
4
,
};
typedef
struct
tSQLExpr
{
uint16_t
type
;
// sql node type
uint32_t
tokenId
;
// TK_FUNCTION: sql function, TK_LE: less than(binary expr)
typedef
struct
tSqlExpr
{
uint16_t
type
;
// sql node type
uint32_t
tokenId
;
// TK_LE: less than(binary expr)
// the whole string of the function(col, param), while the function name is kept in token
SStrToken
operand
;
uint32_t
functionId
;
// function id
SStrToken
operand
;
uint32_t
functionId
;
// function id
SStrToken
colInfo
;
// table column info
tVariant
value
;
// the use input value
SStrToken
token
;
// original sql expr string
SStrToken
colInfo
;
// table column info
tVariant
value
;
// the use input value
SStrToken
token
;
// original sql expr string
struct
tS
QLExpr
*
pLeft
;
// left child
struct
tS
QLExpr
*
pRight
;
// right child
struct
tSQLExprList
*
pParam
;
// function parameters list
}
tS
QL
Expr
;
struct
tS
qlExpr
*
pLeft
;
// left child
struct
tS
qlExpr
*
pRight
;
// right child
struct
SArray
*
pParam
;
// function parameters list
}
tS
ql
Expr
;
// used in select clause. select <
tSQLExprList
> from xxx
// used in select clause. select <
SArray
> from xxx
typedef
struct
tSqlExprItem
{
tS
QLExpr
*
pNode
;
// The list of expressions
char
*
aliasName
;
// alias name, null-terminated string
bool
distinct
;
tS
qlExpr
*
pNode
;
// The list of expressions
char
*
aliasName
;
// alias name, null-terminated string
bool
distinct
;
}
tSqlExprItem
;
// todo refactor by using SArray
typedef
struct
tSQLExprList
{
int32_t
nExpr
;
/* Number of expressions on the list */
int32_t
nAlloc
;
/* Number of entries allocated below */
tSqlExprItem
*
a
;
/* One entry for each expression */
}
tSQLExprList
;
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void
Parse
(
void
*
yyp
,
int
yymajor
,
ParseTOKENTYPE
yyminor
,
SSqlInfo
*
);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void
ParseFree
(
void
*
p
,
void
(
*
freeProc
)(
void
*
));
SArray
*
tVariantListAppend
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
tSQLExpr
*
tSqlExprCreate
(
tSQLExpr
*
pLeft
,
tSQLExpr
*
pRight
,
int32_t
optrType
);
// sql expr leaf node
tSqlExpr
*
tSqlExprCreateIdValue
(
SStrToken
*
pToken
,
int32_t
optrType
);
tSqlExpr
*
tSqlExprCreateFunction
(
SArray
*
pParam
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
);
tSQLExpr
*
tSqlExprClone
(
tSQLExpr
*
pSrc
);
tSqlExpr
*
tSqlExprCreate
(
tSqlExpr
*
pLeft
,
tSqlExpr
*
pRight
,
int32_t
optrType
);
tSqlExpr
*
tSqlExprClone
(
tSqlExpr
*
pSrc
);
void
tSqlExprCompact
(
tSqlExpr
**
pExpr
);
bool
tSqlExprIsLeaf
(
tSqlExpr
*
pExpr
);
bool
tSqlExprIsParentOfLeaf
(
tSqlExpr
*
pExpr
);
void
tSqlExprDestroy
(
tSqlExpr
*
pExpr
);
SArray
*
tSqlExprListAppend
(
SArray
*
pList
,
tSqlExpr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
);
void
tSqlExprListDestroy
(
SArray
*
pList
);
void
tSqlExprDestroy
(
tSQLExpr
*
pExpr
);
SQuerySqlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SArray
*
pFrom
,
tSqlExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
ps
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pgLimit
);
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
);
SCreateTableSql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
);
void
tSqlExprListDestroy
(
tSQLExprList
*
pList
);
SQuerySQL
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQLExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
SCreateTableSQL
*
tSetCreateSqlElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySQL
*
pSelect
,
int32_t
type
);
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
);
SAlterTableInfo
*
tAlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SAlterTableInfo
*
tSetAlterTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableTable
);
SCreatedTableInfo
createNewChildTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pTagNames
,
SArray
*
pTagVals
,
SStrToken
*
pToken
,
SStrToken
*
igExists
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
void
d
oDestroyQuerySql
(
SQuerySQL
*
pSql
);
void
d
estroyQuerySqlNode
(
SQuerySqlNode
*
pSql
);
void
freeCreateTableInfo
(
void
*
p
);
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
);
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
);
SSubclauseInfo
*
setSubclause
(
SSubclauseInfo
*
pClause
,
void
*
pSqlExprInfo
);
SSubclauseInfo
*
appendSelectClause
(
SSubclauseInfo
*
pInfo
,
void
*
pSubclause
);
...
...
@@ -285,7 +268,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
void
SqlInfoDestroy
(
SSqlInfo
*
pInfo
);
void
setDCLS
QL
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParams
,
...);
void
setDCLS
ql
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParams
,
...);
void
setDropDbTableInfo
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
pToken
,
SStrToken
*
existsCheck
,
int16_t
dbType
,
int16_t
tableType
);
void
setShowOptions
(
SSqlInfo
*
pInfo
,
int32_t
type
,
SStrToken
*
prefix
,
SStrToken
*
pPatterns
);
...
...
@@ -300,19 +283,39 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo);
void
setDefaultCreateTopicOption
(
SCreateDbInfo
*
pDBInfo
);
// prefix show db.tables;
void
s
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
);
void
tS
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
);
tSQLExpr
*
tSqlExprIdValueCreate
(
SStrToken
*
pToken
,
int32_t
optrType
);
void
tSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
);
void
tSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
);
tSQLExpr
*
tSqlExprCreateFunction
(
tSQLExprList
*
pList
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
);
void
tSqlSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
);
/**
*
* @param yyp The parser
* @param yymajor The major token code number
* @param yyminor The value for the token
*/
void
Parse
(
void
*
yyp
,
int
yymajor
,
ParseTOKENTYPE
yyminor
,
SSqlInfo
*
);
void
tSqlSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
);
/**
*
* @param p The parser to be deleted
* @param freeProc Function used to reclaim memory
*/
void
ParseFree
(
void
*
p
,
void
(
*
freeProc
)(
void
*
));
/**
*
* @param mallocProc The parser allocator
* @return
*/
void
*
ParseAlloc
(
void
*
(
*
mallocProc
)(
size_t
));
SSqlInfo
qSQLParse
(
const
char
*
str
);
/**
*
* @param str sql string
* @return sql ast
*/
SSqlInfo
qSqlParse
(
const
char
*
str
);
#ifdef __cplusplus
}
...
...
src/query/inc/sql.y
浏览文件 @
a838ce83
无法预览此类型文件
src/query/src/qExecutor.c
浏览文件 @
a838ce83
...
...
@@ -476,22 +476,41 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes
return
getResultRow
(
pResultRowInfo
,
pResultRowInfo
->
curIndex
);
}
static
void
getInitialStartTimeWindow
(
SQuery
*
pQuery
,
TSKEY
ts
,
STimeWindow
*
w
)
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
getAlignQueryTimeWindow
(
pQuery
,
ts
,
ts
,
pQuery
->
window
.
ekey
,
w
);
}
else
{
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
getAlignQueryTimeWindow
(
pQuery
,
ts
,
pQuery
->
window
.
ekey
,
ts
,
w
);
int64_t
key
=
w
->
skey
;
while
(
key
<
ts
)
{
// moving towards end
if
(
pQuery
->
interval
.
intervalUnit
==
'n'
||
pQuery
->
interval
.
intervalUnit
==
'y'
)
{
key
=
taosTimeAdd
(
key
,
pQuery
->
interval
.
sliding
,
pQuery
->
interval
.
slidingUnit
,
pQuery
->
precision
);
}
else
{
key
+=
pQuery
->
interval
.
sliding
;
}
if
(
key
>=
ts
)
{
break
;
}
w
->
skey
=
key
;
}
}
}
// get the correct time window according to the handled timestamp
static
STimeWindow
getActiveTimeWindow
(
SResultRowInfo
*
pResultRowInfo
,
int64_t
ts
,
SQuery
*
pQuery
)
{
STimeWindow
w
=
{
0
};
if
(
pResultRowInfo
->
curIndex
==
-
1
)
{
// the first window, from the previous stored value
if
(
pResultRowInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
getAlignQueryTimeWindow
(
pQuery
,
ts
,
ts
,
pQuery
->
window
.
ekey
,
&
w
);
}
else
{
// the start position of the first time window in the endpoint that spreads beyond the queried last timestamp
getAlignQueryTimeWindow
(
pQuery
,
ts
,
pQuery
->
window
.
ekey
,
ts
,
&
w
);
}
pResultRowInfo
->
prevSKey
=
w
.
skey
;
}
else
{
w
.
skey
=
pResultRowInfo
->
prevSKey
;
}
if
(
pResultRowInfo
->
prevSKey
==
TSKEY_INITIAL_VAL
)
{
getInitialStartTimeWindow
(
pQuery
,
ts
,
&
w
);
pResultRowInfo
->
prevSKey
=
w
.
skey
;
}
else
{
w
.
skey
=
pResultRowInfo
->
prevSKey
;
}
if
(
pQuery
->
interval
.
intervalUnit
==
'n'
||
pQuery
->
interval
.
intervalUnit
==
'y'
)
{
w
.
ekey
=
taosTimeAdd
(
w
.
skey
,
pQuery
->
interval
.
interval
,
pQuery
->
interval
.
intervalUnit
,
pQuery
->
precision
)
-
1
;
...
...
@@ -4564,7 +4583,7 @@ static SSDataBlock* doOffset(void* param) {
if
(
pRuntimeEnv
->
currentOffset
==
0
)
{
return
pBlock
;
}
else
if
(
pRuntimeEnv
->
currentOffset
>
pBlock
->
info
.
rows
)
{
}
else
if
(
pRuntimeEnv
->
currentOffset
>
=
pBlock
->
info
.
rows
)
{
pRuntimeEnv
->
currentOffset
-=
pBlock
->
info
.
rows
;
}
else
{
int32_t
remain
=
(
int32_t
)(
pBlock
->
info
.
rows
-
pRuntimeEnv
->
currentOffset
);
...
...
src/query/src/q
ParserImpl
.c
→
src/query/src/q
SqlParser
.c
浏览文件 @
a838ce83
...
...
@@ -23,7 +23,7 @@
#include "ttokendef.h"
#include "tutil.h"
SSqlInfo
qS
QL
Parse
(
const
char
*
pStr
)
{
SSqlInfo
qS
ql
Parse
(
const
char
*
pStr
)
{
void
*
pParser
=
ParseAlloc
(
malloc
);
SSqlInfo
sqlInfo
=
{
0
};
...
...
@@ -80,53 +80,48 @@ abort_parse:
return
sqlInfo
;
}
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQL
Expr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
)
{
SArray
*
tSqlExprListAppend
(
SArray
*
pList
,
tSql
Expr
*
pNode
,
SStrToken
*
pDistinct
,
SStrToken
*
pToken
)
{
if
(
pList
==
NULL
)
{
pList
=
calloc
(
1
,
sizeof
(
tSQLExprList
));
pList
=
taosArrayInit
(
4
,
sizeof
(
tSqlExprItem
));
}
if
(
pList
->
nAlloc
<=
pList
->
nExpr
)
{
pList
->
nAlloc
=
(
pList
->
nAlloc
<<
1u
)
+
4
;
pList
->
a
=
realloc
(
pList
->
a
,
pList
->
nAlloc
*
sizeof
(
pList
->
a
[
0
]));
if
(
pList
->
a
==
0
)
{
pList
->
nExpr
=
pList
->
nAlloc
=
0
;
return
pList
;
}
}
assert
(
pList
->
a
!=
0
);
if
(
pNode
||
pToken
)
{
struct
tSqlExprItem
*
pItem
=
&
pList
->
a
[
pList
->
nExpr
++
];
memset
(
pItem
,
0
,
sizeof
(
*
pItem
));
pItem
->
pNode
=
pNode
;
struct
tSqlExprItem
item
=
{
0
};
item
.
pNode
=
pNode
;
item
.
distinct
=
(
pDistinct
!=
NULL
);
if
(
pToken
)
{
// set the as clause
pItem
->
aliasName
=
malloc
(
pToken
->
n
+
1
);
strncpy
(
pItem
->
aliasName
,
pToken
->
z
,
pToken
->
n
);
pItem
->
aliasName
[
pToken
->
n
]
=
0
;
item
.
aliasName
=
malloc
(
pToken
->
n
+
1
);
strncpy
(
item
.
aliasName
,
pToken
->
z
,
pToken
->
n
);
item
.
aliasName
[
pToken
->
n
]
=
0
;
strdequote
(
pItem
->
aliasName
);
strdequote
(
item
.
aliasName
);
}
pItem
->
distinct
=
(
pDistinct
!=
NULL
);
taosArrayPush
(
pList
,
&
item
);
}
return
pList
;
}
void
tSqlExprListDestroy
(
tSQLExprList
*
pList
)
{
if
(
pList
==
NULL
)
return
;
static
void
freeExprElem
(
void
*
item
)
{
tSqlExprItem
*
exprItem
=
item
;
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
if
(
pList
->
a
[
i
].
aliasName
!=
NULL
)
{
free
(
pList
->
a
[
i
].
aliasName
);
}
tSqlExprDestroy
(
pList
->
a
[
i
].
pNode
);
tfree
(
exprItem
->
aliasName
);
tSqlExprDestroy
(
exprItem
->
pNode
);
}
void
tSqlExprListDestroy
(
SArray
*
pList
)
{
if
(
pList
==
NULL
)
{
return
;
}
free
(
pList
->
a
);
free
(
pList
);
taosArrayDestroyEx
(
pList
,
freeExprElem
);
}
tS
QLExpr
*
tSqlExprIdValueCreat
e
(
SStrToken
*
pToken
,
int32_t
optrType
)
{
tS
QLExpr
*
pSqlExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
tSqlExprCreateIdValu
e
(
SStrToken
*
pToken
,
int32_t
optrType
)
{
tS
qlExpr
*
pSqlExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
if
(
pToken
!=
NULL
)
{
pSqlExpr
->
token
=
*
pToken
;
...
...
@@ -171,15 +166,15 @@ tSQLExpr *tSqlExprIdValueCreate(SStrToken *pToken, int32_t optrType) {
* pList is the parameters for function with id(optType)
* function name is denoted by pFunctionToken
*/
tS
QLExpr
*
tSqlExprCreateFunction
(
tSQLExprList
*
pList
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
)
{
tS
qlExpr
*
tSqlExprCreateFunction
(
SArray
*
pParam
,
SStrToken
*
pFuncToken
,
SStrToken
*
endToken
,
int32_t
optType
)
{
if
(
pFuncToken
==
NULL
)
{
return
NULL
;
}
tS
QLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pExpr
->
tokenId
=
optType
;
pExpr
->
type
=
SQL_NODE_SQLFUNCTION
;
pExpr
->
pParam
=
p
List
;
pExpr
->
pParam
=
p
Param
;
int32_t
len
=
(
int32_t
)((
endToken
->
z
+
endToken
->
n
)
-
pFuncToken
->
z
);
pExpr
->
operand
=
(
*
pFuncToken
);
...
...
@@ -193,14 +188,14 @@ tSQLExpr *tSqlExprCreateFunction(tSQLExprList *pList, SStrToken *pFuncToken, SSt
/*
* create binary expression in this procedure
* if the expr is arithmetic, calculate the result and set it to tS
QL
Expr Object
* if the expr is arithmetic, calculate the result and set it to tS
ql
Expr Object
*/
tS
QLExpr
*
tSqlExprCreate
(
tSQLExpr
*
pLeft
,
tSQL
Expr
*
pRight
,
int32_t
optrType
)
{
tS
QLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
tSqlExprCreate
(
tSqlExpr
*
pLeft
,
tSql
Expr
*
pRight
,
int32_t
optrType
)
{
tS
qlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pExpr
->
type
=
SQL_NODE_EXPR
;
if
(
pLeft
!=
NULL
&&
pRight
!=
NULL
&&
(
optrType
!=
TK_IN
))
{
char
*
endPos
=
pRight
->
token
.
z
+
pRight
->
token
.
n
;
char
*
endPos
=
pRight
->
token
.
z
+
pRight
->
token
.
n
;
pExpr
->
token
.
z
=
pLeft
->
token
.
z
;
pExpr
->
token
.
n
=
(
uint32_t
)(
endPos
-
pExpr
->
token
.
z
);
pExpr
->
token
.
type
=
pLeft
->
token
.
type
;
...
...
@@ -291,9 +286,9 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr
->
tokenId
=
optrType
;
pExpr
->
pLeft
=
pLeft
;
tS
QLExpr
*
pRSub
=
calloc
(
1
,
sizeof
(
tSQL
Expr
));
tS
qlExpr
*
pRSub
=
calloc
(
1
,
sizeof
(
tSql
Expr
));
pRSub
->
tokenId
=
TK_SET
;
// TODO refactor .....
pRSub
->
pParam
=
(
tSQLExprList
*
)
pRight
;
pRSub
->
pParam
=
(
SArray
*
)
pRight
;
pExpr
->
pRight
=
pRSub
;
}
else
{
...
...
@@ -301,7 +296,7 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
pExpr
->
pLeft
=
pLeft
;
if
(
pLeft
!=
NULL
&&
pRight
==
NULL
)
{
pRight
=
calloc
(
1
,
sizeof
(
tS
QL
Expr
));
pRight
=
calloc
(
1
,
sizeof
(
tS
ql
Expr
));
}
pExpr
->
pRight
=
pRight
;
...
...
@@ -310,10 +305,8 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType) {
return
pExpr
;
}
tSQLExpr
*
tSqlExprClone
(
tSQLExpr
*
pSrc
)
{
tSQLExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSQLExpr
));
tSqlExpr
*
tSqlExprClone
(
tSqlExpr
*
pSrc
)
{
tSqlExpr
*
pExpr
=
calloc
(
1
,
sizeof
(
tSqlExpr
));
memcpy
(
pExpr
,
pSrc
,
sizeof
(
*
pSrc
));
...
...
@@ -327,12 +320,51 @@ tSQLExpr *tSqlExprClone(tSQLExpr *pSrc) {
//we don't clone pParam now because clone is only used for between/and
assert
(
pSrc
->
pParam
==
NULL
);
return
pExpr
;
}
void
tSqlExprCompact
(
tSqlExpr
**
pExpr
)
{
if
(
*
pExpr
==
NULL
||
tSqlExprIsParentOfLeaf
(
*
pExpr
))
{
return
;
}
if
((
*
pExpr
)
->
pLeft
)
{
tSqlExprCompact
(
&
(
*
pExpr
)
->
pLeft
);
}
void
tSqlExprNodeDestroy
(
tSQLExpr
*
pExpr
)
{
if
((
*
pExpr
)
->
pRight
)
{
tSqlExprCompact
(
&
(
*
pExpr
)
->
pRight
);
}
if
((
*
pExpr
)
->
pLeft
==
NULL
&&
(
*
pExpr
)
->
pRight
==
NULL
&&
((
*
pExpr
)
->
tokenId
==
TK_OR
||
(
*
pExpr
)
->
tokenId
==
TK_AND
))
{
tSqlExprDestroy
(
*
pExpr
);
*
pExpr
=
NULL
;
}
else
if
((
*
pExpr
)
->
pLeft
==
NULL
&&
(
*
pExpr
)
->
pRight
!=
NULL
)
{
tSqlExpr
*
tmpPtr
=
(
*
pExpr
)
->
pRight
;
(
*
pExpr
)
->
pRight
=
NULL
;
tSqlExprDestroy
(
*
pExpr
);
(
*
pExpr
)
=
tmpPtr
;
}
else
if
((
*
pExpr
)
->
pRight
==
NULL
&&
(
*
pExpr
)
->
pLeft
!=
NULL
)
{
tSqlExpr
*
tmpPtr
=
(
*
pExpr
)
->
pLeft
;
(
*
pExpr
)
->
pLeft
=
NULL
;
tSqlExprDestroy
(
*
pExpr
);
(
*
pExpr
)
=
tmpPtr
;
}
}
bool
tSqlExprIsLeaf
(
tSqlExpr
*
pExpr
)
{
return
(
pExpr
->
pRight
==
NULL
&&
pExpr
->
pLeft
==
NULL
)
&&
(
pExpr
->
tokenId
==
0
||
pExpr
->
tokenId
==
TK_ID
||
(
pExpr
->
tokenId
>=
TK_BOOL
&&
pExpr
->
tokenId
<=
TK_NCHAR
)
||
pExpr
->
tokenId
==
TK_SET
);
}
bool
tSqlExprIsParentOfLeaf
(
tSqlExpr
*
pExpr
)
{
return
(
pExpr
->
pLeft
!=
NULL
&&
pExpr
->
pRight
!=
NULL
)
&&
(
tSqlExprIsLeaf
(
pExpr
->
pLeft
)
&&
tSqlExprIsLeaf
(
pExpr
->
pRight
));
}
static
void
doDestroySqlExprNode
(
tSqlExpr
*
pExpr
)
{
if
(
pExpr
==
NULL
)
{
return
;
}
...
...
@@ -342,11 +374,10 @@ void tSqlExprNodeDestroy(tSQLExpr *pExpr) {
}
tSqlExprListDestroy
(
pExpr
->
pParam
);
free
(
pExpr
);
}
void
tSqlExprDestroy
(
tS
QL
Expr
*
pExpr
)
{
void
tSqlExprDestroy
(
tS
ql
Expr
*
pExpr
)
{
if
(
pExpr
==
NULL
)
{
return
;
}
...
...
@@ -355,7 +386,8 @@ void tSqlExprDestroy(tSQLExpr *pExpr) {
pExpr
->
pLeft
=
NULL
;
tSqlExprDestroy
(
pExpr
->
pRight
);
pExpr
->
pRight
=
NULL
;
tSqlExprNodeDestroy
(
pExpr
);
doDestroySqlExprNode
(
pExpr
);
}
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pToken
,
uint8_t
order
)
{
...
...
@@ -411,13 +443,13 @@ SArray *tVariantListInsert(SArray *pList, tVariant *pVar, uint8_t sortOrder, int
return
pList
;
}
void
s
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
)
{
void
tS
etDbName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDb
)
{
pCpxName
->
type
=
pDb
->
type
;
pCpxName
->
z
=
pDb
->
z
;
pCpxName
->
n
=
pDb
->
n
;
}
void
tS
qlS
etColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
)
{
void
tSetColumnInfo
(
TAOS_FIELD
*
pField
,
SStrToken
*
pName
,
TAOS_FIELD
*
pType
)
{
int32_t
maxLen
=
sizeof
(
pField
->
name
)
/
sizeof
(
pField
->
name
[
0
]);
// truncate the column name
...
...
@@ -485,7 +517,7 @@ static int32_t tryParseNameTwoParts(SStrToken *type) {
}
}
void
tS
qlS
etColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
)
{
void
tSetColumnType
(
TAOS_FIELD
*
pField
,
SStrToken
*
type
)
{
// set the field type invalid
pField
->
type
=
-
1
;
pField
->
name
[
0
]
=
0
;
...
...
@@ -550,43 +582,59 @@ void tSqlSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/*
* extract the select info out of sql string
*/
SQueryS
QL
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQL
Expr
*
pWhere
,
SQueryS
qlNode
*
tSetQuerySqlNode
(
SStrToken
*
pSelectToken
,
SArray
*
pSelectList
,
SArray
*
pFrom
,
tSql
Expr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SSessionWindowVal
*
pSession
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
p
G
Limit
)
{
assert
(
pSelect
ion
!=
NULL
);
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
p
s
Limit
)
{
assert
(
pSelect
List
!=
NULL
);
SQuerySQL
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuerySQL
));
pQuery
->
selectToken
=
*
pSelectToken
;
pQuery
->
selectToken
.
n
=
(
uint32_t
)
strlen
(
pQuery
->
selectToken
.
z
);
// all later sql string are belonged to the stream sql
SQuerySqlNode
*
pSqlNode
=
calloc
(
1
,
sizeof
(
SQuerySqlNode
));
pQuery
->
pSelection
=
pSelection
;
pQuery
->
from
=
pFrom
;
pQuery
->
pGroupby
=
pGroupby
;
pQuery
->
pSortOrder
=
pSortOrder
;
pQuery
->
pWhere
=
pWhere
;
// all later sql string are belonged to the stream sql
pSqlNode
->
sqlstr
=
*
pSelectToken
;
pSqlNode
->
sqlstr
.
n
=
(
uint32_t
)
strlen
(
pSqlNode
->
sqlstr
.
z
);
pSqlNode
->
pSelectList
=
pSelectList
;
pSqlNode
->
from
=
pFrom
;
pSqlNode
->
pGroupby
=
pGroupby
;
pSqlNode
->
pSortOrder
=
pSortOrder
;
pSqlNode
->
pWhere
=
pWhere
;
pSqlNode
->
fillType
=
pFill
;
if
(
pLimit
!=
NULL
)
{
pQuery
->
limit
=
*
pLimit
;
pSqlNode
->
limit
=
*
pLimit
;
}
else
{
pSqlNode
->
limit
.
limit
=
-
1
;
pSqlNode
->
limit
.
offset
=
0
;
}
if
(
pGLimit
!=
NULL
)
{
pQuery
->
slimit
=
*
pGLimit
;
if
(
psLimit
!=
NULL
)
{
pSqlNode
->
slimit
=
*
psLimit
;
}
else
{
pSqlNode
->
slimit
.
limit
=
-
1
;
pSqlNode
->
slimit
.
offset
=
0
;
}
if
(
pInterval
!=
NULL
)
{
pQuery
->
interval
=
*
pInterval
;
pSqlNode
->
interval
=
*
pInterval
;
}
else
{
TPARSER_SET_NONE_TOKEN
(
pSqlNode
->
interval
.
interval
);
TPARSER_SET_NONE_TOKEN
(
pSqlNode
->
interval
.
offset
);
}
if
(
pSliding
!=
NULL
)
{
pQuery
->
sliding
=
*
pSliding
;
pSqlNode
->
sliding
=
*
pSliding
;
}
else
{
TPARSER_SET_NONE_TOKEN
(
pSqlNode
->
sliding
);
}
if
(
pSession
!=
NULL
)
{
pQuery
->
sessionVal
=
*
pSession
;
pSqlNode
->
sessionVal
=
*
pSession
;
}
else
{
TPARSER_SET_NONE_TOKEN
(
pSqlNode
->
sessionVal
.
gap
);
TPARSER_SET_NONE_TOKEN
(
pSqlNode
->
sessionVal
.
col
);
}
pQuery
->
fillType
=
pFill
;
return
pQuery
;
return
pSqlNode
;
}
static
void
freeVariant
(
void
*
pItem
)
{
...
...
@@ -602,14 +650,14 @@ void freeCreateTableInfo(void* p) {
tfree
(
pInfo
->
tagdata
.
data
);
}
void
d
oDestroyQuerySql
(
SQuerySQL
*
pQuerySql
)
{
void
d
estroyQuerySqlNode
(
SQuerySqlNode
*
pQuerySql
)
{
if
(
pQuerySql
==
NULL
)
{
return
;
}
tSqlExprListDestroy
(
pQuerySql
->
pSelect
ion
);
tSqlExprListDestroy
(
pQuerySql
->
pSelect
List
);
pQuerySql
->
pSelect
ion
=
NULL
;
pQuerySql
->
pSelect
List
=
NULL
;
tSqlExprDestroy
(
pQuerySql
->
pWhere
);
pQuerySql
->
pWhere
=
NULL
;
...
...
@@ -635,15 +683,15 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
}
for
(
int32_t
i
=
0
;
i
<
pClause
->
numOfClause
;
++
i
)
{
SQueryS
QL
*
pQuerySql
=
pClause
->
pClause
[
i
];
d
oDestroyQuerySql
(
pQuerySql
);
SQueryS
qlNode
*
pQuerySql
=
pClause
->
pClause
[
i
];
d
estroyQuerySqlNode
(
pQuerySql
);
}
tfree
(
pClause
->
pClause
);
}
SCreateTableS
QL
*
tSetCreateSqlElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySQL
*
pSelect
,
int32_t
type
)
{
SCreateTableS
QL
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateTableSQL
));
SCreateTableS
ql
*
tSetCreateTableInfo
(
SArray
*
pCols
,
SArray
*
pTags
,
SQuerySqlNode
*
pSelect
,
int32_t
type
)
{
SCreateTableS
ql
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateTableSql
));
switch
(
type
)
{
case
TSQL_CREATE_TABLE
:
{
...
...
@@ -687,7 +735,7 @@ SCreatedTableInfo createNewChildTableInfo(SStrToken *pTableName, SArray *pTagNam
return
info
;
}
SAlterTableInfo
*
t
AlterTableSqlElems
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableType
)
{
SAlterTableInfo
*
t
SetAlterTableInfo
(
SStrToken
*
pTableName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
,
int16_t
tableType
)
{
SAlterTableInfo
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableInfo
));
pAlterTable
->
name
=
*
pTableName
;
...
...
@@ -709,8 +757,8 @@ SAlterTableInfo *tAlterTableSqlElems(SStrToken *pTableName, SArray *pCols, SArra
return
pAlterTable
;
}
void
*
destroyCreateTableSql
(
SCreateTableS
QL
*
pCreate
)
{
d
oDestroyQuerySql
(
pCreate
->
pSelect
);
void
*
destroyCreateTableSql
(
SCreateTableS
ql
*
pCreate
)
{
d
estroyQuerySqlNode
(
pCreate
->
pSelect
);
taosArrayDestroy
(
pCreate
->
colInfo
.
pColumns
);
taosArrayDestroy
(
pCreate
->
colInfo
.
pTagColumns
);
...
...
@@ -757,7 +805,7 @@ SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
return
pSubclause
;
}
pSubclause
->
pClause
=
(
SQueryS
QL
**
)
tmp
;
pSubclause
->
pClause
=
(
SQueryS
qlNode
**
)
tmp
;
pSubclause
->
pClause
[
newSize
-
1
]
=
pSqlExprInfo
;
pSubclause
->
numOfClause
++
;
...
...
@@ -765,7 +813,7 @@ SSubclauseInfo* setSubclause(SSubclauseInfo* pSubclause, void *pSqlExprInfo) {
return
pSubclause
;
}
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
)
{
SSqlInfo
*
setSqlInfo
(
SSqlInfo
*
pInfo
,
void
*
pSqlExprInfo
,
SStrToken
*
pTableName
,
int32_t
type
)
{
pInfo
->
type
=
type
;
if
(
type
==
TSDB_SQL_SELECT
)
{
...
...
@@ -788,7 +836,7 @@ SSubclauseInfo* appendSelectClause(SSubclauseInfo *pQueryInfo, void *pSubclause)
return
pQueryInfo
;
}
pQueryInfo
->
pClause
=
(
SQueryS
QL
**
)
tmp
;
pQueryInfo
->
pClause
=
(
SQueryS
qlNode
**
)
tmp
;
pQueryInfo
->
pClause
[
pQueryInfo
->
numOfClause
++
]
=
pSubclause
;
return
pQueryInfo
;
...
...
@@ -799,7 +847,7 @@ void setCreatedTableName(SSqlInfo *pInfo, SStrToken *pTableNameToken, SStrToken
pInfo
->
pCreateTableInfo
->
existCheck
=
(
pIfNotExists
->
n
!=
0
);
}
void
setDCLS
QL
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParam
,
...)
{
void
setDCLS
ql
Elems
(
SSqlInfo
*
pInfo
,
int32_t
type
,
int32_t
nParam
,
...)
{
pInfo
->
type
=
type
;
if
(
nParam
==
0
)
{
return
;
...
...
src/query/src/sql.c
浏览文件 @
a838ce83
此差异已折叠。
点击以展开。
tests/script/general/parser/sliding.sim
浏览文件 @
a838ce83
...
...
@@ -469,11 +469,12 @@ if $data25 != 33 then
endi
sql select count(*),stddev(c1),count(c1),first(c2),last(c3) from sliding_tb0 where ts>'2000-1-1 00:00:00' and ts<'2000-1-1 00:00:01.002' and c2 >= 0 interval(30s) sliding(10s) order by ts desc limit 1000;
if $row !=
1
then
if $row !=
3
then
return -1
endi
if $data00 != @99-12-31 23:59:40.000@ then
if $data00 != @00-01-01 00:00:00.000@ then
print expect 00-01-01 00:00:00.000, actual: $data00
return -1
endi
...
...
@@ -489,7 +490,28 @@ if $data03 != 33 then
return -1
endi
print check boundary check crash at client side
if $data10 != @99-12-31 23:59:50.000@ then
return -1
endi
if $data11 != 33 then
return -1
endi
if $data12 != 9.521904571 then
return -1
endi
if $data20 != @99-12-31 23:59:40.000@ then
return -1
endi
if $data21 != 33 then
return -1
endi
if $data22 != 9.521904571 then
return -1
endi
print ====================>check boundary check crash at client side
sql select count(*) from sliding_mt0 where ts>now and ts < now-1h;
print ========================query on super table
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录